Merge pull request #2357 from sbwalker/dev

add support for preserving state when loading admin components
This commit is contained in:
Shaun Walker 2022-08-12 10:45:05 -04:00 committed by GitHub
commit 66e3e6729b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 27 additions and 25 deletions

View File

@ -191,13 +191,6 @@
private string CloseUrl() private string CloseUrl()
{ {
if (!PageState.QueryString.ContainsKey("level")) return (!string.IsNullOrEmpty(PageState.ReturnUrl)) ? PageState.ReturnUrl : NavigateUrl();
{
return NavigateUrl();
}
else
{
return NavigateUrl(PageState.Page.Path, "level=" + PageState.QueryString["level"] + "&function=" + PageState.QueryString["function"] + "&rows=" + PageState.QueryString["rows"] + "&page=" + PageState.QueryString["page"]);
}
} }
} }

View File

@ -63,7 +63,7 @@ else
<th>@Localizer["Function"]</th> <th>@Localizer["Function"]</th>
</Header> </Header>
<Row> <Row>
<td class="@GetClass(context.Function)"><ActionLink Action="Detail" Parameters="@($"id=" + context.LogId.ToString() + "&level=" + _level + "&function=" + _function + "&rows=" + _rows + "&page=" + _page.ToString())" ResourceKey="LogDetails" /></td> <td class="@GetClass(context.Function)"><ActionLink Action="Detail" Parameters="@($"id={context.LogId}")" ReturnUrl="@(NavigateUrl(PageState.Page.Path, $"level={_level}&function={_function}&rows={_rows}&page={_page}"))" ResourceKey="LogDetails" /></td>
<td class="@GetClass(context.Function)">@context.LogDate</td> <td class="@GetClass(context.Function)">@context.LogDate</td>
<td class="@GetClass(context.Function)">@context.Level</td> <td class="@GetClass(context.Function)">@context.Level</td>
<td class="@GetClass(context.Function)">@context.Feature</td> <td class="@GetClass(context.Function)">@context.Feature</td>

View File

@ -128,13 +128,6 @@
private string CloseUrl() private string CloseUrl()
{ {
if (!PageState.QueryString.ContainsKey("type")) return (!string.IsNullOrEmpty(PageState.ReturnUrl)) ? PageState.ReturnUrl : NavigateUrl();
{
return NavigateUrl();
}
else
{
return NavigateUrl(PageState.Page.Path, "type=" + PageState.QueryString["type"] + "&days=" + PageState.QueryString["days"] + "&page=" + PageState.QueryString["page"]);
}
} }
} }

View File

@ -43,7 +43,7 @@ else
<th>@Localizer["Created"]</th> <th>@Localizer["Created"]</th>
</Header> </Header>
<Row> <Row>
<td><ActionLink Action="Detail" Parameters="@($"id=" + context.VisitorId.ToString() + "&type=" + _type.ToString() + "&days=" + _days.ToString() + "&page=" + _page.ToString())" ResourceKey="Details" /></td> <td><ActionLink Action="Detail" Parameters="@($"id={context.VisitorId}")" ReturnUrl="@(NavigateUrl(PageState.Page.Path, $"type={_type}&days={_days}&page={_page}"))" ResourceKey="Details" /></td>
<td>@context.IPAddress</td> <td>@context.IPAddress</td>
<td> <td>
@if (context.UserId != null) @if (context.UserId != null)

View File

@ -1,4 +1,5 @@
@namespace Oqtane.Modules.Controls @namespace Oqtane.Modules.Controls
@using System.Net
@inherits LocalizableComponent @inherits LocalizableComponent
@inject IUserService UserService @inject IUserService UserService
@ -71,6 +72,9 @@
[Parameter] [Parameter]
public bool IconOnly { get; set; } // optional - specifies only icon in link public bool IconOnly { get; set; } // optional - specifies only icon in link
[Parameter]
public string ReturnUrl { get; set; } // optional - used to set a url to redirect to
protected override void OnParametersSet() protected override void OnParametersSet()
{ {
base.OnParametersSet(); base.OnParametersSet();
@ -117,7 +121,11 @@
_permissions = (string.IsNullOrEmpty(Permissions)) ? ModuleState.Permissions : Permissions; _permissions = (string.IsNullOrEmpty(Permissions)) ? ModuleState.Permissions : Permissions;
_text = Localize(nameof(Text), _text); _text = Localize(nameof(Text), _text);
_url = (ModuleId == -1) ? EditUrl(Action, _parameters) : EditUrl(ModuleId, Action, _parameters); if (!string.IsNullOrEmpty(ReturnUrl))
{
_parameters += ((!string.IsNullOrEmpty(_parameters)) ? "&" : "") + $"returnurl={WebUtility.UrlEncode(ReturnUrl)}";
}
_url = (ModuleId == -1) ? EditUrl(Action, _parameters) : EditUrl(ModuleId, Action, _parameters);
_authorized = IsAuthorized(); _authorized = IsAuthorized();
} }

View File

@ -19,9 +19,9 @@
</div> </div>
@code { @code {
private void CloseModal() private void CloseModal()
{ {
NavigationManager.NavigateTo(NavigateUrl()); NavigationManager.NavigateTo((!string.IsNullOrEmpty(PageState.ReturnUrl)) ? PageState.ReturnUrl : NavigateUrl());
} }
} }

View File

@ -20,8 +20,9 @@ namespace Oqtane.UI
public string Action { get; set; } public string Action { get; set; }
public bool EditMode { get; set; } public bool EditMode { get; set; }
public DateTime LastSyncDate { get; set; } public DateTime LastSyncDate { get; set; }
public Oqtane.Shared.Runtime Runtime { get; set; } public Shared.Runtime Runtime { get; set; }
public int VisitorId { get; set; } public int VisitorId { get; set; }
public string RemoteIPAddress { get; set; } public string RemoteIPAddress { get; set; }
public string ReturnUrl { get; set; }
} }
} }

View File

@ -1,4 +1,5 @@
@using System.Diagnostics.CodeAnalysis @using System.Diagnostics.CodeAnalysis
@using System.Net
@namespace Oqtane.UI @namespace Oqtane.UI
@inject AuthenticationStateProvider AuthenticationStateProvider @inject AuthenticationStateProvider AuthenticationStateProvider
@inject SiteState SiteState @inject SiteState SiteState
@ -85,6 +86,11 @@
int moduleid = (int.TryParse(route.ModuleId, out moduleid)) ? moduleid : -1; int moduleid = (int.TryParse(route.ModuleId, out moduleid)) ? moduleid : -1;
var action = (!string.IsNullOrEmpty(route.Action)) ? route.Action : Constants.DefaultAction; var action = (!string.IsNullOrEmpty(route.Action)) ? route.Action : Constants.DefaultAction;
var querystring = ParseQueryString(route.Query); var querystring = ParseQueryString(route.Query);
var returnurl = "";
if (querystring.ContainsKey("returnurl"))
{
returnurl = WebUtility.UrlDecode(querystring["returnurl"]);
}
// reload the client application from the server if there is a forced reload or the user navigated to a site with a different alias // reload the client application from the server if there is a forced reload or the user navigated to a site with a different alias
if (querystring.ContainsKey("reload") || (!NavigationManager.ToBaseRelativePath(_absoluteUri).ToLower().StartsWith(SiteState.Alias.Path.ToLower()) && !string.IsNullOrEmpty(SiteState.Alias.Path))) if (querystring.ContainsKey("reload") || (!NavigationManager.ToBaseRelativePath(_absoluteUri).ToLower().StartsWith(SiteState.Alias.Path.ToLower()) && !string.IsNullOrEmpty(SiteState.Alias.Path)))
@ -248,7 +254,8 @@
LastSyncDate = lastsyncdate, LastSyncDate = lastsyncdate,
Runtime = runtime, Runtime = runtime,
VisitorId = VisitorId, VisitorId = VisitorId,
RemoteIPAddress = SiteState.RemoteIPAddress RemoteIPAddress = SiteState.RemoteIPAddress,
ReturnUrl = returnurl
}; };
OnStateChange?.Invoke(_pagestate); OnStateChange?.Invoke(_pagestate);