Optimized page reloading
This commit is contained in:
@ -89,8 +89,7 @@
|
||||
if (user.IsAuthenticated)
|
||||
{
|
||||
authstateprovider.NotifyAuthenticationChanged();
|
||||
PageState.Reload = Constants.ReloadSite;
|
||||
NavigationManager.NavigateTo(NavigateUrl(ReturnUrl));
|
||||
NavigationManager.NavigateTo(NavigateUrl(ReturnUrl, Reload.Site));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -45,7 +45,6 @@ else
|
||||
private async Task InstallFile()
|
||||
{
|
||||
await ModuleDefinitionService.InstallModulesAsync();
|
||||
PageState.Reload = Constants.ReloadApplication;
|
||||
NavigationManager.NavigateTo(NavigateUrl());
|
||||
NavigationManager.NavigateTo(NavigateUrl(Reload.Application));
|
||||
}
|
||||
}
|
||||
|
@ -121,8 +121,7 @@
|
||||
moduleType.GetMethod("UpdateSettings").Invoke(settings, null); // method must be public in settings component
|
||||
}
|
||||
|
||||
PageState.Reload = Constants.ReloadPage;
|
||||
NavigationManager.NavigateTo(NavigateUrl());
|
||||
NavigationManager.NavigateTo(NavigateUrl(Reload.Page));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -278,8 +278,7 @@
|
||||
await PageService.AddPageAsync(page);
|
||||
await PageService.UpdatePageOrderAsync(page.SiteId, page.ParentId);
|
||||
|
||||
PageState.Reload = Constants.ReloadSite;
|
||||
NavigationManager.NavigateTo(NavigateUrl(page.Path));
|
||||
NavigationManager.NavigateTo(NavigateUrl(page.Path, Reload.Site));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -179,15 +179,7 @@
|
||||
try
|
||||
{
|
||||
await PageService.DeletePageAsync(Int32.Parse(PageState.QueryString["id"]));
|
||||
PageState.Reload = Constants.ReloadSite;
|
||||
if (PageState.Page.Name == "Page Management")
|
||||
{
|
||||
NavigationManager.NavigateTo(NavigateUrl());
|
||||
}
|
||||
else
|
||||
{
|
||||
NavigationManager.NavigateTo(NavigateUrl(""));
|
||||
}
|
||||
NavigationManager.NavigateTo(NavigateUrl("", Reload.Site));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -354,8 +354,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
PageState.Reload = Constants.ReloadSite;
|
||||
NavigationManager.NavigateTo(NavigateUrl(page.Path));
|
||||
NavigationManager.NavigateTo(NavigateUrl(page.Path, Reload.Site));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
50
Oqtane.Client/Modules/Admin/Themes/Add.razor
Normal file
50
Oqtane.Client/Modules/Admin/Themes/Add.razor
Normal file
@ -0,0 +1,50 @@
|
||||
@using Microsoft.AspNetCore.Components.Routing
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using Oqtane.Modules.Controls
|
||||
@using Oqtane.Modules
|
||||
@using Oqtane.Services
|
||||
@using Oqtane.Shared
|
||||
@namespace Oqtane.Modules.Admin.Themes
|
||||
@inherits ModuleBase
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IFileService FileService
|
||||
@inject IThemeService ThemeService
|
||||
|
||||
<table class="table table-borderless">
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Name" class="control-label">Theme: </label>
|
||||
</td>
|
||||
<td>
|
||||
<FileUpload Filter=".nupkg"></FileUpload>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@if (uploaded)
|
||||
{
|
||||
<button type="button" class="btn btn-success" @onclick="InstallFile">Install</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button type="button" class="btn btn-success" @onclick="UploadFile">Upload</button>
|
||||
}
|
||||
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
|
||||
|
||||
@code {
|
||||
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Host; } }
|
||||
|
||||
bool uploaded = false;
|
||||
|
||||
private async Task UploadFile()
|
||||
{
|
||||
await FileService.UploadFilesAsync("Themes");
|
||||
uploaded = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task InstallFile()
|
||||
{
|
||||
await ThemeService.InstallThemesAsync();
|
||||
NavigationManager.NavigateTo(NavigateUrl(Reload.Application));
|
||||
}
|
||||
}
|
@ -2,9 +2,9 @@
|
||||
@using Oqtane.Services
|
||||
@using Oqtane.Models
|
||||
@using Oqtane.Modules
|
||||
@using Oqtane.Modules.Controls
|
||||
@namespace Oqtane.Modules.Admin.Themes
|
||||
@inherits ModuleBase
|
||||
|
||||
@inject IThemeService ThemeService
|
||||
|
||||
@if (Themes == null)
|
||||
@ -13,6 +13,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
<ActionLink Action="Add" Text="Install Theme" />
|
||||
<table class="table table-borderless">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -80,8 +80,7 @@
|
||||
htmltext.Content = content;
|
||||
await htmltextservice.AddHtmlTextAsync(htmltext);
|
||||
}
|
||||
PageState.Reload = Constants.ReloadPage;
|
||||
NavigationManager.NavigateTo(NavigateUrl());
|
||||
NavigationManager.NavigateTo(NavigateUrl(Reload.Page));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Components;
|
||||
using Oqtane.Services;
|
||||
using Oqtane.Modules.HtmlText.Models;
|
||||
using Oqtane.Shared;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Oqtane.Modules.HtmlText.Services
|
||||
{
|
||||
@ -29,7 +30,17 @@ namespace Oqtane.Modules.HtmlText.Services
|
||||
|
||||
public async Task<HtmlTextInfo> GetHtmlTextAsync(int ModuleId)
|
||||
{
|
||||
return await http.GetJsonAsync<HtmlTextInfo>(apiurl + "/" + ModuleId.ToString() + "?entityid=" + ModuleId.ToString());
|
||||
HtmlTextInfo htmltext;
|
||||
try
|
||||
{
|
||||
// exception handling is required because GetJsonAsync() returns an error if no content exists for the ModuleId ( https://github.com/aspnet/AspNetCore/issues/14041 )
|
||||
htmltext = await http.GetJsonAsync<HtmlTextInfo>(apiurl + "/" + ModuleId.ToString() + "?entityid=" + ModuleId.ToString());
|
||||
}
|
||||
catch
|
||||
{
|
||||
htmltext = null;
|
||||
}
|
||||
return htmltext;
|
||||
}
|
||||
|
||||
public async Task AddHtmlTextAsync(HtmlTextInfo htmltext)
|
||||
|
@ -25,14 +25,29 @@ namespace Oqtane.Modules
|
||||
return NavigateUrl(PageState.Page.Path);
|
||||
}
|
||||
|
||||
public string NavigateUrl(Reload reload)
|
||||
{
|
||||
return NavigateUrl(PageState.Page.Path, reload);
|
||||
}
|
||||
|
||||
public string NavigateUrl(string path)
|
||||
{
|
||||
return NavigateUrl(path, "");
|
||||
return NavigateUrl(path, "", Reload.None);
|
||||
}
|
||||
|
||||
public string NavigateUrl(string path, Reload reload)
|
||||
{
|
||||
return NavigateUrl(path, "", reload);
|
||||
}
|
||||
|
||||
public string NavigateUrl(string path, string parameters)
|
||||
{
|
||||
return Utilities.NavigateUrl(PageState.Alias.Path, path, parameters);
|
||||
return Utilities.NavigateUrl(PageState.Alias.Path, path, parameters, Reload.None);
|
||||
}
|
||||
|
||||
public string NavigateUrl(string path, string parameters, Reload reload)
|
||||
{
|
||||
return Utilities.NavigateUrl(PageState.Alias.Path, path, parameters, reload);
|
||||
}
|
||||
|
||||
public string EditUrl(string action)
|
||||
|
@ -10,5 +10,6 @@ namespace Oqtane.Services
|
||||
Dictionary<string, string> GetThemeTypes(List<Theme> themes);
|
||||
Dictionary<string, string> GetPaneLayoutTypes(List<Theme> themes);
|
||||
Dictionary<string, string> GetContainerTypes(List<Theme> themes);
|
||||
Task InstallThemesAsync();
|
||||
}
|
||||
}
|
||||
|
@ -99,5 +99,10 @@ namespace Oqtane.Services
|
||||
}
|
||||
return selectableContainers;
|
||||
}
|
||||
|
||||
public async Task InstallThemesAsync()
|
||||
{
|
||||
await http.GetJsonAsync<List<string>>(apiurl + "/install");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,5 @@ namespace Oqtane.Shared
|
||||
public string Control { get; set; }
|
||||
public bool EditMode { get; set; }
|
||||
public bool DesignMode { get; set; }
|
||||
public int Reload { get; set; }
|
||||
}
|
||||
}
|
||||
|
10
Oqtane.Client/Shared/Reload.cs
Normal file
10
Oqtane.Client/Shared/Reload.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace Oqtane.Shared
|
||||
{
|
||||
public enum Reload
|
||||
{
|
||||
None,
|
||||
Page,
|
||||
Site,
|
||||
Application
|
||||
}
|
||||
}
|
@ -90,16 +90,34 @@
|
||||
string control = "";
|
||||
bool editmode = false;
|
||||
bool designmode = false;
|
||||
int reload = 0;
|
||||
Reload reload = Reload.None;
|
||||
|
||||
// get Url path and querystring ( and remove anchors )
|
||||
string path = new Uri(_absoluteUri).PathAndQuery.Substring(1);
|
||||
if (path.IndexOf("#") != -1)
|
||||
{
|
||||
path = path.Substring(0, path.IndexOf("#"));
|
||||
}
|
||||
|
||||
// parse querystring and remove
|
||||
Dictionary<string, string> querystring = new Dictionary<string, string>();
|
||||
if (path.IndexOf("?") != -1)
|
||||
{
|
||||
querystring = ParseQueryString(path);
|
||||
path = path.Substring(0, path.IndexOf("?"));
|
||||
}
|
||||
if (querystring.ContainsKey("reload"))
|
||||
{
|
||||
reload = (Reload)int.Parse(querystring["reload"]);
|
||||
}
|
||||
|
||||
if (PageState != null)
|
||||
{
|
||||
reload = PageState.Reload;
|
||||
editmode = PageState.EditMode;
|
||||
designmode = PageState.DesignMode;
|
||||
}
|
||||
|
||||
if (PageState == null || reload == Constants.ReloadApplication)
|
||||
if (PageState == null || reload == Reload.Application)
|
||||
{
|
||||
moduledefinitions = await ModuleDefinitionService.GetModuleDefinitionsAsync();
|
||||
themes = await ThemeService.GetThemesAsync();
|
||||
@ -119,9 +137,9 @@
|
||||
{
|
||||
alias = GetAlias(_absoluteUri, aliases);
|
||||
SiteState.Alias = alias; // set state for services
|
||||
reload = Constants.ReloadSite;
|
||||
reload = Reload.Site;
|
||||
}
|
||||
if (PageState == null || reload <= Constants.ReloadSite)
|
||||
if (PageState == null || reload <= Reload.Site)
|
||||
{
|
||||
site = await SiteService.GetSiteAsync(alias.SiteId);
|
||||
}
|
||||
@ -131,7 +149,7 @@
|
||||
}
|
||||
if (site != null)
|
||||
{
|
||||
if (PageState == null || reload >= Constants.ReloadSite)
|
||||
if (PageState == null || reload >= Reload.Site)
|
||||
{
|
||||
pages = await PageService.GetPagesAsync(site.SiteId);
|
||||
}
|
||||
@ -140,21 +158,6 @@
|
||||
pages = PageState.Pages;
|
||||
}
|
||||
|
||||
// get Url path and querystring ( and remove anchors )
|
||||
string path = new Uri(_absoluteUri).PathAndQuery.Substring(1);
|
||||
if (path.IndexOf("#") != -1)
|
||||
{
|
||||
path = path.Substring(0, path.IndexOf("#"));
|
||||
}
|
||||
|
||||
// parse querystring and remove
|
||||
Dictionary<string, string> querystring = new Dictionary<string, string>();
|
||||
if (path.IndexOf("?") != -1)
|
||||
{
|
||||
querystring = ParseQueryString(path);
|
||||
path = path.Substring(0, path.IndexOf("?"));
|
||||
}
|
||||
|
||||
// format path and remove alias
|
||||
path = path.Replace("//", "/");
|
||||
if (!path.EndsWith("/")) { path += "/"; }
|
||||
@ -185,7 +188,7 @@
|
||||
// remove trailing slash so it can be used as a key for Pages
|
||||
if (path.EndsWith("/")) path = path.Substring(0, path.Length - 1);
|
||||
|
||||
if (PageState == null || reload >= Constants.ReloadPage)
|
||||
if (PageState == null || reload >= Reload.Page)
|
||||
{
|
||||
page = pages.Where(item => item.Path == path).FirstOrDefault();
|
||||
}
|
||||
@ -204,13 +207,13 @@
|
||||
if (page.Path != path)
|
||||
{
|
||||
page = pages.Where(item => item.Path == path).FirstOrDefault();
|
||||
reload = Constants.ReloadPage;
|
||||
reload = Reload.Page;
|
||||
editmode = page.EditMode;
|
||||
designmode = false;
|
||||
}
|
||||
|
||||
user = null;
|
||||
if (PageState == null || reload >= Constants.ReloadPage)
|
||||
if (PageState == null || reload >= Reload.Page)
|
||||
{
|
||||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
if (authState.User.Identity.IsAuthenticated)
|
||||
@ -244,10 +247,10 @@
|
||||
|
||||
if (PageState != null && (PageState.ModuleId != pagestate.ModuleId || PageState.Control != pagestate.Control))
|
||||
{
|
||||
reload = Constants.ReloadPage;
|
||||
reload = Reload.Page;
|
||||
}
|
||||
|
||||
if (PageState == null || reload >= Constants.ReloadPage)
|
||||
if (PageState == null || reload >= Reload.Page)
|
||||
{
|
||||
modules = await ModuleService.GetModulesAsync(page.PageId);
|
||||
modules = ProcessModules(modules, moduledefinitions, pagestate.Control, page.Panes);
|
||||
@ -259,7 +262,6 @@
|
||||
pagestate.Modules = modules;
|
||||
pagestate.EditMode = editmode;
|
||||
pagestate.DesignMode = designmode;
|
||||
pagestate.Reload = Constants.ReloadReset;
|
||||
|
||||
OnStateChange?.Invoke(pagestate);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ namespace Oqtane.Shared
|
||||
public class Utilities
|
||||
{
|
||||
|
||||
public static string NavigateUrl(string alias, string path, string parameters)
|
||||
public static string NavigateUrl(string alias, string path, string parameters, Reload reload)
|
||||
{
|
||||
string url = "";
|
||||
if (alias != "")
|
||||
@ -25,6 +25,10 @@ namespace Oqtane.Shared
|
||||
{
|
||||
url += "?" + parameters;
|
||||
}
|
||||
if (reload != Reload.None)
|
||||
{
|
||||
url += ((string.IsNullOrEmpty(parameters)) ? "?" : "&") + "reload=" + ((int)reload).ToString();
|
||||
}
|
||||
if (!url.StartsWith("/"))
|
||||
{
|
||||
url = "/" + url;
|
||||
@ -34,7 +38,7 @@ namespace Oqtane.Shared
|
||||
|
||||
public static string EditUrl(string alias, string path, int moduleid, string action, string parameters)
|
||||
{
|
||||
string url = NavigateUrl(alias, path, "");
|
||||
string url = NavigateUrl(alias, path, "", Reload.None);
|
||||
if (url == "/") url = "";
|
||||
if (moduleid != -1)
|
||||
{
|
||||
|
@ -19,15 +19,31 @@ namespace Oqtane.Themes
|
||||
return NavigateUrl(PageState.Page.Path);
|
||||
}
|
||||
|
||||
public string NavigateUrl(Reload reload)
|
||||
{
|
||||
return NavigateUrl(PageState.Page.Path, reload);
|
||||
}
|
||||
|
||||
public string NavigateUrl(string path)
|
||||
{
|
||||
return NavigateUrl(path, "");
|
||||
return NavigateUrl(path, "", Reload.None);
|
||||
}
|
||||
|
||||
public string NavigateUrl(string path, Reload reload)
|
||||
{
|
||||
return NavigateUrl(path, "", reload);
|
||||
}
|
||||
|
||||
public string NavigateUrl(string path, string parameters)
|
||||
{
|
||||
return Utilities.NavigateUrl(PageState.Alias.Path, path, parameters);
|
||||
return Utilities.NavigateUrl(PageState.Alias.Path, path, parameters, Reload.None);
|
||||
}
|
||||
|
||||
public string NavigateUrl(string path, string parameters, Reload reload)
|
||||
{
|
||||
return Utilities.NavigateUrl(PageState.Alias.Path, path, parameters, reload);
|
||||
}
|
||||
|
||||
public string EditUrl(string action, string parameters)
|
||||
{
|
||||
return EditUrl(ModuleState.ModuleId, action, parameters);
|
||||
|
@ -164,8 +164,7 @@
|
||||
await PageModuleService.AddPageModuleAsync(pagemodule);
|
||||
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
|
||||
|
||||
PageState.Reload = Constants.ReloadPage;
|
||||
NavigationManager.NavigateTo(NavigateUrl());
|
||||
NavigationManager.NavigateTo(NavigateUrl(Reload.Page));
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,8 +203,7 @@
|
||||
PageState.EditMode = true;
|
||||
PageState.DesignMode = true;
|
||||
}
|
||||
PageState.Reload = Constants.ReloadPage;
|
||||
NavigationManager.NavigateTo(NavigateUrl(PageState.Page.Path, "edit=" + PageState.EditMode.ToString().ToLower()));
|
||||
NavigationManager.NavigateTo(NavigateUrl(PageState.Page.Path, "edit=" + PageState.EditMode.ToString().ToLower(), Reload.Page));
|
||||
}
|
||||
}
|
||||
}
|
@ -53,8 +53,7 @@
|
||||
{
|
||||
// client-side Blazor
|
||||
authstateprovider.NotifyAuthenticationChanged();
|
||||
PageState.Reload = Constants.ReloadSite;
|
||||
NavigationManager.NavigateTo(NavigateUrl(PageState.Page.Path, "logout"));
|
||||
NavigationManager.NavigateTo(NavigateUrl(PageState.Page.Path, "logout", Reload.Site));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@
|
||||
{
|
||||
PageModule pagemodule = await PageModuleService.GetPageModuleAsync(ModuleState.PageModuleId);
|
||||
|
||||
string url = NavigateUrl();
|
||||
string url = NavigateUrl(Reload.Page);
|
||||
switch (action)
|
||||
{
|
||||
case "<<":
|
||||
@ -104,7 +104,6 @@
|
||||
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pane);
|
||||
break;
|
||||
}
|
||||
PageState.Reload = Constants.ReloadPage;
|
||||
NavigationManager.NavigateTo(url);
|
||||
}
|
||||
}
|
||||
|
@ -15,14 +15,29 @@ namespace Oqtane.Themes
|
||||
return NavigateUrl(PageState.Page.Path);
|
||||
}
|
||||
|
||||
public string NavigateUrl(Reload reload)
|
||||
{
|
||||
return NavigateUrl(PageState.Page.Path, reload);
|
||||
}
|
||||
|
||||
public string NavigateUrl(string path)
|
||||
{
|
||||
return NavigateUrl(path, "");
|
||||
return NavigateUrl(path, "", Reload.None);
|
||||
}
|
||||
|
||||
public string NavigateUrl(string path, Reload reload)
|
||||
{
|
||||
return NavigateUrl(path, "", reload);
|
||||
}
|
||||
|
||||
public string NavigateUrl(string path, string parameters)
|
||||
{
|
||||
return Utilities.NavigateUrl(PageState.Alias.Path, path, parameters);
|
||||
return Utilities.NavigateUrl(PageState.Alias.Path, path, parameters, Reload.None);
|
||||
}
|
||||
|
||||
public string NavigateUrl(string path, string parameters, Reload reload)
|
||||
{
|
||||
return Utilities.NavigateUrl(PageState.Alias.Path, path, parameters, reload);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,14 +13,29 @@ namespace Oqtane.Themes
|
||||
return NavigateUrl(PageState.Page.Path);
|
||||
}
|
||||
|
||||
public string NavigateUrl(Reload reload)
|
||||
{
|
||||
return NavigateUrl(PageState.Page.Path, reload);
|
||||
}
|
||||
|
||||
public string NavigateUrl(string path)
|
||||
{
|
||||
return NavigateUrl(path, "");
|
||||
return NavigateUrl(path, "", Reload.None);
|
||||
}
|
||||
|
||||
public string NavigateUrl(string path, Reload reload)
|
||||
{
|
||||
return NavigateUrl(path, "", reload);
|
||||
}
|
||||
|
||||
public string NavigateUrl(string path, string parameters)
|
||||
{
|
||||
return Utilities.NavigateUrl(PageState.Alias.Path, path, parameters);
|
||||
return Utilities.NavigateUrl(PageState.Alias.Path, path, parameters, Reload.None);
|
||||
}
|
||||
|
||||
public string NavigateUrl(string path, string parameters, Reload reload)
|
||||
{
|
||||
return Utilities.NavigateUrl(PageState.Alias.Path, path, parameters, reload);
|
||||
}
|
||||
|
||||
public string EditUrl(int moduleid, string action)
|
||||
|
Reference in New Issue
Block a user