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 IPageService PageService
@inject IThemeService ThemeService @inject IThemeService ThemeService
@message
<table class="form-group"> <table class="form-group">
<tr> <tr>
<td> <td>
@ -32,9 +34,9 @@
<td> <td>
<select class="form-control" @bind="@parentid"> <select class="form-control" @bind="@parentid">
<option value="">&lt;Select Parent&gt;</option> <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> </select>
</td> </td>
@ -53,8 +55,8 @@
</td> </td>
<td> <td>
<select class="form-control" @bind="@isnavigation"> <select class="form-control" @bind="@isnavigation">
<option value="true">Yes</option> <option value="True">Yes</option>
<option value="false">No</option> <option value="False">No</option>
</select> </select>
</td> </td>
</tr> </tr>
@ -117,6 +119,8 @@
@code { @code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
string message = "";
Dictionary<string, string> themes = new Dictionary<string, string>(); Dictionary<string, string> themes = new Dictionary<string, string>();
Dictionary<string, string> panelayouts = new Dictionary<string, string>(); Dictionary<string, string> panelayouts = new Dictionary<string, string>();
@ -133,44 +137,59 @@
protected override void OnInitialized() protected override void OnInitialized()
{ {
themes = ThemeService.GetThemeTypes(PageState.Themes); try
panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes); {
themes = ThemeService.GetThemeTypes(PageState.Themes);
panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes);
}
catch (Exception ex)
{
message = ex.Message;
}
} }
private async Task SavePage() private async Task SavePage()
{ {
Page p = new Page(); try
p.SiteId = PageState.Page.SiteId;
if (string.IsNullOrEmpty(parentid))
{ {
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.Services
@using Oqtane.Modules @using Oqtane.Modules
@using Oqtane.Shared @using Oqtane.Shared
@using Oqtane.Client.Modules.Controls
@inherits ModuleBase @inherits ModuleBase
@inject IUriHelper UriHelper @inject IUriHelper UriHelper
@inject IPageService PageService @inject IPageService PageService
@inject IThemeService ThemeService @inject IThemeService ThemeService
@message
<table class="form-group"> <table class="form-group">
<tr> <tr>
<td> <td>
@ -53,8 +56,8 @@
</td> </td>
<td> <td>
<select class="form-control" @bind="@isnavigation" readonly> <select class="form-control" @bind="@isnavigation" readonly>
<option value="true">Yes</option> <option value="True">Yes</option>
<option value="false">No</option> <option value="False">No</option>
</select> </select>
</td> </td>
</tr> </tr>
@ -63,7 +66,7 @@
<label for="Name" class="control-label">Theme: </label> <label for="Name" class="control-label">Theme: </label>
</td> </td>
<td> <td>
<select class="form-control" @bind="@themetype"> <select class="form-control" @bind="@themetype" readonly>
<option value="">&lt;Select Theme&gt;</option> <option value="">&lt;Select Theme&gt;</option>
@foreach (KeyValuePair<string, string> item in themes) @foreach (KeyValuePair<string, string> item in themes)
{ {
@ -77,7 +80,7 @@
<label for="Name" class="control-label">Layout: </label> <label for="Name" class="control-label">Layout: </label>
</td> </td>
<td> <td>
<select class="form-control" @bind="@layouttype"> <select class="form-control" @bind="@layouttype" readonly>
<option value="">&lt;Select Layout&gt;</option> <option value="">&lt;Select Layout&gt;</option>
@foreach (KeyValuePair<string, string> panelayout in panelayouts) @foreach (KeyValuePair<string, string> panelayout in panelayouts)
{ {
@ -113,10 +116,14 @@
</table> </table>
<button type="button" class="btn btn-danger" @onclick="@DeletePage">Delete</button> <button type="button" class="btn btn-danger" @onclick="@DeletePage">Delete</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink> <NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
<br /><br />
<AuditInfo CreatedBy="@createdby" CreatedOn="@createdon" ModifiedBy="@modifiedby" ModifiedOn="@modifiedon"></AuditInfo>
@code { @code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
string message = "";
Dictionary<string, string> themes = new Dictionary<string, string>(); Dictionary<string, string> themes = new Dictionary<string, string>();
Dictionary<string, string> panelayouts = new Dictionary<string, string>(); Dictionary<string, string> panelayouts = new Dictionary<string, string>();
@ -131,33 +138,55 @@
string icon; string icon;
string viewpermissions; string viewpermissions;
string editpermissions; string editpermissions;
string createdby;
DateTime createdon;
string modifiedby;
DateTime modifiedon;
protected override void OnInitialized() protected override void OnInitialized()
{ {
themes = ThemeService.GetThemeTypes(PageState.Themes); try
panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes);
PageId = Int32.Parse(PageState.QueryString["id"]);
Page p = PageState.Pages.Where(item => item.PageId == PageId).FirstOrDefault();
if (p != null)
{ {
name = p.Name; themes = ThemeService.GetThemeTypes(PageState.Themes);
path = p.Path; panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes);
order = p.Order.ToString(); PageId = Int32.Parse(PageState.QueryString["id"]);
isnavigation = p.IsNavigation.ToString(); Page page = PageState.Pages.Where(item => item.PageId == PageId).FirstOrDefault();
themetype = p.ThemeType; if (page != null)
layouttype = p.LayoutType; {
icon = p.Icon; name = page.Name;
viewpermissions = p.ViewPermissions; path = page.Path;
editpermissions = p.EditPermissions;
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() private async Task DeletePage()
{ {
await PageService.DeletePageAsync(Int32.Parse(PageState.QueryString["id"])); try
PageState.Reload = Constants.ReloadSite; {
UriHelper.NavigateTo(NavigateUrl()); 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 IPageService PageService
@inject IThemeService ThemeService @inject IThemeService ThemeService
@message
<table class="form-group"> <table class="form-group">
<tr> <tr>
<td> <td>
@ -33,9 +35,9 @@
<td> <td>
<select class="form-control" @bind="@parentid"> <select class="form-control" @bind="@parentid">
<option value="">&lt;Select Parent&gt;</option> <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> </select>
</td> </td>
@ -54,8 +56,8 @@
</td> </td>
<td> <td>
<select class="form-control" @bind="@isnavigation"> <select class="form-control" @bind="@isnavigation">
<option value="true">Yes</option> <option value="True">Yes</option>
<option value="false">No</option> <option value="False">No</option>
</select> </select>
</td> </td>
</tr> </tr>
@ -114,10 +116,14 @@
</table> </table>
<button type="button" class="btn btn-success" @onclick="@SavePage">Save</button> <button type="button" class="btn btn-success" @onclick="@SavePage">Save</button>
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink> <NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
<br /><br />
<AuditInfo CreatedBy="@createdby" CreatedOn="@createdon" ModifiedBy="@modifiedby" ModifiedOn="@modifiedon"></AuditInfo>
@code { @code {
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } } public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
string message = "";
Dictionary<string, string> themes = new Dictionary<string, string>(); Dictionary<string, string> themes = new Dictionary<string, string>();
Dictionary<string, string> panelayouts = new Dictionary<string, string>(); Dictionary<string, string> panelayouts = new Dictionary<string, string>();
@ -132,69 +138,93 @@
string icon; string icon;
string viewpermissions; string viewpermissions;
string editpermissions; string editpermissions;
string createdby;
DateTime createdon;
string modifiedby;
DateTime modifiedon;
protected override void OnInitialized() protected override void OnInitialized()
{ {
themes = ThemeService.GetThemeTypes(PageState.Themes); try
panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes);
PageId = Int32.Parse(PageState.QueryString["id"]);
Page p = PageState.Pages.Where(item => item.PageId == PageId).FirstOrDefault();
if (p != null)
{ {
name = p.Name; themes = ThemeService.GetThemeTypes(PageState.Themes);
path = p.Path; panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes);
if (p.ParentId == null)
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 }
{ catch (Exception ex)
parentid = p.ParentId.ToString(); {
} message = ex.Message;
order = p.Order.ToString();
isnavigation = p.IsNavigation.ToString();
themetype = p.ThemeType;
layouttype = p.LayoutType;
icon = p.Icon;
viewpermissions = p.ViewPermissions;
editpermissions = p.EditPermissions;
} }
} }
private async Task SavePage() private async Task SavePage()
{ {
Page p = PageState.Page; try
p.PageId = Int32.Parse(PageState.QueryString["id"]);
if (string.IsNullOrEmpty(parentid))
{ {
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.Modules
@using Oqtane.Client.Modules.Controls @using Oqtane.Client.Modules.Controls
@inherits ModuleBase @inherits ModuleBase
@inject IPageService PageService @inject IPageService PageService
@if (PageState.Pages == null) @if (PageState.Pages == null)
@ -12,27 +11,28 @@
} }
else else
{ {
<ActionLink Action="Add" Text="Add Page" Style="float: right; margin: 10px;" />
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
<th> </th> <th>&nbsp;</th>
<th>&nbsp;</th>
<th>Path</th> <th>Path</th>
<th>Name</th> <th>Name</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach (var p in PageState.Pages) @foreach (Page page in PageState.Pages)
{ {
<tr> <tr>
<td><ActionLink Action="Edit" Parameters="@($"id=" + p.PageId.ToString())" /></td> <td><ActionLink Action="Edit" Parameters="@($"id=" + page.PageId.ToString())" /></td>
<td><ActionLink Action="Delete" Parameters="@($"id=" + p.PageId.ToString())" ButtonClass="btn-danger" /></td> <td><ActionLink Action="Delete" Parameters="@($"id=" + page.PageId.ToString())" Class="btn btn-danger" /></td>
<td>@p.Path</td> <td>@(page.Path)</td>
<td>@p.Name</td> <td>@(page.Name)</td>
</tr> </tr>
} }
</tbody> </tbody>
</table> </table>
<ActionLink Action="Add" Text="Add Page" />
} }
@code { @code {

View File

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