Merge pull request #6073 from sbwalker/dev
relocate folder hierarchy logic to folder repository (consistent with page approach)
This commit is contained in:
@@ -43,7 +43,7 @@ namespace Oqtane.Controllers
|
|||||||
int SiteId;
|
int SiteId;
|
||||||
if (int.TryParse(siteid, out SiteId) && SiteId == _alias.SiteId)
|
if (int.TryParse(siteid, out SiteId) && SiteId == _alias.SiteId)
|
||||||
{
|
{
|
||||||
var hierarchy = GetFoldersHierarchy(_folders.GetFolders(SiteId).ToList());
|
var hierarchy = _folders.GetFolders(SiteId).ToList();
|
||||||
foreach (Folder folder in hierarchy)
|
foreach (Folder folder in hierarchy)
|
||||||
{
|
{
|
||||||
// note that Browse permission is used for this method
|
// note that Browse permission is used for this method
|
||||||
@@ -281,47 +281,5 @@ namespace Oqtane.Controllers
|
|||||||
HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
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;
|
|
||||||
getPath = (folderList, folder) =>
|
|
||||||
{
|
|
||||||
IEnumerable<Folder> children;
|
|
||||||
int level;
|
|
||||||
if (folder == null)
|
|
||||||
{
|
|
||||||
level = -1;
|
|
||||||
children = folders.Where(item => item.ParentId == null);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
level = folder.Level;
|
|
||||||
children = folders.Where(item => item.ParentId == folder.FolderId);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (Folder child in children)
|
|
||||||
{
|
|
||||||
child.Level = level + 1;
|
|
||||||
child.HasChildren = folders.Any(item => item.ParentId == child.FolderId);
|
|
||||||
hierarchy.Add(child);
|
|
||||||
getPath(folderList, child);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
folders = folders.OrderBy(item => item.Name).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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
@@ -45,7 +46,49 @@ namespace Oqtane.Repository
|
|||||||
{
|
{
|
||||||
folder.PermissionList = permissions.Where(item => item.EntityId == folder.FolderId).ToList();
|
folder.PermissionList = permissions.Where(item => item.EntityId == folder.FolderId).ToList();
|
||||||
}
|
}
|
||||||
return folders;
|
return GetFoldersHierarchy(folders);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<Folder> GetFoldersHierarchy(List<Folder> folders)
|
||||||
|
{
|
||||||
|
List<Folder> hierarchy = new List<Folder>();
|
||||||
|
Action<List<Folder>, Folder> getPath = null;
|
||||||
|
getPath = (folderList, folder) =>
|
||||||
|
{
|
||||||
|
IEnumerable<Folder> children;
|
||||||
|
int level;
|
||||||
|
if (folder == null)
|
||||||
|
{
|
||||||
|
level = -1;
|
||||||
|
children = folders.Where(item => item.ParentId == null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
level = folder.Level;
|
||||||
|
children = folders.Where(item => item.ParentId == folder.FolderId);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (Folder child in children)
|
||||||
|
{
|
||||||
|
child.Level = level + 1;
|
||||||
|
child.HasChildren = folders.Any(item => item.ParentId == child.FolderId);
|
||||||
|
hierarchy.Add(child);
|
||||||
|
getPath(folderList, child);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
folders = folders.OrderBy(item => item.Name).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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Folder AddFolder(Folder folder)
|
public Folder AddFolder(Folder folder)
|
||||||
|
|||||||
Reference in New Issue
Block a user