mirror of https://github.com/abpframework/abp.git
committed by
GitHub
9 changed files with 218 additions and 0 deletions
@ -0,0 +1,16 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using JetBrains.Annotations; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.Toolbars |
||||
|
{ |
||||
|
public class AbpToolbarOptions |
||||
|
{ |
||||
|
[NotNull] |
||||
|
public List<IToolbarContributor> Contributors { get; } |
||||
|
|
||||
|
public AbpToolbarOptions() |
||||
|
{ |
||||
|
Contributors = new List<IToolbarContributor>(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using JetBrains.Annotations; |
||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using Microsoft.Extensions.Localization; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.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,9 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.Toolbars |
||||
|
{ |
||||
|
public interface IToolbarContributor |
||||
|
{ |
||||
|
Task ConfigureToolbarAsync(IToolbarConfigurationContext context); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.Toolbars |
||||
|
{ |
||||
|
public interface IToolbarManager |
||||
|
{ |
||||
|
Task<Toolbar> GetAsync(string name); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.Toolbars |
||||
|
{ |
||||
|
public static class StandardToolbars |
||||
|
{ |
||||
|
public const string Main = "Main"; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using JetBrains.Annotations; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.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,68 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using JetBrains.Annotations; |
||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Localization; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.Toolbars |
||||
|
{ |
||||
|
public class ToolbarConfigurationContext : IToolbarConfigurationContext |
||||
|
{ |
||||
|
public IServiceProvider ServiceProvider { get; } |
||||
|
private readonly object _serviceProviderLock = new object(); |
||||
|
|
||||
|
private TRef LazyGetRequiredService<TRef>(Type serviceType, ref TRef reference) |
||||
|
{ |
||||
|
if (reference == null) |
||||
|
{ |
||||
|
lock (_serviceProviderLock) |
||||
|
{ |
||||
|
if (reference == null) |
||||
|
{ |
||||
|
reference = (TRef)ServiceProvider.GetRequiredService(serviceType); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return reference; |
||||
|
} |
||||
|
|
||||
|
public IAuthorizationService AuthorizationService => LazyGetRequiredService(typeof(IAuthorizationService), ref _authorizationService); |
||||
|
private IAuthorizationService _authorizationService; |
||||
|
|
||||
|
private IStringLocalizerFactory _stringLocalizerFactory; |
||||
|
public IStringLocalizerFactory StringLocalizerFactory => LazyGetRequiredService(typeof(IStringLocalizerFactory),ref _stringLocalizerFactory); |
||||
|
|
||||
|
public Toolbar Toolbar { get; } |
||||
|
|
||||
|
public ToolbarConfigurationContext(Toolbar toolbar, IServiceProvider serviceProvider) |
||||
|
{ |
||||
|
Toolbar = toolbar; |
||||
|
ServiceProvider = serviceProvider; |
||||
|
} |
||||
|
|
||||
|
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,23 @@ |
|||||
|
using System; |
||||
|
using JetBrains.Annotations; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.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 Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Options; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.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; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue