Merge remote-tracking branch 'oqtane/dev' into dev

This commit is contained in:
Leigh Pointer 2023-06-23 14:32:00 +02:00
commit ef8c47a49f
6 changed files with 56 additions and 37 deletions

View File

@ -355,7 +355,7 @@
// appearance // appearance
_title = _page.Title; _title = _page.Title;
_themetype = _page.ThemeType; _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; _themetype = PageState.Site.DefaultThemeType;
} }

View File

@ -24,6 +24,14 @@ namespace Oqtane.Services
/// <returns></returns> /// <returns></returns>
Task<Theme> GetThemeAsync(int themeId, int siteId); Task<Theme> GetThemeAsync(int themeId, int siteId);
/// <summary>
/// Returns a theme <see cref="ThemeControl"/>s containing a specific theme control type
/// </summary>
/// <param name="themes"></param>
/// <param name="themeControlType"></param>
/// <returns></returns>
Theme GetTheme(List<Theme> themes, string themeControlType);
/// <summary> /// <summary>
/// Returns a list of <see cref="ThemeControl"/>s from the given themes /// Returns a list of <see cref="ThemeControl"/>s from the given themes
/// </summary> /// </summary>
@ -32,19 +40,20 @@ namespace Oqtane.Services
List<ThemeControl> GetThemeControls(List<Theme> themes); List<ThemeControl> GetThemeControls(List<Theme> themes);
/// <summary> /// <summary>
/// Returns a list of <see cref="ThemeControl"/>s from the given themes with a matching theme type /// Returns a list of <see cref="ThemeControl"/>s for a theme containing a specific theme control type
/// </summary> /// </summary>
/// <param name="themes"></param> /// <param name="themes"></param>
/// <param name="themeControlType"></param>
/// <returns></returns> /// <returns></returns>
List<ThemeControl> GetThemeControls(List<Theme> themes, string themeType); List<ThemeControl> GetThemeControls(List<Theme> themes, string themeControlType);
/// <summary> /// <summary>
/// Returns a list of containers (<see cref="ThemeControl"/>) from the given themes with a matching theme type /// Returns a list of containers (<see cref="ThemeControl"/>) for a theme containing a specific theme control type
/// </summary> /// </summary>
/// <param name="themes"></param> /// <param name="themes"></param>
/// <param name="themeName"></param> /// <param name="themeControlType"></param>
/// <returns></returns> /// <returns></returns>
List<ThemeControl> GetContainerControls(List<Theme> themes, string themeType); List<ThemeControl> GetContainerControls(List<Theme> themes, string themeControlType);
/// <summary> /// <summary>
/// Updates a existing theem /// Updates a existing theem

View File

@ -26,20 +26,25 @@ namespace Oqtane.Services
return await GetJsonAsync<Theme>($"{ApiUrl}/{themeId}?siteid={siteId}"); return await GetJsonAsync<Theme>($"{ApiUrl}/{themeId}?siteid={siteId}");
} }
public Theme GetTheme(List<Theme> themes, string themeControlType)
{
return themes.FirstOrDefault(item => item.Themes.Any(item => item.TypeName == themeControlType));
}
public List<ThemeControl> GetThemeControls(List<Theme> themes) public List<ThemeControl> GetThemeControls(List<Theme> themes)
{ {
return themes.SelectMany(item => item.Themes).OrderBy(item => item.Name).ToList(); return themes.SelectMany(item => item.Themes).OrderBy(item => item.Name).ToList();
} }
public List<ThemeControl> GetThemeControls(List<Theme> themes, string themeType) public List<ThemeControl> GetThemeControls(List<Theme> 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<ThemeControl> GetContainerControls(List<Theme> themes, string themeType) public List<ThemeControl> GetContainerControls(List<Theme> 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) public async Task UpdateThemeAsync(Theme theme)

View File

@ -19,7 +19,12 @@ namespace Oqtane.Themes.Controls
{ {
if (page.IsClickable) 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 else
{ {

View File

@ -15,6 +15,7 @@
{ {
<link id="app-manifest" rel="manifest" /> <link id="app-manifest" rel="manifest" />
} }
@Html.Raw(Model.StyleSheets)
<link id="app-stylesheet-page" /> <link id="app-stylesheet-page" />
<link id="app-stylesheet-module" /> <link id="app-stylesheet-module" />
<component type="typeof(Oqtane.Head)" render-mode="@((RenderMode)Enum.Parse(typeof(RenderMode), Model.RenderMode, true))" /> <component type="typeof(Oqtane.Head)" render-mode="@((RenderMode)Enum.Parse(typeof(RenderMode), Model.RenderMode, true))" />

View File

@ -21,7 +21,6 @@ using Oqtane.Security;
using Oqtane.Extensions; using Oqtane.Extensions;
using Oqtane.Themes; using Oqtane.Themes;
using System.Collections.Generic; using System.Collections.Generic;
using Oqtane.UI;
namespace Oqtane.Pages namespace Oqtane.Pages
{ {
@ -69,6 +68,7 @@ namespace Oqtane.Pages
public string RemoteIPAddress = ""; public string RemoteIPAddress = "";
public string HeadResources = ""; public string HeadResources = "";
public string BodyResources = ""; public string BodyResources = "";
public string StyleSheets = "";
public string PWAScript = ""; public string PWAScript = "";
public string ReconnectScript = ""; public string ReconnectScript = "";
public string Message = ""; public string Message = "";
@ -167,6 +167,8 @@ namespace Oqtane.Pages
} }
// stylesheets // stylesheets
if (!HttpContext.Request.Query.ContainsKey("method") || (HttpContext.Request.Query.ContainsKey("method") && HttpContext.Request.Query["method"] == "old"))
{
var resources = new List<Resource>(); var resources = new List<Resource>();
if (string.IsNullOrEmpty(page.ThemeType)) if (string.IsNullOrEmpty(page.ThemeType))
{ {
@ -186,7 +188,8 @@ namespace Oqtane.Pages
resources.AddRange(obj.Resources.Where(item => item.ResourceType == ResourceType.Stylesheet).ToList()); resources.AddRange(obj.Resources.Where(item => item.ResourceType == ResourceType.Stylesheet).ToList());
} }
} }
ManageResources(resources, alias, theme.ThemeName); ManageStyleSheets(resources, alias, theme.ThemeName);
}
// scripts // scripts
if (Runtime == "Server") if (Runtime == "Server")
@ -494,7 +497,7 @@ namespace Oqtane.Pages
CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture))); CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture)));
} }
private void ManageResources(List<Resource> resources, Alias alias, string name) private void ManageStyleSheets(List<Resource> resources, Alias alias, string name)
{ {
if (resources != null) if (resources != null)
{ {
@ -510,15 +513,11 @@ namespace Oqtane.Pages
resource.Url = alias.BaseUrl + resource.Url; 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++; count++;
id = "id=\"app-stylesheet-" + ResourceLevel.Page.ToString().ToLower() + "-" + DateTime.UtcNow.ToString("yyyyMMddHHmmssfff") + "-" + count.ToString("00") + "\" "; string id = "id=\"app-stylesheet-" + ResourceLevel.Page.ToString().ToLower() + "-" + DateTime.UtcNow.ToString("yyyyMMddHHmmssfff") + "-" + count.ToString("00") + "\" ";
} StyleSheets += "<link " + id + "rel=\"stylesheet\" href=\"" + resource.Url + "\"" + (!string.IsNullOrEmpty(resource.Integrity) ? " integrity=\"" + resource.Integrity + "\"" : "") + (!string.IsNullOrEmpty(resource.CrossOrigin) ? " crossorigin=\"" + resource.CrossOrigin + "\"" : "") + " type=\"text/css\"/>" + Environment.NewLine;
HeadResources += "<link " + id + "rel=\"stylesheet\" href=\"" + resource.Url + "\"" + (!string.IsNullOrEmpty(resource.Integrity) ? " integrity=\"" + resource.Integrity + "\"" : "") + (!string.IsNullOrEmpty(resource.CrossOrigin) ? " crossorigin=\"" + resource.CrossOrigin + "\"" : "") + " type=\"text/css\"/>" + Environment.NewLine;
} }
} }
} }