oqtane.framework/Oqtane.Client/Themes/Controls/ModuleActions.razor
2019-08-14 11:16:39 -04:00

86 lines
2.9 KiB
Plaintext

@using Oqtane.Themes
@using Oqtane.Services
@using Oqtane.Models
@using Oqtane.Shared
@inherits ContainerBase
@inject IUriHelper UriHelper
@inject IUserService UserService
@inject IPageModuleService PageModuleService
<div class="dropdown" style="@display">
<button type="button" class="btn dropdown-toggle" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"></button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
@foreach (var action in actions)
{
<a class="dropdown-item" @onclick="@(async () => await ModuleAction(action.Action))">@action.Name</a>
}
</div>
</div>
@code {
string display = "display: none";
List<ActionViewModel> actions;
protected override void OnInit()
{
actions = new List<ActionViewModel>();
if (ModuleState.PaneModuleIndex > 0)
{
actions.Add(new ActionViewModel { Action = "up", Name = "Move Up" });
}
if (ModuleState.PaneModuleIndex < (ModuleState.PaneModuleCount - 1))
{
actions.Add(new ActionViewModel { Action = "down", Name = "Move Down" });
}
foreach (string pane in PageState.Page.Panes.Split(';'))
{
if (pane != ModuleState.Pane)
{
actions.Add(new ActionViewModel { Action = pane, Name = "Move To " + pane + " Pane" });
}
}
actions.Add(new ActionViewModel { Action = "settings", Name = "Settings" });
actions.Add(new ActionViewModel { Action = "delete", Name = "Delete" });
if (UserService.IsAuthorized(PageState.User, ModuleState.EditPermissions))
{
display = "display: inline";
}
}
protected async Task ModuleAction(string action)
{
PageModule pagemodule = await PageModuleService.GetPageModuleAsync(ModuleState.PageModuleId);
string url = NavigateUrl();
switch (action)
{
case "up":
pagemodule.Order += -1;
await PageModuleService.UpdatePageModuleAsync(pagemodule);
break;
case "down":
pagemodule.Order += 1;
await PageModuleService.UpdatePageModuleAsync(pagemodule);
break;
case "settings":
url = EditUrl(pagemodule.ModuleId, "Settings");
break;
case "delete":
await PageModuleService.DeletePageModuleAsync(pagemodule.PageModuleId);
break;
default: // move to pane
pagemodule.Pane = action;
await PageModuleService.UpdatePageModuleAsync(pagemodule);
break;
}
PageState.Reload = Constants.ReloadPage;
UriHelper.NavigateTo(url);
}
public class ActionViewModel
{
public string Action { set; get; }
public string Name { set; get; }
}
}