updated modules for input requirements
This commit is contained in:
		| @ -7,495 +7,508 @@ | ||||
| @inject IStringLocalizer<Edit> Localizer | ||||
| @inject IStringLocalizer<SharedResources> SharedLocalizer | ||||
|  | ||||
| <TabStrip Refresh="@_refresh"> | ||||
|     <TabPanel Name="Settings" ResourceKey="Settings"> | ||||
|         @if (_themeList != null) | ||||
|         { | ||||
|             <div class="container"> | ||||
|                 <div class="row mb-1 align-items-center"> | ||||
|                     <Label Class="col-sm-3" For="Name" HelpText="Enter the page name" ResourceKey="Name">Name: </Label> | ||||
|                     <div class="col-sm-9"> | ||||
|                         <input id="Name" class="form-control" @bind="@_name" /> | ||||
|                     </div> | ||||
|                 </div> | ||||
|                 <div class="row mb-1 align-items-center"> | ||||
|                     <Label Class="col-sm-3" For="Parent" HelpText="Select the parent for the page in the site hierarchy" ResourceKey="Parent">Parent: </Label> | ||||
|                     <div class="col-sm-9"> | ||||
|                         <select id="Parent" class="form-select" value="@_parentid" @onchange="(e => ParentChanged(e))"> | ||||
|                             <option value="-1"><@Localizer["SiteRoot"]></option> | ||||
|                             @foreach (Page page in _pageList) | ||||
|                             { | ||||
|                                 if (page.PageId != _pageId) | ||||
|                                 { | ||||
|                                     <option value="@(page.PageId)">@(new string('-', page.Level * 2))@(page.Name)</option> | ||||
|                                 } | ||||
|                             } | ||||
|                         </select> | ||||
|                     </div> | ||||
|                 </div> | ||||
|                 <div class="row mb-1 align-items-center"> | ||||
|                     <Label Class="col-sm-3" For="Move" HelpText="Select the location where you would like the page to be moved in relation to other pages" ResourceKey="Move">Move: </Label> | ||||
|                     <div class="col-sm-9"> | ||||
|                         <select id="Move" class="form-select" @bind="@_insert"> | ||||
|                             @if (_parentid == _currentparentid) | ||||
|                             { | ||||
|                                 <option value="="><@Localizer["ThisLocation.Keep"]></option> | ||||
|                             } | ||||
|                             <option value="<<">@Localizer["ToBeginning"]</option> | ||||
|                             @if (_children != null && _children.Count > 0) | ||||
|                             { | ||||
|                                 <option value="<">@Localizer["Before"]</option> | ||||
|                                 <option value=">">@Localizer["After"]</option> | ||||
|                             } | ||||
|                             <option value=">>">@Localizer["ToEnd"]</option> | ||||
|                         </select> | ||||
|                         @if (_children != null && _children.Count > 0 && (_insert == "<" || _insert == ">")) | ||||
|                         { | ||||
|                             <select class="form-select" @bind="@_childid"> | ||||
|                                 <option value="-1"><@Localizer["Page.Select"]></option> | ||||
|                                 @foreach (Page page in _children) | ||||
|                                 { | ||||
|                                     <option value="@(page.PageId)">@(page.Name)</option> | ||||
|                                 } | ||||
|                             </select> | ||||
|                         } | ||||
|                     </div> | ||||
|                 </div> | ||||
|                 <div class="row mb-1 align-items-center"> | ||||
|                     <Label Class="col-sm-3" For="Navigation" HelpText="Select whether the page is part of the site navigation or hidden" ResourceKey="Navigation">Navigation? </Label> | ||||
|                     <div class="col-sm-9"> | ||||
|                         <select id="Navigation" class="form-select" @bind="@_isnavigation"> | ||||
|                             <option value="True">@SharedLocalizer["Yes"]</option> | ||||
|                             <option value="False">@SharedLocalizer["No"]</option> | ||||
|                         </select> | ||||
|                     </div> | ||||
|                 </div> | ||||
|                 <div class="row mb-1 align-items-center"> | ||||
|                     <Label Class="col-sm-3" For="Clickablen" HelpText="Select whether the link in the site navigation is enabled or disabled" ResourceKey="Clickable">Clickable? </Label> | ||||
|                     <div class="col-sm-9"> | ||||
|                         <select id="Navigation" class="form-select" @bind="@_isclickable"> | ||||
|                             <option value="True">@SharedLocalizer["Yes"]</option> | ||||
|                             <option value="False">@SharedLocalizer["No"]</option> | ||||
|                         </select> | ||||
|                     </div> | ||||
|                 </div> | ||||
|                 <div class="row mb-1 align-items-center"> | ||||
|                     <Label Class="col-sm-3" For="Path" HelpText="Optionally enter a url path for this page (ie. home ). If you do not provide a url path, the page name will be used." ResourceKey="UrlPath">Url Path: </Label> | ||||
|                     <div class="col-sm-9"> | ||||
|                         <input id="Path" class="form-control" @bind="@_path" /> | ||||
|                     </div> | ||||
|                 </div> | ||||
|                 <div class="row mb-1 align-items-center"> | ||||
|                     <Label Class="col-sm-3" For="Url" HelpText="Optionally enter a url which this page should redirect to when a user navigates to it" ResourceKey="Redirect">Redirect: </Label> | ||||
|                     <div class="col-sm-9"> | ||||
|                         <input id="Url" class="form-control" @bind="@_url" /> | ||||
|                     </div> | ||||
|                 </div> | ||||
|             </div> | ||||
|             <Section Name="Appearance" ResourceKey="Appearance"> | ||||
| <form @ref="form" class="@(validated ? "was-validated" : "needs-validation")" novalidate> | ||||
|     <TabStrip Refresh="@_refresh"> | ||||
|         <TabPanel Name="Settings" ResourceKey="Settings"> | ||||
|             @if (_themeList != null) | ||||
|             { | ||||
|                 <div class="container"> | ||||
|                     <div class="row mb-1 align-items-center"> | ||||
|                         <Label Class="col-sm-3" For="Title" HelpText="Optionally enter the page title. If you do not provide a page title, the page name will be used." ResourceKey="Title">Title: </Label> | ||||
|                         <Label Class="col-sm-3" For="Name" HelpText="Enter the page name" ResourceKey="Name">Name: </Label> | ||||
|                         <div class="col-sm-9"> | ||||
|                             <input id="Title" class="form-control" @bind="@_title" /> | ||||
|                             <input id="Name" class="form-control" @bind="@_name" required/> | ||||
|                         </div> | ||||
|                     </div> | ||||
|                     <div class="row mb-1 align-items-center"> | ||||
|                         <Label Class="col-sm-3" For="Theme" HelpText="Select the theme for this page" ResourceKey="Theme">Theme: </Label> | ||||
|                         <Label Class="col-sm-3" For="Parent" HelpText="Select the parent for the page in the site hierarchy" ResourceKey="Parent">Parent: </Label> | ||||
|                         <div class="col-sm-9"> | ||||
|                             <select id="Theme" class="form-select" value="@_themetype" @onchange="(e => ThemeChanged(e))"> | ||||
|                                 @foreach (var theme in _themes) | ||||
|                             <select id="Parent" class="form-select" value="@_parentid" @onchange="(e => ParentChanged(e))" required> | ||||
|                                 <option value="-1"><@Localizer["SiteRoot"]></option> | ||||
|                                 @foreach (Page page in _pageList) | ||||
|                                 { | ||||
|                                     <option value="@theme.TypeName">@theme.Name</option> | ||||
|                                     if (page.PageId != _pageId) | ||||
|                                     { | ||||
|                                         <option value="@(page.PageId)">@(new string('-', page.Level * 2))@(page.Name)</option> | ||||
|                                     } | ||||
|                                 } | ||||
|                             </select> | ||||
|                         </div> | ||||
|                     </div> | ||||
|                     <div class="row mb-1 align-items-center"> | ||||
|                         <Label Class="col-sm-3" For="defaultContainer" HelpText="Select the default container for the page" ResourceKey="DefaultContainer">Default Container: </Label> | ||||
|                         <Label Class="col-sm-3" For="Move" HelpText="Select the location where you would like the page to be moved in relation to other pages" ResourceKey="Move">Move: </Label> | ||||
|                         <div class="col-sm-9"> | ||||
|                             <select id="defaultContainer" class="form-select" @bind="@_containertype"> | ||||
|                                 <option value="-"><@Localizer["Container.Select"]></option> | ||||
|                                 @foreach (var container in _containers) | ||||
|                             <select id="Move" class="form-select" @bind="@_insert" required> | ||||
|                                 @if (_parentid == _currentparentid) | ||||
|                                 { | ||||
|                                     <option value="@container.TypeName">@container.Name</option> | ||||
|                                     <option value="="><@Localizer["ThisLocation.Keep"]></option> | ||||
|                                 } | ||||
|                                 <option value="<<">@Localizer["ToBeginning"]</option> | ||||
|                                 @if (_children != null && _children.Count > 0) | ||||
|                                 { | ||||
|                                     <option value="<">@Localizer["Before"]</option> | ||||
|                                     <option value=">">@Localizer["After"]</option> | ||||
|                                 } | ||||
|                                 <option value=">>">@Localizer["ToEnd"]</option> | ||||
|                             </select> | ||||
|                             @if (_children != null && _children.Count > 0 && (_insert == "<" || _insert == ">")) | ||||
|                             { | ||||
|                                 <select class="form-select" @bind="@_childid"> | ||||
|                                     <option value="-1"><@Localizer["Page.Select"]></option> | ||||
|                                     @foreach (Page page in _children) | ||||
|                                     { | ||||
|                                         <option value="@(page.PageId)">@(page.Name)</option> | ||||
|                                     } | ||||
|                                 </select> | ||||
|                             } | ||||
|                         </div> | ||||
|                     </div> | ||||
|                     <div class="row mb-1 align-items-center"> | ||||
|                         <Label Class="col-sm-3" For="Icon" HelpText="Optionally provide an icon class name for this page which will be displayed in the site navigation" ResourceKey="Icon">Icon: </Label> | ||||
|                         <Label Class="col-sm-3" For="Navigation" HelpText="Select whether the page is part of the site navigation or hidden" ResourceKey="Navigation">Navigation? </Label> | ||||
|                         <div class="col-sm-9"> | ||||
|                             <input id="Icon" class="form-control" @bind="@_icon" /> | ||||
|                         </div> | ||||
|                     </div> | ||||
|                     <div class="row mb-1 align-items-center"> | ||||
|                         <Label Class="col-sm-3" For="Personalizable" HelpText="Select whether you would like users to be able to personalize this page with their own content" ResourceKey="Personalizable">Personalizable? </Label> | ||||
|                         <div class="col-sm-9"> | ||||
|                             <select id="Personalizable" class="form-select" @bind="@_ispersonalizable"> | ||||
|                             <select id="Navigation" class="form-select" @bind="@_isnavigation" required> | ||||
|                                 <option value="True">@SharedLocalizer["Yes"]</option> | ||||
|                                 <option value="False">@SharedLocalizer["No"]</option> | ||||
|                             </select> | ||||
|                         </div> | ||||
|                     </div> | ||||
|                     <div class="row mb-1 align-items-center"> | ||||
|                         <Label Class="col-sm-3" For="Clickablen" HelpText="Select whether the link in the site navigation is enabled or disabled" ResourceKey="Clickable">Clickable? </Label> | ||||
|                         <div class="col-sm-9"> | ||||
|                             <select id="Navigation" class="form-select" @bind="@_isclickable" required> | ||||
|                                 <option value="True">@SharedLocalizer["Yes"]</option> | ||||
|                                 <option value="False">@SharedLocalizer["No"]</option> | ||||
|                             </select> | ||||
|                         </div> | ||||
|                     </div> | ||||
|                     <div class="row mb-1 align-items-center"> | ||||
|                         <Label Class="col-sm-3" For="Path" HelpText="Optionally enter a url path for this page (ie. home ). If you do not provide a url path, the page name will be used." ResourceKey="UrlPath">Url Path: </Label> | ||||
|                         <div class="col-sm-9"> | ||||
|                             <input id="Path" class="form-control" @bind="@_path" /> | ||||
|                         </div> | ||||
|                     </div> | ||||
|                     <div class="row mb-1 align-items-center"> | ||||
|                         <Label Class="col-sm-3" For="Url" HelpText="Optionally enter a url which this page should redirect to when a user navigates to it" ResourceKey="Redirect">Redirect: </Label> | ||||
|                         <div class="col-sm-9"> | ||||
|                             <input id="Url" class="form-control" @bind="@_url" /> | ||||
|                         </div> | ||||
|                     </div> | ||||
|                 </div> | ||||
|             </Section> | ||||
|             <br /><br /> | ||||
|             <AuditInfo CreatedBy="@_createdby" CreatedOn="@_createdon" ModifiedBy="@_modifiedby" ModifiedOn="@_modifiedon" DeletedBy="@_deletedby" DeletedOn="@_deletedon"></AuditInfo> | ||||
|         } | ||||
|     </TabPanel> | ||||
|     <TabPanel Name="Permissions" ResourceKey="Permissions"> | ||||
|         @if (_permissions != null) | ||||
|         { | ||||
|             <div class="container"> | ||||
|                 <div class="row mb-1 align-items-center"> | ||||
|                     <PermissionGrid EntityName="@EntityNames.Page" Permissions="@_permissions" @ref="_permissionGrid" /> | ||||
|         | ||||
|                 </div> | ||||
|             </div> | ||||
|   | ||||
|         } | ||||
|     </TabPanel> | ||||
|     @if (_themeSettingsType != null) | ||||
|     { | ||||
|         <TabPanel Name="ThemeSettings" Heading="Theme Settings" ResourceKey="ThemeSettings"> | ||||
|             @ThemeSettingsComponent | ||||
|                 <Section Name="Appearance" ResourceKey="Appearance"> | ||||
|                     <div class="container"> | ||||
|                         <div class="row mb-1 align-items-center"> | ||||
|                             <Label Class="col-sm-3" For="Title" HelpText="Optionally enter the page title. If you do not provide a page title, the page name will be used." ResourceKey="Title">Title: </Label> | ||||
|                             <div class="col-sm-9"> | ||||
|                                 <input id="Title" class="form-control" @bind="@_title" /> | ||||
|                             </div> | ||||
|                         </div> | ||||
|                         <div class="row mb-1 align-items-center"> | ||||
|                             <Label Class="col-sm-3" For="Theme" HelpText="Select the theme for this page" ResourceKey="Theme">Theme: </Label> | ||||
|                             <div class="col-sm-9"> | ||||
|                                 <select id="Theme" class="form-select" value="@_themetype" @onchange="(e => ThemeChanged(e))" required> | ||||
|                                     @foreach (var theme in _themes) | ||||
|                                     { | ||||
|                                         <option value="@theme.TypeName">@theme.Name</option> | ||||
|                                     } | ||||
|                                 </select> | ||||
|                             </div> | ||||
|                         </div> | ||||
|                         <div class="row mb-1 align-items-center"> | ||||
|                             <Label Class="col-sm-3" For="defaultContainer" HelpText="Select the default container for the page" ResourceKey="DefaultContainer">Default Container: </Label> | ||||
|                             <div class="col-sm-9"> | ||||
|                                 <select id="defaultContainer" class="form-select" @bind="@_containertype" required> | ||||
|                                     <option value="-"><@Localizer["Container.Select"]></option> | ||||
|                                     @foreach (var container in _containers) | ||||
|                                     { | ||||
|                                         <option value="@container.TypeName">@container.Name</option> | ||||
|                                     } | ||||
|                                 </select> | ||||
|                             </div> | ||||
|                         </div> | ||||
|                         <div class="row mb-1 align-items-center"> | ||||
|                             <Label Class="col-sm-3" For="Icon" HelpText="Optionally provide an icon class name for this page which will be displayed in the site navigation" ResourceKey="Icon">Icon: </Label> | ||||
|                             <div class="col-sm-9"> | ||||
|                                 <input id="Icon" class="form-control" @bind="@_icon" /> | ||||
|                             </div> | ||||
|                         </div> | ||||
|                         <div class="row mb-1 align-items-center"> | ||||
|                             <Label Class="col-sm-3" For="Personalizable" HelpText="Select whether you would like users to be able to personalize this page with their own content" ResourceKey="Personalizable">Personalizable? </Label> | ||||
|                             <div class="col-sm-9"> | ||||
|                                 <select id="Personalizable" class="form-select" @bind="@_ispersonalizable" required> | ||||
|                                     <option value="True">@SharedLocalizer["Yes"]</option> | ||||
|                                     <option value="False">@SharedLocalizer["No"]</option> | ||||
|                                 </select> | ||||
|                             </div> | ||||
|                         </div> | ||||
|                     </div> | ||||
|                 </Section> | ||||
|                 <br /><br /> | ||||
|                 <AuditInfo CreatedBy="@_createdby" CreatedOn="@_createdon" ModifiedBy="@_modifiedby" ModifiedOn="@_modifiedon" DeletedBy="@_deletedby" DeletedOn="@_deletedon"></AuditInfo> | ||||
|             } | ||||
|         </TabPanel> | ||||
|     } | ||||
| </TabStrip> | ||||
| <button type="button" class="btn btn-success" @onclick="SavePage">@SharedLocalizer["Save"]</button> | ||||
| <button type="button" class="btn btn-secondary" @onclick="Cancel">@SharedLocalizer["Cancel"]</button> | ||||
|  | ||||
| @code { | ||||
|     public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; | ||||
|  | ||||
|     private List<Theme> _themeList; | ||||
|     private List<ThemeControl> _themes = new List<ThemeControl>(); | ||||
|     private List<ThemeControl> _containers = new List<ThemeControl>(); | ||||
|     private List<Page> _pageList; | ||||
|     private int _pageId; | ||||
|     private string _name; | ||||
|     private string _title; | ||||
|     private string _path; | ||||
|     private string _currentparentid; | ||||
|     private string _parentid; | ||||
|     private string _insert = "="; | ||||
|     private List<Page> _children; | ||||
|     private int _childid = -1; | ||||
|     private string _isnavigation; | ||||
|     private string _isclickable; | ||||
|     private string _url; | ||||
|     private string _ispersonalizable; | ||||
|     private string _themetype; | ||||
|     private string _containertype = "-"; | ||||
|     private string _icon; | ||||
|     private string _permissions = null; | ||||
|     private string _createdby; | ||||
|     private DateTime _createdon; | ||||
|     private string _modifiedby; | ||||
|     private DateTime _modifiedon; | ||||
|     private string _deletedby; | ||||
|     private DateTime? _deletedon; | ||||
|     private PermissionGrid _permissionGrid; | ||||
|     private Type _themeSettingsType; | ||||
|     private object _themeSettings; | ||||
|     private RenderFragment ThemeSettingsComponent { get; set; } | ||||
|     private bool _refresh = false; | ||||
|  | ||||
|     protected override async Task OnInitializedAsync() | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             _pageList = PageState.Pages; | ||||
|             _children = PageState.Pages.Where(item => item.ParentId == null).ToList(); | ||||
|  | ||||
|             _themeList = await ThemeService.GetThemesAsync(); | ||||
|             _themes = ThemeService.GetThemeControls(_themeList); | ||||
|  | ||||
|             _pageId = Int32.Parse(PageState.QueryString["id"]); | ||||
|             var page = PageState.Pages.FirstOrDefault(item => item.PageId == _pageId); | ||||
|             if (page != null) | ||||
|         <TabPanel Name="Permissions" ResourceKey="Permissions"> | ||||
|             @if (_permissions != null) | ||||
|             { | ||||
|                 _name = page.Name; | ||||
|                 _title = page.Title; | ||||
|                 _path = page.Path; | ||||
|                 <div class="container"> | ||||
|                     <div class="row mb-1 align-items-center"> | ||||
|                         <PermissionGrid EntityName="@EntityNames.Page" Permissions="@_permissions" @ref="_permissionGrid" /> | ||||
|  | ||||
|                 if (_path.Contains("/")) | ||||
|                 { | ||||
|                     _path = _path.Substring(_path.LastIndexOf("/") + 1); | ||||
|                 } | ||||
|                     </div> | ||||
|                 </div> | ||||
|  | ||||
|                 if (page.ParentId == null) | ||||
|                 { | ||||
|                     _parentid = string.Empty; | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     _parentid = page.ParentId.ToString(); | ||||
|                 } | ||||
|  | ||||
|                 _currentparentid = _parentid; | ||||
|                 _isnavigation = page.IsNavigation.ToString(); | ||||
|                 _isclickable = page.IsClickable.ToString(); | ||||
|                 _url = page.Url; | ||||
|                 _ispersonalizable = page.IsPersonalizable.ToString(); | ||||
|                 _themetype = page.ThemeType; | ||||
|                 if (string.IsNullOrEmpty(_themetype)) | ||||
|                 { | ||||
|                     _themetype = PageState.Site.DefaultThemeType; | ||||
|                 } | ||||
|                 _containers = ThemeService.GetContainerControls(_themeList, _themetype); | ||||
|                 _containertype = page.DefaultContainerType; | ||||
|                 if (string.IsNullOrEmpty(_containertype)) | ||||
|                 { | ||||
|                     _containertype = PageState.Site.DefaultContainerType; | ||||
|                 } | ||||
|                 _icon = page.Icon; | ||||
|                 _permissions = page.Permissions; | ||||
|                 _createdby = page.CreatedBy; | ||||
|                 _createdon = page.CreatedOn; | ||||
|                 _modifiedby = page.ModifiedBy; | ||||
|                 _modifiedon = page.ModifiedOn; | ||||
|                 _deletedby = page.DeletedBy; | ||||
|                 _deletedon = page.DeletedOn; | ||||
|  | ||||
|                 ThemeSettings(); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         </TabPanel> | ||||
|         @if (_themeSettingsType != null) | ||||
|         { | ||||
|             await logger.LogError(ex, "Error Loading Page {PageId} {Error}", _pageId, ex.Message); | ||||
|             AddModuleMessage(Localizer["Error.Page.Load"], MessageType.Error); | ||||
|             <TabPanel Name="ThemeSettings" Heading="Theme Settings" ResourceKey="ThemeSettings"> | ||||
|                 @ThemeSettingsComponent | ||||
|             </TabPanel> | ||||
|         } | ||||
|     } | ||||
|     </TabStrip> | ||||
|     <button type="button" class="btn btn-success" @onclick="SavePage">@SharedLocalizer["Save"]</button> | ||||
|     <button type="button" class="btn btn-secondary" @onclick="Cancel">@SharedLocalizer["Cancel"]</button> | ||||
| </form> | ||||
|  | ||||
|     private async void ParentChanged(ChangeEventArgs e) | ||||
|     { | ||||
|         try | ||||
|     @code { | ||||
|         public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; | ||||
|  | ||||
|         private ElementReference form; | ||||
|         private bool validated = false; | ||||
|         private List<Theme> _themeList; | ||||
|         private List<ThemeControl> _themes = new List<ThemeControl>(); | ||||
|         private List<ThemeControl> _containers = new List<ThemeControl>(); | ||||
|         private List<Page> _pageList; | ||||
|         private int _pageId; | ||||
|         private string _name; | ||||
|         private string _title; | ||||
|         private string _path; | ||||
|         private string _currentparentid; | ||||
|         private string _parentid; | ||||
|         private string _insert = "="; | ||||
|         private List<Page> _children; | ||||
|         private int _childid = -1; | ||||
|         private string _isnavigation; | ||||
|         private string _isclickable; | ||||
|         private string _url; | ||||
|         private string _ispersonalizable; | ||||
|         private string _themetype; | ||||
|         private string _containertype = "-"; | ||||
|         private string _icon; | ||||
|         private string _permissions = null; | ||||
|         private string _createdby; | ||||
|         private DateTime _createdon; | ||||
|         private string _modifiedby; | ||||
|         private DateTime _modifiedon; | ||||
|         private string _deletedby; | ||||
|         private DateTime? _deletedon; | ||||
|         private PermissionGrid _permissionGrid; | ||||
|         private Type _themeSettingsType; | ||||
|         private object _themeSettings; | ||||
|         private RenderFragment ThemeSettingsComponent { get; set; } | ||||
|         private bool _refresh = false; | ||||
|  | ||||
|         protected override async Task OnInitializedAsync() | ||||
|         { | ||||
|             _parentid = (string)e.Value; | ||||
|             _children = new List<Page>(); | ||||
|             if (_parentid == "-1") | ||||
|             try | ||||
|             { | ||||
|                 foreach (Page p in PageState.Pages.Where(item => item.ParentId == null)) | ||||
|                 _pageList = PageState.Pages; | ||||
|                 _children = PageState.Pages.Where(item => item.ParentId == null).ToList(); | ||||
|  | ||||
|                 _themeList = await ThemeService.GetThemesAsync(); | ||||
|                 _themes = ThemeService.GetThemeControls(_themeList); | ||||
|  | ||||
|                 _pageId = Int32.Parse(PageState.QueryString["id"]); | ||||
|                 var page = PageState.Pages.FirstOrDefault(item => item.PageId == _pageId); | ||||
|                 if (page != null) | ||||
|                 { | ||||
|                     if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, p.Permissions)) | ||||
|                     _name = page.Name; | ||||
|                     _title = page.Title; | ||||
|                     _path = page.Path; | ||||
|  | ||||
|                     if (_path.Contains("/")) | ||||
|                     { | ||||
|                         _children.Add(p); | ||||
|                         _path = _path.Substring(_path.LastIndexOf("/") + 1); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 foreach (Page p in PageState.Pages.Where(item => item.ParentId == int.Parse(_parentid))) | ||||
|                 { | ||||
|                     if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, p.Permissions)) | ||||
|  | ||||
|                     if (page.ParentId == null) | ||||
|                     { | ||||
|                         _children.Add(p); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             if (_parentid == _currentparentid) | ||||
|             { | ||||
|                 _insert = "="; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 _insert = ">>"; | ||||
|             } | ||||
|             StateHasChanged(); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             await logger.LogError(ex, "Error Loading Child Pages For Parent {PageId} {Error}", _parentid, ex.Message); | ||||
|             AddModuleMessage(Localizer["Error.ChildPage.Load"], MessageType.Error); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private async void ThemeChanged(ChangeEventArgs e) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             _themetype = (string)e.Value; | ||||
|             _containers = ThemeService.GetContainerControls(_themeList, _themetype); | ||||
|             _containertype = "-"; | ||||
|             ThemeSettings(); | ||||
|             StateHasChanged(); | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             await logger.LogError(ex, "Error Loading Pane Layouts For Theme {ThemeType} {Error}", _themetype, ex.Message); | ||||
|             AddModuleMessage(Localizer["Error.Pane.Load"], MessageType.Error); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void ThemeSettings() | ||||
|     { | ||||
|         _themeSettingsType = null; | ||||
|         var theme = _themeList.FirstOrDefault(item => item.Themes.Any(themecontrol => themecontrol.TypeName.Equals(_themetype))); | ||||
|         if (theme != null && !string.IsNullOrEmpty(theme.ThemeSettingsType)) | ||||
|         { | ||||
|             _themeSettingsType = Type.GetType(theme.ThemeSettingsType); | ||||
|             if (_themeSettingsType != null) | ||||
|             { | ||||
|                 ThemeSettingsComponent = builder => | ||||
|                 { | ||||
|                     builder.OpenComponent(0, _themeSettingsType); | ||||
|                     builder.AddComponentReferenceCapture(1, inst => { _themeSettings = Convert.ChangeType(inst, _themeSettingsType); }); | ||||
|                     builder.CloseComponent(); | ||||
|                 }; | ||||
|             } | ||||
|             _refresh = true; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private async Task SavePage() | ||||
|     { | ||||
|         Page page = null; | ||||
|         try | ||||
|         { | ||||
|             if (_name != string.Empty && !string.IsNullOrEmpty(_themetype) && _containertype != "-") | ||||
|             { | ||||
|                 page = PageState.Pages.FirstOrDefault(item => item.PageId == _pageId); | ||||
|                 string currentPath = page.Path; | ||||
|  | ||||
|                 page.Name = _name; | ||||
|                 page.Title = _title; | ||||
|                 if (_path == "" && _name.ToLower() != "home") | ||||
|                     if (_path == string.Empty && _name.ToLower() != "home") | ||||
|                     { | ||||
|                         _path = _name; | ||||
|                     } | ||||
|                 if (_path.Contains("/")) | ||||
|                 { | ||||
|                     _path = _path.Substring(_path.LastIndexOf("/") + 1); | ||||
|                 } | ||||
|                 if (string.IsNullOrEmpty(_parentid) || _parentid == "-1") | ||||
|                 { | ||||
|                     page.ParentId = null; | ||||
|                     page.Path = Utilities.GetFriendlyUrl(_path); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     page.ParentId = Int32.Parse(_parentid); | ||||
|                     Page parent = PageState.Pages.FirstOrDefault(item => item.PageId == page.ParentId); | ||||
|                     if (parent.Path == string.Empty) | ||||
|                     { | ||||
|                         page.Path = Utilities.GetFriendlyUrl(parent.Name) + "/" + Utilities.GetFriendlyUrl(_path); | ||||
|                         _parentid = string.Empty; | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         page.Path = parent.Path + "/" + Utilities.GetFriendlyUrl(_path); | ||||
|                         _parentid = page.ParentId.ToString(); | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 if (!PagePathIsUnique(page.Path, page.SiteId, page.PageId, _pageList)) | ||||
|                 { | ||||
|                     AddModuleMessage(string.Format(Localizer["Mesage.Page.PathExists"], _path), MessageType.Warning); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 if (_insert != "=") | ||||
|                 { | ||||
|                     Page child; | ||||
|                     switch (_insert) | ||||
|                     _currentparentid = _parentid; | ||||
|                     _isnavigation = page.IsNavigation.ToString(); | ||||
|                     _isclickable = page.IsClickable.ToString(); | ||||
|                     _url = page.Url; | ||||
|                     _ispersonalizable = page.IsPersonalizable.ToString(); | ||||
|                     _themetype = page.ThemeType; | ||||
|                     if (string.IsNullOrEmpty(_themetype)) | ||||
|                     { | ||||
|                         case "<<": | ||||
|                             page.Order = 0; | ||||
|                             break; | ||||
|                         case "<": | ||||
|                             child = PageState.Pages.FirstOrDefault(item => item.PageId == _childid); | ||||
|                             if (child != null) page.Order = child.Order - 1; | ||||
|                             break; | ||||
|                         case ">": | ||||
|                             child = PageState.Pages.FirstOrDefault(item => item.PageId == _childid); | ||||
|                             if (child != null) page.Order = child.Order + 1; | ||||
|                             break; | ||||
|                         case ">>": | ||||
|                             page.Order = int.MaxValue; | ||||
|                             break; | ||||
|                         _themetype = PageState.Site.DefaultThemeType; | ||||
|                     } | ||||
|                 } | ||||
|                 page.IsNavigation = (_isnavigation == null || Boolean.Parse(_isnavigation)); | ||||
|                 page.IsClickable = (_isclickable == null ? true : Boolean.Parse(_isclickable)); | ||||
|                 page.Url = _url; | ||||
|                 page.ThemeType = (_themetype != "-") ? _themetype : string.Empty; | ||||
|                 if (!string.IsNullOrEmpty(page.ThemeType) && page.ThemeType == PageState.Site.DefaultThemeType) | ||||
|                 { | ||||
|                     page.ThemeType = string.Empty; | ||||
|                 } | ||||
|                 page.DefaultContainerType = (_containertype != "-") ? _containertype : string.Empty; | ||||
|                 if (!string.IsNullOrEmpty(page.DefaultContainerType) && page.DefaultContainerType == PageState.Site.DefaultContainerType) | ||||
|                 { | ||||
|                     page.DefaultContainerType = string.Empty; | ||||
|                 } | ||||
|                 page.Icon = _icon ?? string.Empty; | ||||
|                 page.Permissions = _permissionGrid.GetPermissions(); | ||||
|                 page.IsPersonalizable = (_ispersonalizable != null && Boolean.Parse(_ispersonalizable)); | ||||
|                 page.UserId = null; | ||||
|                     _containers = ThemeService.GetContainerControls(_themeList, _themetype); | ||||
|                     _containertype = page.DefaultContainerType; | ||||
|                     if (string.IsNullOrEmpty(_containertype)) | ||||
|                     { | ||||
|                         _containertype = PageState.Site.DefaultContainerType; | ||||
|                     } | ||||
|                     _icon = page.Icon; | ||||
|                     _permissions = page.Permissions; | ||||
|                     _createdby = page.CreatedBy; | ||||
|                     _createdon = page.CreatedOn; | ||||
|                     _modifiedby = page.ModifiedBy; | ||||
|                     _modifiedon = page.ModifiedOn; | ||||
|                     _deletedby = page.DeletedBy; | ||||
|                     _deletedon = page.DeletedOn; | ||||
|  | ||||
|                 page = await PageService.UpdatePageAsync(page); | ||||
|                 await PageService.UpdatePageOrderAsync(page.SiteId, page.PageId, page.ParentId); | ||||
|                 if (_currentparentid == string.Empty) | ||||
|                     ThemeSettings(); | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 await logger.LogError(ex, "Error Loading Page {PageId} {Error}", _pageId, ex.Message); | ||||
|                 AddModuleMessage(Localizer["Error.Page.Load"], MessageType.Error); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         private async void ParentChanged(ChangeEventArgs e) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 _parentid = (string)e.Value; | ||||
|                 _children = new List<Page>(); | ||||
|                 if (_parentid == "-1") | ||||
|                 { | ||||
|                     await PageService.UpdatePageOrderAsync(page.SiteId, page.PageId, null); | ||||
|                     foreach (Page p in PageState.Pages.Where(item => item.ParentId == null)) | ||||
|                     { | ||||
|                         if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, p.Permissions)) | ||||
|                         { | ||||
|                             _children.Add(p); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     await PageService.UpdatePageOrderAsync(page.SiteId, page.PageId, int.Parse(_currentparentid)); | ||||
|                 } | ||||
|  | ||||
|                 // update child paths | ||||
|                 if (_parentid != _currentparentid) | ||||
|                 { | ||||
|                     foreach (Page p in PageState.Pages.Where(item => item.Path.StartsWith(currentPath))) | ||||
|                     foreach (Page p in PageState.Pages.Where(item => item.ParentId == int.Parse(_parentid))) | ||||
|                     { | ||||
|                         p.Path = p.Path.Replace(currentPath, page.Path); | ||||
|                         await PageService.UpdatePageAsync(p); | ||||
|                         if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, p.Permissions)) | ||||
|                         { | ||||
|                             _children.Add(p); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 if (_themeSettingsType != null && _themeSettings is ISettingsControl themeSettingsControl) | ||||
|                 if (_parentid == _currentparentid) | ||||
|                 { | ||||
|                     await themeSettingsControl.UpdateSettings(); | ||||
|                 } | ||||
|  | ||||
|                 await logger.LogInformation("Page Saved {Page}", page); | ||||
|                 if (PageState.QueryString.ContainsKey("cp")) | ||||
|                 { | ||||
|                     NavigationManager.NavigateTo(NavigateUrl(PageState.Pages.First(item => item.PageId == int.Parse(PageState.QueryString["cp"])).Path)); | ||||
|                     _insert = "="; | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     NavigationManager.NavigateTo(NavigateUrl(page.Path)); | ||||
|                     _insert = ">>"; | ||||
|                 } | ||||
|                 StateHasChanged(); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 await logger.LogError(ex, "Error Loading Child Pages For Parent {PageId} {Error}", _parentid, ex.Message); | ||||
|                 AddModuleMessage(Localizer["Error.ChildPage.Load"], MessageType.Error); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         private async void ThemeChanged(ChangeEventArgs e) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 _themetype = (string)e.Value; | ||||
|                 _containers = ThemeService.GetContainerControls(_themeList, _themetype); | ||||
|                 _containertype = "-"; | ||||
|                 ThemeSettings(); | ||||
|                 StateHasChanged(); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 await logger.LogError(ex, "Error Loading Pane Layouts For Theme {ThemeType} {Error}", _themetype, ex.Message); | ||||
|                 AddModuleMessage(Localizer["Error.Pane.Load"], MessageType.Error); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         private void ThemeSettings() | ||||
|         { | ||||
|             _themeSettingsType = null; | ||||
|             var theme = _themeList.FirstOrDefault(item => item.Themes.Any(themecontrol => themecontrol.TypeName.Equals(_themetype))); | ||||
|             if (theme != null && !string.IsNullOrEmpty(theme.ThemeSettingsType)) | ||||
|             { | ||||
|                 _themeSettingsType = Type.GetType(theme.ThemeSettingsType); | ||||
|                 if (_themeSettingsType != null) | ||||
|                 { | ||||
|                     ThemeSettingsComponent = builder => | ||||
|                     { | ||||
|                         builder.OpenComponent(0, _themeSettingsType); | ||||
|                         builder.AddComponentReferenceCapture(1, inst => { _themeSettings = Convert.ChangeType(inst, _themeSettingsType); }); | ||||
|                         builder.CloseComponent(); | ||||
|                     }; | ||||
|                 } | ||||
|                 _refresh = true; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         private async Task SavePage() | ||||
|         { | ||||
|             validated = true; | ||||
|             var interop = new Interop(JSRuntime); | ||||
|             if (await interop.FormValid(form)) | ||||
|             { | ||||
|                 Page page = null; | ||||
|                 try | ||||
|                 { | ||||
|                     if (_name != string.Empty && !string.IsNullOrEmpty(_themetype) && _containertype != "-") | ||||
|                     { | ||||
|                         page = PageState.Pages.FirstOrDefault(item => item.PageId == _pageId); | ||||
|                         string currentPath = page.Path; | ||||
|  | ||||
|                         page.Name = _name; | ||||
|                         page.Title = _title; | ||||
|                         if (_path == "" && _name.ToLower() != "home") | ||||
|                             if (_path == string.Empty && _name.ToLower() != "home") | ||||
|                             { | ||||
|                                 _path = _name; | ||||
|                             } | ||||
|                         if (_path.Contains("/")) | ||||
|                         { | ||||
|                             _path = _path.Substring(_path.LastIndexOf("/") + 1); | ||||
|                         } | ||||
|                         if (string.IsNullOrEmpty(_parentid) || _parentid == "-1") | ||||
|                         { | ||||
|                             page.ParentId = null; | ||||
|                             page.Path = Utilities.GetFriendlyUrl(_path); | ||||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                             page.ParentId = Int32.Parse(_parentid); | ||||
|                             Page parent = PageState.Pages.FirstOrDefault(item => item.PageId == page.ParentId); | ||||
|                             if (parent.Path == string.Empty) | ||||
|                             { | ||||
|                                 page.Path = Utilities.GetFriendlyUrl(parent.Name) + "/" + Utilities.GetFriendlyUrl(_path); | ||||
|                             } | ||||
|                             else | ||||
|                             { | ||||
|                                 page.Path = parent.Path + "/" + Utilities.GetFriendlyUrl(_path); | ||||
|                             } | ||||
|                         } | ||||
|  | ||||
|                         if (!PagePathIsUnique(page.Path, page.SiteId, page.PageId, _pageList)) | ||||
|                         { | ||||
|                             AddModuleMessage(string.Format(Localizer["Mesage.Page.PathExists"], _path), MessageType.Warning); | ||||
|                             return; | ||||
|                         } | ||||
|  | ||||
|                         if (_insert != "=") | ||||
|                         { | ||||
|                             Page child; | ||||
|                             switch (_insert) | ||||
|                             { | ||||
|                                 case "<<": | ||||
|                                     page.Order = 0; | ||||
|                                     break; | ||||
|                                 case "<": | ||||
|                                     child = PageState.Pages.FirstOrDefault(item => item.PageId == _childid); | ||||
|                                     if (child != null) page.Order = child.Order - 1; | ||||
|                                     break; | ||||
|                                 case ">": | ||||
|                                     child = PageState.Pages.FirstOrDefault(item => item.PageId == _childid); | ||||
|                                     if (child != null) page.Order = child.Order + 1; | ||||
|                                     break; | ||||
|                                 case ">>": | ||||
|                                     page.Order = int.MaxValue; | ||||
|                                     break; | ||||
|                             } | ||||
|                         } | ||||
|                         page.IsNavigation = (_isnavigation == null || Boolean.Parse(_isnavigation)); | ||||
|                         page.IsClickable = (_isclickable == null ? true : Boolean.Parse(_isclickable)); | ||||
|                         page.Url = _url; | ||||
|                         page.ThemeType = (_themetype != "-") ? _themetype : string.Empty; | ||||
|                         if (!string.IsNullOrEmpty(page.ThemeType) && page.ThemeType == PageState.Site.DefaultThemeType) | ||||
|                         { | ||||
|                             page.ThemeType = string.Empty; | ||||
|                         } | ||||
|                         page.DefaultContainerType = (_containertype != "-") ? _containertype : string.Empty; | ||||
|                         if (!string.IsNullOrEmpty(page.DefaultContainerType) && page.DefaultContainerType == PageState.Site.DefaultContainerType) | ||||
|                         { | ||||
|                             page.DefaultContainerType = string.Empty; | ||||
|                         } | ||||
|                         page.Icon = _icon ?? string.Empty; | ||||
|                         page.Permissions = _permissionGrid.GetPermissions(); | ||||
|                         page.IsPersonalizable = (_ispersonalizable != null && Boolean.Parse(_ispersonalizable)); | ||||
|                         page.UserId = null; | ||||
|  | ||||
|                         page = await PageService.UpdatePageAsync(page); | ||||
|                         await PageService.UpdatePageOrderAsync(page.SiteId, page.PageId, page.ParentId); | ||||
|                         if (_currentparentid == string.Empty) | ||||
|                         { | ||||
|                             await PageService.UpdatePageOrderAsync(page.SiteId, page.PageId, null); | ||||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                             await PageService.UpdatePageOrderAsync(page.SiteId, page.PageId, int.Parse(_currentparentid)); | ||||
|                         } | ||||
|  | ||||
|                         // update child paths | ||||
|                         if (_parentid != _currentparentid) | ||||
|                         { | ||||
|                             foreach (Page p in PageState.Pages.Where(item => item.Path.StartsWith(currentPath))) | ||||
|                             { | ||||
|                                 p.Path = p.Path.Replace(currentPath, page.Path); | ||||
|                                 await PageService.UpdatePageAsync(p); | ||||
|                             } | ||||
|                         } | ||||
|  | ||||
|                         if (_themeSettingsType != null && _themeSettings is ISettingsControl themeSettingsControl) | ||||
|                         { | ||||
|                             await themeSettingsControl.UpdateSettings(); | ||||
|                         } | ||||
|  | ||||
|                         await logger.LogInformation("Page Saved {Page}", page); | ||||
|                         if (PageState.QueryString.ContainsKey("cp")) | ||||
|                         { | ||||
|                             NavigationManager.NavigateTo(NavigateUrl(PageState.Pages.First(item => item.PageId == int.Parse(PageState.QueryString["cp"])).Path)); | ||||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                             NavigationManager.NavigateTo(NavigateUrl(page.Path)); | ||||
|                         } | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         AddModuleMessage(Localizer["Message.Required.PageInfo"], MessageType.Warning); | ||||
|                     } | ||||
|                 } | ||||
|                 catch (Exception ex) | ||||
|                 { | ||||
|                     await logger.LogError(ex, "Error Saving Page {Page} {Error}", page, ex.Message); | ||||
|                     AddModuleMessage(Localizer["Error.Page.Save"], MessageType.Error); | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 AddModuleMessage(Localizer["Message.Required.PageInfo"], MessageType.Warning); | ||||
|                 AddModuleMessage(SharedLocalizer["Message.InfoRequired"], MessageType.Warning); | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) | ||||
|         { | ||||
|             await logger.LogError(ex, "Error Saving Page {Page} {Error}", page, ex.Message); | ||||
|             AddModuleMessage(Localizer["Error.Page.Save"], MessageType.Error); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void Cancel() | ||||
|     { | ||||
|         if (PageState.QueryString.ContainsKey("cp")) | ||||
|         private void Cancel() | ||||
|         { | ||||
|             NavigationManager.NavigateTo(NavigateUrl(PageState.Pages.First(item => item.PageId == int.Parse(PageState.QueryString["cp"])).Path)); | ||||
|             if (PageState.QueryString.ContainsKey("cp")) | ||||
|             { | ||||
|                 NavigationManager.NavigateTo(NavigateUrl(PageState.Pages.First(item => item.PageId == int.Parse(PageState.QueryString["cp"])).Path)); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 NavigationManager.NavigateTo(NavigateUrl()); | ||||
|             } | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             NavigationManager.NavigateTo(NavigateUrl()); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private static bool PagePathIsUnique(string pagePath, int siteId, int pageId, List<Page> existingPages) | ||||
|     { | ||||
|         return !existingPages.Any(page => page.SiteId == siteId && page.Path == pagePath && page.PageId != pageId); | ||||
|         private static bool PagePathIsUnique(string pagePath, int siteId, int pageId, List<Page> existingPages) | ||||
|         { | ||||
|             return !existingPages.Any(page => page.SiteId == siteId && page.Path == pagePath && page.PageId != pageId); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Grayson Walker
					Grayson Walker