diff --git a/Oqtane.Client/Services/FolderService.cs b/Oqtane.Client/Services/FolderService.cs index 6375d9a6..b6c5ff93 100644 --- a/Oqtane.Client/Services/FolderService.cs +++ b/Oqtane.Client/Services/FolderService.cs @@ -1,10 +1,8 @@ using Oqtane.Models; using System.Threading.Tasks; -using System.Linq; using System.Net.Http; using System.Collections.Generic; using Oqtane.Shared; -using System; using System.Diagnostics.CodeAnalysis; using System.Net; using Oqtane.Documentation; @@ -20,9 +18,7 @@ namespace Oqtane.Services public async Task> GetFoldersAsync(int siteId) { - List folders = await GetJsonAsync>($"{ApiUrl}?siteid={siteId}"); - folders = GetFoldersHierarchy(folders); - return folders; + return await GetJsonAsync>($"{ApiUrl}?siteid={siteId}"); } public async Task GetFolderAsync(int folderId) @@ -58,48 +54,5 @@ namespace Oqtane.Services { await DeleteAsync($"{ApiUrl}/{folderId}"); } - - private static List GetFoldersHierarchy(List folders) - { - List hierarchy = new List(); - Action, Folder> getPath = null; - var folders1 = folders; - getPath = (folderList, folder) => - { - IEnumerable 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; - } } } diff --git a/Oqtane.Client/Services/PageService.cs b/Oqtane.Client/Services/PageService.cs index e9d7991d..0725ccf8 100644 --- a/Oqtane.Client/Services/PageService.cs +++ b/Oqtane.Client/Services/PageService.cs @@ -1,10 +1,8 @@ using Oqtane.Models; using System.Threading.Tasks; -using System.Linq; using System.Net.Http; using System.Collections.Generic; using Oqtane.Shared; -using System; using System.Net; using Oqtane.Documentation; @@ -19,9 +17,7 @@ namespace Oqtane.Services public async Task> GetPagesAsync(int siteId) { - List pages = await GetJsonAsync>($"{Apiurl}?siteid={siteId}"); - pages = GetPagesHierarchy(pages); - return pages; + return await GetJsonAsync>($"{Apiurl}?siteid={siteId}"); } public async Task GetPageAsync(int pageId) @@ -73,45 +69,5 @@ namespace Oqtane.Services { await DeleteAsync($"{Apiurl}/{pageId}"); } - - private static List GetPagesHierarchy(List pages) - { - List hierarchy = new List(); - Action, Page> getPath = null; - getPath = (pageList, page) => - { - IEnumerable 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); - 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; - } } } diff --git a/Oqtane.Server/Controllers/FolderController.cs b/Oqtane.Server/Controllers/FolderController.cs index 5bdede15..cb2c0cf0 100644 --- a/Oqtane.Server/Controllers/FolderController.cs +++ b/Oqtane.Server/Controllers/FolderController.cs @@ -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 GetFoldersHierarchy(List folders) + { + List hierarchy = new List(); + Action, Folder> getPath = null; + var folders1 = folders; + getPath = (folderList, folder) => + { + IEnumerable 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; + } } } diff --git a/Oqtane.Server/Controllers/SiteController.cs b/Oqtane.Server/Controllers/SiteController.cs index 2f50b195..a2b7f2b7 100644 --- a/Oqtane.Server/Controllers/SiteController.cs +++ b/Oqtane.Server/Controllers/SiteController.cs @@ -97,6 +97,7 @@ namespace Oqtane.Controllers site.Pages.Add(page); } } + site.Pages = GetPagesHierarchy(site.Pages); // modules List moduledefinitions = _moduleDefinitions.GetModuleDefinitions(site.SiteId).ToList(); @@ -213,5 +214,45 @@ namespace Oqtane.Controllers HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden; } } + + private static List GetPagesHierarchy(List pages) + { + List hierarchy = new List(); + Action, Page> getPath = null; + getPath = (pageList, page) => + { + IEnumerable 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); + 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; + } } }