Improved page reload efficiency, refactored NavigateUrl and EditUrl helpers, added antiforgery token and returnurl to Logout scenario, fixed PageModule service call api url, modified rendering engine to allow for component differentiation
This commit is contained in:
@ -13,5 +13,9 @@
|
||||
|
||||
public const string AllUsersRole = "All Users";
|
||||
public const string AdminRole = "Administrators";
|
||||
|
||||
public const int ReloadApplication = 3;
|
||||
public const int ReloadSite = 2;
|
||||
public const int ReloadPage = 1;
|
||||
}
|
||||
}
|
||||
|
@ -21,26 +21,32 @@
|
||||
{
|
||||
DynamicComponent = builder =>
|
||||
{
|
||||
Type containerType = Type.GetType(container);
|
||||
if (containerType != null)
|
||||
if (ModuleState != null)
|
||||
{
|
||||
builder.OpenComponent(0, containerType);
|
||||
builder.CloseComponent();
|
||||
}
|
||||
else
|
||||
{
|
||||
// container does not exist with type specified
|
||||
Type containerType = Type.GetType(container);
|
||||
if (containerType != null)
|
||||
{
|
||||
builder.OpenComponent(ModuleState.ModuleId, containerType); // set sequence to moduleid so that component tree is able to differentiate
|
||||
builder.CloseComponent();
|
||||
}
|
||||
else
|
||||
{
|
||||
// container does not exist with type specified
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected override Task OnParametersSetAsync()
|
||||
{
|
||||
ModuleState = Module; // passed in from Pane component
|
||||
container = ModuleState.ContainerType;
|
||||
if (PageState.ModuleId != -1 && PageState.Control != "")
|
||||
if (PageState.Page.PageId == Module.PageId)
|
||||
{
|
||||
container = Constants.DefaultAdminContainer;
|
||||
ModuleState = Module; // passed in from Pane component
|
||||
container = ModuleState.ContainerType;
|
||||
if (PageState.ModuleId != -1 && PageState.Control != "")
|
||||
{
|
||||
container = Constants.DefaultAdminContainer;
|
||||
}
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
Type moduleType = Type.GetType(typename);
|
||||
if (moduleType != null)
|
||||
{
|
||||
builder.OpenComponent(0, moduleType);
|
||||
builder.OpenComponent(ModuleState.ModuleId, moduleType); // set sequence to moduleid so that component tree is able to differentiate
|
||||
builder.CloseComponent();
|
||||
}
|
||||
else
|
||||
|
@ -19,5 +19,6 @@ namespace Oqtane.Shared
|
||||
public Dictionary<string, string> QueryString { get; set; }
|
||||
public int ModuleId { get; set; }
|
||||
public string Control { get; set; }
|
||||
public int Reload { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@
|
||||
|
||||
DynamicComponent = builder =>
|
||||
{
|
||||
if (pagestate != null)
|
||||
if (PageState != null)
|
||||
{
|
||||
builder.OpenComponent(0, Type.GetType(Constants.DefaultPage));
|
||||
builder.CloseComponent();
|
||||
@ -75,38 +75,54 @@
|
||||
List<Module> modules;
|
||||
int moduleid = -1;
|
||||
string control = "";
|
||||
int reload = 0;
|
||||
|
||||
bool reload = false;
|
||||
if (PageState == null)
|
||||
if (PageState != null)
|
||||
{
|
||||
reload = PageState.Reload;
|
||||
}
|
||||
|
||||
if (PageState == null || reload == Constants.ReloadApplication)
|
||||
{
|
||||
moduledefinitions = await ModuleDefinitionService.GetModuleDefinitionsAsync();
|
||||
themes = await ThemeService.GetThemesAsync();
|
||||
aliases = await AliasService.GetAliasesAsync();
|
||||
alias = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
moduledefinitions = PageState.ModuleDefinitions;
|
||||
themes = PageState.Themes;
|
||||
aliases = PageState.Aliases;
|
||||
alias = PageState.Alias;
|
||||
}
|
||||
|
||||
// check if site has changed
|
||||
if (alias == null || GetAlias(_absoluteUri, aliases).Name != alias.Name)
|
||||
{
|
||||
alias = GetAlias(_absoluteUri, aliases);
|
||||
SiteState.Alias = alias; // set state for services
|
||||
reload = true;
|
||||
reload = Constants.ReloadSite;
|
||||
}
|
||||
if (PageState == null || reload == true)
|
||||
if (PageState == null || reload <= Constants.ReloadSite)
|
||||
{
|
||||
moduledefinitions = await ModuleDefinitionService.GetModuleDefinitionsAsync();
|
||||
themes = await ThemeService.GetThemesAsync();
|
||||
site = await SiteService.GetSiteAsync(alias.SiteId);
|
||||
}
|
||||
else
|
||||
{
|
||||
moduledefinitions = PageState.ModuleDefinitions;
|
||||
themes = PageState.Themes;
|
||||
site = PageState.Site;
|
||||
}
|
||||
if (site != null || reload == true)
|
||||
if (site != null)
|
||||
{
|
||||
if (PageState == null || reload >= Constants.ReloadSite)
|
||||
{
|
||||
pages = await PageService.GetPagesAsync(site.SiteId);
|
||||
}
|
||||
else
|
||||
{
|
||||
pages = PageState.Pages;
|
||||
}
|
||||
|
||||
// get Url path and querystring
|
||||
string path = new Uri(_absoluteUri).PathAndQuery.Substring(1);
|
||||
|
||||
@ -148,13 +164,23 @@
|
||||
// remove trailing slash so it can be used as a key for Pages
|
||||
if (path.EndsWith("/")) path = path.Substring(0, path.Length - 1);
|
||||
|
||||
if (querystring.ContainsKey("reload"))
|
||||
if (PageState == null || reload >= Constants.ReloadPage)
|
||||
{
|
||||
reload = true;
|
||||
page = pages.Where(item => item.Path == path).FirstOrDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
page = PageState.Page;
|
||||
}
|
||||
// check if page has changed
|
||||
if (page.Path != path)
|
||||
{
|
||||
page = pages.Where(item => item.Path == path).FirstOrDefault();
|
||||
reload = Constants.ReloadPage;
|
||||
}
|
||||
|
||||
user = null;
|
||||
if (PageState == null || reload == true)
|
||||
if (PageState == null || reload >= Constants.ReloadPage)
|
||||
{
|
||||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
if (authState.User.Identity.IsAuthenticated)
|
||||
@ -167,29 +193,6 @@
|
||||
user = PageState.User;
|
||||
}
|
||||
|
||||
if (PageState == null || reload == true)
|
||||
{
|
||||
pages = await PageService.GetPagesAsync(site.SiteId);
|
||||
}
|
||||
else
|
||||
{
|
||||
pages = PageState.Pages;
|
||||
}
|
||||
|
||||
if (PageState == null || reload == true)
|
||||
{
|
||||
page = pages.Where(item => item.Path == path).FirstOrDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
page = PageState.Page;
|
||||
}
|
||||
if (page.Path != path)
|
||||
{
|
||||
page = pages.Where(item => item.Path == path).FirstOrDefault();
|
||||
reload = true;
|
||||
}
|
||||
|
||||
if (page != null)
|
||||
{
|
||||
// check if user is authorized to view page
|
||||
@ -211,10 +214,10 @@
|
||||
|
||||
if (PageState != null && (PageState.ModuleId != pagestate.ModuleId || PageState.Control != pagestate.Control))
|
||||
{
|
||||
reload = true;
|
||||
reload = Constants.ReloadPage;
|
||||
}
|
||||
|
||||
if (PageState == null || reload == true)
|
||||
if (PageState == null || reload >= Constants.ReloadPage)
|
||||
{
|
||||
modules = await ModuleService.GetModulesAsync(page.PageId);
|
||||
modules = ProcessModules(modules, moduledefinitions, pagestate.Control, page.Panes);
|
||||
@ -224,6 +227,7 @@
|
||||
modules = PageState.Modules;
|
||||
}
|
||||
pagestate.Modules = modules;
|
||||
pagestate.Reload = 0;
|
||||
|
||||
OnStateChange?.Invoke(pagestate);
|
||||
}
|
||||
|
@ -5,52 +5,37 @@ namespace Oqtane.Shared
|
||||
{
|
||||
public class Utilities
|
||||
{
|
||||
public static string NavigateUrl(PageState pagestate)
|
||||
{
|
||||
return NavigateUrl(pagestate, pagestate.Page.Path, false);
|
||||
}
|
||||
|
||||
public static string NavigateUrl(PageState pagestate, bool reload)
|
||||
public static string NavigateUrl(string alias, string path)
|
||||
{
|
||||
return NavigateUrl(pagestate, pagestate.Page.Path, reload);
|
||||
}
|
||||
|
||||
public static string NavigateUrl(PageState pagestate, string path)
|
||||
{
|
||||
return NavigateUrl(pagestate, path, false);
|
||||
}
|
||||
|
||||
public static string NavigateUrl(PageState pagestate, string path, bool reload)
|
||||
{
|
||||
string url = pagestate.Alias.Path + "/" + path;
|
||||
if (reload)
|
||||
string url = "";
|
||||
if (alias != "")
|
||||
{
|
||||
if (url.Contains("?"))
|
||||
{
|
||||
url += "&reload=true";
|
||||
}
|
||||
else
|
||||
{
|
||||
url += "?reload=true";
|
||||
}
|
||||
url += alias + "/";
|
||||
}
|
||||
if (path != "")
|
||||
{
|
||||
url += path + "/";
|
||||
}
|
||||
if (!url.StartsWith("/"))
|
||||
{
|
||||
url = "/" + url;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
public static string EditUrl(PageState pagestate, Module modulestate, string action)
|
||||
public static string EditUrl(string alias, string path, int moduleid, string action, string parameters)
|
||||
{
|
||||
return EditUrl(pagestate, modulestate, action, "");
|
||||
}
|
||||
|
||||
public static string EditUrl(PageState pagestate, Module modulestate, string action, string parameters)
|
||||
{
|
||||
string url = pagestate.Alias.Path;
|
||||
if (pagestate.Page.Path != "")
|
||||
string url = NavigateUrl(alias, path);
|
||||
if ( url == "/" )
|
||||
{
|
||||
url += "/" + pagestate.Page.Path;
|
||||
url = "";
|
||||
}
|
||||
url += "/" + modulestate.ModuleId.ToString();
|
||||
if (action != "")
|
||||
if (moduleid != -1)
|
||||
{
|
||||
url += "/" + moduleid.ToString();
|
||||
}
|
||||
if (moduleid != -1 && action != "")
|
||||
{
|
||||
url += "/" + action;
|
||||
}
|
||||
@ -58,6 +43,10 @@ namespace Oqtane.Shared
|
||||
{
|
||||
url += "?" + parameters;
|
||||
}
|
||||
if (!url.StartsWith("/"))
|
||||
{
|
||||
url = "/" + url;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user