373 lines
15 KiB
Plaintext
373 lines
15 KiB
Plaintext
@namespace Oqtane.Themes.Controls
|
|
@inherits ThemeControlBase
|
|
@inject NavigationManager NavigationManager
|
|
@inject IUserService UserService
|
|
@inject IModuleDefinitionService ModuleDefinitionService
|
|
@inject IThemeService ThemeService
|
|
@inject IModuleService ModuleService
|
|
@inject IPageService PageService
|
|
@inject IPageModuleService PageModuleService
|
|
|
|
@if (UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions))
|
|
{
|
|
<div class="app-controlpanel" style="@display">
|
|
<div class="card @cardclass mb-3">
|
|
<div class="card-header">
|
|
Control Panel
|
|
<button type="button" class="close" @onclick="HideControlPanel" data-dismiss="modal" aria-label="Close">
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
</div>
|
|
<div class="card-body">
|
|
<ul class="nav flex-column">
|
|
<li class="nav-item px-3"><button type="button" class="btn btn-primary btn-block mx-auto" @onclick=@(async () => Navigate("Admin"))>Admin Dashboard</button></li>
|
|
<li class="nav-item px-3"> </li>
|
|
<li class="nav-item px-3"><button type="button" class="btn btn-primary btn-block mx-auto" @onclick=@(async () => Navigate("Add"))>Add Page</button></li>
|
|
<li class="nav-item px-3"><button type="button" class="btn btn-primary btn-block mx-auto" @onclick=@(async () => Navigate("Edit"))>Edit Page</button></li>
|
|
<li class="nav-item px-3"><button type="button" class="btn btn-primary btn-block mx-auto" @onclick=@(async () => await Delete(PageState.Page))>Delete Page</button></li>
|
|
</ul>
|
|
<hr class="app-rule" />
|
|
<table class="table table-borderless">
|
|
<tr>
|
|
<td>
|
|
<label for="Module" class="control-label">Module: </label>
|
|
</td>
|
|
<td>
|
|
<select class="form-control" @bind="@moduletype">
|
|
<option value="new">Add New Module</option>
|
|
<option value="existing">Add Existing Module</option>
|
|
</select>
|
|
@if (moduletype == "new")
|
|
{
|
|
@if (moduledefinitions != null)
|
|
{
|
|
<select class="form-control" @onchange="(e => CategoryChanged(e))">
|
|
<option value="-"><Common Modules></option>
|
|
@foreach (var category in categories)
|
|
{
|
|
<option value="@category">@category</option>
|
|
}
|
|
</select>
|
|
<select class="form-control" @bind="@moduledefinitionname">
|
|
<option value="-"><Select Module></option>
|
|
@foreach (var moduledefinition in moduledefinitions)
|
|
{
|
|
if (moduledefinition.Permissions == "[]" || UserSecurity.IsAuthorized(PageState.User, "Utilize", moduledefinition.Permissions))
|
|
{
|
|
<option value="@moduledefinition.ModuleDefinitionName">@moduledefinition.Name</option>
|
|
}
|
|
}
|
|
</select>
|
|
}
|
|
}
|
|
else
|
|
{
|
|
<select class="form-control" @onchange="(e => PageChanged(e))">
|
|
<option value="-"><Select Page></option>
|
|
@foreach (Page p in pages)
|
|
{
|
|
<option value="@p.PageId">@p.Name</option>
|
|
}
|
|
</select>
|
|
<select class="form-control" @bind="@moduleid">
|
|
<option value="-"><Select Module></option>
|
|
@foreach (Module module in modules)
|
|
{
|
|
<option value="@module.ModuleId">@module.Title</option>
|
|
}
|
|
</select>
|
|
|
|
}
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Title" class="control-label">Title: </label>
|
|
</td>
|
|
<td>
|
|
<input type="text" name="Title" class="form-control" @bind="@title" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Pane" class="control-label">Pane: </label>
|
|
</td>
|
|
<td>
|
|
<select class="form-control" @bind="@pane">
|
|
<option value=""><Select Pane></option>
|
|
@foreach (string pane in PageState.Page.Panes.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
|
|
{
|
|
<option value="@pane">@pane Pane</option>
|
|
}
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Container" class="control-label">Container: </label>
|
|
</td>
|
|
<td>
|
|
<select class="form-control" @bind="@containertype">
|
|
@foreach (KeyValuePair<string, string> container in containers)
|
|
{
|
|
<option value="@container.Key">@container.Value</option>
|
|
}
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<button type="button" class="btn btn-primary btn-block mx-auto" @onclick="@AddModule">Add Module To Page</button>
|
|
@((MarkupString)@message)
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
@if (PageState.EditMode)
|
|
{
|
|
<button type="button" class="btn @buttonclass active" data-toggle="button" aria-pressed="true" autocomplete="off" @onclick="EditMode">
|
|
<span class="oi oi-pencil"></span>
|
|
</button>
|
|
}
|
|
else
|
|
{
|
|
<button type="button" class="btn @buttonclass" data-toggle="button" aria-pressed="false" autocomplete="off" @onclick="EditMode">
|
|
<span class="oi oi-pencil"></span>
|
|
</button>
|
|
}
|
|
<button type="button" class="btn @buttonclass" @onclick="ShowControlPanel">
|
|
<span class="oi oi-menu"></span>
|
|
</button>
|
|
}
|
|
|
|
@code {
|
|
[Parameter]
|
|
public string ButtonClass { get; set; }
|
|
|
|
[Parameter]
|
|
public string CardClass { get; set; }
|
|
|
|
string moduletype = "new";
|
|
List<string> categories = new List<string>();
|
|
List<ModuleDefinition> moduledefinitions;
|
|
List<Page> pages = new List<Page>();
|
|
string pageid = "";
|
|
string moduleid = "-";
|
|
List<Module> modules = new List<Module>();
|
|
Dictionary<string, string> containers = new Dictionary<string, string>();
|
|
string moduledefinitionname = "-";
|
|
string pane = "";
|
|
string title = "";
|
|
string containertype = "";
|
|
string display = "display: none;";
|
|
string buttonclass = "btn-outline-primary";
|
|
string cardclass = "text-white bg-secondary";
|
|
string message = "";
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
if (!string.IsNullOrEmpty(ButtonClass))
|
|
{
|
|
buttonclass = ButtonClass;
|
|
}
|
|
if (!string.IsNullOrEmpty(CardClass))
|
|
{
|
|
cardclass = CardClass;
|
|
}
|
|
|
|
if (UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions))
|
|
{
|
|
pages?.Clear();
|
|
|
|
foreach (ModuleDefinition moduledefinition in PageState.ModuleDefinitions)
|
|
{
|
|
if (moduledefinition.Categories != "")
|
|
{
|
|
foreach (string category in moduledefinition.Categories.Split(','))
|
|
{
|
|
if (!categories.Contains(category))
|
|
{
|
|
categories.Add(category);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
moduledefinitions = PageState.ModuleDefinitions.Where(item => item.Categories == "").ToList();
|
|
foreach (Page p in PageState.Pages)
|
|
{
|
|
if (UserSecurity.IsAuthorized(PageState.User, "View", p.Permissions))
|
|
{
|
|
pages.Add(p);
|
|
}
|
|
}
|
|
var panes = PageState.Page.Panes.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
|
|
pane = panes.Count() == 1 ? panes.SingleOrDefault() : "";
|
|
containers = ThemeService.GetContainerTypes(PageState.Themes);
|
|
containertype = PageState.Site.DefaultContainerType;
|
|
}
|
|
}
|
|
|
|
private void CategoryChanged(ChangeEventArgs e)
|
|
{
|
|
string category = (string)e.Value;
|
|
if (category == "-")
|
|
{
|
|
moduledefinitions = PageState.ModuleDefinitions.Where(item => item.Categories == "").ToList();
|
|
}
|
|
else
|
|
{
|
|
moduledefinitions = PageState.ModuleDefinitions.Where(item => item.Categories.Contains(e.Value.ToString())).ToList();
|
|
}
|
|
moduledefinitionname = "-";
|
|
StateHasChanged();
|
|
}
|
|
|
|
private void PageChanged(ChangeEventArgs e)
|
|
{
|
|
pageid = (string)e.Value;
|
|
modules?.Clear();
|
|
if (pageid != "")
|
|
{
|
|
foreach (Module module in PageState.Modules.Where(item => item.PageId == int.Parse(pageid) && !item.IsDeleted))
|
|
{
|
|
if (UserSecurity.IsAuthorized(PageState.User, "View", module.Permissions))
|
|
{
|
|
modules.Add(module);
|
|
}
|
|
}
|
|
}
|
|
moduleid = "-";
|
|
StateHasChanged();
|
|
}
|
|
|
|
private async Task AddModule()
|
|
{
|
|
if (UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions))
|
|
{
|
|
if (moduletype == "new")
|
|
{
|
|
Module module = new Module();
|
|
module.SiteId = PageState.Site.SiteId;
|
|
module.ModuleDefinitionName = moduledefinitionname;
|
|
module.Permissions = PageState.Page.Permissions;
|
|
module = await ModuleService.AddModuleAsync(module);
|
|
moduleid = module.ModuleId.ToString();
|
|
}
|
|
|
|
PageModule pagemodule = new PageModule();
|
|
pagemodule.PageId = string.IsNullOrWhiteSpace(pageid) ? PageState.Page.PageId : int.Parse(pageid);
|
|
pagemodule.ModuleId = int.Parse(moduleid);
|
|
pagemodule.Title = title;
|
|
if (pagemodule.Title == "")
|
|
{
|
|
if (moduletype == "new")
|
|
{
|
|
pagemodule.Title = moduledefinitions.Where(item => item.ModuleDefinitionName == moduledefinitionname).FirstOrDefault().Name;
|
|
}
|
|
else
|
|
{
|
|
pagemodule.Title = modules.Where(item => item.ModuleId == int.Parse(moduleid)).FirstOrDefault().Title;
|
|
}
|
|
}
|
|
pagemodule.Pane = pane;
|
|
pagemodule.Order = int.MaxValue;
|
|
pagemodule.ContainerType = containertype;
|
|
|
|
if (pagemodule.ContainerType == PageState.Site.DefaultContainerType)
|
|
{
|
|
pagemodule.ContainerType = "";
|
|
}
|
|
|
|
await PageModuleService.AddPageModuleAsync(pagemodule);
|
|
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
|
|
|
|
message = "<br /><div class=\"alert alert-success\" role=\"alert\">Module Added To Page</div>";
|
|
|
|
moduledefinitionname = "-";
|
|
pane = "";
|
|
title = "";
|
|
containertype = "";
|
|
moduleid = "-";
|
|
|
|
NavigationManager.NavigateTo(NavigateUrl(Reload.Page));
|
|
}
|
|
}
|
|
|
|
private void EditMode()
|
|
{
|
|
if (UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions))
|
|
{
|
|
if (PageState.EditMode)
|
|
{
|
|
PageState.EditMode = false;
|
|
PageState.DesignMode = false;
|
|
}
|
|
else
|
|
{
|
|
PageState.EditMode = true;
|
|
PageState.DesignMode = true;
|
|
}
|
|
NavigationManager.NavigateTo(NavigateUrl(PageState.Page.Path, "edit=" + ((PageState.EditMode) ? "1" : "0"), Reload.Page));
|
|
}
|
|
}
|
|
|
|
private void ShowControlPanel()
|
|
{
|
|
message = "";
|
|
display = "width: 25%;";
|
|
StateHasChanged();
|
|
}
|
|
|
|
private void HideControlPanel()
|
|
{
|
|
message = "";
|
|
display = "width: 0%;";
|
|
StateHasChanged();
|
|
}
|
|
|
|
private void Navigate(string location)
|
|
{
|
|
HideControlPanel();
|
|
Module module;
|
|
switch (location)
|
|
{
|
|
case "Admin":
|
|
// get admin dashboard moduleid
|
|
module = PageState.Modules.Where(item => item.ModuleDefinitionName == Constants.AdminDashboardModule).FirstOrDefault();
|
|
if (module != null)
|
|
{
|
|
NavigationManager.NavigateTo(EditUrl(PageState.Page.Path, module.ModuleId, "Index", ""));
|
|
}
|
|
break;
|
|
case "Add":
|
|
case "Edit":
|
|
string url = "";
|
|
// get page management moduleid
|
|
module = PageState.Modules.Where(item => item.ModuleDefinitionName == Constants.PageManagementModule).FirstOrDefault();
|
|
if (module != null)
|
|
{
|
|
switch (location)
|
|
{
|
|
case "Add":
|
|
url = EditUrl(PageState.Page.Path, module.ModuleId, location, "");
|
|
break;
|
|
case "Edit":
|
|
url = EditUrl(PageState.Page.Path, module.ModuleId, location, "id=" + PageState.Page.PageId.ToString());
|
|
break;
|
|
}
|
|
}
|
|
if (url != "")
|
|
{
|
|
NavigationManager.NavigateTo(url);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
private async Task Delete(Page Page)
|
|
{
|
|
Page.IsDeleted = true;
|
|
await PageService.UpdatePageAsync(Page);
|
|
NavigationManager.NavigateTo(NavigateUrl("", Reload.Site));
|
|
}
|
|
}
|