From 61266246311e8182c7fffa060e6d4580b5708d3e Mon Sep 17 00:00:00 2001 From: sbwalker Date: Fri, 23 Jun 2023 07:38:33 -0400 Subject: [PATCH 1/4] add validation logic to ensure page theme martches site theme --- Oqtane.Client/Modules/Admin/Pages/Edit.razor | 2 +- Oqtane.Client/Services/Interfaces/IThemeService.cs | 7 +++++++ Oqtane.Client/Services/ThemeService.cs | 9 +++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Oqtane.Client/Modules/Admin/Pages/Edit.razor b/Oqtane.Client/Modules/Admin/Pages/Edit.razor index 7ff54a15..f77c3970 100644 --- a/Oqtane.Client/Modules/Admin/Pages/Edit.razor +++ b/Oqtane.Client/Modules/Admin/Pages/Edit.razor @@ -355,7 +355,7 @@ // appearance _title = _page.Title; _themetype = _page.ThemeType; - if (string.IsNullOrEmpty(_themetype)) + if (string.IsNullOrEmpty(_themetype) || ThemeService.GetTheme(PageState.Site.Themes, _themetype)?.ThemeName != ThemeService.GetTheme(PageState.Site.Themes, PageState.Site.DefaultThemeType)?.ThemeName) { _themetype = PageState.Site.DefaultThemeType; } diff --git a/Oqtane.Client/Services/Interfaces/IThemeService.cs b/Oqtane.Client/Services/Interfaces/IThemeService.cs index aafff7b2..6ad83fba 100644 --- a/Oqtane.Client/Services/Interfaces/IThemeService.cs +++ b/Oqtane.Client/Services/Interfaces/IThemeService.cs @@ -24,6 +24,13 @@ namespace Oqtane.Services /// Task GetThemeAsync(int themeId, int siteId); + /// + /// Returns a theme s containing a theme control type + /// + /// + /// + Theme GetTheme(List themes, string themeType); + /// /// Returns a list of s from the given themes /// diff --git a/Oqtane.Client/Services/ThemeService.cs b/Oqtane.Client/Services/ThemeService.cs index b86b63e1..e4cf06d6 100644 --- a/Oqtane.Client/Services/ThemeService.cs +++ b/Oqtane.Client/Services/ThemeService.cs @@ -26,6 +26,11 @@ namespace Oqtane.Services return await GetJsonAsync($"{ApiUrl}/{themeId}?siteid={siteId}"); } + public Theme GetTheme(List themes, string themeType) + { + return themes.FirstOrDefault(item => item.Themes.Any(item => item.TypeName == themeType)); + } + public List GetThemeControls(List themes) { return themes.SelectMany(item => item.Themes).OrderBy(item => item.Name).ToList(); @@ -33,13 +38,13 @@ namespace Oqtane.Services public List GetThemeControls(List themes, string themeType) { - return themes.First(item => item.Themes.Any(item => item.TypeName == themeType)).Themes.OrderBy(item => item.Name).ToList(); + return GetTheme(themes, themeType)?.Themes.OrderBy(item => item.Name).ToList(); } public List GetContainerControls(List themes, string themeType) { - return themes.First(item => item.Themes.Any(item => item.TypeName == themeType)).Containers.OrderBy(item => item.Name).ToList(); + return GetTheme(themes, themeType)?.Containers.OrderBy(item => item.Name).ToList(); } public async Task UpdateThemeAsync(Theme theme) From ee4068d67129bf3750b96a6cf9a027e1bf9c610d Mon Sep 17 00:00:00 2001 From: sbwalker Date: Fri, 23 Jun 2023 07:44:15 -0400 Subject: [PATCH 2/4] clarify documentation and parameter names --- .../Services/Interfaces/IThemeService.cs | 16 +++++++++------- Oqtane.Client/Services/ThemeService.cs | 12 ++++++------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Oqtane.Client/Services/Interfaces/IThemeService.cs b/Oqtane.Client/Services/Interfaces/IThemeService.cs index 6ad83fba..4dc636c2 100644 --- a/Oqtane.Client/Services/Interfaces/IThemeService.cs +++ b/Oqtane.Client/Services/Interfaces/IThemeService.cs @@ -25,11 +25,12 @@ namespace Oqtane.Services Task GetThemeAsync(int themeId, int siteId); /// - /// Returns a theme s containing a theme control type + /// Returns a theme s containing a specific theme control type /// /// + /// /// - Theme GetTheme(List themes, string themeType); + Theme GetTheme(List themes, string themeControlType); /// /// Returns a list of s from the given themes @@ -39,19 +40,20 @@ namespace Oqtane.Services List GetThemeControls(List themes); /// - /// Returns a list of s from the given themes with a matching theme type + /// Returns a list of s for a theme containing a specific theme control type /// /// + /// /// - List GetThemeControls(List themes, string themeType); + List GetThemeControls(List themes, string themeControlType); /// - /// Returns a list of containers () from the given themes with a matching theme type + /// Returns a list of containers () for a theme containing a specific theme control type /// /// - /// + /// /// - List GetContainerControls(List themes, string themeType); + List GetContainerControls(List themes, string themeControlType); /// /// Updates a existing theem diff --git a/Oqtane.Client/Services/ThemeService.cs b/Oqtane.Client/Services/ThemeService.cs index e4cf06d6..d1c03495 100644 --- a/Oqtane.Client/Services/ThemeService.cs +++ b/Oqtane.Client/Services/ThemeService.cs @@ -26,9 +26,9 @@ namespace Oqtane.Services return await GetJsonAsync($"{ApiUrl}/{themeId}?siteid={siteId}"); } - public Theme GetTheme(List themes, string themeType) + public Theme GetTheme(List themes, string themeControlType) { - return themes.FirstOrDefault(item => item.Themes.Any(item => item.TypeName == themeType)); + return themes.FirstOrDefault(item => item.Themes.Any(item => item.TypeName == themeControlType)); } public List GetThemeControls(List themes) @@ -36,15 +36,15 @@ namespace Oqtane.Services return themes.SelectMany(item => item.Themes).OrderBy(item => item.Name).ToList(); } - public List GetThemeControls(List themes, string themeType) + public List GetThemeControls(List themes, string themeControlType) { - return GetTheme(themes, themeType)?.Themes.OrderBy(item => item.Name).ToList(); + return GetTheme(themes, themeControlType)?.Themes.OrderBy(item => item.Name).ToList(); } - public List GetContainerControls(List themes, string themeType) + public List GetContainerControls(List themes, string themeControlType) { - return GetTheme(themes, themeType)?.Containers.OrderBy(item => item.Name).ToList(); + return GetTheme(themes, themeControlType)?.Containers.OrderBy(item => item.Name).ToList(); } public async Task UpdateThemeAsync(Theme theme) From 2ff365765d67184f42811a66bbedaed241624807 Mon Sep 17 00:00:00 2001 From: sbwalker Date: Fri, 23 Jun 2023 08:07:06 -0400 Subject: [PATCH 3/4] fix ordering of stylesheets --- Oqtane.Server/Pages/_Host.cshtml | 1 + Oqtane.Server/Pages/_Host.cshtml.cs | 51 ++++++++++++++--------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Oqtane.Server/Pages/_Host.cshtml b/Oqtane.Server/Pages/_Host.cshtml index 4aee45f2..af8444f8 100644 --- a/Oqtane.Server/Pages/_Host.cshtml +++ b/Oqtane.Server/Pages/_Host.cshtml @@ -15,6 +15,7 @@ { } + @Html.Raw(Model.StyleSheets) diff --git a/Oqtane.Server/Pages/_Host.cshtml.cs b/Oqtane.Server/Pages/_Host.cshtml.cs index 5a946859..55ddb127 100644 --- a/Oqtane.Server/Pages/_Host.cshtml.cs +++ b/Oqtane.Server/Pages/_Host.cshtml.cs @@ -21,7 +21,6 @@ using Oqtane.Security; using Oqtane.Extensions; using Oqtane.Themes; using System.Collections.Generic; -using Oqtane.UI; namespace Oqtane.Pages { @@ -69,6 +68,7 @@ namespace Oqtane.Pages public string RemoteIPAddress = ""; public string HeadResources = ""; public string BodyResources = ""; + public string StyleSheets = ""; public string PWAScript = ""; public string ReconnectScript = ""; public string Message = ""; @@ -167,26 +167,29 @@ namespace Oqtane.Pages } // stylesheets - var resources = new List(); - if (string.IsNullOrEmpty(page.ThemeType)) + if (!HttpContext.Request.Query.ContainsKey("method") || (HttpContext.Request.Query.ContainsKey("method") && HttpContext.Request.Query["method"] == "old")) { - page.ThemeType = site.DefaultThemeType; - } - var theme = site.Themes.FirstOrDefault(item => item.Themes.Any(item => item.TypeName == page.ThemeType)); - if (theme?.Resources != null) - { - resources.AddRange(theme.Resources.Where(item => item.ResourceType == ResourceType.Stylesheet).ToList()); - } - var type = Type.GetType(page.ThemeType); - if (type != null) - { - var obj = Activator.CreateInstance(type) as IThemeControl; - if (obj?.Resources != null) + var resources = new List(); + if (string.IsNullOrEmpty(page.ThemeType)) { - resources.AddRange(obj.Resources.Where(item => item.ResourceType == ResourceType.Stylesheet).ToList()); + page.ThemeType = site.DefaultThemeType; } + var theme = site.Themes.FirstOrDefault(item => item.Themes.Any(item => item.TypeName == page.ThemeType)); + if (theme?.Resources != null) + { + resources.AddRange(theme.Resources.Where(item => item.ResourceType == ResourceType.Stylesheet).ToList()); + } + var type = Type.GetType(page.ThemeType); + if (type != null) + { + var obj = Activator.CreateInstance(type) as IThemeControl; + if (obj?.Resources != null) + { + resources.AddRange(obj.Resources.Where(item => item.ResourceType == ResourceType.Stylesheet).ToList()); + } + } + ManageStyleSheets(resources, alias, theme.ThemeName); } - ManageResources(resources, alias, theme.ThemeName); // scripts if (Runtime == "Server") @@ -494,7 +497,7 @@ namespace Oqtane.Pages CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture))); } - private void ManageResources(List resources, Alias alias, string name) + private void ManageStyleSheets(List resources, Alias alias, string name) { if (resources != null) { @@ -510,15 +513,11 @@ namespace Oqtane.Pages resource.Url = alias.BaseUrl + resource.Url; } - if (!HeadResources.Contains(resource.Url, StringComparison.OrdinalIgnoreCase)) + if (!StyleSheets.Contains(resource.Url, StringComparison.OrdinalIgnoreCase)) { - string id = ""; - if (!HttpContext.Request.Query.ContainsKey("method") || (HttpContext.Request.Query.ContainsKey("method") && HttpContext.Request.Query["method"] == "old")) - { - count++; - id = "id=\"app-stylesheet-" + ResourceLevel.Page.ToString().ToLower() + "-" + DateTime.UtcNow.ToString("yyyyMMddHHmmssfff") + "-" + count.ToString("00") + "\" "; - } - HeadResources += "" + Environment.NewLine; + count++; + string id = "id=\"app-stylesheet-" + ResourceLevel.Page.ToString().ToLower() + "-" + DateTime.UtcNow.ToString("yyyyMMddHHmmssfff") + "-" + count.ToString("00") + "\" "; + StyleSheets += "" + Environment.NewLine; } } } From f6cca5cb3538ee5752e201dcc7b07cc55a95a63a Mon Sep 17 00:00:00 2001 From: sbwalker Date: Fri, 23 Jun 2023 08:16:39 -0400 Subject: [PATCH 4/4] allow for testing CSS page transitions --- Oqtane.Client/Themes/Controls/Theme/MenuBase.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Oqtane.Client/Themes/Controls/Theme/MenuBase.cs b/Oqtane.Client/Themes/Controls/Theme/MenuBase.cs index 689b7a04..dd697ef0 100644 --- a/Oqtane.Client/Themes/Controls/Theme/MenuBase.cs +++ b/Oqtane.Client/Themes/Controls/Theme/MenuBase.cs @@ -19,7 +19,12 @@ namespace Oqtane.Themes.Controls { if (page.IsClickable) { - return string.IsNullOrEmpty(page.Url) ? NavigateUrl(page.Path) : page.Url; + var url = string.IsNullOrEmpty(page.Url) ? NavigateUrl(page.Path) : page.Url; + if (PageState.QueryString.ContainsKey("method")) + { + url += ((url.Contains("?")) ? "&" : "?") + "method=" + PageState.QueryString["method"]; + } + return url; } else {