Page management cleanup

This commit is contained in:
Shaun Walker 2019-08-21 10:37:02 -04:00
parent 42c6efbfdb
commit ad2d865d7c
6 changed files with 266 additions and 124 deletions

View File

@ -8,6 +8,8 @@
@inject IPageService PageService
@inject IThemeService ThemeService
@message
<table class="form-group">
<tr>
<td>
@ -32,9 +34,9 @@
<td>
<select class="form-control" @bind="@parentid">
<option value="">&lt;Select Parent&gt;</option>
@foreach (Page p in PageState.Pages)
@foreach (Page page in PageState.Pages)
{
<option value="@p.PageId">@p.Name</option>
<option value="@(page.PageId)">@(page.Name)</option>
}
</select>
</td>
@ -53,8 +55,8 @@
</td>
<td>
<select class="form-control" @bind="@isnavigation">
<option value="true">Yes</option>
<option value="false">No</option>
<option value="True">Yes</option>
<option value="False">No</option>
</select>
</td>
</tr>
@ -117,6 +119,8 @@
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
string message = "";
Dictionary<string, string> themes = new Dictionary<string, string>();
Dictionary<string, string> panelayouts = new Dictionary<string, string>();
@ -133,44 +137,59 @@
protected override void OnInitialized()
{
themes = ThemeService.GetThemeTypes(PageState.Themes);
panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes);
try
{
themes = ThemeService.GetThemeTypes(PageState.Themes);
panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes);
}
catch (Exception ex)
{
message = ex.Message;
}
}
private async Task SavePage()
{
Page p = new Page();
p.SiteId = PageState.Page.SiteId;
if (string.IsNullOrEmpty(parentid))
try
{
p.ParentId = null;
Page page = new Page();
page.SiteId = PageState.Page.SiteId;
if (string.IsNullOrEmpty(parentid))
{
page.ParentId = null;
}
else
{
page.ParentId = Int32.Parse(parentid);
}
page.Name = name;
page.Path = path;
page.Order = (order == null ? 1 : Int32.Parse(order));
page.IsNavigation = (isnavigation == null ? true : Boolean.Parse(isnavigation));
page.ThemeType = themetype;
page.LayoutType = (layouttype == null ? "" : layouttype);
page.Icon = (icon == null ? "" : icon);
Type type;
if (!string.IsNullOrEmpty(layouttype))
{
type = Type.GetType(layouttype);
}
else
{
type = Type.GetType(themetype);
}
System.Reflection.PropertyInfo property = type.GetProperty("Panes");
page.Panes = (string)property.GetValue(Activator.CreateInstance(type), null);
page.ViewPermissions = viewpermissions;
page.EditPermissions = editpermissions;
await PageService.AddPageAsync(page);
PageState.Reload = Constants.ReloadSite;
UriHelper.NavigateTo(NavigateUrl(path));
}
else
catch (Exception ex)
{
p.ParentId = Int32.Parse(parentid);
message = ex.Message;
}
p.Name = name;
p.Path = path;
p.Order = (order == null ? 1 : Int32.Parse(order));
p.IsNavigation = (isnavigation == null ? true : Boolean.Parse(isnavigation));
p.ThemeType = themetype;
p.LayoutType = (layouttype == null ? "" : layouttype);
p.Icon = (icon == null ? "" : icon);
Type type;
if (!string.IsNullOrEmpty(layouttype))
{
type = Type.GetType(layouttype);
}
else
{
type = Type.GetType(themetype);
}
System.Reflection.PropertyInfo property = type.GetProperty("Panes");
p.Panes = (string)property.GetValue(Activator.CreateInstance(type), null);
p.ViewPermissions = viewpermissions;
p.EditPermissions = editpermissions;
await PageService.AddPageAsync(p);
PageState.Reload = Constants.ReloadSite;
UriHelper.NavigateTo(NavigateUrl(path));
}
}

View File

@ -3,11 +3,14 @@
@using Oqtane.Services
@using Oqtane.Modules
@using Oqtane.Shared
@using Oqtane.Client.Modules.Controls
@inherits ModuleBase
@inject IUriHelper UriHelper
@inject IPageService PageService
@inject IThemeService ThemeService
@message
<table class="form-group">
<tr>
<td>
@ -53,8 +56,8 @@
</td>
<td>
<select class="form-control" @bind="@isnavigation" readonly>
<option value="true">Yes</option>
<option value="false">No</option>
<option value="True">Yes</option>
<option value="False">No</option>
</select>
</td>
</tr>
@ -63,7 +66,7 @@
<label for="Name" class="control-label">Theme: </label>
</td>
<td>
<select class="form-control" @bind="@themetype">
<select class="form-control" @bind="@themetype" readonly>
<option value="">&lt;Select Theme&gt;</option>
@foreach (KeyValuePair<string, string> item in themes)
{
@ -77,7 +80,7 @@
<label for="Name" class="control-label">Layout: </label>
</td>
<td>
<select class="form-control" @bind="@layouttype">
<select class="form-control" @bind="@layouttype" readonly>
<option value="">&lt;Select Layout&gt;</option>
@foreach (KeyValuePair<string, string> panelayout in panelayouts)
{
@ -113,10 +116,14 @@
</table>
<button type="button" class="btn btn-danger" @onclick="@DeletePage">Delete</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
<br /><br />
<AuditInfo CreatedBy="@createdby" CreatedOn="@createdon" ModifiedBy="@modifiedby" ModifiedOn="@modifiedon"></AuditInfo>
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
string message = "";
Dictionary<string, string> themes = new Dictionary<string, string>();
Dictionary<string, string> panelayouts = new Dictionary<string, string>();
@ -131,33 +138,55 @@
string icon;
string viewpermissions;
string editpermissions;
string createdby;
DateTime createdon;
string modifiedby;
DateTime modifiedon;
protected override void OnInitialized()
{
themes = ThemeService.GetThemeTypes(PageState.Themes);
panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes);
PageId = Int32.Parse(PageState.QueryString["id"]);
Page p = PageState.Pages.Where(item => item.PageId == PageId).FirstOrDefault();
if (p != null)
try
{
name = p.Name;
path = p.Path;
themes = ThemeService.GetThemeTypes(PageState.Themes);
panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes);
order = p.Order.ToString();
isnavigation = p.IsNavigation.ToString();
themetype = p.ThemeType;
layouttype = p.LayoutType;
icon = p.Icon;
viewpermissions = p.ViewPermissions;
editpermissions = p.EditPermissions;
PageId = Int32.Parse(PageState.QueryString["id"]);
Page page = PageState.Pages.Where(item => item.PageId == PageId).FirstOrDefault();
if (page != null)
{
name = page.Name;
path = page.Path;
order = page.Order.ToString();
isnavigation = page.IsNavigation.ToString();
themetype = page.ThemeType;
layouttype = page.LayoutType;
icon = page.Icon;
viewpermissions = page.ViewPermissions;
editpermissions = page.EditPermissions;
createdby = page.CreatedBy;
createdon = page.CreatedOn;
modifiedby = page.ModifiedBy;
modifiedon = page.ModifiedOn;
}
}
catch (Exception ex)
{
message = ex.Message;
}
}
private async Task DeletePage()
{
await PageService.DeletePageAsync(Int32.Parse(PageState.QueryString["id"]));
PageState.Reload = Constants.ReloadSite;
UriHelper.NavigateTo(NavigateUrl());
try
{
await PageService.DeletePageAsync(Int32.Parse(PageState.QueryString["id"]));
PageState.Reload = Constants.ReloadSite;
UriHelper.NavigateTo(NavigateUrl());
}
catch (Exception ex)
{
message = ex.Message;
}
}
}

View File

@ -9,6 +9,8 @@
@inject IPageService PageService
@inject IThemeService ThemeService
@message
<table class="form-group">
<tr>
<td>
@ -33,9 +35,9 @@
<td>
<select class="form-control" @bind="@parentid">
<option value="">&lt;Select Parent&gt;</option>
@foreach (Page p in PageState.Pages)
@foreach (Page page in PageState.Pages)
{
<option value="@p.PageId">@p.Name</option>
<option value="@(page.PageId)">@(page.Name)</option>
}
</select>
</td>
@ -54,8 +56,8 @@
</td>
<td>
<select class="form-control" @bind="@isnavigation">
<option value="true">Yes</option>
<option value="false">No</option>
<option value="True">Yes</option>
<option value="False">No</option>
</select>
</td>
</tr>
@ -114,10 +116,14 @@
</table>
<button type="button" class="btn btn-success" @onclick="@SavePage">Save</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
<br /><br />
<AuditInfo CreatedBy="@createdby" CreatedOn="@createdon" ModifiedBy="@modifiedby" ModifiedOn="@modifiedon"></AuditInfo>
@code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
string message = "";
Dictionary<string, string> themes = new Dictionary<string, string>();
Dictionary<string, string> panelayouts = new Dictionary<string, string>();
@ -132,69 +138,93 @@
string icon;
string viewpermissions;
string editpermissions;
string createdby;
DateTime createdon;
string modifiedby;
DateTime modifiedon;
protected override void OnInitialized()
{
themes = ThemeService.GetThemeTypes(PageState.Themes);
panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes);
PageId = Int32.Parse(PageState.QueryString["id"]);
Page p = PageState.Pages.Where(item => item.PageId == PageId).FirstOrDefault();
if (p != null)
try
{
name = p.Name;
path = p.Path;
if (p.ParentId == null)
themes = ThemeService.GetThemeTypes(PageState.Themes);
panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes);
PageId = Int32.Parse(PageState.QueryString["id"]);
Page page = PageState.Pages.Where(item => item.PageId == PageId).FirstOrDefault();
if (page != null)
{
parentid = "";
name = page.Name;
path = page.Path;
if (page.ParentId == null)
{
parentid = "";
}
else
{
parentid = page.ParentId.ToString();
}
order = page.Order.ToString();
isnavigation = page.IsNavigation.ToString();
themetype = page.ThemeType;
layouttype = page.LayoutType;
icon = page.Icon;
viewpermissions = page.ViewPermissions;
editpermissions = page.EditPermissions;
createdby = page.CreatedBy;
createdon = page.CreatedOn;
modifiedby = page.ModifiedBy;
modifiedon = page.ModifiedOn;
}
else
{
parentid = p.ParentId.ToString();
}
order = p.Order.ToString();
isnavigation = p.IsNavigation.ToString();
themetype = p.ThemeType;
layouttype = p.LayoutType;
icon = p.Icon;
viewpermissions = p.ViewPermissions;
editpermissions = p.EditPermissions;
}
catch (Exception ex)
{
message = ex.Message;
}
}
private async Task SavePage()
{
Page p = PageState.Page;
p.PageId = Int32.Parse(PageState.QueryString["id"]);
if (string.IsNullOrEmpty(parentid))
try
{
p.ParentId = null;
Page page = PageState.Page;
page.PageId = Int32.Parse(PageState.QueryString["id"]);
if (string.IsNullOrEmpty(parentid))
{
page.ParentId = null;
}
else
{
page.ParentId = Int32.Parse(parentid);
}
page.Name = name;
page.Path = path;
page.Order = (order == null ? 1 : Int32.Parse(order));
page.IsNavigation = (isnavigation == null ? true : Boolean.Parse(isnavigation));
page.ThemeType = themetype;
page.LayoutType = (layouttype == null ? "" : layouttype);
page.Icon = (icon == null ? "" : icon);
Type type;
if (!string.IsNullOrEmpty(layouttype))
{
type = Type.GetType(layouttype);
}
else
{
type = Type.GetType(themetype);
}
System.Reflection.PropertyInfo property = type.GetProperty("Panes");
page.Panes = (string)property.GetValue(Activator.CreateInstance(type), null);
page.ViewPermissions = viewpermissions;
page.EditPermissions = editpermissions;
await PageService.UpdatePageAsync(page);
PageState.Reload = Constants.ReloadSite;
UriHelper.NavigateTo(NavigateUrl(path));
}
else
catch (Exception ex)
{
p.ParentId = Int32.Parse(parentid);
message = ex.Message;
}
p.Name = name;
p.Path = path;
p.Order = (order == null ? 1 : Int32.Parse(order));
p.IsNavigation = (isnavigation == null ? true : Boolean.Parse(isnavigation));
p.ThemeType = themetype;
p.LayoutType = (layouttype == null ? "" : layouttype);
p.Icon = (icon == null ? "" : icon);
Type type;
if (!string.IsNullOrEmpty(layouttype))
{
type = Type.GetType(layouttype);
}
else
{
type = Type.GetType(themetype);
}
System.Reflection.PropertyInfo property = type.GetProperty("Panes");
p.Panes = (string)property.GetValue(Activator.CreateInstance(type), null);
p.ViewPermissions = viewpermissions;
p.EditPermissions = editpermissions;
await PageService.UpdatePageAsync(p);
UriHelper.NavigateTo(NavigateUrl(path));
}
}

View File

@ -3,7 +3,6 @@
@using Oqtane.Modules
@using Oqtane.Client.Modules.Controls
@inherits ModuleBase
@inject IPageService PageService
@if (PageState.Pages == null)
@ -12,27 +11,28 @@
}
else
{
<ActionLink Action="Add" Text="Add Page" Style="float: right; margin: 10px;" />
<table class="table">
<thead>
<tr>
<th> </th>
<th>&nbsp;</th>
<th>&nbsp;</th>
<th>Path</th>
<th>Name</th>
</tr>
</thead>
<tbody>
@foreach (var p in PageState.Pages)
@foreach (Page page in PageState.Pages)
{
<tr>
<td><ActionLink Action="Edit" Parameters="@($"id=" + p.PageId.ToString())" /></td>
<td><ActionLink Action="Delete" Parameters="@($"id=" + p.PageId.ToString())" ButtonClass="btn-danger" /></td>
<td>@p.Path</td>
<td>@p.Name</td>
<td><ActionLink Action="Edit" Parameters="@($"id=" + page.PageId.ToString())" /></td>
<td><ActionLink Action="Delete" Parameters="@($"id=" + page.PageId.ToString())" Class="btn btn-danger" /></td>
<td>@(page.Path)</td>
<td>@(page.Name)</td>
</tr>
}
</tbody>
</table>
<ActionLink Action="Add" Text="Add Page" />
</table>
}
@code {

View File

@ -7,7 +7,7 @@
@if (authorized)
{
<NavLink class="@buttonClass" href="@url">@text</NavLink>
<NavLink class="@classname" href="@url" style="@style">@text</NavLink>
}
@code {
@ -21,12 +21,16 @@
public string Parameters { get; set; } // optional
[Parameter]
public string ButtonClass { get; set; } // optional
public string Class { get; set; } // optional
[Parameter]
public string Style { get; set; } // optional
string text = "";
string url = "";
string parameters = "";
string buttonClass = "btn btn-primary";
string classname = "btn btn-primary";
string style = "";
bool authorized = false;
protected override void OnInitialized()
@ -42,9 +46,14 @@
parameters = Parameters;
}
if (!string.IsNullOrEmpty(ButtonClass))
if (!string.IsNullOrEmpty(Class))
{
buttonClass = "btn " + ButtonClass;
classname = Class;
}
if (!string.IsNullOrEmpty(Style))
{
style = Style;
}
url = EditUrl(Action, parameters);

View File

@ -0,0 +1,55 @@
@using Oqtane.Modules
@inherits ModuleBase
@((MarkupString)@text)
@code {
[Parameter]
public string CreatedBy { get; set; }
[Parameter]
public DateTime CreatedOn { get; set; }
[Parameter]
public string ModifiedBy { get; set; }
[Parameter]
public DateTime ModifiedOn { get; set; }
[Parameter]
public string Style { get; set; }
string text = "";
string style = "";
protected override void OnInitialized()
{
if (!String.IsNullOrEmpty(CreatedBy) || CreatedOn != null)
{
text += "<p style=\"" + Style + "\">Created ";
if (!String.IsNullOrEmpty(CreatedBy))
{
text += " by <b>" + CreatedBy + "</b>";
}
if (CreatedOn != null)
{
text += " on <b>" + CreatedOn.ToString("MMM dd yyyy HH:mm:ss") + "</b>";
}
text += "</p>";
}
if (!String.IsNullOrEmpty(ModifiedBy) || ModifiedOn != null)
{
text += "<p style=\"" + Style + "\">Last modified ";
if (!String.IsNullOrEmpty(ModifiedBy))
{
text += " by <b>" + ModifiedBy + "</b>";
}
if (ModifiedOn != null)
{
text += " on <b>" + ModifiedOn.ToString("MMM dd yyyy HH:mm:ss") + "</b>";
}
text += "</p>";
}
}
}