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:
@ -158,8 +158,8 @@
|
||||
if (firstRender)
|
||||
{
|
||||
var interop = new Interop(JSRuntime);
|
||||
await interop.IncludeLink("", "stylesheet", "https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/css/bootstrap.min.css", "text/css", "sha512-GQGU0fMMi238uA+a/bdWJfpUGKUkBdgfFdgBm72SUQ6BeyWjoY/ton0tEjH+OSH9iP4Dfh+7HM0I9f5eR0L/4w==", "anonymous", "");
|
||||
await interop.IncludeScript("", "https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/js/bootstrap.bundle.min.js", "sha512-pax4MlgXjHEPfCwcJLQhigY7+N8rt6bVvWLFyUMuxShv170X53TRzGPmPkZmGBhk+jikR8WBM4yl7A9WMHHqvg==", "anonymous", "", "head", "");
|
||||
await interop.IncludeLink("", "stylesheet", "https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/css/bootstrap.min.css", "text/css", "sha512-GQGU0fMMi238uA+a/bdWJfpUGKUkBdgfFdgBm72SUQ6BeyWjoY/ton0tEjH+OSH9iP4Dfh+7HM0I9f5eR0L/4w==", "anonymous");
|
||||
await interop.IncludeScript("", "https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/js/bootstrap.bundle.min.js", "sha512-pax4MlgXjHEPfCwcJLQhigY7+N8rt6bVvWLFyUMuxShv170X53TRzGPmPkZmGBhk+jikR8WBM4yl7A9WMHHqvg==", "anonymous", "", "head");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,6 @@
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
var admin = PageState.Pages.FirstOrDefault(item => item.Path == "admin");
|
||||
_pages = PageState.Pages.Where(item => item.ParentId == admin?.PageId && !item.IsDeleted).ToList();
|
||||
_pages = PageState.Pages.Where(item => item.ParentId == admin?.PageId).ToList();
|
||||
}
|
||||
}
|
||||
|
@ -252,7 +252,7 @@
|
||||
_title = page.Title;
|
||||
_meta = page.Meta;
|
||||
_path = page.Path;
|
||||
_pageModules = PageState.Modules.Where(m => m.PageId == page.PageId && m.IsDeleted == false).ToList();
|
||||
_pageModules = PageState.Modules.Where(m => m.PageId == page.PageId).ToList();
|
||||
|
||||
if (string.IsNullOrEmpty(_path))
|
||||
{
|
||||
|
@ -13,6 +13,7 @@
|
||||
<Header>
|
||||
<th style="width: 1px;"> </th>
|
||||
<th style="width: 1px;"> </th>
|
||||
<th style="width: 1px;"> </th>
|
||||
<th>@SharedLocalizer["Name"]</th>
|
||||
</Header>
|
||||
<Row>
|
||||
|
@ -53,7 +53,7 @@ namespace Oqtane.Modules
|
||||
if (Resources != null && Resources.Exists(item => item.ResourceType == ResourceType.Script))
|
||||
{
|
||||
var scripts = new List<object>();
|
||||
foreach (Resource resource in Resources.Where(item => item.ResourceType == ResourceType.Script && item.Declaration != ResourceDeclaration.Global))
|
||||
foreach (Resource resource in Resources.Where(item => item.ResourceType == ResourceType.Script))
|
||||
{
|
||||
scripts.Add(new { href = resource.Url, bundle = resource.Bundle ?? "", integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "", es6module = resource.ES6Module });
|
||||
}
|
||||
|
@ -333,9 +333,8 @@
|
||||
if (PageId != "-")
|
||||
{
|
||||
_modules = PageState.Modules
|
||||
.Where(module => module.PageId == int.Parse(PageId)
|
||||
&& !module.IsDeleted
|
||||
&& UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, module.Permissions))
|
||||
.Where(module => module.PageId == int.Parse(PageId) &&
|
||||
UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, module.Permissions))
|
||||
.ToList();
|
||||
}
|
||||
ModuleId = "-";
|
||||
|
@ -30,7 +30,7 @@ namespace Oqtane.Themes.Controls
|
||||
private IEnumerable<Page> GetMenuPages()
|
||||
{
|
||||
var securityLevel = int.MaxValue;
|
||||
foreach (Page p in PageState.Pages.Where(item => item.IsNavigation && !item.IsDeleted))
|
||||
foreach (Page p in PageState.Pages.Where(item => item.IsNavigation))
|
||||
{
|
||||
if (p.Level <= securityLevel && UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, p.Permissions))
|
||||
{
|
||||
|
@ -32,7 +32,7 @@ namespace Oqtane.Themes
|
||||
if (Resources != null && Resources.Exists(item => item.ResourceType == ResourceType.Script))
|
||||
{
|
||||
var scripts = new List<object>();
|
||||
foreach (Resource resource in Resources.Where(item => item.ResourceType == ResourceType.Script && item.Declaration != ResourceDeclaration.Global))
|
||||
foreach (Resource resource in Resources.Where(item => item.ResourceType == ResourceType.Script))
|
||||
{
|
||||
scripts.Add(new { href = resource.Url, bundle = resource.Bundle ?? "", integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "", es6module = resource.ES6Module });
|
||||
}
|
||||
|
@ -72,13 +72,13 @@ namespace Oqtane.UI
|
||||
}
|
||||
}
|
||||
|
||||
public Task IncludeLink(string id, string rel, string href, string type, string integrity, string crossorigin, string key)
|
||||
public Task IncludeLink(string id, string rel, string href, string type, string integrity, string crossorigin)
|
||||
{
|
||||
try
|
||||
{
|
||||
_jsRuntime.InvokeVoidAsync(
|
||||
"Oqtane.Interop.includeLink",
|
||||
id, rel, href, type, integrity, crossorigin, key);
|
||||
id, rel, href, type, integrity, crossorigin);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
catch
|
||||
@ -102,13 +102,13 @@ namespace Oqtane.UI
|
||||
}
|
||||
}
|
||||
|
||||
public Task IncludeScript(string id, string src, string integrity, string crossorigin, string content, string location, string key)
|
||||
public Task IncludeScript(string id, string src, string integrity, string crossorigin, string content, string location)
|
||||
{
|
||||
try
|
||||
{
|
||||
_jsRuntime.InvokeVoidAsync(
|
||||
"Oqtane.Interop.includeScript",
|
||||
id, src, integrity, crossorigin, content, location, key);
|
||||
id, src, integrity, crossorigin, content, location);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
catch
|
||||
|
@ -48,7 +48,7 @@ else
|
||||
if (Name.ToLower() == PaneNames.Admin.ToLower())
|
||||
{
|
||||
Module module = PageState.Modules.FirstOrDefault(item => item.ModuleId == PageState.ModuleId);
|
||||
if (module != null && !module.IsDeleted)
|
||||
if (module != null)
|
||||
{
|
||||
var moduleType = Type.GetType(module.ModuleType);
|
||||
if (moduleType != null)
|
||||
@ -97,7 +97,7 @@ else
|
||||
if (PageState.ModuleId != -1)
|
||||
{
|
||||
Module module = PageState.Modules.FirstOrDefault(item => item.ModuleId == PageState.ModuleId);
|
||||
if (module != null && module.Pane.ToLower() == Name.ToLower() && !module.IsDeleted)
|
||||
if (module != null && module.Pane.ToLower() == Name.ToLower())
|
||||
{
|
||||
// check if user is authorized to view module
|
||||
if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, module.Permissions))
|
||||
@ -108,7 +108,7 @@ else
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (Module module in PageState.Modules.Where(item => item.PageId == PageState.Page.PageId && item.Pane.ToLower() == Name.ToLower() && !item.IsDeleted).OrderBy(x => x.Order).ToArray())
|
||||
foreach (Module module in PageState.Modules.Where(item => item.PageId == PageState.Page.PageId && item.Pane.ToLower() == Name.ToLower()).OrderBy(x => x.Order).ToArray())
|
||||
{
|
||||
// check if user is authorized to view module
|
||||
if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, module.Permissions))
|
||||
|
@ -164,6 +164,7 @@
|
||||
if (PageState == null || refresh == UI.Refresh.Site)
|
||||
{
|
||||
pages = await PageService.GetPagesAsync(site.SiteId);
|
||||
pages = pages.Where(item => !item.IsDeleted).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -206,6 +207,7 @@
|
||||
if (PageState == null || refresh == UI.Refresh.Site)
|
||||
{
|
||||
modules = await ModuleService.GetModulesAsync(site.SiteId);
|
||||
modules = modules.Where(item => !item.IsDeleted).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -268,7 +270,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
// site does not exist
|
||||
// site does not exist
|
||||
}
|
||||
}
|
||||
|
||||
@ -322,7 +324,7 @@
|
||||
{
|
||||
if (page.IsPersonalizable && user != null)
|
||||
{
|
||||
// load the personalized page
|
||||
// load the personalized page
|
||||
page = await PageService.GetPageAsync(page.PageId, user.UserId);
|
||||
}
|
||||
|
||||
@ -338,7 +340,7 @@
|
||||
Type themetype = Type.GetType(page.ThemeType);
|
||||
if (themetype == null)
|
||||
{
|
||||
// fallback
|
||||
// fallback
|
||||
page.ThemeType = Constants.DefaultTheme;
|
||||
themetype = Type.GetType(Constants.DefaultTheme);
|
||||
}
|
||||
@ -351,14 +353,14 @@
|
||||
{
|
||||
panes = themeobject.Panes;
|
||||
}
|
||||
page.Resources = ManagePageResources(page.Resources, themeobject.Resources);
|
||||
page.Resources = ManagePageResources(page.Resources, themeobject.Resources, ResourceLevel.Page);
|
||||
}
|
||||
}
|
||||
page.Panes = panes.Replace(";", ",").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// error loading theme or layout
|
||||
// error loading theme or layout
|
||||
}
|
||||
|
||||
return page;
|
||||
@ -369,7 +371,7 @@
|
||||
var paneindex = new Dictionary<string, int>();
|
||||
foreach (Module module in modules)
|
||||
{
|
||||
// initialize module control properties
|
||||
// initialize module control properties
|
||||
module.SecurityAccessLevel = SecurityAccessLevel.Host;
|
||||
module.ControlTitle = "";
|
||||
module.Actions = "";
|
||||
@ -422,17 +424,17 @@
|
||||
// get additional metadata from IModuleControl interface
|
||||
if (moduletype != null && module.ModuleType != "")
|
||||
{
|
||||
// retrieve module component resources
|
||||
// retrieve module component resources
|
||||
var moduleobject = Activator.CreateInstance(moduletype) as IModuleControl;
|
||||
page.Resources = ManagePageResources(page.Resources, moduleobject.Resources);
|
||||
page.Resources = ManagePageResources(page.Resources, moduleobject.Resources, ResourceLevel.Module);
|
||||
if (action.ToLower() == "settings" && module.ModuleDefinition != null)
|
||||
{
|
||||
// settings components are embedded within a framework settings module
|
||||
// settings components are embedded within a framework settings module
|
||||
moduletype = Type.GetType(module.ModuleDefinition.ControlTypeTemplate.Replace(Constants.ActionToken, action), false, true);
|
||||
if (moduletype != null)
|
||||
{
|
||||
moduleobject = Activator.CreateInstance(moduletype) as IModuleControl;
|
||||
page.Resources = ManagePageResources(page.Resources, moduleobject.Resources);
|
||||
page.Resources = ManagePageResources(page.Resources, moduleobject.Resources, ResourceLevel.Module);
|
||||
}
|
||||
}
|
||||
|
||||
@ -483,15 +485,16 @@
|
||||
return (page, modules);
|
||||
}
|
||||
|
||||
private List<Resource> ManagePageResources(List<Resource> pageresources, List<Resource> resources)
|
||||
private List<Resource> ManagePageResources(List<Resource> pageresources, List<Resource> resources, ResourceLevel level)
|
||||
{
|
||||
if (resources != null)
|
||||
{
|
||||
foreach (var resource in resources)
|
||||
{
|
||||
// ensure resource does not exist already
|
||||
// ensure resource does not exist already
|
||||
if (pageresources.Find(item => item.Url == resource.Url) == null)
|
||||
{
|
||||
resource.Level = level;
|
||||
pageresources.Add(resource);
|
||||
}
|
||||
}
|
||||
|
@ -28,20 +28,22 @@
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
var interop = new Interop(JsRuntime);
|
||||
var interop = new Interop(JsRuntime);
|
||||
|
||||
// manage stylesheets for this page
|
||||
string batch = DateTime.UtcNow.ToString("yyyyMMddHHmmssfff");
|
||||
var links = new List<object>();
|
||||
foreach (Resource resource in PageState.Page.Resources.Where(item => item.ResourceType == ResourceType.Stylesheet && item.Declaration != ResourceDeclaration.Global))
|
||||
{
|
||||
links.Add(new { id = "app-stylesheet-" + batch + "-" + (links.Count + 1).ToString("00"), rel = "stylesheet", href = resource.Url, type = "text/css", integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "", key = "" });
|
||||
string batch = DateTime.UtcNow.ToString("yyyyMMddHHmmssfff");
|
||||
var links = new List<object>();
|
||||
foreach (Resource resource in PageState.Page.Resources.Where(item => item.ResourceType == ResourceType.Stylesheet))
|
||||
{
|
||||
var prefix = "app-stylesheet-" + resource.Level.ToString().ToLower();
|
||||
links.Add(new { id = prefix + "-" + batch + "-" + (links.Count + 1).ToString("00"), rel = "stylesheet", href = resource.Url, type = "text/css", integrity = resource.Integrity ?? "", crossorigin = resource.CrossOrigin ?? "", insertbefore = prefix });
|
||||
}
|
||||
if (links.Any())
|
||||
{
|
||||
await interop.IncludeLinks(links.ToArray());
|
||||
}
|
||||
await interop.RemoveElementsById("app-stylesheet", "", "app-stylesheet-" + batch + "-00");
|
||||
await interop.RemoveElementsById("app-stylesheet-page-", "", "app-stylesheet-page-" + batch + "-00");
|
||||
await interop.RemoveElementsById("app-stylesheet-module-", "", "app-stylesheet-module-" + batch + "-00");
|
||||
|
||||
// set page title
|
||||
if (!string.IsNullOrEmpty(PageState.Page.Title))
|
||||
|
Reference in New Issue
Block a user