50 changed files with 1040 additions and 26 deletions
@ -0,0 +1,37 @@ |
|||
using Lsw.Abp.AspnetCore.Components.Server.AntDesignTheme.Bundling; |
|||
using Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme; |
|||
using Volo.Abp.AspNetCore.Components.Server; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Packages; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Server.AntDesignTheme; |
|||
|
|||
[DependsOn( |
|||
typeof(AbpAspNetCoreComponentsServerModule), |
|||
typeof(AbpAspNetCoreMvcUiPackagesModule), |
|||
typeof(AbpAspNetCoreMvcUiBundlingModule), |
|||
typeof(AbpAspNetCoreComponentsWebAntDesignThemeModule) |
|||
)] |
|||
public class AbpAspNetCoreComponentsServerAntDesignThemeModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
Configure<AbpBundlingOptions>(options => |
|||
{ |
|||
options |
|||
.StyleBundles |
|||
.Add(BlazorStandardBundles.Styles.Global, bundle => |
|||
{ |
|||
bundle.AddContributors(typeof(BlazorGlobalStyleContributor)); |
|||
}); |
|||
|
|||
options |
|||
.ScriptBundles |
|||
.Add(BlazorStandardBundles.Scripts.Global, bundle => |
|||
{ |
|||
bundle.AddContributors(typeof(BlazorGlobalScriptContributor)); |
|||
}); |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
namespace Lsw.Abp.AspnetCore.Components.Server.AntDesignTheme.Bundling; |
|||
|
|||
public class BlazorStandardBundles |
|||
{ |
|||
public static class Styles |
|||
{ |
|||
public static string Global = "Blazor.Global"; |
|||
} |
|||
|
|||
public static class Scripts |
|||
{ |
|||
public static string Global = "Blazor.Global"; |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Server.AntDesignTheme.Bundling; |
|||
|
|||
public class BlazorGlobalScriptContributor : BundleContributor |
|||
{ |
|||
public override void ConfigureBundle(BundleConfigurationContext context) |
|||
{ |
|||
context.Files.AddIfNotContains("/_framework/blazor.server.js"); |
|||
context.Files.AddIfNotContains("/_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/js/abp.js"); |
|||
context.Files.AddIfNotContains("/_content/AntDesign/js/ant-design-blazor.js"); |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bundling; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Server.AntDesignTheme.Bundling; |
|||
|
|||
public class BlazorGlobalStyleContributor : BundleContributor |
|||
{ |
|||
public override void ConfigureBundle(BundleConfigurationContext context) |
|||
{ |
|||
context.Files.AddIfNotContains("/_content/AntDesign/css/ant-design-blazor.css"); |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk.Razor"> |
|||
|
|||
<Import Project=".\..\configureawait.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net6.0</TargetFramework> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Volo.Abp.AspNetCore.Components.Server" Version="5.1.3" /> |
|||
<PackageReference Include="Volo.Abp.AspNetCore.Mvc.UI.Bundling" Version="5.1.3" /> |
|||
<PackageReference Include="Volo.Abp.AspNetCore.Mvc.UI.Packages" Version="5.1.3" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme\Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<Folder Include="Themes\AntDesign" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,26 @@ |
|||
using AntDesign; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme; |
|||
|
|||
public class AbpAntDesignThemeOptions |
|||
{ |
|||
public MenuOptions Menu { get; set; } |
|||
} |
|||
|
|||
public class MenuOptions |
|||
{ |
|||
public MenuTheme Theme { get; set; } |
|||
|
|||
public MenuPlace Place { get; set; } |
|||
|
|||
public MenuMode GetMode() |
|||
{ |
|||
return Place == MenuPlace.Left ? MenuMode.Inline : MenuMode.Horizontal; |
|||
} |
|||
|
|||
public enum MenuPlace |
|||
{ |
|||
Top, |
|||
Left |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using Lsw.Abp.AntDesignUI; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.UI.Navigation; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme; |
|||
|
|||
[DependsOn( |
|||
typeof(AbpAntDesignUIModule), |
|||
typeof(AbpUiNavigationModule) |
|||
)] |
|||
public class AbpAspNetCoreComponentsWebAntDesignThemeModule : AbpModule |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
@using AntDesign |
|||
@using Microsoft.Extensions.Options |
|||
@inject IOptions<PageHeaderOptions> Options |
|||
|
|||
<Row> |
|||
@if (Options.Value.RenderPageTitle) |
|||
{ |
|||
<PageHeader Class="site-page-header" Title="@PageLayout.Title"></PageHeader> |
|||
} |
|||
|
|||
@if (Options.Value.RenderBreadcrumbs && PageLayout.BreadcrumbItems.Any()) |
|||
{ |
|||
<Breadcrumb> |
|||
@if (BreadcrumbShowHome) |
|||
{ |
|||
<BreadcrumbItem Href=""> |
|||
<Icon Type="home"/> |
|||
</BreadcrumbItem> |
|||
} |
|||
@foreach (var item in PageLayout.BreadcrumbItems) |
|||
{ |
|||
<BreadcrumbItem Href="@item.Url"> |
|||
@if (!item.Icon.IsNullOrWhiteSpace()) |
|||
{ |
|||
<Icon Type="@item.Icon"/> |
|||
} |
|||
@item.Text |
|||
</BreadcrumbItem> |
|||
} |
|||
</Breadcrumb> |
|||
} |
|||
|
|||
@if (Options.Value.RenderToolbar) |
|||
{ |
|||
<div> |
|||
<Row justify="end"> |
|||
@if (Toolbar == null) |
|||
{ |
|||
@ChildContent |
|||
} |
|||
|
|||
@foreach (var toolbarItemRender in ToolbarItemRenders) |
|||
{ |
|||
<div class="px-1 pt-2"> |
|||
@toolbarItemRender |
|||
</div> |
|||
} |
|||
</Row> |
|||
</div> |
|||
} |
|||
</Row> |
|||
@ -0,0 +1,88 @@ |
|||
using System.Collections.Generic; |
|||
using System.Collections.ObjectModel; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Lsw.Abp.AntDesignUI; |
|||
using Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.PageToolbars; |
|||
using Microsoft.AspNetCore.Components; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Layout; |
|||
|
|||
public partial class AbpPageHeader : ComponentBase |
|||
{ |
|||
protected List<RenderFragment> ToolbarItemRenders { get; set; } |
|||
|
|||
public IPageToolbarManager PageToolbarManager { get; set; } |
|||
|
|||
[Inject] |
|||
public PageLayout PageLayout { get; private set; } |
|||
|
|||
[Parameter] |
|||
public string Title { get => PageLayout.Title; set => PageLayout.Title = value; } |
|||
|
|||
[Parameter] |
|||
public bool BreadcrumbShowHome { get; set; } = true; |
|||
|
|||
[Parameter] |
|||
public bool BreadcrumbShowCurrent { get; set; } = true; |
|||
|
|||
[Parameter] |
|||
public RenderFragment ChildContent { get; set; } |
|||
|
|||
[Parameter] |
|||
public List<BreadcrumbItem> BreadcrumbItems { |
|||
get => PageLayout.BreadcrumbItems.ToList(); |
|||
set => PageLayout.BreadcrumbItems = new ObservableCollection<BreadcrumbItem>(value); |
|||
} |
|||
|
|||
[Parameter] |
|||
public PageToolbar Toolbar { get; set; } |
|||
|
|||
public AbpPageHeader() |
|||
{ |
|||
ToolbarItemRenders = new List<RenderFragment>(); |
|||
} |
|||
|
|||
protected override async Task OnParametersSetAsync() |
|||
{ |
|||
await base.OnParametersSetAsync(); |
|||
if (Toolbar != null) |
|||
{ |
|||
var toolbarItems = await PageToolbarManager.GetItemsAsync(Toolbar); |
|||
ToolbarItemRenders.Clear(); |
|||
|
|||
if (!Options.Value.RenderToolbar) |
|||
{ |
|||
PageLayout.ToolbarItems.Clear(); |
|||
foreach (var item in toolbarItems) |
|||
{ |
|||
PageLayout.ToolbarItems.Add(item); |
|||
} |
|||
return; |
|||
} |
|||
|
|||
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(); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
|
|||
protected override async Task OnInitializedAsync() |
|||
{ |
|||
await base.OnInitializedAsync(); |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Layout; |
|||
|
|||
public class PageHeaderOptions |
|||
{ |
|||
public bool RenderPageTitle { get; set; } = true; |
|||
public bool RenderBreadcrumbs { get; set; } = true; |
|||
public bool RenderToolbar { get; set; } = true; |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
using System.Collections.ObjectModel; |
|||
using System.ComponentModel; |
|||
using Lsw.Abp.AntDesignUI; |
|||
using Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.PageToolbars; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Layout; |
|||
|
|||
public class PageLayout : IScopedDependency, INotifyPropertyChanged |
|||
{ |
|||
private string title; |
|||
|
|||
// TODO: Consider using this property for setting Page Title too.
|
|||
public virtual string Title |
|||
{ |
|||
get => title; |
|||
set |
|||
{ |
|||
title = value; |
|||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Title))); |
|||
} |
|||
} |
|||
|
|||
public virtual ObservableCollection<BreadcrumbItem> BreadcrumbItems { get; set; } = new(); |
|||
|
|||
public virtual ObservableCollection<PageToolbarItem> ToolbarItems { get; set; } = new(); |
|||
|
|||
public event PropertyChangedEventHandler PropertyChanged; |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk.Razor"> |
|||
|
|||
<Import Project="..\..\configureawait.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net6.0</TargetFramework> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Volo.Abp.UI.Navigation" Version="5.1.3" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\src\Lsw.Abp.AntDesignUI\Lsw.Abp.AntDesignUI.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,9 @@ |
|||
using System.Threading.Tasks; |
|||
using Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.PageToolbars; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.PageToolbars; |
|||
|
|||
public interface IPageToolbarContributor |
|||
{ |
|||
Task ContributeAsync(PageToolbarContributionContext context); |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.PageToolbars; |
|||
|
|||
public interface IPageToolbarManager |
|||
{ |
|||
Task<PageToolbarItem[]> GetItemsAsync(PageToolbar toolbar); |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.PageToolbars; |
|||
|
|||
public class PageToolbar |
|||
{ |
|||
public PageToolbarContributorList Contributors { get; set; } |
|||
|
|||
public PageToolbar() |
|||
{ |
|||
Contributors = new PageToolbarContributorList(); |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using JetBrains.Annotations; |
|||
using System; |
|||
using Volo.Abp; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.PageToolbars; |
|||
|
|||
public class PageToolbarContributionContext |
|||
{ |
|||
[NotNull] |
|||
public IServiceProvider ServiceProvider { get; } |
|||
|
|||
[NotNull] |
|||
public PageToolbarItemList Items { get; } |
|||
|
|||
public PageToolbarContributionContext( |
|||
[NotNull] IServiceProvider serviceProvider) |
|||
{ |
|||
ServiceProvider = Check.NotNull(serviceProvider, nameof(serviceProvider)); |
|||
Items = new PageToolbarItemList(); |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using System.Threading.Tasks; |
|||
using Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.PageToolbars; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.PageToolbars; |
|||
|
|||
public abstract class PageToolbarContributor : IPageToolbarContributor |
|||
{ |
|||
public abstract Task ContributeAsync(PageToolbarContributionContext context); |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using System.Collections.Generic; |
|||
using Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.PageToolbars; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.PageToolbars; |
|||
|
|||
public class PageToolbarContributorList : List<IPageToolbarContributor> |
|||
{ |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.PageToolbars; |
|||
|
|||
public class PageToolbarDictionary : Dictionary<string, PageToolbar> |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,69 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using AntDesign; |
|||
using Lsw.Abp.AntDesignUI.Components; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.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, |
|||
string color = ButtonType.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; |
|||
using Volo.Abp; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.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,8 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.PageToolbars; |
|||
|
|||
public class PageToolbarItemList : List<PageToolbarItem> |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
using Microsoft.Extensions.Options; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.PageToolbars; |
|||
|
|||
public class PageToolbarManager : IPageToolbarManager, ITransientDependency |
|||
{ |
|||
protected IHybridServiceScopeFactory ServiceScopeFactory { get; } |
|||
|
|||
public PageToolbarManager( |
|||
IHybridServiceScopeFactory serviceScopeFactory) |
|||
{ |
|||
ServiceScopeFactory = serviceScopeFactory; |
|||
} |
|||
|
|||
public virtual async Task<PageToolbarItem[]> GetItemsAsync(PageToolbar toolbar) |
|||
{ |
|||
if (toolbar == null || !toolbar.Contributors.Any()) |
|||
{ |
|||
return Array.Empty<PageToolbarItem>(); |
|||
} |
|||
|
|||
using (var scope = ServiceScopeFactory.CreateScope()) |
|||
{ |
|||
var context = new PageToolbarContributionContext(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; |
|||
using Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.PageToolbars; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.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,15 @@ |
|||
using System.Reflection; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Routing; |
|||
|
|||
public class AbpRouterOptions |
|||
{ |
|||
public Assembly AppAssembly { get; set; } |
|||
|
|||
public RouterAssemblyList AdditionalAssemblies { get; } |
|||
|
|||
public AbpRouterOptions() |
|||
{ |
|||
AdditionalAssemblies = new RouterAssemblyList(); |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using System.Collections.Generic; |
|||
using System.Reflection; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Routing; |
|||
|
|||
public class RouterAssemblyList : List<Assembly> |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
@using Microsoft.Extensions.Options |
|||
@using Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Routing |
|||
@inject IOptions<AbpRouterOptions> RouterOptions |
|||
<CascadingAuthenticationState> |
|||
<Router AppAssembly="RouterOptions.Value.AppAssembly" |
|||
AdditionalAssemblies="RouterOptions.Value.AdditionalAssemblies"> |
|||
<Found Context="routeData"> |
|||
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"> |
|||
<NotAuthorized> |
|||
@if (!context.User.Identity.IsAuthenticated) |
|||
{ |
|||
<RedirectToLogin/> |
|||
} |
|||
else |
|||
{ |
|||
<p>You are not authorized to access this resource.</p> |
|||
} |
|||
</NotAuthorized> |
|||
</AuthorizeRouteView> |
|||
</Found> |
|||
<NotFound> |
|||
<LayoutView Layout="@typeof(MainLayout)"> |
|||
<p>Sorry, there's nothing at this address.</p> |
|||
</LayoutView> |
|||
</NotFound> |
|||
</Router> |
|||
<AntContainer/> |
|||
</CascadingAuthenticationState> |
|||
@ -0,0 +1,9 @@ |
|||
<Menu Mode="@Options.Value.Menu.GetMode()" Theme="@Options.Value.Menu.Theme"> |
|||
@if (Menu != null) |
|||
{ |
|||
foreach (var menu in Menu.Items) |
|||
{ |
|||
<MainMenuItem Menu="@menu"></MainMenuItem> |
|||
} |
|||
} |
|||
</Menu> |
|||
@ -0,0 +1,45 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Components; |
|||
using Microsoft.AspNetCore.Components.Authorization; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.UI.Navigation; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Themes.AntDesign; |
|||
|
|||
public partial class MainMenu : IDisposable |
|||
{ |
|||
[Inject] |
|||
protected IMenuManager MenuManager { get; set; } |
|||
|
|||
[Inject] |
|||
protected IOptions<AbpAntDesignThemeOptions> Options { get; set; } |
|||
|
|||
[Inject] |
|||
protected AuthenticationStateProvider AuthenticationStateProvider { get; set; } |
|||
|
|||
|
|||
protected ApplicationMenu Menu { get; set; } |
|||
|
|||
protected override async Task OnInitializedAsync() |
|||
{ |
|||
await GetMenuAsync(); |
|||
AuthenticationStateProvider.AuthenticationStateChanged += AuthenticationStateProviderOnAuthenticationStateChanged; |
|||
} |
|||
|
|||
private async Task GetMenuAsync() |
|||
{ |
|||
Menu = await MenuManager.GetMainMenuAsync(); |
|||
} |
|||
|
|||
private async void AuthenticationStateProviderOnAuthenticationStateChanged(Task<AuthenticationState> task) |
|||
{ |
|||
await GetMenuAsync(); |
|||
await InvokeAsync(StateHasChanged); |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
AuthenticationStateProvider.AuthenticationStateChanged -= AuthenticationStateProviderOnAuthenticationStateChanged; |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
@using Volo.Abp.UI.Navigation |
|||
|
|||
@if (Menu != null) |
|||
{ |
|||
var elementId = Menu.ElementId ?? "MenuItem_" + Menu.Name.Replace(".", "_"); |
|||
var url = Menu.Url == null ? "#" : Menu.Url.TrimStart('/', '~'); |
|||
|
|||
if (Menu.IsLeaf && Menu.Url != null) |
|||
{ |
|||
<MenuItem Id="@elementId" RouterLink="@url" Disabled="@Menu.IsDisabled"> |
|||
@if (Menu.Icon != null) |
|||
{ |
|||
<Icon Type="@Menu.Icon" Theme="outline"></Icon> |
|||
} |
|||
@Menu.Name |
|||
</MenuItem> |
|||
} |
|||
else |
|||
{ |
|||
<SubMenu Title="@Menu.Name" TitleTemplate="@GetSubMenuTemplate()" Id="elementId"> |
|||
@foreach (var menuItem in Menu.Items) |
|||
{ |
|||
<MainMenuItem Menu="@menuItem"></MainMenuItem> |
|||
} |
|||
</SubMenu> |
|||
} |
|||
} |
|||
|
|||
@code { |
|||
|
|||
[Parameter] |
|||
public ApplicationMenuItem Menu { get; set; } |
|||
|
|||
private RenderFragment GetSubMenuTemplate() |
|||
{ |
|||
return @<span> |
|||
@if (Menu.Icon != null) |
|||
{ |
|||
<Icon Type="@Menu.Icon" Theme="outline"></Icon> |
|||
} |
|||
<span>@Menu.Name</span> |
|||
</span>; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
@using System.Net.Http |
|||
@using Microsoft.AspNetCore.Components.Authorization |
|||
@using Microsoft.AspNetCore.Components.Forms |
|||
@using Microsoft.AspNetCore.Components.Routing |
|||
@using Microsoft.AspNetCore.Components.Web |
|||
@using Microsoft.JSInterop |
|||
@using AntDesign |
|||
@using Lsw.Abp.AntDesignUI |
|||
@using Lsw.Abp.AntDesignUI.Components |
|||
@ -0,0 +1,16 @@ |
|||
using System.Collections.Generic; |
|||
using JetBrains.Annotations; |
|||
using Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Toolbars; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Toolbars; |
|||
|
|||
public class AbpToolbarOptions |
|||
{ |
|||
[NotNull] |
|||
public List<IToolbarContributor> Contributors { get; } |
|||
|
|||
public AbpToolbarOptions() |
|||
{ |
|||
Contributors = new List<IToolbarContributor>(); |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using JetBrains.Annotations; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.Extensions.Localization; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Toolbars; |
|||
|
|||
public interface IToolbarConfigurationContext : IServiceProviderAccessor |
|||
{ |
|||
Toolbar Toolbar { get; } |
|||
|
|||
IAuthorizationService AuthorizationService { get; } |
|||
|
|||
IStringLocalizerFactory StringLocalizerFactory { get; } |
|||
|
|||
Task<bool> IsGrantedAsync(string policyName); |
|||
|
|||
[CanBeNull] |
|||
IStringLocalizer GetDefaultLocalizer(); |
|||
|
|||
[NotNull] |
|||
public IStringLocalizer GetLocalizer<T>(); |
|||
|
|||
[NotNull] |
|||
public IStringLocalizer GetLocalizer(Type resourceType); |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Toolbars; |
|||
|
|||
public interface IToolbarContributor |
|||
{ |
|||
Task ConfigureToolbarAsync(IToolbarConfigurationContext context); |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Toolbars; |
|||
|
|||
public interface IToolbarManager |
|||
{ |
|||
Task<Toolbar> GetAsync(string name); |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Toolbars; |
|||
|
|||
public static class StandardToolbars |
|||
{ |
|||
public const string Main = "Main"; |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using System.Collections.Generic; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Toolbars; |
|||
|
|||
public class Toolbar |
|||
{ |
|||
public string Name { get; } |
|||
|
|||
public List<ToolbarItem> Items { get; } |
|||
|
|||
public Toolbar([NotNull] string name) |
|||
{ |
|||
Name = Check.NotNull(name, nameof(name)); |
|||
Items = new List<ToolbarItem>(); |
|||
} |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using JetBrains.Annotations; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Localization; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Toolbars; |
|||
|
|||
public class ToolbarConfigurationContext : IToolbarConfigurationContext |
|||
{ |
|||
public IServiceProvider ServiceProvider { get; } |
|||
|
|||
private readonly IAbpLazyServiceProvider _lazyServiceProvider; |
|||
|
|||
public IAuthorizationService AuthorizationService => _lazyServiceProvider.LazyGetRequiredService<IAuthorizationService>(); |
|||
|
|||
public IStringLocalizerFactory StringLocalizerFactory => _lazyServiceProvider.LazyGetRequiredService<IStringLocalizerFactory>(); |
|||
|
|||
public Toolbar Toolbar { get; } |
|||
|
|||
public ToolbarConfigurationContext(Toolbar toolbar, IServiceProvider serviceProvider) |
|||
{ |
|||
Toolbar = toolbar; |
|||
ServiceProvider = serviceProvider; |
|||
_lazyServiceProvider = ServiceProvider.GetRequiredService<IAbpLazyServiceProvider>(); |
|||
} |
|||
|
|||
public Task<bool> IsGrantedAsync(string policyName) |
|||
{ |
|||
return AuthorizationService.IsGrantedAsync(policyName); |
|||
} |
|||
|
|||
[CanBeNull] |
|||
public IStringLocalizer GetDefaultLocalizer() |
|||
{ |
|||
return StringLocalizerFactory.CreateDefaultOrNull(); |
|||
} |
|||
|
|||
[NotNull] |
|||
public IStringLocalizer GetLocalizer<T>() |
|||
{ |
|||
return StringLocalizerFactory.Create<T>(); |
|||
} |
|||
|
|||
[NotNull] |
|||
public IStringLocalizer GetLocalizer(Type resourceType) |
|||
{ |
|||
return StringLocalizerFactory.Create(resourceType); |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Toolbars; |
|||
|
|||
public class ToolbarItem |
|||
{ |
|||
public Type ComponentType { |
|||
get => _componentType; |
|||
set => _componentType = Check.NotNull(value, nameof(value)); |
|||
} |
|||
private Type _componentType; |
|||
|
|||
public int Order { get; set; } |
|||
|
|||
public ToolbarItem([NotNull] Type componentType, int order = 0) |
|||
{ |
|||
Order = order; |
|||
ComponentType = Check.NotNull(componentType, nameof(componentType)); |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Toolbars; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.Toolbars; |
|||
|
|||
public class ToolbarManager : IToolbarManager, ITransientDependency |
|||
{ |
|||
protected AbpToolbarOptions Options { get; } |
|||
protected IServiceProvider ServiceProvider { get; } |
|||
|
|||
public ToolbarManager( |
|||
IOptions<AbpToolbarOptions> options, |
|||
IServiceProvider serviceProvider) |
|||
{ |
|||
ServiceProvider = serviceProvider; |
|||
Options = options.Value; |
|||
} |
|||
|
|||
public async Task<Toolbar> GetAsync(string name) |
|||
{ |
|||
var toolbar = new Toolbar(name); |
|||
|
|||
using (var scope = ServiceProvider.CreateScope()) |
|||
{ |
|||
var context = new ToolbarConfigurationContext(toolbar, scope.ServiceProvider); |
|||
|
|||
foreach (var contributor in Options.Contributors) |
|||
{ |
|||
await contributor.ConfigureToolbarAsync(context); |
|||
} |
|||
} |
|||
|
|||
return toolbar; |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme; |
|||
using Volo.Abp.AspNetCore.Components.WebAssembly; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme; |
|||
|
|||
[DependsOn( |
|||
typeof(AbpAspNetCoreComponentsWebAntDesignThemeModule), |
|||
typeof(AbpAspNetCoreComponentsWebAssemblyModule) |
|||
)] |
|||
public class AbpAspNetCoreComponentsWebAssemblyAntDesignThemeModule : AbpModule |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using Volo.Abp.Bundling; |
|||
|
|||
namespace Lsw.Abp.AspnetCore.Components.WebAssembly.AntDesignTheme; |
|||
|
|||
public class ComponentsComponentsBundleContributor : IBundleContributor |
|||
{ |
|||
public void AddScripts(BundleContext context) |
|||
{ |
|||
context.Add("_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js"); |
|||
context.Add("_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/js/abp.js"); |
|||
context.Add("_content/Volo.Abp.AspNetCore.Components.Web/libs/abp/js/lang-utils.js"); |
|||
context.Add("_content/AntDesign/js/ant-design-blazor.js"); |
|||
} |
|||
|
|||
public void AddStyles(BundleContext context) |
|||
{ |
|||
context.Add("_content/AntDesign/css/ant-design-blazor.css"); |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk.Razor"> |
|||
|
|||
<Import Project="..\..\..\configureawait.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net6.0</TargetFramework> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme\Lsw.Abp.AspnetCore.Components.Web.AntDesignTheme.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Volo.Abp.AspNetCore.Components.WebAssembly" Version="5.1.3" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -1,19 +0,0 @@ |
|||
using Blazorise; |
|||
|
|||
namespace Lsw.Abp.AntDesignUI; |
|||
|
|||
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; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue