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..4dc636c2 100644 --- a/Oqtane.Client/Services/Interfaces/IThemeService.cs +++ b/Oqtane.Client/Services/Interfaces/IThemeService.cs @@ -24,6 +24,14 @@ namespace Oqtane.Services /// Task GetThemeAsync(int themeId, int siteId); + /// + /// Returns a theme s containing a specific theme control type + /// + /// + /// + /// + Theme GetTheme(List themes, string themeControlType); + /// /// Returns a list of s from the given themes /// @@ -32,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 b86b63e1..d1c03495 100644 --- a/Oqtane.Client/Services/ThemeService.cs +++ b/Oqtane.Client/Services/ThemeService.cs @@ -26,20 +26,25 @@ namespace Oqtane.Services return await GetJsonAsync($"{ApiUrl}/{themeId}?siteid={siteId}"); } + public Theme GetTheme(List themes, string themeControlType) + { + return themes.FirstOrDefault(item => item.Themes.Any(item => item.TypeName == themeControlType)); + } + public List GetThemeControls(List themes) { 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 themes.First(item => item.Themes.Any(item => item.TypeName == 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 themes.First(item => item.Themes.Any(item => item.TypeName == themeType)).Containers.OrderBy(item => item.Name).ToList(); + return GetTheme(themes, themeControlType)?.Containers.OrderBy(item => item.Name).ToList(); } public async Task UpdateThemeAsync(Theme theme) 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 { 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; } } }