Add Edit Mode for Administration

This commit is contained in:
Shaun Walker
2019-09-04 11:07:48 -04:00
parent 1e4c07889b
commit e1cc1ce973
14 changed files with 253 additions and 192 deletions

View File

@ -11,7 +11,7 @@
<ModuleMessage Message="@message" /> <ModuleMessage Message="@message" />
@if (profiles != null) @if (PageState.User != null && profiles != null)
{ {
<table class="table table-borderless"> <table class="table table-borderless">
<tr> <tr>
@ -55,6 +55,7 @@
</table> </table>
<button type="button" class="btn btn-primary" @onclick="@SaveUser">Save</button> <button type="button" class="btn btn-primary" @onclick="@SaveUser">Save</button>
<button type="button" class="btn btn-secondary" @onclick="@Cancel">Cancel</button> <button type="button" class="btn btn-secondary" @onclick="@Cancel">Cancel</button>
<br /><br />
} }
@code { @code {
@ -70,12 +71,19 @@
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
try try
{
if (PageState.User != null)
{ {
displayname = PageState.User.DisplayName; displayname = PageState.User.DisplayName;
email = PageState.User.Email; email = PageState.User.Email;
profiles = await ProfileService.GetProfilesAsync(ModuleState.SiteId); profiles = await ProfileService.GetProfilesAsync(ModuleState.SiteId);
settings = await SettingService.GetUserSettingsAsync(PageState.User.UserId); settings = await SettingService.GetUserSettingsAsync(PageState.User.UserId);
} }
else
{
message = "Current User Is Not Logged In";
}
}
catch (Exception ex) catch (Exception ex)
{ {
message = ex.Message; message = ex.Message;
@ -88,6 +96,8 @@
} }
private async Task SaveUser() private async Task SaveUser()
{
try
{ {
User user = PageState.User; User user = PageState.User;
user.DisplayName = displayname; user.DisplayName = displayname;
@ -102,10 +112,15 @@
UriHelper.NavigateTo(""); UriHelper.NavigateTo("");
} }
catch (Exception ex)
{
message = ex.Message;
}
}
private void Cancel() private void Cancel()
{ {
UriHelper.NavigateTo(NavigateUrl("")); // navigate to home UriHelper.NavigateTo(NavigateUrl(""));
} }
private void ProfileChanged(UIChangeEventArgs e, string SettingName) private void ProfileChanged(UIChangeEventArgs e, string SettingName)

View File

@ -34,7 +34,7 @@
string style = ""; string style = "";
bool authorized = false; bool authorized = false;
protected override void OnInitialized() protected override void OnParametersSet()
{ {
text = Action; text = Action;
if (!String.IsNullOrEmpty(Text)) if (!String.IsNullOrEmpty(Text))
@ -59,6 +59,8 @@
url = EditUrl(Action, parameters); url = EditUrl(Action, parameters);
if (PageState.EditMode)
{
string typename = ModuleState.ModuleType.Replace(Utilities.GetTypeNameClass(ModuleState.ModuleType) + ",", Action + ","); string typename = ModuleState.ModuleType.Replace(Utilities.GetTypeNameClass(ModuleState.ModuleType) + ",", Action + ",");
Type moduleType = Type.GetType(typename); Type moduleType = Type.GetType(typename);
if (moduleType != null) if (moduleType != null)
@ -85,4 +87,5 @@
} }
} }
} }
}
} }

View File

@ -18,7 +18,7 @@
RenderFragment DynamicComponent { get; set; } RenderFragment DynamicComponent { get; set; }
protected override void OnInitialized() protected override void OnParametersSet()
{ {
DynamicComponent = builder => DynamicComponent = builder =>
{ {

View File

@ -13,7 +13,7 @@
RenderFragment DynamicComponent { get; set; } RenderFragment DynamicComponent { get; set; }
protected override void OnInitialized() protected override void OnParametersSet()
{ {
DynamicComponent = builder => DynamicComponent = builder =>
{ {

View File

@ -19,6 +19,7 @@ namespace Oqtane.Shared
public Dictionary<string, string> QueryString { get; set; } public Dictionary<string, string> QueryString { get; set; }
public int ModuleId { get; set; } public int ModuleId { get; set; }
public string Control { get; set; } public string Control { get; set; }
public bool EditMode { get; set; }
public int Reload { get; set; } public int Reload { get; set; }
} }
} }

View File

@ -26,9 +26,9 @@
string paneadminborder = ""; string paneadminborder = "";
string panetitle = ""; string panetitle = "";
protected override void OnInitialized() protected override void OnParametersSet()
{ {
if (UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions) && Name != Constants.AdminPane) if (PageState.EditMode && UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions) && Name != Constants.AdminPane)
{ {
paneadminborder = "pane-admin-border"; paneadminborder = "pane-admin-border";
panetitle = "<div class=\"pane-admin-title\">" + Name + " Pane</div>"; panetitle = "<div class=\"pane-admin-title\">" + Name + " Pane</div>";

View File

@ -9,7 +9,7 @@
RenderFragment DynamicComponent { get; set; } RenderFragment DynamicComponent { get; set; }
protected override void OnInitialized() protected override void OnParametersSet()
{ {
DynamicComponent = builder => DynamicComponent = builder =>
{ {

View File

@ -86,11 +86,13 @@
List<Module> modules; List<Module> modules;
int moduleid = -1; int moduleid = -1;
string control = ""; string control = "";
bool editmode = false;
int reload = 0; int reload = 0;
if (PageState != null) if (PageState != null)
{ {
reload = PageState.Reload; reload = PageState.Reload;
editmode = PageState.EditMode;
} }
if (PageState == null || reload == Constants.ReloadApplication) if (PageState == null || reload == Constants.ReloadApplication)
@ -188,6 +190,7 @@
{ {
page = pages.Where(item => item.Path == path).FirstOrDefault(); page = pages.Where(item => item.Path == path).FirstOrDefault();
reload = Constants.ReloadPage; reload = Constants.ReloadPage;
editmode = false;
} }
user = null; user = null;
@ -238,6 +241,7 @@
modules = PageState.Modules; modules = PageState.Modules;
} }
pagestate.Modules = modules; pagestate.Modules = modules;
pagestate.EditMode = editmode;
pagestate.Reload = 0; pagestate.Reload = 0;
OnStateChange?.Invoke(pagestate); OnStateChange?.Invoke(pagestate);

View File

@ -8,7 +8,7 @@
RenderFragment DynamicComponent { get; set; } RenderFragment DynamicComponent { get; set; }
protected override void OnInitialized() protected override void OnParametersSet()
{ {
DynamicComponent = builder => DynamicComponent = builder =>
{ {

View File

@ -12,7 +12,9 @@
@inject IModuleService ModuleService @inject IModuleService ModuleService
@inject IPageModuleService PageModuleService @inject IPageModuleService PageModuleService
<div id="actions" class="overlay"> @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> <a href="javascript:void(0)" class="closebtn" onclick="closeActions()">x</a>
<div class="overlay-content"> <div class="overlay-content">
<ul class="nav flex-column"> <ul class="nav flex-column">
@ -68,11 +70,25 @@
<button type="button" class="btn btn-primary" @onclick="@AddModule">Add Module To Page</button> <button type="button" class="btn btn-primary" @onclick="@AddModule">Add Module To Page</button>
</div> </div>
</div> </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 { @code {
string display = "display: none";
List<ModuleDefinition> moduledefinitions; List<ModuleDefinition> moduledefinitions;
Dictionary<string, string> containers = new Dictionary<string, string>(); Dictionary<string, string> containers = new Dictionary<string, string>();
int pagemanagementmoduleid = -1; int pagemanagementmoduleid = -1;
@ -82,6 +98,8 @@
string containertype; string containertype;
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{
if (UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions))
{ {
moduledefinitions = PageState.ModuleDefinitions; moduledefinitions = PageState.ModuleDefinitions;
containers = ThemeService.GetContainerTypes(PageState.Themes); containers = ThemeService.GetContainerTypes(PageState.Themes);
@ -90,13 +108,12 @@
{ {
pagemanagementmoduleid = modules.FirstOrDefault().ModuleId; pagemanagementmoduleid = modules.FirstOrDefault().ModuleId;
} }
if (UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions))
{
display = "display: inline";
} }
} }
private async Task AddModule() private async Task AddModule()
{
if (UserSecurity.IsAuthorized(PageState.User, "Edit", PageState.Page.Permissions))
{ {
Module module = new Module(); Module module = new Module();
module.SiteId = PageState.Site.SiteId; module.SiteId = PageState.Site.SiteId;
@ -123,6 +140,7 @@
PageState.Reload = Constants.ReloadPage; PageState.Reload = Constants.ReloadPage;
UriHelper.NavigateTo(NavigateUrl()); UriHelper.NavigateTo(NavigateUrl());
} }
}
private string PageUrl(string action) private string PageUrl(string action)
{ {
@ -144,4 +162,21 @@
} }
return url; 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()));
}
}
} }

View File

@ -8,7 +8,9 @@
@inject IUserService UserService @inject IUserService UserService
@inject IPageModuleService PageModuleService @inject IPageModuleService PageModuleService
<div class="dropdown" style="@display"> @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> <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"> <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
@foreach (var action in actions) @foreach (var action in actions)
@ -16,13 +18,15 @@
<a class="dropdown-item" @onclick="@(async () => await ModuleAction(action.Action))">@action.Name</a> <a class="dropdown-item" @onclick="@(async () => await ModuleAction(action.Action))">@action.Name</a>
} }
</div> </div>
</div> </div>
}
@code { @code {
string display = "display: none";
List<ActionViewModel> actions; List<ActionViewModel> actions;
protected override void OnInitialized() protected override void OnParametersSet()
{
if (PageState.EditMode && UserSecurity.IsAuthorized(PageState.User, "Edit", ModuleState.Permissions))
{ {
actions = new List<ActionViewModel>(); actions = new List<ActionViewModel>();
if (ModuleState.PaneModuleIndex > 0) if (ModuleState.PaneModuleIndex > 0)
@ -42,14 +46,12 @@
} }
actions.Add(new ActionViewModel { Action = "settings", Name = "Settings" }); actions.Add(new ActionViewModel { Action = "settings", Name = "Settings" });
actions.Add(new ActionViewModel { Action = "delete", Name = "Delete" }); actions.Add(new ActionViewModel { Action = "delete", Name = "Delete" });
if (UserSecurity.IsAuthorized(PageState.User, "Edit", ModuleState.Permissions))
{
display = "display: inline";
} }
} }
protected async Task ModuleAction(string action) protected async Task ModuleAction(string action)
{
if (PageState.EditMode && UserSecurity.IsAuthorized(PageState.User, "Edit", ModuleState.Permissions))
{ {
PageModule pagemodule = await PageModuleService.GetPageModuleAsync(ModuleState.PageModuleId); PageModule pagemodule = await PageModuleService.GetPageModuleAsync(ModuleState.PageModuleId);
@ -78,6 +80,7 @@
PageState.Reload = Constants.ReloadPage; PageState.Reload = Constants.ReloadPage;
UriHelper.NavigateTo(url); UriHelper.NavigateTo(url);
} }
}
public class ActionViewModel public class ActionViewModel
{ {

View File

@ -21,7 +21,7 @@ namespace Oqtane.Repository
public IEnumerable<Profile> GetProfiles(int SiteId) public IEnumerable<Profile> GetProfiles(int SiteId)
{ {
return db.Profile.Where(item => item.SiteId == SiteId); return db.Profile.Where(item => item.SiteId == SiteId || item.SiteId == null);
} }
public Profile AddProfile(Profile Profile) public Profile AddProfile(Profile Profile)

View File

@ -383,28 +383,28 @@ GO
SET IDENTITY_INSERT [dbo].[Profile] ON SET IDENTITY_INSERT [dbo].[Profile] ON
GO GO
INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
VALUES (1, 1, 'FirstName', 'First Name', 'Your First Or Given Name', 'Name', 1, 50, '', 1, 0, '', getdate(), '', getdate()) VALUES (1, null, 'FirstName', 'First Name', 'Your First Or Given Name', 'Name', 1, 50, '', 1, 0, '', getdate(), '', getdate())
GO GO
INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
VALUES (2, 1, 'LastName', 'Last Name', 'Your Last Or family Name', 'Name', 2, 50, '', 1, 0, '', getdate(), '', getdate()) VALUES (2, null, 'LastName', 'Last Name', 'Your Last Or family Name', 'Name', 2, 50, '', 1, 0, '', getdate(), '', getdate())
GO GO
INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
VALUES (3, 1, 'Street', 'Street', 'Street Or Building Address', 'Address', 3, 50, '', 1, 0, '', getdate(), '', getdate()) VALUES (3, null, 'Street', 'Street', 'Street Or Building Address', 'Address', 3, 50, '', 1, 0, '', getdate(), '', getdate())
GO GO
INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
VALUES (4, 1, 'City', 'City', 'City', 'Address', 4, 50, '', 1, 0, '', getdate(), '', getdate()) VALUES (4, null, 'City', 'City', 'City', 'Address', 4, 50, '', 1, 0, '', getdate(), '', getdate())
GO GO
INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
VALUES (5, 1, 'Region', 'Region', 'State Or Province', 'Address', 5, 50, '', 1, 0, '', getdate(), '', getdate()) VALUES (5, null, 'Region', 'Region', 'State Or Province', 'Address', 5, 50, '', 1, 0, '', getdate(), '', getdate())
GO GO
INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
VALUES (6, 1, 'Country', 'Country', 'Country', 'Address', 6, 50, '', 1, 0, '', getdate(), '', getdate()) VALUES (6, null, 'Country', 'Country', 'Country', 'Address', 6, 50, '', 1, 0, '', getdate(), '', getdate())
GO GO
INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
VALUES (7, 1, 'PostalCode', 'Postal Code', 'Postal Code Or Zip Code', 'Address', 7, 50, '', 1, 0, '', getdate(), '', getdate()) VALUES (7, null, 'PostalCode', 'Postal Code', 'Postal Code Or Zip Code', 'Address', 7, 50, '', 1, 0, '', getdate(), '', getdate())
GO GO
INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn]) INSERT [dbo].[Profile]([ProfileId], [SiteId], [Name], [Title], [Description], [Category], [ViewOrder], [MaxLength], [DefaultValue], [IsRequired], [IsPrivate], [CreatedBy], [CreatedOn], [ModifiedBy], [ModifiedOn])
VALUES (8, 1, 'Phone', 'Phone Number', 'Phone Number', 'Contact', 8, 50, '', 1, 0, '', getdate(), '', getdate()) VALUES (8, null, 'Phone', 'Phone Number', 'Phone Number', 'Contact', 8, 50, '', 1, 0, '', getdate(), '', getdate())
GO GO
SET IDENTITY_INSERT [dbo].[Profile] OFF SET IDENTITY_INSERT [dbo].[Profile] OFF
GO GO

View File

@ -5,7 +5,7 @@ namespace Oqtane.Models
public class Profile : IAuditable public class Profile : IAuditable
{ {
public int ProfileId { get; set; } public int ProfileId { get; set; }
public int SiteId { get; set; } public int? SiteId { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string Title { get; set; } public string Title { get; set; }
public string Description { get; set; } public string Description { get; set; }