updated namespaces, improved page management,
This commit is contained in:
@ -5,6 +5,7 @@ using System.Net.Http;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Shared;
|
||||
using System;
|
||||
|
||||
namespace Oqtane.Services
|
||||
{
|
||||
@ -29,7 +30,8 @@ namespace Oqtane.Services
|
||||
public async Task<List<Page>> GetPagesAsync(int SiteId)
|
||||
{
|
||||
List<Page> pages = await http.GetJsonAsync<List<Page>>(apiurl + "?siteid=" + SiteId.ToString());
|
||||
return pages.OrderBy(item => item.Order).ToList();
|
||||
pages = GetPagesHierarchy(pages);
|
||||
return pages;
|
||||
}
|
||||
|
||||
public async Task<Page> GetPageAsync(int PageId)
|
||||
@ -46,9 +48,46 @@ namespace Oqtane.Services
|
||||
{
|
||||
return await http.PutJsonAsync<Page>(apiurl + "/" + Page.PageId.ToString(), Page);
|
||||
}
|
||||
|
||||
public async Task UpdatePageOrderAsync(int SiteId, int? ParentId)
|
||||
{
|
||||
await http.PutJsonAsync(apiurl + "/?siteid=" + SiteId.ToString() + "&parentid=" + ((ParentId == null) ? "" : ParentId.ToString()), null);
|
||||
}
|
||||
|
||||
public async Task DeletePageAsync(int PageId)
|
||||
{
|
||||
await http.DeleteAsync(apiurl + "/" + PageId.ToString());
|
||||
}
|
||||
|
||||
private static List<Page> GetPagesHierarchy(List<Page> Pages)
|
||||
{
|
||||
List<Page> hierarchy = new List<Page>();
|
||||
Action<List<Page>, Page> GetPath = null;
|
||||
GetPath = (List<Page> pages, Page 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.Where(item => item.ParentId == child.PageId).Any();
|
||||
hierarchy.Add(child);
|
||||
GetPath(pages, child);
|
||||
}
|
||||
};
|
||||
Pages = Pages.OrderBy(item => item.Order).ToList();
|
||||
GetPath(Pages, null);
|
||||
return hierarchy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user