ensure Pages collection is always returned in the same order by moving GetPagesHierarchy method to the repository.

This commit is contained in:
sbwalker 2024-12-19 14:45:12 -05:00
parent b5a1b529ab
commit 80c8433aad
4 changed files with 48 additions and 5 deletions

View File

@ -11,6 +11,8 @@
RenderFragment DynamicComponent { get; set; }
private string lastPagePath = "";
protected override void OnParametersSet()
{
// handle page redirection
@ -90,7 +92,7 @@
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender)
if (!firstRender && PageState.Page.Path != lastPagePath)
{
if (!string.IsNullOrEmpty(PageState.Site.HeadContent) && PageState.Site.HeadContent.Contains("<script"))
{
@ -108,6 +110,7 @@
{
await InjectScripts(PageState.Page.BodyContent, ResourceLocation.Body);
}
lastPagePath = PageState.Page.Path;
}
// style sheets

View File

@ -9,7 +9,7 @@ using System.Net;
using Oqtane.Enums;
using Oqtane.Infrastructure;
using Oqtane.Repository;
using System.IO;
using System;
namespace Oqtane.Controllers
{

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
@ -31,7 +32,47 @@ namespace Oqtane.Repository
{
page.PermissionList = permissions.Where(item => item.EntityId == page.PageId).ToList();
}
return pages;
return GetPagesHierarchy(pages);
}
private static List<Page> GetPagesHierarchy(List<Page> pages)
{
List<Page> hierarchy = new List<Page>();
Action<List<Page>, Page> getPath = null;
getPath = (pageList, page) =>
{
IEnumerable<Page> children;
int level;
if (page == null)
{
level = -1;
children = pages.Where(item => item.ParentId == null);
}
else
{
level = page.Level;
children = pages.Where(item => item.ParentId == page.PageId);
}
foreach (Page child in children)
{
child.Level = level + 1;
child.HasChildren = pages.Any(item => item.ParentId == child.PageId && !item.IsDeleted && item.IsNavigation);
hierarchy.Add(child);
getPath(pageList, child);
}
};
pages = pages.OrderBy(item => item.Order).ToList();
getPath(pages, null);
// add any non-hierarchical items to the end of the list
foreach (Page page in pages)
{
if (hierarchy.Find(item => item.PageId == page.PageId) == null)
{
hierarchy.Add(page);
}
}
return hierarchy;
}
public Page AddPage(Page page)

View File

@ -127,7 +127,6 @@ namespace Oqtane.Services
.ToDictionary(setting => setting.SettingName, setting => (setting.IsPrivate ? _private : "") + setting.SettingValue);
site.Pages.Add(page);
}
site.Pages = GetPagesHierarchy(site.Pages);
// framework modules
var modules = GetPageModules(site.SiteId);