filter deleted pages and modules in the router, provide support for cascading aspect of style sheets, replace ResourceDeclaration concept with ResourceLevel
This commit is contained in:
@ -19,6 +19,8 @@
|
||||
<script src="js/loadjs.min.js"></script>
|
||||
<link rel="stylesheet" href="css/app.css" />
|
||||
@Html.Raw(Model.HeadResources)
|
||||
<link id="app-stylesheet-page" rel="stylesheet" href="disabled" disabled />
|
||||
<link id="app-stylesheet-module" rel="stylesheet" href="disabled" disabled />
|
||||
</head>
|
||||
<body>
|
||||
@if (string.IsNullOrEmpty(Model.Message))
|
||||
|
@ -1,9 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Shared;
|
||||
using Oqtane.Modules;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Themes;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@ -190,8 +188,6 @@ namespace Oqtane.Pages
|
||||
foreach (Assembly assembly in assemblies)
|
||||
{
|
||||
ProcessHostResources(assembly);
|
||||
ProcessModuleControls(assembly);
|
||||
ProcessThemeControls(assembly);
|
||||
}
|
||||
|
||||
// set culture if not specified
|
||||
@ -411,65 +407,19 @@ namespace Oqtane.Pages
|
||||
var obj = Activator.CreateInstance(type) as IHostResources;
|
||||
foreach (var resource in obj.Resources)
|
||||
{
|
||||
resource.Declaration = ResourceDeclaration.Global;
|
||||
ProcessResource(resource, 0);
|
||||
ProcessResource(resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessModuleControls(Assembly assembly)
|
||||
{
|
||||
var types = assembly.GetTypes().Where(item => item.GetInterfaces().Contains(typeof(IModuleControl)));
|
||||
foreach (var type in types)
|
||||
{
|
||||
// Check if type should be ignored
|
||||
if (type.IsOqtaneIgnore()) continue;
|
||||
|
||||
var obj = Activator.CreateInstance(type) as IModuleControl;
|
||||
if (obj.Resources != null)
|
||||
{
|
||||
foreach (var resource in obj.Resources)
|
||||
{
|
||||
if (resource.Declaration == ResourceDeclaration.Global)
|
||||
{
|
||||
ProcessResource(resource, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessThemeControls(Assembly assembly)
|
||||
{
|
||||
var types = assembly.GetTypes().Where(item => item.GetInterfaces().Contains(typeof(IThemeControl)));
|
||||
foreach (var type in types)
|
||||
{
|
||||
// Check if type should be ignored
|
||||
if (type.IsOqtaneIgnore()) continue;
|
||||
|
||||
var obj = Activator.CreateInstance(type) as IThemeControl;
|
||||
if (obj.Resources != null)
|
||||
{
|
||||
int count = 0; // required for local stylesheets for current theme
|
||||
foreach (var resource in obj.Resources)
|
||||
{
|
||||
if (resource.Declaration == ResourceDeclaration.Global || (Utilities.GetFullTypeName(type.AssemblyQualifiedName) == ThemeType && resource.ResourceType == ResourceType.Stylesheet))
|
||||
{
|
||||
ProcessResource(resource, count++);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ProcessResource(Resource resource, int count)
|
||||
private void ProcessResource(Resource resource)
|
||||
{
|
||||
switch (resource.ResourceType)
|
||||
{
|
||||
case ResourceType.Stylesheet:
|
||||
if (!HeadResources.Contains(resource.Url, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var id = (resource.Declaration == ResourceDeclaration.Global) ? "" : "id=\"app-stylesheet-" + DateTime.UtcNow.ToString("yyyyMMddHHmmssfff") + "-" + count.ToString("00") + "\" ";
|
||||
HeadResources += "<link " + id + "rel=\"stylesheet\" href=\"" + resource.Url + "\"" + CrossOrigin(resource.CrossOrigin) + Integrity(resource.Integrity) + " />" + Environment.NewLine;
|
||||
HeadResources += "<link rel=\"stylesheet\" href=\"" + resource.Url + "\"" + CrossOrigin(resource.CrossOrigin) + Integrity(resource.Integrity) + " />" + Environment.NewLine;
|
||||
}
|
||||
break;
|
||||
case ResourceType.Script:
|
||||
|
@ -53,14 +53,8 @@ Oqtane.Interop = {
|
||||
}
|
||||
}
|
||||
},
|
||||
includeLink: function (id, rel, href, type, integrity, crossorigin, key) {
|
||||
var link;
|
||||
if (id !== "" && key === "id") {
|
||||
link = document.getElementById(id);
|
||||
}
|
||||
else {
|
||||
link = document.querySelector("link[href=\"" + CSS.escape(href) + "\"]");
|
||||
}
|
||||
includeLink: function (id, rel, href, type, integrity, crossorigin, insertbefore) {
|
||||
var link = document.querySelector("link[href=\"" + CSS.escape(href) + "\"]");
|
||||
if (link === null) {
|
||||
link = document.createElement("link");
|
||||
if (id !== "") {
|
||||
@ -77,7 +71,13 @@ Oqtane.Interop = {
|
||||
if (crossorigin !== "") {
|
||||
link.crossOrigin = crossorigin;
|
||||
}
|
||||
document.head.appendChild(link);
|
||||
if (insertbefore === "") {
|
||||
document.head.appendChild(link);
|
||||
}
|
||||
else {
|
||||
var sibling = document.getElementById(insertbefore);
|
||||
sibling.parentNode.insertBefore(link, sibling);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (link.id !== id) {
|
||||
@ -116,17 +116,11 @@ Oqtane.Interop = {
|
||||
},
|
||||
includeLinks: function (links) {
|
||||
for (let i = 0; i < links.length; i++) {
|
||||
this.includeLink(links[i].id, links[i].rel, links[i].href, links[i].type, links[i].integrity, links[i].crossorigin, links[i].key);
|
||||
this.includeLink(links[i].id, links[i].rel, links[i].href, links[i].type, links[i].integrity, links[i].crossorigin, links[i].insertbefore);
|
||||
}
|
||||
},
|
||||
includeScript: function (id, src, integrity, crossorigin, content, location, key) {
|
||||
var script;
|
||||
if (id !== "" && key === "id") {
|
||||
script = document.getElementById(id);
|
||||
}
|
||||
else {
|
||||
script = document.querySelector("script[src=\"" + CSS.escape(src) + "\"]");
|
||||
}
|
||||
includeScript: function (id, src, integrity, crossorigin, content, location) {
|
||||
var script = document.querySelector("script[src=\"" + CSS.escape(src) + "\"]");
|
||||
if (script === null) {
|
||||
script = document.createElement("script");
|
||||
if (id !== "") {
|
||||
|
Reference in New Issue
Block a user