improve performance of alias handling and allow aliases to be an unlimited number of subfolders in depth

This commit is contained in:
Shaun Walker
2020-05-05 09:15:36 -04:00
parent bf84f12471
commit a02cfea6c9
54 changed files with 320 additions and 586 deletions

View File

@ -2,7 +2,6 @@
using System.Threading.Tasks;
using System.Linq;
using System.Net.Http;
using Microsoft.AspNetCore.Components;
using System.Collections.Generic;
using Oqtane.Shared;
using System;
@ -14,42 +13,37 @@ namespace Oqtane.Services
{
private readonly SiteState _siteState;
private readonly NavigationManager _navigationManager;
public PageService(HttpClient http, SiteState siteState, NavigationManager navigationManager) : base(http)
public PageService(HttpClient http, SiteState siteState) : base(http)
{
_siteState = siteState;
_navigationManager = navigationManager;
}
private string Apiurl
{
get { return CreateApiUrl(_siteState.Alias, _navigationManager.Uri, "Page"); }
}
private string Apiurl => CreateApiUrl(_siteState.Alias, "Page");
public async Task<List<Page>> GetPagesAsync(int siteId)
{
List<Page> pages = await GetJsonAsync<List<Page>>($"{Apiurl}?siteid={siteId.ToString()}");
List<Page> pages = await GetJsonAsync<List<Page>>($"{Apiurl}?siteid={siteId}");
pages = GetPagesHierarchy(pages);
return pages;
}
public async Task<Page> GetPageAsync(int pageId)
{
return await GetJsonAsync<Page>($"{Apiurl}/{pageId.ToString()}");
return await GetJsonAsync<Page>($"{Apiurl}/{pageId}");
}
public async Task<Page> GetPageAsync(int pageId, int userId)
{
return await GetJsonAsync<Page>($"{Apiurl}/{pageId.ToString()}?userid={userId.ToString()}");
return await GetJsonAsync<Page>($"{Apiurl}/{pageId}?userid={userId}");
}
public async Task<Page> GetPageAsync(string path, int siteId)
{
try
{
return await GetJsonAsync<Page>($"{Apiurl}/path/{siteId.ToString()}?path={WebUtility.UrlEncode(path)}");
return await GetJsonAsync<Page>($"{Apiurl}/path/{siteId}?path={WebUtility.UrlEncode(path)}");
}
catch
{
@ -64,12 +58,12 @@ namespace Oqtane.Services
public async Task<Page> AddPageAsync(int pageId, int userId)
{
return await PostJsonAsync<Page>($"{Apiurl}/{pageId.ToString()}?userid={userId.ToString()}", null);
return await PostJsonAsync<Page>($"{Apiurl}/{pageId}?userid={userId}", null);
}
public async Task<Page> UpdatePageAsync(Page page)
{
return await PutJsonAsync<Page>($"{Apiurl}/{page.PageId.ToString()}", page);
return await PutJsonAsync<Page>($"{Apiurl}/{page.PageId}", page);
}
public async Task UpdatePageOrderAsync(int siteId, int pageId, int? parentId)
@ -77,12 +71,12 @@ namespace Oqtane.Services
var parent = parentId == null
? string.Empty
: parentId.ToString();
await PutAsync($"{Apiurl}/?siteid={siteId.ToString()}&pageid={pageId.ToString()}&parentid={parent}");
await PutAsync($"{Apiurl}/?siteid={siteId}&pageid={pageId}&parentid={parent}");
}
public async Task DeletePageAsync(int pageId)
{
await DeleteAsync($"{Apiurl}/{pageId.ToString()}");
await DeleteAsync($"{Apiurl}/{pageId}");
}
private static List<Page> GetPagesHierarchy(List<Page> pages)