moved hierarchical ordering logic to server for pages and folders
This commit is contained in:
@ -11,7 +11,7 @@ using Oqtane.Extensions;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Repository;
|
||||
using Oqtane.Security;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using System;
|
||||
|
||||
namespace Oqtane.Controllers
|
||||
{
|
||||
@ -46,6 +46,7 @@ namespace Oqtane.Controllers
|
||||
folders.Add(folder);
|
||||
}
|
||||
}
|
||||
folders = GetFoldersHierarchy(folders);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -237,5 +238,48 @@ namespace Oqtane.Controllers
|
||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Folder> GetFoldersHierarchy(List<Folder> folders)
|
||||
{
|
||||
List<Folder> hierarchy = new List<Folder>();
|
||||
Action<List<Folder>, Folder> getPath = null;
|
||||
var folders1 = folders;
|
||||
getPath = (folderList, folder) =>
|
||||
{
|
||||
IEnumerable<Folder> children;
|
||||
int level;
|
||||
if (folder == null)
|
||||
{
|
||||
level = -1;
|
||||
children = folders1.Where(item => item.ParentId == null);
|
||||
}
|
||||
else
|
||||
{
|
||||
level = folder.Level;
|
||||
children = folders1.Where(item => item.ParentId == folder.FolderId);
|
||||
}
|
||||
|
||||
foreach (Folder child in children)
|
||||
{
|
||||
child.Level = level + 1;
|
||||
child.HasChildren = folders1.Any(item => item.ParentId == child.FolderId);
|
||||
hierarchy.Add(child);
|
||||
if (getPath != null) getPath(folderList, child);
|
||||
}
|
||||
};
|
||||
folders = folders.OrderBy(item => item.Order).ToList();
|
||||
getPath(folders, null);
|
||||
|
||||
// add any non-hierarchical items to the end of the list
|
||||
foreach (Folder folder in folders)
|
||||
{
|
||||
if (hierarchy.Find(item => item.FolderId == folder.FolderId) == null)
|
||||
{
|
||||
hierarchy.Add(folder);
|
||||
}
|
||||
}
|
||||
|
||||
return hierarchy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user