Add Edit Mode for Administration
This commit is contained in:
		| @ -12,67 +12,83 @@ | ||||
| @inject IModuleService ModuleService | ||||
| @inject IPageModuleService PageModuleService | ||||
|  | ||||
| <div id="actions" class="overlay"> | ||||
|     <a href="javascript:void(0)" class="closebtn" onclick="closeActions()">x</a> | ||||
|     <div class="overlay-content"> | ||||
|         <ul class="nav flex-column"> | ||||
|             <li class="nav-item px-3"> | ||||
|                 <NavLink class="btn btn-primary" href="@PageUrl("Add")" Match="NavLinkMatch.All">Add Page</NavLink> | ||||
|             </li> | ||||
|             <li class="nav-item px-3"> | ||||
|                 <NavLink class="btn btn-primary" href="@PageUrl("Edit")" Match="NavLinkMatch.All">Edit Page</NavLink> | ||||
|             </li> | ||||
|             <li class="nav-item px-3"> | ||||
|                 <NavLink class="btn btn-primary" href="@PageUrl("Delete")" Match="NavLinkMatch.All">Delete Page</NavLink> | ||||
|             </li> | ||||
|         </ul> | ||||
|         <hr style="width: 100%; color: white; height: 1px; background-color:white;" /> | ||||
|         <div class="container"> | ||||
|             <div class="form-group"> | ||||
|                 <label for="Module" class="control-label" style="color: white !important;">Module: </label> | ||||
|                 @if (moduledefinitions != null) | ||||
|                 { | ||||
|                     <select class="form-control" @bind="@moduledefinitionname"> | ||||
|                         <option value=""><Select Module></option> | ||||
|                         @foreach (var moduledefinition in moduledefinitions) | ||||
| @if (UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions)) | ||||
| { | ||||
|     <div id="actions" class="overlay"> | ||||
|         <a href="javascript:void(0)" class="closebtn" onclick="closeActions()">x</a> | ||||
|         <div class="overlay-content"> | ||||
|             <ul class="nav flex-column"> | ||||
|                 <li class="nav-item px-3"> | ||||
|                     <NavLink class="btn btn-primary" href="@PageUrl("Add")" Match="NavLinkMatch.All">Add Page</NavLink> | ||||
|                 </li> | ||||
|                 <li class="nav-item px-3"> | ||||
|                     <NavLink class="btn btn-primary" href="@PageUrl("Edit")" Match="NavLinkMatch.All">Edit Page</NavLink> | ||||
|                 </li> | ||||
|                 <li class="nav-item px-3"> | ||||
|                     <NavLink class="btn btn-primary" href="@PageUrl("Delete")" Match="NavLinkMatch.All">Delete Page</NavLink> | ||||
|                 </li> | ||||
|             </ul> | ||||
|             <hr style="width: 100%; color: white; height: 1px; background-color:white;" /> | ||||
|             <div class="container"> | ||||
|                 <div class="form-group"> | ||||
|                     <label for="Module" class="control-label" style="color: white !important;">Module: </label> | ||||
|                     @if (moduledefinitions != null) | ||||
|                     { | ||||
|                         <select class="form-control" @bind="@moduledefinitionname"> | ||||
|                             <option value=""><Select Module></option> | ||||
|                             @foreach (var moduledefinition in moduledefinitions) | ||||
|                             { | ||||
|                                 <option value="@moduledefinition.ModuleDefinitionName">@moduledefinition.Name</option> | ||||
|                             } | ||||
|                         </select> | ||||
|                     } | ||||
|                 </div> | ||||
|                 <div class="form-group"> | ||||
|                     <label for="Pane" class="control-label" style="color: white !important;">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="@moduledefinition.ModuleDefinitionName">@moduledefinition.Name</option> | ||||
|                             <option value="@pane">@pane Pane</option> | ||||
|                         } | ||||
|                     </select> | ||||
|                 } | ||||
|                 </div> | ||||
|                 <div class="form-group"> | ||||
|                     <label for="Title" class="control-label" style="color: white !important;">Title: </label> | ||||
|                     <input type="text" name="Title" class="form-control" @bind="@title" /> | ||||
|                 </div> | ||||
|                 <div class="form-group"> | ||||
|                     <label for="Container" class="control-label" style="color: white !important;">Container: </label> | ||||
|                     <select class="form-control" @bind="@containertype"> | ||||
|                         <option value=""><Select Container></option> | ||||
|                         @foreach (KeyValuePair<string, string> container in containers) | ||||
|                         { | ||||
|                             <option value="@container.Key">@container.Value</option> | ||||
|                         } | ||||
|                     </select> | ||||
|                 </div> | ||||
|                 <button type="button" class="btn btn-primary" @onclick="@AddModule">Add Module To Page</button> | ||||
|             </div> | ||||
|             <div class="form-group"> | ||||
|                 <label for="Pane" class="control-label" style="color: white !important;">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 class="form-group"> | ||||
|                 <label for="Title" class="control-label" style="color: white !important;">Title: </label> | ||||
|                 <input type="text" name="Title" class="form-control" @bind="@title" /> | ||||
|             </div> | ||||
|             <div class="form-group"> | ||||
|                 <label for="Container" class="control-label" style="color: white !important;">Container: </label> | ||||
|                 <select class="form-control" @bind="@containertype"> | ||||
|                     <option value=""><Select Container></option> | ||||
|                     @foreach (KeyValuePair<string, string> container in containers) | ||||
|                     { | ||||
|                         <option value="@container.Key">@container.Value</option> | ||||
|                     } | ||||
|                 </select> | ||||
|             </div> | ||||
|             <button type="button" class="btn btn-primary" @onclick="@AddModule">Add Module To Page</button> | ||||
|         </div> | ||||
|     </div> | ||||
| </div> | ||||
| <span class="oi oi-menu" style="@display" onclick="openActions()"></span> | ||||
|  | ||||
|     @if (PageState.EditMode) | ||||
|     { | ||||
|         <button type="button" class="btn btn-outline-primary active" data-toggle="button" aria-pressed="true" autocomplete="off" @onclick="EditMode"> | ||||
|             <span class="oi oi-pencil"></span> | ||||
|         </button> | ||||
|  | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         <button type="button" class="btn btn-outline-primary" data-toggle="button" aria-pressed="false" autocomplete="off" @onclick="EditMode"> | ||||
|             <span class="oi oi-pencil"></span> | ||||
|         </button> | ||||
|     } | ||||
|     <span class="oi oi-menu" onclick="openActions()"></span> | ||||
| } | ||||
|  | ||||
| @code { | ||||
|     string display = "display: none"; | ||||
|     List<ModuleDefinition> moduledefinitions; | ||||
|     Dictionary<string, string> containers = new Dictionary<string, string>(); | ||||
|     int pagemanagementmoduleid = -1; | ||||
| @ -83,45 +99,47 @@ | ||||
|  | ||||
|     protected override async Task OnInitializedAsync() | ||||
|     { | ||||
|         moduledefinitions = PageState.ModuleDefinitions; | ||||
|         containers = ThemeService.GetContainerTypes(PageState.Themes); | ||||
|         List<Module> modules = await ModuleService.GetModulesAsync(PageState.Site.SiteId, Constants.PageManagementModule); | ||||
|         if (modules.Count > 0) | ||||
|         { | ||||
|             pagemanagementmoduleid = modules.FirstOrDefault().ModuleId; | ||||
|         } | ||||
|         if (UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions)) | ||||
|         { | ||||
|             display = "display: inline"; | ||||
|             moduledefinitions = PageState.ModuleDefinitions; | ||||
|             containers = ThemeService.GetContainerTypes(PageState.Themes); | ||||
|             List<Module> modules = await ModuleService.GetModulesAsync(PageState.Site.SiteId, Constants.PageManagementModule); | ||||
|             if (modules.Count > 0) | ||||
|             { | ||||
|                 pagemanagementmoduleid = modules.FirstOrDefault().ModuleId; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private async Task AddModule() | ||||
|     { | ||||
|         Module module = new Module(); | ||||
|         module.SiteId = PageState.Site.SiteId; | ||||
|         module.ModuleDefinitionName = moduledefinitionname; | ||||
|         module.Permissions = PageState.Page.Permissions; | ||||
|         await ModuleService.AddModuleAsync(module); | ||||
|  | ||||
|         List<Module> modules = await ModuleService.GetModulesAsync(PageState.Site.SiteId, moduledefinitionname); | ||||
|         int ModuleId = modules.LastOrDefault().ModuleId; | ||||
|  | ||||
|         PageModule pagemodule = new PageModule(); | ||||
|         pagemodule.PageId = PageState.Page.PageId; | ||||
|         pagemodule.ModuleId = ModuleId; | ||||
|         if (title == "") | ||||
|         if (UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions)) | ||||
|         { | ||||
|             title = moduledefinitions.Where(item => item.ModuleDefinitionName == moduledefinitionname).FirstOrDefault().Name; | ||||
|         } | ||||
|         pagemodule.Title = title; | ||||
|         pagemodule.Pane = pane; | ||||
|         pagemodule.Order = 0; | ||||
|         pagemodule.ContainerType = containertype; | ||||
|         await PageModuleService.AddPageModuleAsync(pagemodule); | ||||
|             Module module = new Module(); | ||||
|             module.SiteId = PageState.Site.SiteId; | ||||
|             module.ModuleDefinitionName = moduledefinitionname; | ||||
|             module.Permissions = PageState.Page.Permissions; | ||||
|             await ModuleService.AddModuleAsync(module); | ||||
|  | ||||
|         PageState.Reload = Constants.ReloadPage; | ||||
|         UriHelper.NavigateTo(NavigateUrl()); | ||||
|             List<Module> modules = await ModuleService.GetModulesAsync(PageState.Site.SiteId, moduledefinitionname); | ||||
|             int ModuleId = modules.LastOrDefault().ModuleId; | ||||
|  | ||||
|             PageModule pagemodule = new PageModule(); | ||||
|             pagemodule.PageId = PageState.Page.PageId; | ||||
|             pagemodule.ModuleId = ModuleId; | ||||
|             if (title == "") | ||||
|             { | ||||
|                 title = moduledefinitions.Where(item => item.ModuleDefinitionName == moduledefinitionname).FirstOrDefault().Name; | ||||
|             } | ||||
|             pagemodule.Title = title; | ||||
|             pagemodule.Pane = pane; | ||||
|             pagemodule.Order = 0; | ||||
|             pagemodule.ContainerType = containertype; | ||||
|             await PageModuleService.AddPageModuleAsync(pagemodule); | ||||
|  | ||||
|             PageState.Reload = Constants.ReloadPage; | ||||
|             UriHelper.NavigateTo(NavigateUrl()); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private string PageUrl(string action) | ||||
| @ -144,4 +162,21 @@ | ||||
|         } | ||||
|         return url; | ||||
|     } | ||||
|  | ||||
|     private void EditMode() | ||||
|     { | ||||
|         if (UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions)) | ||||
|         { | ||||
|             if (PageState.EditMode) | ||||
|             { | ||||
|                 PageState.EditMode = false; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 PageState.EditMode = true; | ||||
|             } | ||||
|             PageState.Reload = Constants.ReloadPage; | ||||
|             UriHelper.NavigateTo(NavigateUrl(PageState.Page.Path, "edit=" + PageState.EditMode.ToString().ToLower())); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -8,75 +8,78 @@ | ||||
| @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> | ||||
|         } | ||||
| @if (PageState.EditMode && UserSecurity.IsAuthorized(PageState.User, "Edit", ModuleState.Permissions)) | ||||
| { | ||||
|     <div class="dropdown"> | ||||
|         <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> | ||||
| </div> | ||||
| } | ||||
|  | ||||
| @code { | ||||
|     string display = "display: none"; | ||||
|     List<ActionViewModel> actions; | ||||
|  | ||||
|     protected override void OnInitialized() | ||||
|     protected override void OnParametersSet() | ||||
|     { | ||||
|         actions = new List<ActionViewModel>(); | ||||
|         if (ModuleState.PaneModuleIndex > 0) | ||||
|         if (PageState.EditMode && UserSecurity.IsAuthorized(PageState.User, "Edit", ModuleState.Permissions)) | ||||
|         { | ||||
|             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(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) | ||||
|         { | ||||
|             if (pane != ModuleState.Pane) | ||||
|             actions = new List<ActionViewModel>(); | ||||
|             if (ModuleState.PaneModuleIndex > 0) | ||||
|             { | ||||
|                 actions.Add(new ActionViewModel { Action = pane, Name = "Move To " + pane + " Pane" }); | ||||
|                 actions.Add(new ActionViewModel { Action = "up", Name = "Move Up" }); | ||||
|             } | ||||
|         } | ||||
|         actions.Add(new ActionViewModel { Action = "settings", Name = "Settings" }); | ||||
|         actions.Add(new ActionViewModel { Action = "delete", Name = "Delete" }); | ||||
|  | ||||
|         if (UserSecurity.IsAuthorized(PageState.User, "Edit", ModuleState.Permissions)) | ||||
|         { | ||||
|             display = "display: inline"; | ||||
|             if (ModuleState.PaneModuleIndex < (ModuleState.PaneModuleCount - 1)) | ||||
|             { | ||||
|                 actions.Add(new ActionViewModel { Action = "down", Name = "Move Down" }); | ||||
|             } | ||||
|             foreach (string pane in PageState.Page.Panes.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) | ||||
|             { | ||||
|                 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" }); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     protected async Task ModuleAction(string action) | ||||
|     { | ||||
|         PageModule pagemodule = await PageModuleService.GetPageModuleAsync(ModuleState.PageModuleId); | ||||
|  | ||||
|         string url = NavigateUrl(); | ||||
|         switch (action) | ||||
|         if (PageState.EditMode && UserSecurity.IsAuthorized(PageState.User, "Edit", ModuleState.Permissions)) | ||||
|         { | ||||
|             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; | ||||
|             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); | ||||
|         } | ||||
|         PageState.Reload = Constants.ReloadPage; | ||||
|         UriHelper.NavigateTo(url); | ||||
|     } | ||||
|  | ||||
|     public class ActionViewModel | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Shaun Walker
					Shaun Walker