Theme base components refactoring
This commit is contained in:
parent
8523f0d719
commit
ced2051704
|
@ -1,32 +1,34 @@
|
|||
@namespace Oqtane.Themes.Controls
|
||||
@inherits ThemeControlBase
|
||||
|
||||
@if (breadcrumbs != string.Empty)
|
||||
@if (BreadCrumbPages.Any())
|
||||
{
|
||||
@((MarkupString)breadcrumbs)
|
||||
<ol class="breadcrumb">
|
||||
@foreach (var p in BreadCrumbPages)
|
||||
{
|
||||
<li class="breadcrumb-item @ActiveClass(p)">
|
||||
<a href="@NavigateUrl(p.Path)">@p.Name</a>
|
||||
</li>
|
||||
}
|
||||
</ol>
|
||||
}
|
||||
|
||||
@code {
|
||||
string breadcrumbs = string.Empty;
|
||||
|
||||
protected override void OnParametersSet()
|
||||
protected IEnumerable<Page> BreadCrumbPages => GetBreadCrumbPages().Reverse().ToList();
|
||||
|
||||
protected string ActiveClass(Page page)
|
||||
{
|
||||
breadcrumbs = string.Empty;
|
||||
int? pageid = PageState.Page.PageId;
|
||||
for (int i = PageState.Pages.Count - 1; i >= 0; i--)
|
||||
return (page.PageId == PageState.Page.PageId) ? " active" : string.Empty;
|
||||
}
|
||||
|
||||
private IEnumerable<Page> GetBreadCrumbPages()
|
||||
{
|
||||
var page = PageState.Page;
|
||||
do
|
||||
{
|
||||
var p = PageState.Pages[i];
|
||||
if (p.PageId == pageid)
|
||||
{
|
||||
breadcrumbs = "<li class=\"breadcrumb-item" + ((p.PageId == PageState.Page.PageId) ? " active" : string.Empty) +
|
||||
"\"><a href=\"" + NavigateUrl(p.Path) + "\">" + p.Name + "</a></li>" + breadcrumbs;
|
||||
pageid = p.ParentId;
|
||||
}
|
||||
}
|
||||
|
||||
if (breadcrumbs != "")
|
||||
{
|
||||
breadcrumbs = "<ol class=\"breadcrumb\">" + breadcrumbs + "</ol>";
|
||||
}
|
||||
yield return page;
|
||||
page = PageState.Pages.FirstOrDefault(p => page != null && p.PageId == page.ParentId);
|
||||
} while (page != null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,17 +2,20 @@
|
|||
@inherits ThemeControlBase
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
@((MarkupString)logo)
|
||||
@if (PageState.Site.LogoFileId != null)
|
||||
{
|
||||
<a href="@Href">
|
||||
<img src="@ContentUrl(PageState.Site.LogoFileId.Value)" alt="@PageState.Site.Name"/>
|
||||
</a>
|
||||
}
|
||||
|
||||
@code {
|
||||
string logo = "";
|
||||
|
||||
protected override void OnParametersSet()
|
||||
string Href
|
||||
{
|
||||
if (PageState.Site.LogoFileId != null)
|
||||
get
|
||||
{
|
||||
var uri = new Uri(NavigationManager.Uri);
|
||||
logo = "<a href=\"" + uri.Scheme + "://" + uri.Authority + "\"><img src=\"" + ContentUrl(PageState.Site.LogoFileId.Value) + "\" alt=\"" + PageState.Site.Name + "\"/></a>";
|
||||
return $"{uri.Scheme}://{uri.Authority}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,13 +8,11 @@ namespace Oqtane.Themes.Controls
|
|||
{
|
||||
public class MenuBase : ThemeControlBase
|
||||
{
|
||||
private List<Page> _menuPages;
|
||||
|
||||
protected IEnumerable<Page> MenuPages => _menuPages ?? (_menuPages = GetMenuPages().ToList());
|
||||
protected IEnumerable<Page> MenuPages => GetMenuPages().ToList();
|
||||
|
||||
protected string GetTarget(Page page)
|
||||
{
|
||||
return page.Url.StartsWith("http") ? "_new" : string.Empty;
|
||||
return page.Url != null && page.Url.StartsWith("http") ? "_new" : string.Empty;
|
||||
}
|
||||
|
||||
protected string GetUrl(Page page)
|
||||
|
|
|
@ -1,135 +1,20 @@
|
|||
@namespace Oqtane.Themes.Controls
|
||||
@inherits ContainerBase
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IUserService UserService
|
||||
@inject IPageModuleService PageModuleService
|
||||
@inherits ModuleActionsBase
|
||||
|
||||
@if (PageState.EditMode && !PageState.Page.EditMode && UserSecurity.IsAuthorized(PageState.User,PermissionNames.Edit, ModuleState.Permissions))
|
||||
{
|
||||
<a class="nav-link dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"></a>
|
||||
<div class="dropdown-menu" x-placement="bottom-start" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(0px, 37px, 0px);">
|
||||
@foreach (var action in actions)
|
||||
@foreach (var action in Actions)
|
||||
{
|
||||
if (action.Action != "")
|
||||
if (string.IsNullOrEmpty(action.Name))
|
||||
{
|
||||
<a class="dropdown-item" @onclick="(async () => await ModuleAction(action.Action))">@action.Name</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item" @onclick="(async () => await ModuleAction(action))">@action.Name</a>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
private List<ActionViewModel> actions;
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
if (PageState.EditMode && UserSecurity.IsAuthorized(PageState.User,PermissionNames.Edit, ModuleState.Permissions))
|
||||
{
|
||||
actions = new List<ActionViewModel>();
|
||||
actions.Add(new ActionViewModel { Action = "settings", Name = "Manage Settings" });
|
||||
|
||||
if (ModuleState.ModuleDefinition != null && ModuleState.ModuleDefinition.ServerManagerType != "")
|
||||
{
|
||||
actions.Add(new ActionViewModel { Action = "import", Name = "Import Content" });
|
||||
actions.Add(new ActionViewModel { Action = "export", Name = "Export Content" });
|
||||
}
|
||||
|
||||
actions.Add(new ActionViewModel { Action = "delete", Name = "Delete Module" });
|
||||
actions.Add(new ActionViewModel { Action = "", Name = "" });
|
||||
|
||||
if (ModuleState.PaneModuleIndex > 0)
|
||||
{
|
||||
actions.Add(new ActionViewModel { Action = "<<", Name = "Move To Top" });
|
||||
}
|
||||
|
||||
if (ModuleState.PaneModuleIndex > 0)
|
||||
{
|
||||
actions.Add(new ActionViewModel { Action = "<", Name = "Move Up" });
|
||||
}
|
||||
|
||||
if (ModuleState.PaneModuleIndex < (ModuleState.PaneModuleCount - 1))
|
||||
{
|
||||
actions.Add(new ActionViewModel { Action = ">", Name = "Move Down" });
|
||||
}
|
||||
|
||||
if (ModuleState.PaneModuleIndex < (ModuleState.PaneModuleCount - 1))
|
||||
{
|
||||
actions.Add(new ActionViewModel { Action = ">>", Name = "Move To Bottom" });
|
||||
}
|
||||
|
||||
foreach (string pane in PageState.Page.Panes.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
if (pane != ModuleState.Pane)
|
||||
{
|
||||
actions.Add(new ActionViewModel { Action = pane, Name = "Move To " + pane + " Pane" });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task ModuleAction(string action)
|
||||
{
|
||||
if (PageState.EditMode && UserSecurity.IsAuthorized(PageState.User,PermissionNames.Edit, ModuleState.Permissions))
|
||||
{
|
||||
PageModule pagemodule = await PageModuleService.GetPageModuleAsync(ModuleState.PageModuleId);
|
||||
|
||||
string url = NavigateUrl();
|
||||
switch (action)
|
||||
{
|
||||
case "<<":
|
||||
pagemodule.Order = 0;
|
||||
await PageModuleService.UpdatePageModuleAsync(pagemodule);
|
||||
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
|
||||
break;
|
||||
case "<":
|
||||
pagemodule.Order -= 3;
|
||||
await PageModuleService.UpdatePageModuleAsync(pagemodule);
|
||||
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
|
||||
break;
|
||||
case ">":
|
||||
pagemodule.Order += 3;
|
||||
await PageModuleService.UpdatePageModuleAsync(pagemodule);
|
||||
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
|
||||
break;
|
||||
case ">>":
|
||||
pagemodule.Order = int.MaxValue;
|
||||
await PageModuleService.UpdatePageModuleAsync(pagemodule);
|
||||
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
|
||||
break;
|
||||
case "settings":
|
||||
url = EditUrl(pagemodule.ModuleId, "Settings");
|
||||
break;
|
||||
case "import":
|
||||
url = EditUrl(pagemodule.ModuleId, "Import");
|
||||
break;
|
||||
case "export":
|
||||
url = EditUrl(pagemodule.ModuleId, "Export");
|
||||
break;
|
||||
case "delete":
|
||||
pagemodule.IsDeleted = true;
|
||||
await PageModuleService.UpdatePageModuleAsync(pagemodule);
|
||||
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
|
||||
break;
|
||||
default: // move to pane
|
||||
string pane = pagemodule.Pane;
|
||||
pagemodule.Pane = action;
|
||||
pagemodule.Order = int.MaxValue; // add to bottom of pane
|
||||
await PageModuleService.UpdatePageModuleAsync(pagemodule);
|
||||
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
|
||||
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pane);
|
||||
break;
|
||||
}
|
||||
NavigationManager.NavigateTo(url);
|
||||
}
|
||||
}
|
||||
|
||||
public class ActionViewModel
|
||||
{
|
||||
public string Action { set; get; }
|
||||
public string Name { set; get; }
|
||||
}
|
||||
}
|
||||
|
|
154
Oqtane.Client/Themes/Controls/ModuleActionsBase.cs
Normal file
154
Oqtane.Client/Themes/Controls/ModuleActionsBase.cs
Normal file
|
@ -0,0 +1,154 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Security;
|
||||
using Oqtane.Services;
|
||||
using Oqtane.Shared;
|
||||
|
||||
// ReSharper disable UnassignedGetOnlyAutoProperty
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
namespace Oqtane.Themes.Controls
|
||||
{
|
||||
public class ModuleActionsBase : ContainerBase
|
||||
{
|
||||
[Inject]public NavigationManager NavigationManager{get; set;}
|
||||
[Inject]public IPageModuleService PageModuleService{get; set;}
|
||||
|
||||
protected List<ActionViewModel> Actions;
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
Actions = GetActions();
|
||||
}
|
||||
|
||||
protected virtual List<ActionViewModel> GetActions()
|
||||
{
|
||||
var actionList = new List<ActionViewModel>();
|
||||
if (PageState.EditMode && UserSecurity.IsAuthorized(PageState.User,PermissionNames.Edit, ModuleState.Permissions))
|
||||
{
|
||||
|
||||
actionList.Add(new ActionViewModel {Name = "Manage Settings", Action = async (u,m) => Settings(u, m)});
|
||||
|
||||
if (ModuleState.ModuleDefinition != null && ModuleState.ModuleDefinition.ServerManagerType != "")
|
||||
{
|
||||
actionList.Add(new ActionViewModel {Name = "Import Content", Action = async(u,m)=> EditUrl(m.ModuleId, "Import")});
|
||||
actionList.Add(new ActionViewModel {Name = "Export Content", Action = async(u,m)=> EditUrl(m.ModuleId, "Export")});
|
||||
}
|
||||
|
||||
actionList.Add(new ActionViewModel {Name = "Delete Module" , Action = async (u,m) => await DeleteModule(u, m)});
|
||||
actionList.Add(new ActionViewModel {Name = "" });
|
||||
|
||||
if (ModuleState.PaneModuleIndex > 0)
|
||||
{
|
||||
actionList.Add(new ActionViewModel {Name = "Move To Top" , Action = async (s,m) => await MoveTop(s, m)});
|
||||
}
|
||||
|
||||
if (ModuleState.PaneModuleIndex > 0)
|
||||
{
|
||||
actionList.Add(new ActionViewModel {Name = "Move Up" , Action = async (s,m) => await MoveUp(s, m)});
|
||||
}
|
||||
|
||||
if (ModuleState.PaneModuleIndex < (ModuleState.PaneModuleCount - 1))
|
||||
{
|
||||
actionList.Add(new ActionViewModel {Name = "Move Down", Action = async (s,m) => await MoveDown(s, m) });
|
||||
}
|
||||
|
||||
if (ModuleState.PaneModuleIndex < (ModuleState.PaneModuleCount - 1))
|
||||
{
|
||||
actionList.Add(new ActionViewModel {Name = "Move To Bottom", Action = async (s,m) => await MoveBottom(s, m) });
|
||||
}
|
||||
|
||||
foreach (string pane in PageState.Page.Panes.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
if (pane != ModuleState.Pane)
|
||||
{
|
||||
actionList.Add(new ActionViewModel {Name = "Move To " + pane + " Pane", Action = async (s,m) => await MoveToPane(s,pane, m) });
|
||||
}
|
||||
}
|
||||
}
|
||||
return actionList;
|
||||
}
|
||||
|
||||
protected async Task ModuleAction(ActionViewModel action)
|
||||
{
|
||||
if (PageState.EditMode && UserSecurity.IsAuthorized(PageState.User,PermissionNames.Edit, ModuleState.Permissions))
|
||||
{
|
||||
PageModule pagemodule = await PageModuleService.GetPageModuleAsync(ModuleState.PageModuleId);
|
||||
|
||||
string url = NavigateUrl();
|
||||
|
||||
if (action.Action!=null)
|
||||
{
|
||||
url = await action.Action(url, pagemodule);
|
||||
}
|
||||
NavigationManager.NavigateTo(url);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<string> MoveToPane(string url, string newPane, PageModule pagemodule)
|
||||
{
|
||||
string oldPane = pagemodule.Pane;
|
||||
pagemodule.Pane = newPane;
|
||||
pagemodule.Order = int.MaxValue; // add to bottom of pane
|
||||
await PageModuleService.UpdatePageModuleAsync(pagemodule);
|
||||
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
|
||||
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, oldPane);
|
||||
return url;
|
||||
}
|
||||
|
||||
private async Task<string> DeleteModule(string url,PageModule pagemodule)
|
||||
{
|
||||
pagemodule.IsDeleted = true;
|
||||
await PageModuleService.UpdatePageModuleAsync(pagemodule);
|
||||
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
|
||||
return url;
|
||||
}
|
||||
|
||||
private string Settings(string url, PageModule pagemodule)
|
||||
{
|
||||
url = EditUrl(pagemodule.ModuleId, "Settings");
|
||||
return url;
|
||||
}
|
||||
|
||||
private async Task<string> MoveTop(string s, PageModule pagemodule)
|
||||
{
|
||||
pagemodule.Order = 0;
|
||||
await PageModuleService.UpdatePageModuleAsync(pagemodule);
|
||||
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
|
||||
return s;
|
||||
}
|
||||
|
||||
private async Task<string> MoveBottom(string s, PageModule pagemodule)
|
||||
{
|
||||
pagemodule.Order = int.MaxValue;
|
||||
await PageModuleService.UpdatePageModuleAsync(pagemodule);
|
||||
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
|
||||
return s;
|
||||
}
|
||||
private async Task<string> MoveUp(string s, PageModule pagemodule)
|
||||
{
|
||||
pagemodule.Order -= 3;
|
||||
await PageModuleService.UpdatePageModuleAsync(pagemodule);
|
||||
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
|
||||
return s;
|
||||
}
|
||||
private async Task<string> MoveDown(string s, PageModule pagemodule)
|
||||
{
|
||||
pagemodule.Order += 3;
|
||||
await PageModuleService.UpdatePageModuleAsync(pagemodule);
|
||||
await PageModuleService.UpdatePageModuleOrderAsync(pagemodule.PageId, pagemodule.Pane);
|
||||
return s;
|
||||
}
|
||||
|
||||
public class ActionViewModel
|
||||
{
|
||||
public string Name { set; get; }
|
||||
|
||||
public Func<string, PageModule, Task<string>> Action { set; get; }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user