handle site level scripts in App component
This commit is contained in:
parent
0f0d168976
commit
ab09810bef
|
@ -567,9 +567,19 @@
|
||||||
// ensure resource does not exist already
|
// ensure resource does not exist already
|
||||||
if (!pageresources.Exists(item => item.Url.ToLower() == resource.Url.ToLower()))
|
if (!pageresources.Exists(item => item.Url.ToLower() == resource.Url.ToLower()))
|
||||||
{
|
{
|
||||||
resource.Level = level;
|
pageresources.Add(new Resource
|
||||||
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
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
@inject ISiteService SiteService
|
@inject ISiteService SiteService
|
||||||
@inject IThemeRepository ThemeRepository
|
@inject IThemeRepository ThemeRepository
|
||||||
@inject ILanguageRepository LanguageRepository
|
@inject ILanguageRepository LanguageRepository
|
||||||
@inject IServerStateManager ServerStateManager
|
|
||||||
@inject ILocalizationManager LocalizationManager
|
@inject ILocalizationManager LocalizationManager
|
||||||
@inject IAliasRepository AliasRepository
|
@inject IAliasRepository AliasRepository
|
||||||
@inject IUrlMappingRepository UrlMappingRepository
|
@inject IUrlMappingRepository UrlMappingRepository
|
||||||
|
@ -187,11 +186,6 @@
|
||||||
}
|
}
|
||||||
_headResources += ParseScripts(site.HeadContent);
|
_headResources += ParseScripts(site.HeadContent);
|
||||||
_bodyResources += ParseScripts(site.BodyContent);
|
_bodyResources += ParseScripts(site.BodyContent);
|
||||||
var scripts = ServerStateManager.GetServerState(alias.SiteKey).Scripts;
|
|
||||||
foreach (var script in scripts)
|
|
||||||
{
|
|
||||||
AddScript(script, alias);
|
|
||||||
}
|
|
||||||
|
|
||||||
// set culture if not specified
|
// set culture if not specified
|
||||||
string culture = Context.Request.Cookies[CookieRequestCultureProvider.DefaultCookieName];
|
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;
|
return resources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -613,24 +617,31 @@
|
||||||
{
|
{
|
||||||
foreach (var resource in resources)
|
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("//", "/");
|
||||||
{
|
}
|
||||||
resource.Url = resource.Url.Replace("~", "/" + type + "/" + name + "/").Replace("//", "/");
|
if (!resource.Url.Contains("://") && alias.BaseUrl != "" && !resource.Url.StartsWith(alias.BaseUrl))
|
||||||
}
|
{
|
||||||
if (!resource.Url.Contains("://") && alias.BaseUrl != "" && !resource.Url.StartsWith(alias.BaseUrl))
|
resource.Url = alias.BaseUrl + resource.Url;
|
||||||
{
|
}
|
||||||
resource.Url = alias.BaseUrl + resource.Url;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ensure resource does not exist already
|
// ensure resource does not exist already
|
||||||
if (!pageresources.Exists(item => item.Url.ToLower() == resource.Url.ToLower()))
|
if (!pageresources.Exists(item => item.Url.ToLower() == resource.Url.ToLower()))
|
||||||
|
{
|
||||||
|
pageresources.Add(new Resource
|
||||||
{
|
{
|
||||||
resource.Level = level;
|
ResourceType = resource.ResourceType,
|
||||||
resource.Namespace = name;
|
Url = resource.Url,
|
||||||
pageresources.Add(resource);
|
Integrity = resource.Integrity,
|
||||||
}
|
CrossOrigin = resource.CrossOrigin,
|
||||||
|
Bundle = resource.Bundle,
|
||||||
|
Location = resource.Location,
|
||||||
|
ES6Module = resource.ES6Module,
|
||||||
|
Content = resource.Content,
|
||||||
|
Level = level,
|
||||||
|
Namespace = name
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ namespace Oqtane.Infrastructure
|
||||||
{
|
{
|
||||||
public string SiteKey { get; set; }
|
public string SiteKey { get; set; }
|
||||||
public List<string> Assemblies { get; set; } = new List<string>();
|
public List<string> Assemblies { get; set; } = new List<string>();
|
||||||
public List<Resource>Scripts { get; set; } = new List<Resource>();
|
|
||||||
public bool IsInitialized { get; set; } = false;
|
public bool IsInitialized { get; set; } = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Oqtane.Models;
|
|
||||||
|
|
||||||
namespace Oqtane.Infrastructure
|
namespace Oqtane.Infrastructure
|
||||||
{
|
{
|
||||||
|
@ -22,7 +21,6 @@ namespace Oqtane.Infrastructure
|
||||||
serverState = new ServerState();
|
serverState = new ServerState();
|
||||||
serverState.SiteKey = siteKey;
|
serverState.SiteKey = siteKey;
|
||||||
serverState.Assemblies = new List<string>();
|
serverState.Assemblies = new List<string>();
|
||||||
serverState.Scripts = new List<Resource>();
|
|
||||||
serverState.IsInitialized = false;
|
serverState.IsInitialized = false;
|
||||||
_serverStates.Add(serverState);
|
_serverStates.Add(serverState);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
if (permissions.Count == 0)
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ namespace Oqtane.Shared
|
||||||
{
|
{
|
||||||
public enum ResourceLevel
|
public enum ResourceLevel
|
||||||
{
|
{
|
||||||
App,
|
Undefined,
|
||||||
Site,
|
Site,
|
||||||
Page,
|
Page,
|
||||||
Module
|
Module
|
||||||
|
|
Loading…
Reference in New Issue
Block a user