372 lines
13 KiB
Plaintext
372 lines
13 KiB
Plaintext
@namespace Oqtane.Modules.Admin.Pages
|
|
@inherits ModuleBase
|
|
@inject NavigationManager NavigationManager
|
|
@inject IPageService PageService
|
|
@inject IThemeService ThemeService
|
|
|
|
<table class="table table-borderless">
|
|
<tr>
|
|
<td>
|
|
<label for="Name" class="control-label">Name: </label>
|
|
</td>
|
|
<td>
|
|
<input class="form-control" @bind="@name" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Name" class="control-label">Path: </label>
|
|
</td>
|
|
<td>
|
|
<input class="form-control" @bind="@path" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Name" class="control-label">Parent: </label>
|
|
</td>
|
|
<td>
|
|
<select class="form-control" @onchange="(e => ParentChanged(e))">
|
|
<option value="-1"><Site Root></option>
|
|
@foreach (Page page in pages)
|
|
{
|
|
if (page.PageId.ToString() == parentid)
|
|
{
|
|
<option value="@(page.PageId)" selected>@(new string('-', page.Level * 2))@(page.Name)</option>
|
|
}
|
|
else
|
|
{
|
|
<option value="@(page.PageId)">@(new string('-', page.Level * 2))@(page.Name)</option>
|
|
}
|
|
}
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Name" class="control-label">Move : </label>
|
|
</td>
|
|
<td>
|
|
<select class="form-control" @bind="@insert">
|
|
@if (parentid == currentparentid)
|
|
{
|
|
<option value="="><Maintain Current Location></option>
|
|
}
|
|
<option value="<<">To Beginning</option>
|
|
@if (children != null && children.Count > 0)
|
|
{
|
|
<option value="<">Before</option>
|
|
<option value=">">After</option>
|
|
}
|
|
<option value=">>">To End</option>
|
|
</select>
|
|
@if (children != null && children.Count > 0 && (insert == "<" || insert == ">"))
|
|
{
|
|
<select class="form-control" @bind="@childid">
|
|
<option value="-1"><Select Page></option>
|
|
@foreach (Page page in children)
|
|
{
|
|
<option value="@(page.PageId)">@(page.Name)</option>
|
|
}
|
|
</select>
|
|
}
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Name" class="control-label">Navigation? </label>
|
|
</td>
|
|
<td>
|
|
<select class="form-control" @bind="@isnavigation">
|
|
<option value="True">Yes</option>
|
|
<option value="False">No</option>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Name" class="control-label">Default Mode? </label>
|
|
</td>
|
|
<td>
|
|
<select class="form-control" @bind="@mode">
|
|
<option value="view">View Mode</option>
|
|
<option value="edit">Edit Mode</option>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Name" class="control-label">Theme: </label>
|
|
</td>
|
|
<td>
|
|
<select class="form-control" @bind="@themetype">
|
|
<option value=""><Select Theme></option>
|
|
@foreach (KeyValuePair<string, string> item in themes)
|
|
{
|
|
<option value="@item.Key">@item.Value</option>
|
|
}
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Name" class="control-label">Layout: </label>
|
|
</td>
|
|
<td>
|
|
<select class="form-control" @bind="@layouttype">
|
|
<option value=""><Select Layout></option>
|
|
@foreach (KeyValuePair<string, string> panelayout in panelayouts)
|
|
{
|
|
<option value="@panelayout.Key">@panelayout.Value</option>
|
|
}
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Name" class="control-label">Icon: </label>
|
|
</td>
|
|
<td>
|
|
<input class="form-control" @bind="@icon" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Name" class="control-label">Permissions: </label>
|
|
</td>
|
|
<td>
|
|
<PermissionGrid EntityName="Page" Permissions="@permissions" @ref="permissiongrid" />
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Name" class="control-label">Is Deleted? </label>
|
|
</td>
|
|
<td>
|
|
<select class="form-control" @bind="@isdeleted">
|
|
<option value="True">Yes</option>
|
|
<option value="False">No</option>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
</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" DeletedBy="@deletedby" DeletedOn="@deletedon"></AuditInfo>
|
|
|
|
@code {
|
|
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.Admin; } }
|
|
|
|
Dictionary<string, string> themes = new Dictionary<string, string>();
|
|
Dictionary<string, string> panelayouts = new Dictionary<string, string>();
|
|
|
|
List<Page> pages;
|
|
int PageId;
|
|
string name;
|
|
string path;
|
|
string currentparentid;
|
|
string parentid;
|
|
string insert = "=";
|
|
List<Page> children;
|
|
int childid = -1;
|
|
string isnavigation;
|
|
string mode;
|
|
string themetype;
|
|
string layouttype;
|
|
string icon;
|
|
string permissions;
|
|
string createdby;
|
|
DateTime createdon;
|
|
string modifiedby;
|
|
DateTime modifiedon;
|
|
string deletedby;
|
|
DateTime? deletedon;
|
|
string isdeleted;
|
|
|
|
PermissionGrid permissiongrid;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
try
|
|
{
|
|
pages = PageState.Pages;
|
|
children = PageState.Pages.Where(item => item.ParentId == null).ToList();
|
|
|
|
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)
|
|
{
|
|
name = page.Name;
|
|
path = page.Path;
|
|
if (path.Contains("/"))
|
|
{
|
|
path = path.Substring(path.LastIndexOf("/") + 1);
|
|
}
|
|
if (page.ParentId == null)
|
|
{
|
|
parentid = "";
|
|
}
|
|
else
|
|
{
|
|
parentid = page.ParentId.ToString();
|
|
}
|
|
currentparentid = parentid;
|
|
isnavigation = page.IsNavigation.ToString();
|
|
mode = (page.EditMode) ? "edit" : "view";
|
|
themetype = page.ThemeType;
|
|
layouttype = page.LayoutType;
|
|
icon = page.Icon;
|
|
permissions = page.Permissions;
|
|
createdby = page.CreatedBy;
|
|
createdon = page.CreatedOn;
|
|
modifiedby = page.ModifiedBy;
|
|
modifiedon = page.ModifiedOn;
|
|
deletedby = page.DeletedBy;
|
|
deletedon = page.DeletedOn;
|
|
isdeleted = page.IsDeleted.ToString();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ModuleInstance.AddModuleMessage(ex.Message, MessageType.Error);
|
|
}
|
|
}
|
|
|
|
private void ParentChanged(ChangeEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
parentid = (string)e.Value;
|
|
if (parentid == "-1")
|
|
{
|
|
children = PageState.Pages.Where(item => item.ParentId == null).ToList();
|
|
}
|
|
else
|
|
{
|
|
children = PageState.Pages.Where(item => item.ParentId == int.Parse(parentid)).ToList();
|
|
}
|
|
if (parentid == currentparentid)
|
|
{
|
|
insert = "=";
|
|
}
|
|
else
|
|
{
|
|
insert = ">>";
|
|
}
|
|
StateHasChanged();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ModuleInstance.AddModuleMessage(ex.Message, MessageType.Error);
|
|
}
|
|
}
|
|
|
|
private async Task SavePage()
|
|
{
|
|
try
|
|
{
|
|
Page page = PageState.Pages.Where(item => item.PageId == PageId).FirstOrDefault();
|
|
string currentpath = page.Path;
|
|
|
|
page.Name = name;
|
|
if (path == "")
|
|
{
|
|
path = name;
|
|
}
|
|
if (path.Contains("/"))
|
|
{
|
|
path = path.Substring(path.LastIndexOf("/") + 1);
|
|
}
|
|
if (string.IsNullOrEmpty(parentid))
|
|
{
|
|
page.ParentId = null;
|
|
page.Path = Utilities.GetFriendlyUrl(path);
|
|
}
|
|
else
|
|
{
|
|
page.ParentId = Int32.Parse(parentid);
|
|
Page parent = PageState.Pages.Where(item => item.PageId == page.ParentId).FirstOrDefault();
|
|
if (parent.Path == "")
|
|
{
|
|
page.Path = Utilities.GetFriendlyUrl(parent.Name) + "/" + Utilities.GetFriendlyUrl(path);
|
|
}
|
|
else
|
|
{
|
|
page.Path = parent.Path + "/" + Utilities.GetFriendlyUrl(path);
|
|
}
|
|
}
|
|
if (insert != "=")
|
|
{
|
|
Page child;
|
|
switch (insert)
|
|
{
|
|
case "<<":
|
|
page.Order = 0;
|
|
break;
|
|
case "<":
|
|
child = PageState.Pages.Where(item => item.PageId == childid).FirstOrDefault();
|
|
page.Order = child.Order - 1;
|
|
break;
|
|
case ">":
|
|
child = PageState.Pages.Where(item => item.PageId == childid).FirstOrDefault();
|
|
page.Order = child.Order + 1;
|
|
break;
|
|
case ">>":
|
|
page.Order = int.MaxValue;
|
|
break;
|
|
}
|
|
}
|
|
page.IsNavigation = (isnavigation == null ? true : Boolean.Parse(isnavigation));
|
|
page.EditMode = (mode == "edit" ? true : false);
|
|
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.Permissions = permissiongrid.GetPermissions();
|
|
page.IsDeleted = (isdeleted == null ? true : Boolean.Parse(isdeleted));
|
|
|
|
await PageService.UpdatePageAsync(page);
|
|
await PageService.UpdatePageOrderAsync(page.SiteId, page.ParentId);
|
|
if (currentparentid == "")
|
|
{
|
|
await PageService.UpdatePageOrderAsync(page.SiteId, null);
|
|
}
|
|
else
|
|
{
|
|
await PageService.UpdatePageOrderAsync(page.SiteId, int.Parse(currentparentid));
|
|
}
|
|
|
|
// update child paths
|
|
if (parentid != currentparentid)
|
|
{
|
|
foreach (Page p in PageState.Pages.Where(item => item.Path.StartsWith(currentpath)))
|
|
{
|
|
p.Path = p.Path.Replace(currentpath, page.Path);
|
|
await PageService.UpdatePageAsync(p);
|
|
}
|
|
}
|
|
|
|
NavigationManager.NavigateTo(NavigateUrl(page.Path, Reload.Site));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ModuleInstance.AddModuleMessage(ex.Message, MessageType.Error);
|
|
}
|
|
}
|
|
}
|