266 lines
8.8 KiB
Plaintext
266 lines
8.8 KiB
Plaintext
@using Microsoft.AspNetCore.Components.Routing
|
|
@using Oqtane.Modules.Controls
|
|
@using Oqtane.Models
|
|
@using Oqtane.Services
|
|
@using Oqtane.Modules
|
|
@using Oqtane.Shared
|
|
@using Oqtane.Security
|
|
@namespace Oqtane.Modules.Admin.Pages
|
|
@inherits ModuleBase
|
|
@inject IUriHelper UriHelper
|
|
@inject IPageService PageService
|
|
@inject IThemeService ThemeService
|
|
|
|
<ModuleMessage Message="@message" />
|
|
|
|
<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">Parent: </label>
|
|
</td>
|
|
<td>
|
|
<select class="form-control" @onchange="@(e => ParentChanged(e))">
|
|
<option value=""><Site Root></option>
|
|
@foreach (Page page in pages)
|
|
{
|
|
<option value="@(page.PageId)">@(new string('-',page.Level * 2))@(page.Name)</option>
|
|
}
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<label for="Name" class="control-label">Insert: </label>
|
|
</td>
|
|
<td>
|
|
<select class="form-control" @bind="@insert">
|
|
<option value="<<">At Beginning</option>
|
|
@if (children != null && children.Count > 0)
|
|
{
|
|
<option value="<">Before</option>
|
|
<option value=">">After</option>
|
|
}
|
|
<option value=">>" selected>At 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">Edit Mode? </label>
|
|
</td>
|
|
<td>
|
|
<select class="form-control" @bind="@editmode">
|
|
<option value="True">Yes</option>
|
|
<option value="False">No</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" @ref:suppressField />
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<button type="button" class="btn btn-success" @onclick="@SavePage">Save</button>
|
|
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
|
|
|
|
@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>();
|
|
|
|
List<Page> pages;
|
|
string name;
|
|
string parentid;
|
|
string insert;
|
|
List<Page> children;
|
|
int childid = -1;
|
|
string isnavigation = "True";
|
|
string editmode = "False";
|
|
string themetype;
|
|
string layouttype = "";
|
|
string icon = "";
|
|
string permissions = ""; // need to set default permissions
|
|
|
|
PermissionGrid permissiongrid;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
try
|
|
{
|
|
pages = PageState.Pages.Where(item => item.IsNavigation).ToList();
|
|
children = PageState.Pages.Where(item => item.ParentId == null && item.IsNavigation).OrderBy(item => item.Order).ToList();
|
|
|
|
themes = ThemeService.GetThemeTypes(PageState.Themes);
|
|
panelayouts = ThemeService.GetPaneLayoutTypes(PageState.Themes);
|
|
|
|
List<PermissionString> permissionstrings = new List<PermissionString>();
|
|
permissionstrings.Add(new PermissionString { PermissionName = "View", Permissions = Constants.AdminRole });
|
|
permissionstrings.Add(new PermissionString { PermissionName = "Edit", Permissions = Constants.AdminRole });
|
|
permissions = UserSecurity.SetPermissionStrings(permissionstrings);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
message = ex.Message;
|
|
}
|
|
}
|
|
|
|
private void ParentChanged(UIChangeEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
parentid = (string)e.Value;
|
|
if (string.IsNullOrEmpty(parentid))
|
|
{
|
|
children = PageState.Pages.Where(item => item.ParentId == null && item.IsNavigation).OrderBy(item => item.Order).ToList();
|
|
}
|
|
else
|
|
{
|
|
children = PageState.Pages.Where(item => item.ParentId == int.Parse(parentid) && item.IsNavigation).OrderBy(item => item.Order).ToList();
|
|
}
|
|
StateHasChanged();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
message = ex.Message;
|
|
}
|
|
}
|
|
|
|
private async Task SavePage()
|
|
{
|
|
try
|
|
{
|
|
Page page = new Page();
|
|
page.SiteId = PageState.Page.SiteId;
|
|
page.Name = name;
|
|
if (string.IsNullOrEmpty(parentid))
|
|
{
|
|
page.ParentId = null;
|
|
page.Path = page.Name.ToLower();
|
|
}
|
|
else
|
|
{
|
|
page.ParentId = Int32.Parse(parentid);
|
|
Page parent = PageState.Pages.Where(item => item.ParentId == page.ParentId).FirstOrDefault();
|
|
page.Path = parent.Path + "/" + page.Name.ToLower();
|
|
}
|
|
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 = (editmode == null ? true : Boolean.Parse(editmode));
|
|
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();
|
|
await PageService.AddPageAsync(page);
|
|
await PageService.UpdatePageOrderAsync(page.SiteId, page.ParentId);
|
|
|
|
PageState.Reload = Constants.ReloadSite;
|
|
UriHelper.NavigateTo(NavigateUrl());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
message = ex.Message;
|
|
}
|
|
}
|
|
|
|
}
|