From cf404625314214ef51d219a8141f8a6a98826f5c Mon Sep 17 00:00:00 2001 From: Grayson Walker Date: Thu, 29 Jul 2021 16:46:58 -0400 Subject: [PATCH] moduleDefintions - profiles validation changes --- .../Admin/ModuleDefinitions/Create.razor | 141 ++--- .../Admin/ModuleDefinitions/Edit.razor | 181 ++++--- .../Modules/Admin/Modules/Export.razor | 29 +- .../Modules/Admin/Modules/Import.razor | 24 +- .../Modules/Admin/Modules/Settings.razor | 227 ++++---- Oqtane.Client/Modules/Admin/Pages/Add.razor | 414 +++++++-------- Oqtane.Client/Modules/Admin/Pages/Edit.razor | 483 +++++++++--------- .../Modules/Admin/Profiles/Edit.razor | 227 ++++---- 8 files changed, 914 insertions(+), 812 deletions(-) diff --git a/Oqtane.Client/Modules/Admin/ModuleDefinitions/Create.razor b/Oqtane.Client/Modules/Admin/ModuleDefinitions/Create.razor index 765ae2df..e341d69d 100644 --- a/Oqtane.Client/Modules/Admin/ModuleDefinitions/Create.razor +++ b/Oqtane.Client/Modules/Admin/ModuleDefinitions/Create.razor @@ -10,67 +10,71 @@ @if (_templates != null) { -
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
- @if (!string.IsNullOrEmpty(_location)) - { +
+
- +
- +
- } -
- - @SharedLocalizer["Cancel"] +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ @if (!string.IsNullOrEmpty(_location)) + { +
+ +
+ +
+
+ } +
+ + @SharedLocalizer["Cancel"] + } @code { + private ElementReference form; + private bool validated = false; private string _owner = string.Empty; private string _module = string.Empty; private string _description = string.Empty; @@ -99,23 +103,32 @@ private async Task CreateModule() { - try + validated = true; + var interop = new Interop(JSRuntime); + if (await interop.FormValid(form)) { - if (IsValid(_owner) && IsValid(_module) && _owner != _module && _template != "-") + try { - var moduleDefinition = new ModuleDefinition { Owner = _owner, Name = _module, Description = _description, Template = _template, Version = _reference }; - moduleDefinition = await ModuleDefinitionService.CreateModuleDefinitionAsync(moduleDefinition); - GetLocation(); - AddModuleMessage(string.Format(Localizer["Success.Module.Create"], NavigateUrl("admin/system")), MessageType.Success); + if (IsValid(_owner) && IsValid(_module) && _owner != _module && _template != "-") + { + var moduleDefinition = new ModuleDefinition { Owner = _owner, Name = _module, Description = _description, Template = _template, Version = _reference }; + moduleDefinition = await ModuleDefinitionService.CreateModuleDefinitionAsync(moduleDefinition); + GetLocation(); + AddModuleMessage(string.Format(Localizer["Success.Module.Create"], NavigateUrl("admin/system")), MessageType.Success); + } + else + { + AddModuleMessage(Localizer["Message.Require.ValidName"], MessageType.Warning); + } } - else + catch (Exception ex) { - AddModuleMessage(Localizer["Message.Require.ValidName"], MessageType.Warning); + await logger.LogError(ex, "Error Creating Module"); } } - catch (Exception ex) + else { - await logger.LogError(ex, "Error Creating Module"); + AddModuleMessage(SharedLocalizer["Message.InfoRequired"], MessageType.Warning); } } diff --git a/Oqtane.Client/Modules/Admin/ModuleDefinitions/Edit.razor b/Oqtane.Client/Modules/Admin/ModuleDefinitions/Edit.razor index d75464d1..6a8f7105 100644 --- a/Oqtane.Client/Modules/Admin/ModuleDefinitions/Edit.razor +++ b/Oqtane.Client/Modules/Admin/ModuleDefinitions/Edit.razor @@ -5,90 +5,94 @@ @inject IStringLocalizer Localizer @inject IStringLocalizer SharedLocalizer - - -
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
-
+
+ +
- +
- +
- +
- +
- +
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- +
-
-
- -
-
- +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ + +
+
+ +
-
- - - -@SharedLocalizer["Cancel"] -
-
- + + + + @SharedLocalizer["Cancel"] +
+
+ + @code { + private ElementReference form; + private bool validated = false; private int _moduleDefinitionId; private string _name; private string _version; @@ -146,30 +150,39 @@ private async Task SaveModuleDefinition() { - try + validated = true; + var interop = new Interop(JSRuntime); + if (await interop.FormValid(form)) { - var moduledefinition = await ModuleDefinitionService.GetModuleDefinitionAsync(_moduleDefinitionId, ModuleState.SiteId); - if (moduledefinition.Name != _name) + try { - moduledefinition.Name = _name; + var moduledefinition = await ModuleDefinitionService.GetModuleDefinitionAsync(_moduleDefinitionId, ModuleState.SiteId); + if (moduledefinition.Name != _name) + { + moduledefinition.Name = _name; + } + if (moduledefinition.Description != _description) + { + moduledefinition.Description = _description; + } + if (moduledefinition.Categories != _categories) + { + moduledefinition.Categories = _categories; + } + moduledefinition.Permissions = _permissionGrid.GetPermissions(); + await ModuleDefinitionService.UpdateModuleDefinitionAsync(moduledefinition); + await logger.LogInformation("ModuleDefinition Saved {ModuleDefinition}", moduledefinition); + NavigationManager.NavigateTo(NavigateUrl()); } - if (moduledefinition.Description != _description) + catch (Exception ex) { - moduledefinition.Description = _description; + await logger.LogError(ex, "Error Saving ModuleDefinition {ModuleDefinitionId} {Error}", _moduleDefinitionId, ex.Message); + AddModuleMessage(Localizer["Error.Module.Save"], MessageType.Error); } - if (moduledefinition.Categories != _categories) - { - moduledefinition.Categories = _categories; - } - moduledefinition.Permissions = _permissionGrid.GetPermissions(); - await ModuleDefinitionService.UpdateModuleDefinitionAsync(moduledefinition); - await logger.LogInformation("ModuleDefinition Saved {ModuleDefinition}", moduledefinition); - NavigationManager.NavigateTo(NavigateUrl()); } - catch (Exception ex) + else { - await logger.LogError(ex, "Error Saving ModuleDefinition {ModuleDefinitionId} {Error}", _moduleDefinitionId, ex.Message); - AddModuleMessage(Localizer["Error.Module.Save"], MessageType.Error); + AddModuleMessage(SharedLocalizer["Message.InfoRequired"], MessageType.Warning); } } } diff --git a/Oqtane.Client/Modules/Admin/Modules/Export.razor b/Oqtane.Client/Modules/Admin/Modules/Export.razor index d02706ef..d3977dc3 100644 --- a/Oqtane.Client/Modules/Admin/Modules/Export.razor +++ b/Oqtane.Client/Modules/Admin/Modules/Export.razor @@ -5,28 +5,39 @@ @inject IStringLocalizer Localizer @inject IStringLocalizer SharedLocalizer +
- +
@SharedLocalizer["Cancel"] +
+ +@code { + private ElementReference form; + private bool validated = false; + private string _content = string.Empty; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; + public override string Title => "Export Content"; - @code { - private string _content = string.Empty; - - public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; - public override string Title => "Export Content"; - - - private async Task ExportModule() + private async Task ExportModule() + { + validated = true; + var interop = new Interop(JSRuntime); + if (await interop.FormValid(form)) { _content = await ModuleService.ExportModuleAsync(ModuleState.ModuleId); } + else + { + AddModuleMessage(SharedLocalizer["Message.InfoRequired"], MessageType.Warning); + } } +} diff --git a/Oqtane.Client/Modules/Admin/Modules/Import.razor b/Oqtane.Client/Modules/Admin/Modules/Import.razor index 33b7a8d4..709317ed 100644 --- a/Oqtane.Client/Modules/Admin/Modules/Import.razor +++ b/Oqtane.Client/Modules/Admin/Modules/Import.razor @@ -5,6 +5,7 @@ @inject IStringLocalizer Localizer @inject IStringLocalizer SharedLocalizer +
@@ -17,15 +18,21 @@ @SharedLocalizer["Cancel"] + +@code { + private string _content = string.Empty; + private ElementReference form; + private bool validated = false; - @code { - private string _content = string.Empty; + public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; + public override string Title => "Import Content"; - public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; - public override string Title => "Import Content"; - - private async Task ImportModule() + private async Task ImportModule() + { + validated = true; + var interop = new Interop(JSRuntime); + if (await interop.FormValid(form)) { if (_content != string.Empty) { @@ -52,4 +59,9 @@ AddModuleMessage(Localizer["Message.Required.ImportContent"], MessageType.Warning); } } + else + { + AddModuleMessage(SharedLocalizer["Message.InfoRequired"], MessageType.Warning); + } } +} diff --git a/Oqtane.Client/Modules/Admin/Modules/Settings.razor b/Oqtane.Client/Modules/Admin/Modules/Settings.razor index cbf32fef..c2c3f6ef 100644 --- a/Oqtane.Client/Modules/Admin/Modules/Settings.razor +++ b/Oqtane.Client/Modules/Admin/Modules/Settings.razor @@ -8,88 +8,92 @@ @inject IStringLocalizer Localizer @inject IStringLocalizer SharedLocalizer - - - @if (_containers != null) - { -
-
- -
- +
+ + + @if (_containers != null) + { +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
-
-
- -
- + } + + + @if (_permissions != null) + { +
+
+ +
-
-
- -
- -
-
-
- -
- -
-
-
- } - - - @if (_permissions != null) - { -
-
- -
-
+ } +
+ @if (_moduleSettingsType != null) + { + + @ModuleSettingsComponent + } - - @if (_moduleSettingsType != null) - { - - @ModuleSettingsComponent - - } - @if (_containerSettingsType != null) - { - - @ContainerSettingsComponent - - } - - -@SharedLocalizer["Cancel"] -
-
- + @if (_containerSettingsType != null) + { + + @ContainerSettingsComponent + + } + + + @SharedLocalizer["Cancel"] +
+
+ + @code { public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Edit; public override string Title => "Module Settings"; + private ElementReference form; + private bool validated = false; private List _themes; private List _containers = new List(); private string _title; @@ -170,52 +174,61 @@ private async Task SaveModule() { - if (!string.IsNullOrEmpty(_title)) + validated = true; + var interop = new Interop(JSRuntime); + if (await interop.FormValid(form)) { - var pagemodule = await PageModuleService.GetPageModuleAsync(ModuleState.PageModuleId); - pagemodule.PageId = int.Parse(_pageId); - pagemodule.Title = _title; - pagemodule.ContainerType = (_containerType != "-") ? _containerType : string.Empty; - if (!string.IsNullOrEmpty(pagemodule.ContainerType) && pagemodule.ContainerType == PageState.Page.DefaultContainerType) + if (!string.IsNullOrEmpty(_title)) { - pagemodule.ContainerType = string.Empty; - } - if (!string.IsNullOrEmpty(pagemodule.ContainerType) && pagemodule.ContainerType == PageState.Site.DefaultContainerType) - { - pagemodule.ContainerType = string.Empty; - } - await PageModuleService.UpdatePageModuleAsync(pagemodule); - await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane); - - var module = ModuleState; - module.AllPages = bool.Parse(_allPages); - module.Permissions = _permissionGrid.GetPermissions(); - await ModuleService.UpdateModuleAsync(module); - - if (_moduleSettingsType != null) - { - if (_moduleSettings is ISettingsControl moduleSettingsControl) + var pagemodule = await PageModuleService.GetPageModuleAsync(ModuleState.PageModuleId); + pagemodule.PageId = int.Parse(_pageId); + pagemodule.Title = _title; + pagemodule.ContainerType = (_containerType != "-") ? _containerType : string.Empty; + if (!string.IsNullOrEmpty(pagemodule.ContainerType) && pagemodule.ContainerType == PageState.Page.DefaultContainerType) { - // module settings updated using explicit interface - await moduleSettingsControl.UpdateSettings(); + pagemodule.ContainerType = string.Empty; } - else + if (!string.IsNullOrEmpty(pagemodule.ContainerType) && pagemodule.ContainerType == PageState.Site.DefaultContainerType) { - // legacy support - module settings updated by convention ( ie. by calling a public method named "UpdateSettings" in settings component ) - _moduleSettings?.GetType().GetMethod("UpdateSettings")?.Invoke(_moduleSettings, null); + pagemodule.ContainerType = string.Empty; } - } + await PageModuleService.UpdatePageModuleAsync(pagemodule); + await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane); - if (_containerSettingsType != null && _containerSettings is ISettingsControl containerSettingsControl) + var module = ModuleState; + module.AllPages = bool.Parse(_allPages); + module.Permissions = _permissionGrid.GetPermissions(); + await ModuleService.UpdateModuleAsync(module); + + if (_moduleSettingsType != null) + { + if (_moduleSettings is ISettingsControl moduleSettingsControl) + { + // module settings updated using explicit interface + await moduleSettingsControl.UpdateSettings(); + } + else + { + // legacy support - module settings updated by convention ( ie. by calling a public method named "UpdateSettings" in settings component ) + _moduleSettings?.GetType().GetMethod("UpdateSettings")?.Invoke(_moduleSettings, null); + } + } + + if (_containerSettingsType != null && _containerSettings is ISettingsControl containerSettingsControl) + { + await containerSettingsControl.UpdateSettings(); + } + + NavigationManager.NavigateTo(NavigateUrl()); + } + else { - await containerSettingsControl.UpdateSettings(); + AddModuleMessage(Localizer["Message.Required.Title"], MessageType.Warning); } - - NavigationManager.NavigateTo(NavigateUrl()); } else { - AddModuleMessage(Localizer["Message.Required.Title"], MessageType.Warning); + AddModuleMessage(SharedLocalizer["Message.InfoRequired"], MessageType.Warning); } } diff --git a/Oqtane.Client/Modules/Admin/Pages/Add.razor b/Oqtane.Client/Modules/Admin/Pages/Add.razor index 7190ea8f..bfca6df5 100644 --- a/Oqtane.Client/Modules/Admin/Pages/Add.razor +++ b/Oqtane.Client/Modules/Admin/Pages/Add.razor @@ -6,151 +6,154 @@ @inject IStringLocalizer Localizer @inject IStringLocalizer SharedLocalizer - - - @if (_themeList != null) - { -
-
- -
- -
-
-
- -
- -
-
-
- -
- - @if (_children != null && _children.Count > 0 && (_insert == "<" || _insert == ">")) - { - - } -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
-
+
+ + + @if (_themeList != null) + {
- +
- +
- +
- + + @foreach (Page page in _pageList) { - + }
- +
- + + @if (_children != null && _children.Count > 0) { - + + } + + @if (_children != null && _children.Count > 0 && (_insert == "<" || _insert == ">")) + { + + }
- +
- -
-
-
- -
-
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
-
- } -
- -
-
- -
-
-
- @if (_themeSettingsType != null) - { - - @ThemeSettingsComponent + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ }
- } -
- - + +
+
+ +
+
+
+ @if (_themeSettingsType != null) + { + + @ThemeSettingsComponent + + } + + + + @code { public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; @@ -179,6 +182,8 @@ private object _themeSettings; private RenderFragment ThemeSettingsComponent { get; set; } private bool _refresh = false; + private ElementReference form; + private bool validated = false; protected override async Task OnInitializedAsync() { @@ -275,110 +280,119 @@ private async Task SavePage() { - Page page = null; - try + validated = true; + var interop = new Interop(JSRuntime); + if (await interop.FormValid(form)) { - if (!string.IsNullOrEmpty(_name) && !string.IsNullOrEmpty(_themetype) && _containertype != "-") + Page page = null; + try { - page = new Page(); - page.SiteId = PageState.Page.SiteId; - page.Name = _name; - page.Title = _title; - if (_path == "") + if (!string.IsNullOrEmpty(_name) && !string.IsNullOrEmpty(_themetype) && _containertype != "-") { - _path = _name; - } - - if (_path.Contains("/")) - { - _path = _path.Substring(_path.LastIndexOf("/") + 1); - } - - if (string.IsNullOrEmpty(_parentid)) - { - page.ParentId = null; - page.Path = Utilities.GetFriendlyUrl(_path); - } - else - { - page.ParentId = Int32.Parse(_parentid); - var parent = PageState.Pages.Where(item => item.PageId == page.ParentId).FirstOrDefault(); - if (parent.Path == string.Empty) + page = new Page(); + page.SiteId = PageState.Page.SiteId; + page.Name = _name; + page.Title = _title; + if (_path == "") { - page.Path = Utilities.GetFriendlyUrl(parent.Name) + "/" + Utilities.GetFriendlyUrl(_path); + _path = _name; + } + + if (_path.Contains("/")) + { + _path = _path.Substring(_path.LastIndexOf("/") + 1); + } + + if (string.IsNullOrEmpty(_parentid)) + { + page.ParentId = null; + page.Path = Utilities.GetFriendlyUrl(_path); } else { - page.Path = parent.Path + "/" + Utilities.GetFriendlyUrl(_path); + page.ParentId = Int32.Parse(_parentid); + var parent = PageState.Pages.Where(item => item.PageId == page.ParentId).FirstOrDefault(); + 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, _pageList)) - { - AddModuleMessage(string.Format(Localizer["Message.Page.Exists"], _path), MessageType.Warning); - return; - } + if (!PagePathIsUnique(page.Path, page.SiteId, _pageList)) + { + AddModuleMessage(string.Format(Localizer["Message.Page.Exists"], _path), MessageType.Warning); + return; + } - Page child; - switch (_insert) - { - case "<<": - page.Order = 0; - break; - case "<": - child = PageState.Pages.Where(item => item.PageId == _childid).FirstOrDefault(); - page.Order = child.Order - 1; - break; - case ">": - child = PageState.Pages.Where(item => item.PageId == _childid).FirstOrDefault(); - page.Order = child.Order + 1; - break; - case ">>": - page.Order = int.MaxValue; - break; - } + Page child; + switch (_insert) + { + case "<<": + page.Order = 0; + break; + case "<": + child = PageState.Pages.Where(item => item.PageId == _childid).FirstOrDefault(); + page.Order = child.Order - 1; + break; + case ">": + child = PageState.Pages.Where(item => item.PageId == _childid).FirstOrDefault(); + page.Order = child.Order + 1; + break; + case ">>": + page.Order = int.MaxValue; + break; + } - page.IsNavigation = (_isnavigation == null ? true : 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 == null ? string.Empty : _icon); - page.Permissions = _permissionGrid.GetPermissions(); - page.IsPersonalizable = (_ispersonalizable == null ? false : Boolean.Parse(_ispersonalizable)); - page.UserId = null; + page.IsNavigation = (_isnavigation == null ? true : 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 == null ? string.Empty : _icon); + page.Permissions = _permissionGrid.GetPermissions(); + page.IsPersonalizable = (_ispersonalizable == null ? false : Boolean.Parse(_ispersonalizable)); + page.UserId = null; - page = await PageService.AddPageAsync(page); - await PageService.UpdatePageOrderAsync(page.SiteId, page.PageId, page.ParentId); + page = await PageService.AddPageAsync(page); + await PageService.UpdatePageOrderAsync(page.SiteId, page.PageId, page.ParentId); - await logger.LogInformation("Page Added {Page}", page); - if (PageState.QueryString.ContainsKey("cp")) - { - NavigationManager.NavigateTo(NavigateUrl(PageState.Pages.First(item => item.PageId == int.Parse(PageState.QueryString["cp"])).Path)); + await logger.LogInformation("Page Added {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 { - NavigationManager.NavigateTo(NavigateUrl(page.Path)); + AddModuleMessage(Localizer["Message.Required.PageInfo"], MessageType.Warning); } - } - 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); + } } - catch (Exception ex) + else { - await logger.LogError(ex, "Error Saving Page {Page} {Error}", page, ex.Message); - AddModuleMessage(Localizer["Error.Page.Save"], MessageType.Error); + AddModuleMessage(SharedLocalizer["Message.InfoRequired"], MessageType.Warning); } } diff --git a/Oqtane.Client/Modules/Admin/Pages/Edit.razor b/Oqtane.Client/Modules/Admin/Pages/Edit.razor index 5b55f62c..24bc32ca 100644 --- a/Oqtane.Client/Modules/Admin/Pages/Edit.razor +++ b/Oqtane.Client/Modules/Admin/Pages/Edit.razor @@ -7,168 +7,172 @@ @inject IStringLocalizer Localizer @inject IStringLocalizer SharedLocalizer - - - @if (_themeList != null) - { -
-
- -
- -
-
-
- -
- -
-
-
- -
- - @if (_children != null && _children.Count > 0 && (_insert == "<" || _insert == ">")) - { - - } -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
-
+
+ + + @if (_themeList != null) + {
- +
- +
- +
- + + @foreach (Page page in _pageList) { - + if (page.PageId != _pageId) + { + + } }
- +
- + @if (_parentid == _currentparentid) { - + } + + @if (_children != null && _children.Count > 0) + { + + + } + + @if (_children != null && _children.Count > 0 && (_insert == "<" || _insert == ">")) + { + + }
- +
- -
-
-
- -
-
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
-
-

- - } -
- - @if (_permissions != null) - { -
-
- - -
-
- - } -
- @if (_themeSettingsType != null) - { - - @ThemeSettingsComponent +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+

+ + }
- } -
- - + + @if (_permissions != null) + { +
+
+ + +
+
+ + } +
+ @if (_themeSettingsType != null) + { + + @ThemeSettingsComponent + + } + + + + @code { public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.Admin; + private ElementReference form; + private bool validated = false; private List _themeList; private List _themes = new List(); private List _containers = new List(); @@ -351,134 +355,143 @@ private async Task SavePage() { - Page page = null; - try + validated = true; + var interop = new Interop(JSRuntime); + if (await interop.FormValid(form)) { - if (_name != string.Empty && !string.IsNullOrEmpty(_themetype) && _containertype != "-") + Page page = null; + try { - page = PageState.Pages.FirstOrDefault(item => item.PageId == _pageId); - string currentPath = page.Path; + 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") + page.Name = _name; + page.Title = _title; + if (_path == "" && _name.ToLower() != "home") + if (_path == string.Empty && _name.ToLower() != "home") + { + _path = _name; + } + if (_path.Contains("/")) { - _path = _name; + _path = _path.Substring(_path.LastIndexOf("/") + 1); } - 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) + if (string.IsNullOrEmpty(_parentid) || _parentid == "-1") { - page.Path = Utilities.GetFriendlyUrl(parent.Name) + "/" + Utilities.GetFriendlyUrl(_path); + page.ParentId = null; + page.Path = Utilities.GetFriendlyUrl(_path); } else { - page.Path = parent.Path + "/" + Utilities.GetFriendlyUrl(_path); + 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) + if (!PagePathIsUnique(page.Path, page.SiteId, page.PageId, _pageList)) { - 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; + AddModuleMessage(string.Format(Localizer["Mesage.Page.PathExists"], _path), MessageType.Warning); + return; } - } - 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); + 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 { - 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)); + AddModuleMessage(Localizer["Message.Required.PageInfo"], MessageType.Warning); } } - else + catch (Exception ex) { - AddModuleMessage(Localizer["Message.Required.PageInfo"], MessageType.Warning); + await logger.LogError(ex, "Error Saving Page {Page} {Error}", page, ex.Message); + AddModuleMessage(Localizer["Error.Page.Save"], MessageType.Error); } } - catch (Exception ex) + else { - await logger.LogError(ex, "Error Saving Page {Page} {Error}", page, ex.Message); - AddModuleMessage(Localizer["Error.Page.Save"], MessageType.Error); + AddModuleMessage(SharedLocalizer["Message.InfoRequired"], MessageType.Warning); } } diff --git a/Oqtane.Client/Modules/Admin/Profiles/Edit.razor b/Oqtane.Client/Modules/Admin/Profiles/Edit.razor index 0a6ce896..a334c2bb 100644 --- a/Oqtane.Client/Modules/Admin/Profiles/Edit.razor +++ b/Oqtane.Client/Modules/Admin/Profiles/Edit.razor @@ -5,86 +5,90 @@ @inject IStringLocalizer Localizer @inject IStringLocalizer SharedLocalizer -
-
- -
- +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
-
- -@SharedLocalizer["Cancel"] -@if (PageState.QueryString.ContainsKey("id")) -{
-
- -} + + @SharedLocalizer["Cancel"] + @if (PageState.QueryString.ContainsKey("id")) + { +
+
+ + } + @code { private int _profileid = -1; + private ElementReference form; + private bool validated = false; private string _name = string.Empty; private string _title = string.Empty; private string _description = string.Empty; @@ -140,45 +144,54 @@ private async Task SaveProfile() { - try + validated = true; + var interop = new Interop(JSRuntime); + if (await interop.FormValid(form)) { - Profile profile; - if (_profileid != -1) + try { - profile = await ProfileService.GetProfileAsync(_profileid); - } - else - { - profile = new Profile(); - } + Profile profile; + if (_profileid != -1) + { + profile = await ProfileService.GetProfileAsync(_profileid); + } + else + { + profile = new Profile(); + } - profile.SiteId = PageState.Site.SiteId; - profile.Name = _name; - profile.Title = _title; - profile.Description = _description; - profile.Category = _category; - profile.ViewOrder = int.Parse(_vieworder); - profile.MaxLength = int.Parse(_maxlength); - profile.DefaultValue = _defaultvalue; - profile.Options = _options; - profile.IsRequired = (_isrequired == null ? false : Boolean.Parse(_isrequired)); - profile.IsPrivate = (_isprivate == null ? false : Boolean.Parse(_isprivate)); - if (_profileid != -1) - { - profile = await ProfileService.UpdateProfileAsync(profile); - } - else - { - profile = await ProfileService.AddProfileAsync(profile); - } + profile.SiteId = PageState.Site.SiteId; + profile.Name = _name; + profile.Title = _title; + profile.Description = _description; + profile.Category = _category; + profile.ViewOrder = int.Parse(_vieworder); + profile.MaxLength = int.Parse(_maxlength); + profile.DefaultValue = _defaultvalue; + profile.Options = _options; + profile.IsRequired = (_isrequired == null ? false : Boolean.Parse(_isrequired)); + profile.IsPrivate = (_isprivate == null ? false : Boolean.Parse(_isprivate)); + if (_profileid != -1) + { + profile = await ProfileService.UpdateProfileAsync(profile); + } + else + { + profile = await ProfileService.AddProfileAsync(profile); + } - await logger.LogInformation("Profile Saved {Profile}", profile); - NavigationManager.NavigateTo(NavigateUrl()); + await logger.LogInformation("Profile Saved {Profile}", profile); + NavigationManager.NavigateTo(NavigateUrl()); + } + catch (Exception ex) + { + await logger.LogError(ex, "Error Saving Profile {ProfleId} {Error}", _profileid, ex.Message); + AddModuleMessage(Localizer["Error.Profile.Save"], MessageType.Error); + } } - catch (Exception ex) + else { - await logger.LogError(ex, "Error Saving Profile {ProfleId} {Error}", _profileid, ex.Message); - AddModuleMessage(Localizer["Error.Profile.Save"], MessageType.Error); + AddModuleMessage(SharedLocalizer["Message.InfoRequired"], MessageType.Warning); } } }