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..6709d60e 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); } }