Support for user personalizable pages
This commit is contained in:
@ -21,10 +21,13 @@
|
||||
</div>
|
||||
<div class="@BodyClass">
|
||||
<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>
|
||||
@if (UserSecurity.IsAuthorized(PageState.User, Constants.AdminRole))
|
||||
{
|
||||
<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 class="btn btn-primary btn-block mx-auto" @onclick="ConfirmDelete">Delete Page</button>
|
||||
@if (deleteconfirmation)
|
||||
@ -146,19 +149,26 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions) || (PageState.Page.IsPersonalizable && PageState.User != null))
|
||||
{
|
||||
@if (PageState.EditMode)
|
||||
{
|
||||
<button type="button" class="btn @ButtonClass active" data-toggle="button" aria-pressed="true" autocomplete="off" @onclick="(async () => ToggleEditMode(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 () => ToggleEditMode(PageState.EditMode))">
|
||||
<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, "Edit", PageState.Page.Permissions))
|
||||
{
|
||||
<button type="button" class="btn @ButtonClass" @onclick="ShowControlPanel">
|
||||
<span class="oi oi-menu"></span>
|
||||
</button>
|
||||
@ -292,7 +302,7 @@
|
||||
}
|
||||
|
||||
PageModule pagemodule = new PageModule();
|
||||
pagemodule.PageId = string.IsNullOrWhiteSpace(pageid) ? PageState.Page.PageId : int.Parse(pageid);
|
||||
pagemodule.PageId = string.IsNullOrEmpty(pageid) ? PageState.Page.PageId : int.Parse(pageid);
|
||||
pagemodule.ModuleId = int.Parse(moduleid);
|
||||
pagemodule.Title = title;
|
||||
if (pagemodule.Title == "")
|
||||
@ -330,7 +340,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
private void ToggleEditMode(bool EditMode)
|
||||
private async Task ToggleEditMode(bool EditMode)
|
||||
{
|
||||
if (UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions))
|
||||
{
|
||||
@ -346,6 +356,16 @@
|
||||
}
|
||||
NavigationManager.NavigateTo(NavigateUrl(PageState.Page.Path, "edit=" + ((PageState.EditMode) ? "1" : "0"), Reload.Page));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (PageState.Page.IsPersonalizable && PageState.User != null)
|
||||
{
|
||||
await CreatePersonalizedPage();
|
||||
PageState.EditMode = true;
|
||||
PageState.DesignMode = true;
|
||||
NavigationManager.NavigateTo(NavigateUrl(PageState.Page.Path, "edit=" + ((PageState.EditMode) ? "1" : "0"), Reload.Page));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowControlPanel()
|
||||
@ -413,14 +433,86 @@
|
||||
Page page = PageState.Page;
|
||||
try
|
||||
{
|
||||
page.IsDeleted = true;
|
||||
await PageService.UpdatePageAsync(page);
|
||||
await logger.Log(page.PageId, null, PageState.User.UserId, this.GetType().AssemblyQualifiedName, "ControlPanel", LogFunction.Delete, LogLevel.Information, null, "Page Deleted {Page}", page);
|
||||
NavigationManager.NavigateTo(NavigateUrl("", Reload.Site));
|
||||
if (page.UserId == null)
|
||||
{
|
||||
page.IsDeleted = true;
|
||||
await PageService.UpdatePageAsync(page);
|
||||
await logger.Log(page.PageId, null, PageState.User.UserId, this.GetType().AssemblyQualifiedName, "ControlPanel", LogFunction.Delete, LogLevel.Information, null, "Page Deleted {Page}", page);
|
||||
NavigationManager.NavigateTo(NavigateUrl("", Reload.Site));
|
||||
}
|
||||
else // personalized page
|
||||
{
|
||||
await PageService.DeletePageAsync(page.PageId);
|
||||
await logger.Log(page.PageId, null, PageState.User.UserId, this.GetType().AssemblyQualifiedName, "ControlPanel", LogFunction.Delete, LogLevel.Information, null, "Page Deleted {Page}", page);
|
||||
NavigationManager.NavigateTo(NavigateUrl(Reload.Page));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await logger.Log(page.PageId, null, PageState.User.UserId, this.GetType().AssemblyQualifiedName, "ControlPanel", LogFunction.Delete, LogLevel.Information, ex, "Page Deleted {Page} {Error}", page, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CreatePersonalizedPage()
|
||||
{
|
||||
Page page = new Page();
|
||||
page.SiteId = PageState.Page.SiteId;
|
||||
page.Name = PageState.Page.Name;
|
||||
page.Path = PageState.Page.Path;
|
||||
page.ParentId = PageState.Page.ParentId;
|
||||
page.Order = 0;
|
||||
page.IsNavigation = false;
|
||||
page.EditMode = false;
|
||||
page.ThemeType = PageState.Page.ThemeType;
|
||||
if (page.ThemeType == PageState.Site.DefaultThemeType)
|
||||
{
|
||||
page.ThemeType = "";
|
||||
}
|
||||
page.LayoutType = PageState.Page.LayoutType;
|
||||
if (page.LayoutType == PageState.Site.DefaultLayoutType)
|
||||
{
|
||||
page.LayoutType = "";
|
||||
}
|
||||
page.Icon = PageState.Page.Icon;
|
||||
List<PermissionString> permissions = new List<PermissionString>();
|
||||
permissions.Add(new PermissionString { PermissionName = "View", Permissions = "[" + PageState.User.UserId.ToString() + "]" });
|
||||
permissions.Add(new PermissionString { PermissionName = "Edit", Permissions = "[" + PageState.User.UserId.ToString() + "]" });
|
||||
page.Permissions = UserSecurity.SetPermissionStrings(permissions);
|
||||
page.IsPersonalizable = false;
|
||||
page.UserId = PageState.User.UserId;
|
||||
page = await PageService.AddPageAsync(page);
|
||||
|
||||
// copy modules
|
||||
foreach (Module m in PageState.Modules.Where(item => item.PageId == PageState.Page.PageId && !item.IsDeleted))
|
||||
{
|
||||
Module module = new Module();
|
||||
module.SiteId = m.SiteId;
|
||||
module.ModuleDefinitionName = m.ModuleDefinitionName;
|
||||
permissions = new List<PermissionString>();
|
||||
permissions.Add(new PermissionString { PermissionName = "View", Permissions = "[" + PageState.User.UserId.ToString() + "]" });
|
||||
permissions.Add(new PermissionString { PermissionName = "Edit", Permissions = "[" + PageState.User.UserId.ToString() + "]" });
|
||||
module.Permissions = UserSecurity.SetPermissionStrings(permissions);
|
||||
module = await ModuleService.AddModuleAsync(module);
|
||||
|
||||
string content = await ModuleService.ExportModuleAsync(m.ModuleId);
|
||||
if (content != "")
|
||||
{
|
||||
await ModuleService.ImportModuleAsync(module.ModuleId, content);
|
||||
}
|
||||
|
||||
PageModule pagemodule = new PageModule();
|
||||
pagemodule.PageId = page.PageId;
|
||||
pagemodule.ModuleId = module.ModuleId;
|
||||
pagemodule.Title = m.Title;
|
||||
pagemodule.Pane = m.Pane;
|
||||
pagemodule.Order = m.Order;
|
||||
pagemodule.ContainerType = m.ContainerType;
|
||||
if (pagemodule.ContainerType == PageState.Site.DefaultContainerType)
|
||||
{
|
||||
pagemodule.ContainerType = "";
|
||||
}
|
||||
|
||||
await PageModuleService.AddPageModuleAsync(pagemodule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user