Skip to content

Commit

Permalink
Merge pull request #4640 from sbwalker/dev
Browse files Browse the repository at this point in the history
fix #4628 - preserve Url for all ModuleActions
  • Loading branch information
sbwalker authored Sep 19, 2024
2 parents 3682a10 + 49b9712 commit 0639f6c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Oqtane.Client/Modules/Admin/Modules/Export.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</div>

<button type="button" class="btn btn-success" @onclick="ExportModule">@Localizer["Export"]</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">@SharedLocalizer["Cancel"]</NavLink>
<NavLink class="btn btn-secondary" href="@PageState.ReturnUrl">@SharedLocalizer["Cancel"]</NavLink>

@code {
private string _content = string.Empty;
Expand Down
2 changes: 1 addition & 1 deletion Oqtane.Client/Modules/Admin/Modules/Import.razor
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</div>

<button type="button" class="btn btn-success" @onclick="ImportModule">@Localizer["Import"]</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">@SharedLocalizer["Cancel"]</NavLink>
<NavLink class="btn btn-secondary" href="@PageState.ReturnUrl">@SharedLocalizer["Cancel"]</NavLink>
</form>

@code {
Expand Down
65 changes: 32 additions & 33 deletions Oqtane.Client/Themes/Controls/Container/ModuleActionsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
using Microsoft.Extensions.Localization;
using Oqtane.UI;

// ReSharper disable UnassignedGetOnlyAutoProperty
// ReSharper disable MemberCanBePrivate.Global

namespace Oqtane.Themes.Controls
{
public class ModuleActionsBase : ComponentBase
Expand Down Expand Up @@ -92,20 +89,17 @@ protected virtual List<ActionViewModel> GetActions()
return actionList;
}

private async Task<string> EditUrlAsync(string url, int moduleId, string import)
{
await Task.Yield();
return Utilities.EditUrl(PageState.Alias.Path, PageState.Page.Path, moduleId, import, "");
}

protected async Task ModuleAction(ActionViewModel action)
{
if (PageState.EditMode && UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, ModuleState.PermissionList))
{
PageModule pagemodule = await PageModuleService.GetPageModuleAsync(ModuleState.PageModuleId);

string url = Utilities.NavigateUrl(PageState.Alias.Path, PageState.Page.Path, "edit=true&refresh");
var url = NavigationManager.Uri.Substring(NavigationManager.BaseUri.Length - 1);
if (!url.Contains("edit=true&refresh"))
{
url += (!url.Contains("?") ? "?" : "&") + "edit=true&refresh";
}

var pagemodule = await PageModuleService.GetPageModuleAsync(ModuleState.PageModuleId);
if (action.Action != null)
{
url = await action.Action(url, pagemodule);
Expand All @@ -115,29 +109,9 @@ protected async Task ModuleAction(ActionViewModel action)
}
}

private async Task<string> MoveToPane(string url, string newPane, PageModule pagemodule)
{
string oldPane = pagemodule.Pane;
pagemodule.Pane = newPane;
pagemodule.Order = int.MaxValue; // add to bottom of pane
await PageModuleService.UpdatePageModuleAsync(pagemodule);
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, oldPane);
return url;
}

private async Task<string> DeleteModule(string url, PageModule pagemodule)
{
pagemodule.IsDeleted = true;
await PageModuleService.UpdatePageModuleAsync(pagemodule);
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
return url;
}

private Task<string> Settings(string url, PageModule pagemodule)
{
var returnurl = NavigationManager.Uri.Substring(NavigationManager.BaseUri.Length - 1);
url = Utilities.EditUrl(PageState.Alias.Path, PageState.Page.Path, pagemodule.ModuleId, "Settings", "returnurl=" + WebUtility.UrlEncode(returnurl));
url = Utilities.EditUrl(PageState.Alias.Path, PageState.Page.Path, pagemodule.ModuleId, "Settings", "returnurl=" + WebUtility.UrlEncode(url));
return Task.FromResult(url);
}

Expand Down Expand Up @@ -173,6 +147,20 @@ private async Task<string> Unpublish(string url, PageModule pagemodule)
return url;
}

private async Task<string> DeleteModule(string url, PageModule pagemodule)
{
pagemodule.IsDeleted = true;
await PageModuleService.UpdatePageModuleAsync(pagemodule);
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
return url;
}

private Task<string> EditUrlAsync(string url, int moduleId, string import)
{
url = Utilities.EditUrl(PageState.Alias.Path, PageState.Page.Path, moduleId, import, "returnurl=" + WebUtility.UrlEncode(url));
return Task.FromResult(url);
}

private async Task<string> MoveTop(string url, PageModule pagemodule)
{
pagemodule.Order = 0;
Expand Down Expand Up @@ -205,6 +193,17 @@ private async Task<string> MoveDown(string url, PageModule pagemodule)
return url;
}

private async Task<string> MoveToPane(string url, string newPane, PageModule pagemodule)
{
string oldPane = pagemodule.Pane;
pagemodule.Pane = newPane;
pagemodule.Order = int.MaxValue; // add to bottom of pane
await PageModuleService.UpdatePageModuleAsync(pagemodule);
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, oldPane);
return url;
}

public class ActionViewModel
{
public string Icon { get; set; }
Expand Down

0 comments on commit 0639f6c

Please sign in to comment.