Control panel state persistence
This commit is contained in:
parent
2f8a15fb89
commit
ddbb08ea75
|
@ -1,5 +1,5 @@
|
|||
@namespace Oqtane.Themes.Controls
|
||||
@inherits ThemeControlBase
|
||||
@inherits ThemeControlBase
|
||||
@attribute [OqtaneIgnore]
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IUserService UserService
|
||||
|
@ -9,8 +9,9 @@
|
|||
@inject IPageService PageService
|
||||
@inject IPageModuleService PageModuleService
|
||||
@inject ILogService logger
|
||||
@inject ISettingService SettingService
|
||||
|
||||
@if (_moduleDefinitions != null && UserSecurity.IsAuthorized(PageState.User,PermissionNames.Edit, PageState.Page.Permissions))
|
||||
@if (_moduleDefinitions != null && UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, PageState.Page.Permissions))
|
||||
{
|
||||
<div class="app-controlpanel" style="@_display">
|
||||
|
||||
|
@ -31,7 +32,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="app-rule" />
|
||||
<hr class="app-rule"/>
|
||||
|
||||
<div class="row">
|
||||
<div class="col text-center">
|
||||
|
@ -73,23 +74,23 @@
|
|||
</div>
|
||||
</div>
|
||||
}
|
||||
<hr class="app-rule" />
|
||||
<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">
|
||||
<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 (ModuleType == "new")
|
||||
{
|
||||
@if (_moduleDefinitions != null)
|
||||
{
|
||||
<select class="form-control" @onchange="(e => CategoryChanged(e))">
|
||||
@foreach (var category in _categories)
|
||||
{
|
||||
if (category == _category)
|
||||
if (category == Category)
|
||||
{
|
||||
<option value="@category" selected>@category Modules</option>
|
||||
}
|
||||
|
@ -100,7 +101,7 @@
|
|||
}
|
||||
</select>
|
||||
<select class="form-control" @onchange="(e => ModuleChanged(e))">
|
||||
@if (_moduleDefinitionName == "-")
|
||||
@if (ModuleDefinitionName == "-")
|
||||
{
|
||||
<option value="-" selected><Select Module></option>
|
||||
}
|
||||
|
@ -116,7 +117,7 @@
|
|||
}
|
||||
}
|
||||
</select>
|
||||
@((MarkupString)@_description)
|
||||
@((MarkupString) Description)
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -128,7 +129,7 @@
|
|||
<option value="@p.PageId">@p.Name</option>
|
||||
}
|
||||
</select>
|
||||
<select class="form-control" @bind="@_moduleId">
|
||||
<select class="form-control" @bind="@ModuleId">
|
||||
<option value="-"><Select Module></option>
|
||||
@foreach (Module module in _modules)
|
||||
{
|
||||
|
@ -141,13 +142,13 @@
|
|||
<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" />
|
||||
<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">
|
||||
<select class="form-control" @bind="@Pane">
|
||||
<option value=""><Select Pane></option>
|
||||
@foreach (string pane in PageState.Page.Panes)
|
||||
{
|
||||
|
@ -159,7 +160,7 @@
|
|||
<div class="row">
|
||||
<div class="col text-center">
|
||||
<label for="Container" class="control-label">Container: </label>
|
||||
<select class="form-control" @bind="@_containerType">
|
||||
<select class="form-control" @bind="@ContainerType">
|
||||
@foreach (KeyValuePair<string, string> container in _containers)
|
||||
{
|
||||
<option value="@container.Key">@container.Value</option>
|
||||
|
@ -168,16 +169,16 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
<br/>
|
||||
|
||||
<button type="button" class="btn btn-primary btn-block mx-auto" @onclick="@AddModule">Add Module To Page</button>
|
||||
@((MarkupString) _message)
|
||||
@((MarkupString) Message)
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (UserSecurity.IsAuthorized(PageState.User,PermissionNames.Edit, PageState.Page.Permissions) || (PageState.Page.IsPersonalizable && PageState.User != null))
|
||||
@if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, PageState.Page.Permissions) || (PageState.Page.IsPersonalizable && PageState.User != null))
|
||||
{
|
||||
@if (PageState.Page.EditMode)
|
||||
{
|
||||
|
@ -202,32 +203,52 @@
|
|||
}
|
||||
}
|
||||
|
||||
@if (UserSecurity.IsAuthorized(PageState.User,PermissionNames.Edit, PageState.Page.Permissions))
|
||||
@if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, PageState.Page.Permissions))
|
||||
{
|
||||
<button type="button" class="btn @ButtonClass" @onclick="ShowControlPanel">
|
||||
<span class="oi oi-cog"></span>
|
||||
</button>
|
||||
}
|
||||
|
||||
@code {
|
||||
@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 = "";
|
||||
private string _category = "Common";
|
||||
|
||||
protected string PageId { get; private set; } = "-";
|
||||
protected string ModuleId { get; private set; } = "-";
|
||||
protected string ModuleType { get; private set; } = "new";
|
||||
protected string ModuleDefinitionName { get; private set; } = "-";
|
||||
|
||||
protected string Category
|
||||
{
|
||||
get => _category;
|
||||
private set
|
||||
{
|
||||
if (_category != value)
|
||||
{
|
||||
_category = value;
|
||||
_moduleDefinitions = _allModuleDefinitions.Where(item => item.Categories.Contains(Category)).ToList();
|
||||
ModuleDefinitionName = "-";
|
||||
Description = "";
|
||||
StateHasChanged();
|
||||
_ = UpdateSettingsAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected string Description { get; private set; } = "";
|
||||
protected string Pane { get; private set; } = "";
|
||||
protected string Title { get; private set; } = "";
|
||||
protected string ContainerType { get; private set; } = "";
|
||||
protected string Message { get; private set; } = "";
|
||||
|
||||
[Parameter]
|
||||
public string ButtonClass { get; set; }
|
||||
|
@ -241,7 +262,8 @@
|
|||
[Parameter]
|
||||
public string BodyClass { get; set; }
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (string.IsNullOrEmpty(ButtonClass))
|
||||
{
|
||||
|
@ -263,131 +285,107 @@
|
|||
BodyClass = "card-body";
|
||||
}
|
||||
|
||||
if (UserSecurity.IsAuthorized(PageState.User,PermissionNames.Edit, PageState.Page.Permissions))
|
||||
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))
|
||||
if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, p.Permissions))
|
||||
{
|
||||
_pages.Add(p);
|
||||
}
|
||||
}
|
||||
await LoadSettingsAsync();
|
||||
|
||||
var panes = PageState.Page.Panes;
|
||||
_pane = panes.Count() == 1 ? panes.SingleOrDefault() : "";
|
||||
Pane = panes.Count() == 1 ? panes.SingleOrDefault() : "";
|
||||
var themes = await ThemeService.GetThemesAsync();
|
||||
_containers = ThemeService.GetContainerTypes(themes);
|
||||
_containerType = PageState.Site.DefaultContainerType;
|
||||
ContainerType = PageState.Site.DefaultContainerType;
|
||||
|
||||
_allModuleDefinitions = await ModuleDefinitionService.GetModuleDefinitionsAsync(PageState.Site.SiteId);
|
||||
_moduleDefinitions = _allModuleDefinitions.Where(item => item.Categories.Contains(Category)).ToList();
|
||||
|
||||
_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 = "";
|
||||
_categories = _allModuleDefinitions.SelectMany(m => m.Categories.Split(',')).Distinct().ToList();
|
||||
}
|
||||
}
|
||||
|
||||
private void CategoryChanged(ChangeEventArgs e)
|
||||
{
|
||||
_category = (string) e.Value;
|
||||
_moduleDefinitions = _allModuleDefinitions.Where(item => item.Categories.Contains(_category)).ToList();
|
||||
_moduleDefinitionName = "-";
|
||||
_description = "";
|
||||
StateHasChanged();
|
||||
Category = (string) e.Value;
|
||||
}
|
||||
|
||||
private void ModuleChanged(ChangeEventArgs e)
|
||||
{
|
||||
_moduleDefinitionName = (string)e.Value;
|
||||
if (_moduleDefinitionName != "-")
|
||||
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>";
|
||||
var moduleDefinition = _moduleDefinitions.FirstOrDefault(item => item.ModuleDefinitionName == ModuleDefinitionName);
|
||||
Description = "<br /><div class=\"alert alert-info\" role=\"alert\">" + moduleDefinition.Description + "</div>";
|
||||
}
|
||||
else
|
||||
{
|
||||
_description = "";
|
||||
Description = "";
|
||||
}
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void PageChanged(ChangeEventArgs e)
|
||||
{
|
||||
_pageId = (string) e.Value;
|
||||
_modules?.Clear();
|
||||
|
||||
if (_pageId != "-")
|
||||
PageId = (string) e.Value;
|
||||
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);
|
||||
}
|
||||
}
|
||||
_modules = PageState.Modules
|
||||
.Where(module => module.PageId == int.Parse(PageId)
|
||||
&& !module.IsDeleted
|
||||
&& UserSecurity.IsAuthorized(PageState.User, PermissionNames.View, module.Permissions))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
_moduleId = "-";
|
||||
ModuleId = "-";
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task AddModule()
|
||||
{
|
||||
if (UserSecurity.IsAuthorized(PageState.User,PermissionNames.Edit, PageState.Page.Permissions))
|
||||
if (UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, PageState.Page.Permissions))
|
||||
{
|
||||
if ((_moduleType == "new" && _moduleDefinitionName != "-") || (_moduleType != "new" && _moduleId != "-"))
|
||||
if ((ModuleType == "new" && ModuleDefinitionName != "-") || (ModuleType != "new" && ModuleId != "-"))
|
||||
{
|
||||
if (_moduleType == "new")
|
||||
if (ModuleType == "new")
|
||||
{
|
||||
Module module = new Module();
|
||||
module.SiteId = PageState.Site.SiteId;
|
||||
module.PageId = PageState.Page.PageId;
|
||||
module.ModuleDefinitionName = _moduleDefinitionName;
|
||||
module.ModuleDefinitionName = ModuleDefinitionName;
|
||||
module.AllPages = false;
|
||||
module.Permissions = PageState.Page.Permissions;
|
||||
module = await ModuleService.AddModuleAsync(module);
|
||||
_moduleId = module.ModuleId.ToString();
|
||||
ModuleId = module.ModuleId.ToString();
|
||||
}
|
||||
|
||||
var pageModule = new PageModule
|
||||
{
|
||||
PageId = PageState.Page.PageId,
|
||||
ModuleId = int.Parse(_moduleId),
|
||||
Title = _title
|
||||
ModuleId = int.Parse(ModuleId),
|
||||
Title = Title
|
||||
};
|
||||
if (pageModule.Title == "")
|
||||
{
|
||||
if (_moduleType == "new")
|
||||
if (ModuleType == "new")
|
||||
{
|
||||
pageModule.Title = _moduleDefinitions.FirstOrDefault(item => item.ModuleDefinitionName == _moduleDefinitionName)?.Name;
|
||||
pageModule.Title = _moduleDefinitions.FirstOrDefault(item => item.ModuleDefinitionName == ModuleDefinitionName)?.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
pageModule.Title = _modules.FirstOrDefault(item => item.ModuleId == int.Parse(_moduleId))?.Title;
|
||||
pageModule.Title = _modules.FirstOrDefault(item => item.ModuleId == int.Parse(ModuleId))?.Title;
|
||||
}
|
||||
}
|
||||
|
||||
pageModule.Pane = _pane;
|
||||
pageModule.Pane = Pane;
|
||||
pageModule.Order = int.MaxValue;
|
||||
pageModule.ContainerType = _containerType;
|
||||
pageModule.ContainerType = ContainerType;
|
||||
|
||||
if (pageModule.ContainerType == PageState.Site.DefaultContainerType)
|
||||
{
|
||||
|
@ -397,32 +395,23 @@
|
|||
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 = "-";
|
||||
|
||||
Message = "<br /><div class=\"alert alert-success\" role=\"alert\">Module Added To Page</div>";
|
||||
NavigationManager.NavigateTo(NavigateUrl());
|
||||
}
|
||||
else
|
||||
{
|
||||
_message = "<br /><div class=\"alert alert-warning\" role=\"alert\">You Must Select A Module</div>";
|
||||
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>";
|
||||
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 (UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, PageState.Page.Permissions))
|
||||
{
|
||||
if (EditMode)
|
||||
{
|
||||
|
@ -432,6 +421,7 @@
|
|||
{
|
||||
PageState.EditMode = true;
|
||||
}
|
||||
|
||||
NavigationManager.NavigateTo(NavigateUrl(PageState.Page.Path, "edit=" + ((PageState.EditMode) ? "1" : "0")));
|
||||
}
|
||||
else
|
||||
|
@ -447,14 +437,14 @@
|
|||
|
||||
private void ShowControlPanel()
|
||||
{
|
||||
_message = "";
|
||||
Message = "";
|
||||
_display = "width: 25%; min-width: 375px;";
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void HideControlPanel()
|
||||
{
|
||||
_message = "";
|
||||
Message = "";
|
||||
_display = "width: 0%;";
|
||||
StateHasChanged();
|
||||
}
|
||||
|
@ -466,7 +456,7 @@
|
|||
switch (location)
|
||||
{
|
||||
case "Admin":
|
||||
// get admin dashboard moduleid
|
||||
// get admin dashboard moduleid
|
||||
module = PageState.Modules.FirstOrDefault(item => item.ModuleDefinitionName == Constants.AdminDashboardModule);
|
||||
|
||||
if (module != null)
|
||||
|
@ -478,7 +468,7 @@
|
|||
case "Add":
|
||||
case "Edit":
|
||||
string url = "";
|
||||
// get page management moduleid
|
||||
// get page management moduleid
|
||||
module = PageState.Modules.FirstOrDefault(item => item.ModuleDefinitionName == Constants.PageManagementModule);
|
||||
|
||||
if (module != null)
|
||||
|
@ -536,4 +526,18 @@
|
|||
}
|
||||
}
|
||||
|
||||
private string settingName = "CP-category";
|
||||
|
||||
private async Task LoadSettingsAsync()
|
||||
{
|
||||
Dictionary<string, string> settings = await SettingService.GetUserSettingsAsync(PageState.User.UserId);
|
||||
_category = SettingService.GetSetting(settings, settingName, "Common");
|
||||
}
|
||||
|
||||
private async Task UpdateSettingsAsync()
|
||||
{
|
||||
Dictionary<string, string> settings = await SettingService.GetUserSettingsAsync(PageState.User.UserId);
|
||||
SettingService.SetSetting(settings, settingName, _category);
|
||||
await SettingService.UpdateUserSettingsAsync(settings, PageState.User.UserId);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user