Merge pull request #45 from sbwalker/master

Replace querystring routes with conventional routes
This commit is contained in:
Shaun Walker 2019-07-29 21:46:50 -04:00 committed by GitHub
commit 86257b1a29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 292 additions and 273 deletions

View File

@ -75,6 +75,8 @@ private async Task Refresh()
Page page;
User user;
List<Module> modules;
int moduleid = -1;
string control = "";
bool reload = false;
if (PageState == null)
@ -144,10 +146,30 @@ private async Task Refresh()
pages = PageState.Pages;
}
// format path so that it can be located in the pages collection
if (path.IndexOf("?") != -1)
{
// remove querystring from path
path = path.Substring(0, path.IndexOf("?"));
}
// remove admin route elements from path
string[] segments = path.Split('/');
int result;
// admin routes are in the form of path/moduleid/control or path/moduleid
if (segments.Length >= 2 && int.TryParse(segments[segments.Length - 2], out result))
{
control = segments[segments.Length - 1];
moduleid = result;
path = path.Replace("/" + moduleid.ToString() + "/" + control, "");
}
else
{
if (segments.Length >= 1 && int.TryParse(segments[segments.Length - 1], out result))
{
moduleid = result;
path = path.Replace("/" + moduleid.ToString(), "");
}
}
if (PageState == null || reload == true)
{
@ -179,17 +201,9 @@ private async Task Refresh()
pagestate.User = user;
pagestate.Uri = new Uri(_absoluteUri, UriKind.Absolute);
pagestate.QueryString = querystring;
pagestate.ModuleId = -1;
pagestate.Control = "";
pagestate.ModuleId = moduleid;
pagestate.Control = control;
if (querystring.ContainsKey("mid"))
{
pagestate.ModuleId = int.Parse(querystring["mid"]);
}
if (querystring.ContainsKey("ctl"))
{
pagestate.Control = querystring["ctl"];
}
if (PageState != null && (PageState.ModuleId != pagestate.ModuleId || PageState.Control != pagestate.Control))
{
reload = true;

View File

@ -44,14 +44,19 @@ namespace Oqtane.Shared
public static string EditUrl(PageState pagestate, Module modulestate, string action, string parameters)
{
string url = pagestate.Alias.Path + "/" + pagestate.Page.Path + "?mid=" + modulestate.ModuleId.ToString();
string url = pagestate.Alias.Path;
if (pagestate.Page.Path != "")
{
url += "/" + pagestate.Page.Path;
}
url += "/" + modulestate.ModuleId.ToString();
if (action != "")
{
url += "&ctl=" + action;
url += "/" + action;
}
if (!string.IsNullOrEmpty(parameters))
{
url += "&" + parameters;
url += "?" + parameters;
}
return url;
}