using Oqtane.Shared; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text.Json; using System.Text.Json.Serialization; namespace Oqtane.Models { /// /// Describes a Module _Instance_ which will be shown on a page. This is different from a which describes a Module. /// public class Module : ModelBase { /// /// The ID of this instance /// public int ModuleId { get; set; } /// /// Reference to the /// public int SiteId { get; set; } /// /// Reference to the /// public string ModuleDefinitionName { get; set; } /// /// Determines if this module should be shown on all pages of the current /// public bool AllPages { get; set; } /// /// Reference to the used for this module. /// [NotMapped] public ModuleDefinition ModuleDefinition { get; set; } #region IDeletable Properties [NotMapped] public string DeletedBy { get; set; } [NotMapped] public DateTime? DeletedOn { get; set; } [NotMapped] public bool IsDeleted { get; set; } #endregion /// /// list of permissions for this module /// [NotMapped] public List PermissionList { get; set; } /// /// List of settings for this module /// [NotMapped] public Dictionary Settings { get; set; } #region PageModule properties /// /// The id of the PageModule instance /// [NotMapped] public int PageModuleId { get; set; } /// /// Reference to the this module is on. /// [NotMapped] public int PageId { get; set; } /// /// Title of the pagemodule instance /// [NotMapped] public string Title { get; set; } /// /// The pane where this pagemodule instance will be injected on the page /// [NotMapped] public string Pane { get; set; } /// /// The order of the pagemodule instance within the Pane /// [NotMapped] public int Order { get; set; } /// /// The container for the pagemodule instance /// [NotMapped] public string ContainerType { get; set; } /// /// Start of when this module is visible. See also /// [NotMapped] public DateTime? EffectiveDate { get; set; } /// /// End of when this module is visible. See also /// [NotMapped] public DateTime? ExpiryDate { get; set; } #endregion #region SiteRouter properties /// /// Stores the type name for the module component being rendered /// [NotMapped] public string ModuleType { get; set; } /// /// The position of the module instance in a pane /// [NotMapped] public int PaneModuleIndex { get; set; } /// /// The number of modules in a pane /// [NotMapped] public int PaneModuleCount { get; set; } /// /// A unique id to help determine if a component should be rendered /// [NotMapped] public Guid RenderId { get; set; } #endregion #region IModuleControl properties /// /// The minimum access level to view the component being rendered /// [NotMapped] public SecurityAccessLevel SecurityAccessLevel { get; set; } /// /// An optional title for the component /// [NotMapped] public string ControlTitle { get; set; } /// /// Optional mapping of Url actions to a component /// [NotMapped] public string Actions { get; set; } /// /// Optionally indicate if a compoent should not be rendered with the default modal admin container /// [NotMapped] public bool UseAdminContainer { get; set; } /// /// Optionally specify the render mode for the component (overrides the Site setting) /// [NotMapped] public string RenderMode { get; set; } /// /// Optionally specify id the component should be prerendered (overrides the Site setting) /// [NotMapped] public bool? Prerender { get; set; } #endregion #region Deprecated Properties [Obsolete("The Permissions property is deprecated. Use PermissionList instead", false)] [NotMapped] [JsonIgnore] // exclude from API payload public string Permissions { get { return JsonSerializer.Serialize(PermissionList); } set { PermissionList = JsonSerializer.Deserialize>(value); } } #endregion public Module Clone() { return new Module { ModuleId = ModuleId, SiteId = SiteId, ModuleDefinitionName = ModuleDefinitionName, AllPages = AllPages, PageModuleId = PageModuleId, PageId = PageId, Title = Title, Pane = Pane, Order = Order, ContainerType = ContainerType, EffectiveDate = EffectiveDate, ExpiryDate = ExpiryDate, CreatedBy = CreatedBy, CreatedOn = CreatedOn, ModifiedBy = ModifiedBy, ModifiedOn = ModifiedOn, DeletedBy = DeletedBy, DeletedOn = DeletedOn, IsDeleted = IsDeleted, ModuleDefinition = ModuleDefinition, PermissionList = PermissionList.ConvertAll(permission => permission.Clone()), Settings = Settings.ToDictionary(setting => setting.Key, setting => setting.Value) }; } } }