Optimized page reloading
This commit is contained in:
@ -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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user