handle site level scripts in App component

This commit is contained in:
sbwalker 2024-02-20 13:50:09 -05:00
parent 0f0d168976
commit ab09810bef
7 changed files with 46 additions and 50 deletions

View File

@ -567,9 +567,19 @@
// ensure resource does not exist already
if (!pageresources.Exists(item => item.Url.ToLower() == resource.Url.ToLower()))
{
resource.Level = level;
resource.Namespace = name;
pageresources.Add(resource);
pageresources.Add(new Resource
{
ResourceType = resource.ResourceType,
Url = resource.Url,
Integrity = resource.Integrity,
CrossOrigin = resource.CrossOrigin,
Bundle = resource.Bundle,
Location = resource.Location,
ES6Module = resource.ES6Module,
Content = resource.Content,
Level = level,
Namespace = name
});
}
}
}

View File

@ -23,7 +23,6 @@
@inject ISiteService SiteService
@inject IThemeRepository ThemeRepository
@inject ILanguageRepository LanguageRepository
@inject IServerStateManager ServerStateManager
@inject ILocalizationManager LocalizationManager
@inject IAliasRepository AliasRepository
@inject IUrlMappingRepository UrlMappingRepository
@ -187,11 +186,6 @@
}
_headResources += ParseScripts(site.HeadContent);
_bodyResources += ParseScripts(site.BodyContent);
var scripts = ServerStateManager.GetServerState(alias.SiteKey).Scripts;
foreach (var script in scripts)
{
AddScript(script, alias);
}
// set culture if not specified
string culture = Context.Request.Cookies[CookieRequestCultureProvider.DefaultCookieName];
@ -604,6 +598,16 @@
}
}
// site level resources for modules in site
var modules = site.Modules.GroupBy(item => item.ModuleDefinition.ModuleDefinitionName).Select(group => group.First()).ToList();
foreach (var module in modules)
{
if (module.ModuleDefinition.Resources != null)
{
resources = AddResources(resources, module.ModuleDefinition.Resources.Where(item => item.Level == ResourceLevel.Site).ToList(), ResourceLevel.Module, alias, "Modules", Utilities.GetTypeName(module.ModuleDefinition.ModuleDefinitionName));
}
}
return resources;
}
@ -613,24 +617,31 @@
{
foreach (var resource in resources)
{
if (resource.Level != ResourceLevel.Site)
if (resource.Url.StartsWith("~"))
{
if (resource.Url.StartsWith("~"))
{
resource.Url = resource.Url.Replace("~", "/" + type + "/" + name + "/").Replace("//", "/");
}
if (!resource.Url.Contains("://") && alias.BaseUrl != "" && !resource.Url.StartsWith(alias.BaseUrl))
{
resource.Url = alias.BaseUrl + resource.Url;
}
resource.Url = resource.Url.Replace("~", "/" + type + "/" + name + "/").Replace("//", "/");
}
if (!resource.Url.Contains("://") && alias.BaseUrl != "" && !resource.Url.StartsWith(alias.BaseUrl))
{
resource.Url = alias.BaseUrl + resource.Url;
}
// ensure resource does not exist already
if (!pageresources.Exists(item => item.Url.ToLower() == resource.Url.ToLower()))
// ensure resource does not exist already
if (!pageresources.Exists(item => item.Url.ToLower() == resource.Url.ToLower()))
{
pageresources.Add(new Resource
{
resource.Level = level;
resource.Namespace = name;
pageresources.Add(resource);
}
ResourceType = resource.ResourceType,
Url = resource.Url,
Integrity = resource.Integrity,
CrossOrigin = resource.CrossOrigin,
Bundle = resource.Bundle,
Location = resource.Location,
ES6Module = resource.ES6Module,
Content = resource.Content,
Level = level,
Namespace = name
});
}
}
}

View File

@ -7,7 +7,6 @@ namespace Oqtane.Infrastructure
{
public string SiteKey { get; set; }
public List<string> Assemblies { get; set; } = new List<string>();
public List<Resource>Scripts { get; set; } = new List<Resource>();
public bool IsInitialized { get; set; } = false;
}
}

View File

@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Oqtane.Models;
namespace Oqtane.Infrastructure
{
@ -22,7 +21,6 @@ namespace Oqtane.Infrastructure
serverState = new ServerState();
serverState.SiteKey = siteKey;
serverState.Assemblies = new List<string>();
serverState.Scripts = new List<Resource>();
serverState.IsInitialized = false;
_serverStates.Add(serverState);
}

View File

@ -225,17 +225,6 @@ namespace Oqtane.Repository
}
}
}
// build list of scripts for site
if (moduledefinition.Resources != null)
{
foreach (var resource in moduledefinition.Resources.Where(item => item.ResourceType == ResourceType.Script && item.Level == ResourceLevel.Site))
{
if (!serverState.Scripts.Contains(resource))
{
serverState.Scripts.Add(resource);
}
}
}
}
if (permissions.Count == 0)

View File

@ -197,17 +197,6 @@ namespace Oqtane.Repository
}
}
}
// build list of scripts for site
if (theme.Resources != null)
{
foreach (var resource in theme.Resources.Where(item => item.ResourceType == ResourceType.Script && item.Level == ResourceLevel.Site))
{
if (!serverState.Scripts.Contains(resource))
{
serverState.Scripts.Add(resource);
}
}
}
}
}
}

View File

@ -2,7 +2,7 @@ namespace Oqtane.Shared
{
public enum ResourceLevel
{
App,
Undefined,
Site,
Page,
Module