mirror of https://github.com/abpframework/abp.git
19 changed files with 490 additions and 0 deletions
@ -0,0 +1,18 @@ |
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.Layout |
|||
{ |
|||
public class BreadcrumbItem |
|||
{ |
|||
public string Text { get; set; } |
|||
|
|||
public object Icon { get; set; } |
|||
|
|||
public string Url { get; set; } |
|||
|
|||
public BreadcrumbItem(string text, string url = null, object icon = null) |
|||
{ |
|||
Text = text; |
|||
Url = url; |
|||
Icon = icon; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
@using Blazorise |
|||
@using BlazoriseUI |
|||
<Row Class="entry-row"> |
|||
<Column ColumnSize="ColumnSize.IsAuto"> |
|||
<h1 class="content-header-title">@Title</h1> |
|||
</Column> |
|||
@if (BreadcrumbItems.Any()) |
|||
{ |
|||
<Column ColumnSize="ColumnSize.IsAuto.OnWidescreen" Padding="Padding.Is0.FromLeft.OnWidescreen"> |
|||
<Breadcrumb Mode="@(BreadcrumbShowCurrent ? BreadcrumbMode.Auto : BreadcrumbMode.None)"> |
|||
@if (BreadcrumbShowHome) |
|||
{ |
|||
<BreadcrumbItem> |
|||
<BreadcrumbLink To="/"> |
|||
<Icon Name="IconName.Home" /> |
|||
</BreadcrumbLink> |
|||
</BreadcrumbItem> |
|||
} |
|||
@foreach (var item in BreadcrumbItems) |
|||
{ |
|||
<BreadcrumbItem> |
|||
<BreadcrumbLink To="@item.Url"> |
|||
@if (item.Icon != null) |
|||
{ |
|||
<Icon Name="@item.Icon" /> |
|||
} |
|||
@item.Text |
|||
</BreadcrumbLink> |
|||
</BreadcrumbItem> |
|||
} |
|||
</Breadcrumb> |
|||
</Column> |
|||
} |
|||
<Column> |
|||
<Row Class="justify-content-end mx-n1"> |
|||
@foreach (var toolbarItemRender in ToolbarItemRenders) |
|||
{ |
|||
@toolbarItemRender |
|||
} |
|||
</Row> |
|||
</Column> |
|||
</Row> |
|||
@ -0,0 +1,69 @@ |
|||
using Microsoft.AspNetCore.Components; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.AspNetCore.Components.WebAssembly.Theming.PageToolbars; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.Layout |
|||
{ |
|||
public partial class PageHeader : ComponentBase |
|||
{ |
|||
protected List<RenderFragment> ToolbarItemRenders { get; set; } |
|||
|
|||
public IPageToolbarManager PageToolbarManager { get; set; } |
|||
|
|||
[Parameter] |
|||
public string Title { get; set; } |
|||
|
|||
[Parameter] |
|||
public bool BreadcrumbShowHome { get; set; } = true; |
|||
|
|||
[Parameter] |
|||
public bool BreadcrumbShowCurrent { get; set; } = true; |
|||
|
|||
[Parameter] |
|||
public RenderFragment ChildContent { get; set; } |
|||
|
|||
[Parameter] |
|||
public List<BlazoriseUI.BreadcrumbItem> BreadcrumbItems { get; set; } |
|||
|
|||
[Parameter] |
|||
public string PageName { get; set; } |
|||
|
|||
|
|||
public PageHeader(IPageToolbarManager pageToolbarManager) |
|||
{ |
|||
BreadcrumbItems = new List<BlazoriseUI.BreadcrumbItem>(); |
|||
ToolbarItemRenders = new List<RenderFragment>(); |
|||
PageToolbarManager = pageToolbarManager; |
|||
} |
|||
|
|||
protected override async Task OnInitializedAsync() |
|||
{ |
|||
if (!PageName.IsNullOrEmpty()) |
|||
{ |
|||
var toolbarItems = await PageToolbarManager.GetItemsAsync(PageName); |
|||
|
|||
ToolbarItemRenders.Clear(); |
|||
|
|||
foreach (var item in toolbarItems) |
|||
{ |
|||
var sequence = 0; |
|||
ToolbarItemRenders.Add(builder => |
|||
{ |
|||
builder.OpenComponent(sequence, item.ComponentType); |
|||
if (item.Arguments != null) |
|||
{ |
|||
foreach (var argument in item.Arguments) |
|||
{ |
|||
sequence++; |
|||
builder.AddAttribute(sequence, argument.Key, argument.Value); |
|||
} |
|||
} |
|||
builder.CloseComponent(); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
using JetBrains.Annotations; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.PageToolbars |
|||
{ |
|||
public class AbpPageToolbarOptions |
|||
{ |
|||
public PageToolbarDictionary Toolbars { get; } |
|||
|
|||
public AbpPageToolbarOptions() |
|||
{ |
|||
Toolbars = new PageToolbarDictionary(); |
|||
} |
|||
|
|||
public void Configure<TPage>([NotNull] Action<PageToolbar> configureAction) |
|||
{ |
|||
Configure(typeof(TPage).FullName, configureAction); |
|||
} |
|||
|
|||
public void Configure([NotNull] string pageName, [NotNull] Action<PageToolbar> configureAction) |
|||
{ |
|||
Check.NotNullOrWhiteSpace(pageName, nameof(pageName)); |
|||
Check.NotNull(configureAction, nameof(configureAction)); |
|||
|
|||
var toolbar = Toolbars.GetOrAdd(pageName, () => new PageToolbar(pageName)); |
|||
configureAction(toolbar); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.PageToolbars |
|||
{ |
|||
public interface IPageToolbarContributor |
|||
{ |
|||
Task ContributeAsync(PageToolbarContributionContext context); |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.PageToolbars |
|||
{ |
|||
public interface IPageToolbarManager |
|||
{ |
|||
Task<PageToolbarItem[]> GetItemsAsync(string pageName); |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.PageToolbars |
|||
{ |
|||
public class PageToolbar |
|||
{ |
|||
public string PageName { get; } |
|||
|
|||
public PageToolbarContributorList Contributors { get; set; } |
|||
|
|||
public PageToolbar([NotNull] string pageName) |
|||
{ |
|||
PageName = Check.NotNullOrEmpty(pageName, nameof(pageName)); |
|||
Contributors = new PageToolbarContributorList(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
using JetBrains.Annotations; |
|||
using System; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.PageToolbars |
|||
{ |
|||
public class PageToolbarContributionContext |
|||
{ |
|||
[NotNull] |
|||
public string PageName { get; } |
|||
|
|||
[NotNull] |
|||
public IServiceProvider ServiceProvider { get; } |
|||
|
|||
[NotNull] |
|||
public PageToolbarItemList Items { get; } |
|||
|
|||
public PageToolbarContributionContext( |
|||
[NotNull] string pageName, |
|||
[NotNull] IServiceProvider serviceProvider) |
|||
{ |
|||
PageName = Check.NotNull(pageName, nameof(pageName)); |
|||
ServiceProvider = Check.NotNull(serviceProvider, nameof(serviceProvider)); |
|||
|
|||
Items = new PageToolbarItemList(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.PageToolbars |
|||
{ |
|||
public abstract class PageToolbarContributor : IPageToolbarContributor |
|||
{ |
|||
public abstract Task ContributeAsync(PageToolbarContributionContext context); |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.PageToolbars |
|||
{ |
|||
public class PageToolbarContributorList : List<IPageToolbarContributor> |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.PageToolbars |
|||
{ |
|||
public class PageToolbarDictionary : Dictionary<string, PageToolbar> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,71 @@ |
|||
using Blazorise; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.BlazoriseUI.Components; |
|||
using Volo.Abp.Localization; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.PageToolbars |
|||
{ |
|||
public static class PageToolbarExtensions |
|||
{ |
|||
public static PageToolbar AddComponent<TComponent>( |
|||
this PageToolbar toolbar, |
|||
Dictionary<string, object> arguments = null, |
|||
int order = 0, |
|||
string requiredPolicyName = null) |
|||
{ |
|||
return toolbar.AddComponent( |
|||
typeof(TComponent), |
|||
arguments, |
|||
order, |
|||
requiredPolicyName |
|||
); |
|||
} |
|||
|
|||
public static PageToolbar AddComponent( |
|||
this PageToolbar toolbar, |
|||
Type componentType, |
|||
Dictionary<string, object> arguments = null, |
|||
int order = 0, |
|||
string requiredPolicyName = null) |
|||
{ |
|||
toolbar.Contributors.Add( |
|||
new SimplePageToolbarContributor( |
|||
componentType, |
|||
arguments, |
|||
order, |
|||
requiredPolicyName |
|||
) |
|||
); |
|||
|
|||
return toolbar; |
|||
} |
|||
|
|||
public static PageToolbar AddButton( |
|||
this PageToolbar toolbar, |
|||
string text, |
|||
Func<Task> clicked, |
|||
object icon = null, |
|||
Color color = Color.Primary, |
|||
bool disabled = false, |
|||
int order = 0, |
|||
string requiredPolicyName = null) |
|||
{ |
|||
toolbar.AddComponent<ToolbarButton>( |
|||
new Dictionary<string, object> |
|||
{ |
|||
{ nameof(ToolbarButton.Color), color}, |
|||
{ nameof(ToolbarButton.Text), text}, |
|||
{ nameof(ToolbarButton.Disabled), disabled}, |
|||
{ nameof(ToolbarButton.Icon), icon}, |
|||
{ nameof(ToolbarButton.Clicked),clicked}, |
|||
}, |
|||
order, |
|||
requiredPolicyName |
|||
); |
|||
|
|||
return toolbar; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
using JetBrains.Annotations; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.PageToolbars |
|||
{ |
|||
public class PageToolbarItem |
|||
{ |
|||
[NotNull] |
|||
public Type ComponentType { get; } |
|||
|
|||
[CanBeNull] |
|||
public Dictionary<string, object> Arguments { get; set; } |
|||
|
|||
public int Order { get; set; } |
|||
|
|||
public PageToolbarItem( |
|||
[NotNull] Type componentType, |
|||
[CanBeNull] Dictionary<string, object> arguments = null, |
|||
int order = 0) |
|||
{ |
|||
ComponentType = Check.NotNull(componentType, nameof(componentType)); |
|||
Arguments = arguments; |
|||
Order = order; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.PageToolbars |
|||
{ |
|||
public class PageToolbarItemList : List<PageToolbarItem> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
using Microsoft.Extensions.Options; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.PageToolbars |
|||
{ |
|||
public class PageToolbarManager : IPageToolbarManager, ITransientDependency |
|||
{ |
|||
protected AbpPageToolbarOptions Options { get; } |
|||
protected IHybridServiceScopeFactory ServiceScopeFactory { get; } |
|||
|
|||
public PageToolbarManager( |
|||
IOptions<AbpPageToolbarOptions> options, |
|||
IHybridServiceScopeFactory serviceScopeFactory) |
|||
{ |
|||
Options = options.Value; |
|||
ServiceScopeFactory = serviceScopeFactory; |
|||
} |
|||
|
|||
public virtual async Task<PageToolbarItem[]> GetItemsAsync(string pageName) |
|||
{ |
|||
var toolbar = Options.Toolbars.GetOrDefault(pageName); |
|||
if (toolbar == null || !toolbar.Contributors.Any()) |
|||
{ |
|||
return Array.Empty<PageToolbarItem>(); |
|||
} |
|||
|
|||
using (var scope = ServiceScopeFactory.CreateScope()) |
|||
{ |
|||
var context = new PageToolbarContributionContext(pageName, scope.ServiceProvider); |
|||
|
|||
foreach (var contributor in toolbar.Contributors) |
|||
{ |
|||
await contributor.ContributeAsync(context); |
|||
} |
|||
|
|||
return context.Items.OrderBy(i => i.Order).ToArray(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,53 @@ |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.PageToolbars |
|||
{ |
|||
public class SimplePageToolbarContributor : IPageToolbarContributor |
|||
{ |
|||
public Type ComponentType { get; } |
|||
|
|||
public Dictionary<string, object> Arguments { get; set; } |
|||
|
|||
public int Order { get; } |
|||
|
|||
public string RequiredPolicyName { get; } |
|||
|
|||
public SimplePageToolbarContributor( |
|||
Type componentType, |
|||
Dictionary<string, object> arguments = null, |
|||
int order = 0, |
|||
string requiredPolicyName = null) |
|||
{ |
|||
ComponentType = componentType; |
|||
Arguments = arguments; |
|||
Order = order; |
|||
RequiredPolicyName = requiredPolicyName; |
|||
} |
|||
|
|||
public async Task ContributeAsync(PageToolbarContributionContext context) |
|||
{ |
|||
if (await ShouldAddComponentAsync(context)) |
|||
{ |
|||
context.Items.Add(new PageToolbarItem(ComponentType, Arguments, Order)); |
|||
} |
|||
} |
|||
|
|||
protected virtual async Task<bool> ShouldAddComponentAsync(PageToolbarContributionContext context) |
|||
{ |
|||
if (RequiredPolicyName != null) |
|||
{ |
|||
var authorizationService = context.ServiceProvider.GetRequiredService<IAuthorizationService>(); |
|||
if (!await authorizationService.IsGrantedAsync(RequiredPolicyName)) |
|||
{ |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
<Button Color="@Color" Clicked="@Clicked" Disabled="@Disabled"> |
|||
@if (Icon != null) |
|||
{ |
|||
<Icon Name="IconName.Add" Class="mr-1"></Icon> |
|||
} |
|||
@Text |
|||
</Button> |
|||
@ -0,0 +1,25 @@ |
|||
using Blazorise; |
|||
using Microsoft.AspNetCore.Components; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.BlazoriseUI.Components |
|||
{ |
|||
public partial class ToolbarButton : ComponentBase |
|||
{ |
|||
[Parameter] |
|||
public Color Color { get; set; } |
|||
|
|||
[Parameter] |
|||
public object Icon { get; set; } |
|||
|
|||
[Parameter] |
|||
public string Text { get; set; } |
|||
|
|||
[Parameter] |
|||
public Func<Task> Clicked { get; set; } |
|||
|
|||
[Parameter] |
|||
public bool Disabled { get; set; } |
|||
} |
|||
} |
|||
Loading…
Reference in new issue