539 lines
21 KiB
Plaintext
539 lines
21 KiB
Plaintext
@namespace Oqtane.Themes.Controls
|
|
@using Oqtane.Enums
|
|
@inherits ThemeControlBase
|
|
@inject NavigationManager NavigationManager
|
|
@inject IUserService UserService
|
|
@inject IModuleDefinitionService ModuleDefinitionService
|
|
@inject IThemeService ThemeService
|
|
@inject IModuleService ModuleService
|
|
@inject IPageService PageService
|
|
@inject IPageModuleService PageModuleService
|
|
@inject ILogService logger
|
|
|
|
@if (_moduleDefinitions != null && UserSecurity.IsAuthorized(PageState.User,PermissionNames.Edit, PageState.Page.Permissions))
|
|
{
|
|
<div class="app-controlpanel" style="@_display">
|
|
|
|
<div class="@CardClass">
|
|
<div class="@HeaderClass">
|
|
Control Panel
|
|
<button type="button" class="close" @onclick="HideControlPanel" data-dismiss="modal" aria-label="Close">
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
</div>
|
|
<div class="@BodyClass">
|
|
|
|
@if (UserSecurity.IsAuthorized(PageState.User, Constants.AdminRole))
|
|
{
|
|
<div class="row">
|
|
<div class="col">
|
|
<button type="button" class="btn btn-primary btn-block mx-auto" @onclick=@(async () => Navigate("Admin"))>Admin Dashboard</button>
|
|
</div>
|
|
</div>
|
|
|
|
<hr class="app-rule" />
|
|
|
|
<div class="row">
|
|
<div class="col text-center">
|
|
<label class="control-label">Page Management: </label>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col">
|
|
<button type="button" class="btn btn-primary btn-block mx-auto" @onclick=@(async () => Navigate("Add"))>Add</button>
|
|
</div>
|
|
<div class="col">
|
|
<button type="button" class="btn btn-primary btn-block mx-auto" @onclick=@(async () => Navigate("Edit"))>Edit</button>
|
|
</div>
|
|
<div class="col">
|
|
<button class="btn btn-danger btn-block mx-auto" @onclick="ConfirmDelete">Delete</button>
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
@if (_deleteConfirmation)
|
|
{
|
|
<div class="app-admin-modal">
|
|
<div class="modal" tabindex="-1" role="dialog">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">Delete Page</h5>
|
|
<button type="button" class="close" @onclick="ConfirmDelete" aria-label="Close">×</button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<p>Are You Sure You Want To Delete This Page?</p>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-danger" @onclick="DeletePage">Delete</button>
|
|
<button type="button" class="btn btn-secondary" @onclick="ConfirmDelete">Cancel</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
<hr class="app-rule" />
|
|
|
|
<div class="row">
|
|
<div class="col text-center">
|
|
<label for="Module" class="control-label">Module Management: </label>
|
|
<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))">
|
|
@foreach (var category in _categories)
|
|
{
|
|
if (category == _category)
|
|
{
|
|
<option value="@category" selected>@category Modules</option>
|
|
}
|
|
else
|
|
{
|
|
<option value="@category">@category Modules</option>
|
|
}
|
|
}
|
|
</select>
|
|
<select class="form-control" @onchange="(e => ModuleChanged(e))">
|
|
@if (_moduleDefinitionName == "-")
|
|
{
|
|
<option value="-" selected><Select Module></option>
|
|
}
|
|
else
|
|
{
|
|
<option value="-"><Select Module></option>
|
|
}
|
|
@foreach (var moduledefinition in _moduleDefinitions)
|
|
{
|
|
if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.Utilize, moduledefinition.Permissions))
|
|
{
|
|
<option value="@moduledefinition.ModuleDefinitionName">@moduledefinition.Name</option>
|
|
}
|
|
}
|
|
</select>
|
|
@((MarkupString)@_description)
|
|
}
|
|
}
|
|
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>
|
|
}
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col text-center">
|
|
<label for="Title" class="control-label">Title: </label>
|
|
<input type="text" name="Title" class="form-control" @bind="@_title" />
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col text-center">
|
|
<label for="Pane" class="control-label">Pane: </label>
|
|
<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>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col text-center">
|
|
<label for="Container" class="control-label">Container: </label>
|
|
<select class="form-control" @bind="@_containerType">
|
|
@foreach (KeyValuePair<string, string> container in _containers)
|
|
{
|
|
<option value="@container.Key">@container.Value</option>
|
|
}
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<br />
|
|
|
|
<button type="button" class="btn btn-primary btn-block mx-auto" @onclick="@AddModule">Add Module To Page</button>
|
|
@((MarkupString) _message)
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
@if (UserSecurity.IsAuthorized(PageState.User,PermissionNames.Edit, PageState.Page.Permissions) || (PageState.Page.IsPersonalizable && PageState.User != null))
|
|
{
|
|
@if (PageState.Page.EditMode)
|
|
{
|
|
<button type="button" class="btn @ButtonClass active" aria-pressed="true" autocomplete="off">
|
|
<span class="oi oi-pencil"></span>
|
|
</button>
|
|
}
|
|
else
|
|
{
|
|
if (PageState.EditMode)
|
|
{
|
|
<button type="button" class="btn @ButtonClass active" data-toggle="button" aria-pressed="true" autocomplete="off" @onclick="(async () => await ToggleEditMode(PageState.EditMode))">
|
|
<span class="oi oi-pencil"></span>
|
|
</button>
|
|
}
|
|
else
|
|
{
|
|
<button type="button" class="btn @ButtonClass" data-toggle="button" aria-pressed="false" autocomplete="off" @onclick="(async () => await ToggleEditMode(PageState.EditMode))">
|
|
<span class="oi oi-pencil"></span>
|
|
</button>
|
|
}
|
|
}
|
|
}
|
|
|
|
@if (UserSecurity.IsAuthorized(PageState.User,PermissionNames.Edit, PageState.Page.Permissions))
|
|
{
|
|
<button type="button" class="btn @ButtonClass" @onclick="ShowControlPanel">
|
|
<span class="oi oi-menu"></span>
|
|
</button>
|
|
}
|
|
|
|
@code {
|
|
private bool _deleteConfirmation = false;
|
|
private string _moduleType = "new";
|
|
private List<string> _categories = new List<string>();
|
|
private List<ModuleDefinition> _allModuleDefinitions;
|
|
private List<ModuleDefinition> _moduleDefinitions;
|
|
private List<Page> _pages = new List<Page>();
|
|
private string _pageId = "-";
|
|
private string _moduleId = "-";
|
|
private List<Module> _modules = new List<Module>();
|
|
private Dictionary<string, string> _containers = new Dictionary<string, string>();
|
|
private string _moduleDefinitionName = "-";
|
|
private string _category = "Common";
|
|
private string _description = "";
|
|
private string _pane = "";
|
|
private string _title = "";
|
|
private string _containerType = "";
|
|
private string _display = "display: none;";
|
|
private string _message = "";
|
|
|
|
[Parameter]
|
|
public string ButtonClass { get; set; }
|
|
|
|
[Parameter]
|
|
public string CardClass { get; set; }
|
|
|
|
[Parameter]
|
|
public string HeaderClass { get; set; }
|
|
|
|
[Parameter]
|
|
public string BodyClass { get; set; }
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
if (string.IsNullOrEmpty(ButtonClass))
|
|
{
|
|
ButtonClass = "btn-outline-primary";
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(CardClass))
|
|
{
|
|
CardClass = "card bg-secondary mb-3";
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(HeaderClass))
|
|
{
|
|
HeaderClass = "card-header text-white";
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(BodyClass))
|
|
{
|
|
BodyClass = "card-body";
|
|
}
|
|
|
|
if (UserSecurity.IsAuthorized(PageState.User,PermissionNames.Edit, PageState.Page.Permissions))
|
|
{
|
|
_pages?.Clear();
|
|
|
|
foreach (Page p in PageState.Pages)
|
|
{
|
|
if (UserSecurity.IsAuthorized(PageState.User,PermissionNames.View, p.Permissions))
|
|
{
|
|
_pages.Add(p);
|
|
}
|
|
}
|
|
|
|
var panes = PageState.Page.Panes.Split(new[] {';'}, StringSplitOptions.RemoveEmptyEntries);
|
|
_pane = panes.Count() == 1 ? panes.SingleOrDefault() : "";
|
|
var themes = await ThemeService.GetThemesAsync();
|
|
_containers = ThemeService.GetContainerTypes(themes);
|
|
_containerType = PageState.Site.DefaultContainerType;
|
|
|
|
_allModuleDefinitions = await ModuleDefinitionService.GetModuleDefinitionsAsync(PageState.Site.SiteId);
|
|
|
|
_categories = new List<string>();
|
|
foreach (ModuleDefinition moduledefinition in _allModuleDefinitions)
|
|
{
|
|
if (moduledefinition.Categories != "")
|
|
{
|
|
foreach (string category in moduledefinition.Categories.Split(','))
|
|
{
|
|
if (!_categories.Contains(category))
|
|
{
|
|
_categories.Add(category);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
_category = "Common";
|
|
_moduleDefinitions = _allModuleDefinitions.Where(item => item.Categories.Contains(_category)).ToList();
|
|
_moduleDefinitionName = "-";
|
|
_description = "";
|
|
}
|
|
}
|
|
|
|
private void CategoryChanged(ChangeEventArgs e)
|
|
{
|
|
_category = (string) e.Value;
|
|
_moduleDefinitions = _allModuleDefinitions.Where(item => item.Categories.Contains(_category)).ToList();
|
|
_moduleDefinitionName = "-";
|
|
_description = "";
|
|
StateHasChanged();
|
|
}
|
|
|
|
private void ModuleChanged(ChangeEventArgs e)
|
|
{
|
|
_moduleDefinitionName = (string)e.Value;
|
|
if (_moduleDefinitionName != "-")
|
|
{
|
|
var moduleDefinition = _moduleDefinitions.FirstOrDefault(item => item.ModuleDefinitionName == _moduleDefinitionName);
|
|
_description = "<br /><div class=\"alert alert-info\" role=\"alert\">" + moduleDefinition.Description + "</div>";
|
|
}
|
|
else
|
|
{
|
|
_description = "";
|
|
}
|
|
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,PermissionNames.View, module.Permissions))
|
|
{
|
|
_modules.Add(module);
|
|
}
|
|
}
|
|
}
|
|
|
|
_moduleId = "-";
|
|
StateHasChanged();
|
|
}
|
|
|
|
private async Task AddModule()
|
|
{
|
|
if (UserSecurity.IsAuthorized(PageState.User,PermissionNames.Edit, PageState.Page.Permissions))
|
|
{
|
|
if ((_moduleType == "new" && _moduleDefinitionName != "-") || (_moduleType != "new" && _moduleId != "-"))
|
|
{
|
|
if (_moduleType == "new")
|
|
{
|
|
Module module = new Module();
|
|
module.SiteId = PageState.Site.SiteId;
|
|
module.PageId = PageState.Page.PageId;
|
|
module.ModuleDefinitionName = _moduleDefinitionName;
|
|
module.Permissions = PageState.Page.Permissions;
|
|
module = await ModuleService.AddModuleAsync(module);
|
|
_moduleId = module.ModuleId.ToString();
|
|
}
|
|
|
|
var pageModule = new PageModule
|
|
{
|
|
PageId = PageState.Page.PageId,
|
|
ModuleId = int.Parse(_moduleId),
|
|
Title = _title
|
|
};
|
|
if (pageModule.Title == "")
|
|
{
|
|
if (_moduleType == "new")
|
|
{
|
|
pageModule.Title = _moduleDefinitions.FirstOrDefault(item => item.ModuleDefinitionName == _moduleDefinitionName)?.Name;
|
|
}
|
|
else
|
|
{
|
|
pageModule.Title = _modules.FirstOrDefault(item => item.ModuleId == int.Parse(_moduleId))?.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 = "-";
|
|
_description = "";
|
|
_pane = "";
|
|
_title = "";
|
|
_containerType = "";
|
|
_pageId = "-";
|
|
_moduleId = "-";
|
|
|
|
NavigationManager.NavigateTo(NavigateUrl());
|
|
}
|
|
else
|
|
{
|
|
_message = "<br /><div class=\"alert alert-warning\" role=\"alert\">You Must Select A Module</div>";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_message = "<br /><div class=\"alert alert-error\" role=\"alert\">Not Authorized</div>";
|
|
}
|
|
}
|
|
|
|
private async Task ToggleEditMode(bool EditMode)
|
|
{
|
|
if (UserSecurity.IsAuthorized(PageState.User,PermissionNames.Edit, PageState.Page.Permissions))
|
|
{
|
|
if (EditMode)
|
|
{
|
|
PageState.EditMode = false;
|
|
}
|
|
else
|
|
{
|
|
PageState.EditMode = true;
|
|
}
|
|
NavigationManager.NavigateTo(NavigateUrl(PageState.Page.Path, "edit=" + ((PageState.EditMode) ? "1" : "0")));
|
|
}
|
|
else
|
|
{
|
|
if (PageState.Page.IsPersonalizable && PageState.User != null)
|
|
{
|
|
await PageService.AddPageAsync(PageState.Page.PageId, PageState.User.UserId);
|
|
PageState.EditMode = true;
|
|
NavigationManager.NavigateTo(NavigateUrl(PageState.Page.Path, "edit=" + ((PageState.EditMode) ? "1" : "0")));
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ShowControlPanel()
|
|
{
|
|
_message = "";
|
|
_display = "width: 25%; min-width: 375px;";
|
|
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.FirstOrDefault(item => item.ModuleDefinitionName == Constants.AdminDashboardModule);
|
|
|
|
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.FirstOrDefault(item => item.ModuleDefinitionName == Constants.PageManagementModule);
|
|
|
|
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 void ConfirmDelete()
|
|
{
|
|
_deleteConfirmation = !_deleteConfirmation;
|
|
StateHasChanged();
|
|
}
|
|
|
|
private async Task DeletePage()
|
|
{
|
|
ConfirmDelete();
|
|
|
|
var page = PageState.Page;
|
|
try
|
|
{
|
|
if (page.UserId == null)
|
|
{
|
|
page.IsDeleted = true;
|
|
await PageService.UpdatePageAsync(page);
|
|
await logger.Log(page.PageId, null, PageState.User.UserId, GetType().AssemblyQualifiedName, "ControlPanel", LogFunction.Delete, LogLevel.Information, null, "Page Deleted {Page}", page);
|
|
NavigationManager.NavigateTo(NavigateUrl(""));
|
|
}
|
|
else // personalized page
|
|
{
|
|
await PageService.DeletePageAsync(page.PageId);
|
|
await logger.Log(page.PageId, null, PageState.User.UserId, GetType().AssemblyQualifiedName, "ControlPanel", LogFunction.Delete, LogLevel.Information, null, "Page Deleted {Page}", page);
|
|
NavigationManager.NavigateTo(NavigateUrl());
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await logger.Log(page.PageId, null, PageState.User.UserId, GetType().AssemblyQualifiedName, "ControlPanel", LogFunction.Delete, LogLevel.Information, ex, "Page Deleted {Page} {Error}", page, ex.Message);
|
|
}
|
|
}
|
|
|
|
}
|