Browse Source

Introduce toolbar system for the Blazor UI

pull/5607/head
Halil İbrahim Kalkan 6 years ago
parent
commit
2ff244536b
  1. 16
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/Toolbars/AbpToolbarOptions.cs
  2. 29
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/Toolbars/IToolbarConfigurationContext.cs
  3. 9
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/Toolbars/IToolbarContributor.cs
  4. 9
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/Toolbars/IToolbarManager.cs
  5. 7
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/Toolbars/StandardToolbars.cs
  6. 18
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/Toolbars/Toolbar.cs
  7. 68
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/Toolbars/ToolbarConfigurationContext.cs
  8. 23
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/Toolbars/ToolbarItem.cs
  9. 39
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/Toolbars/ToolbarManager.cs

16
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/Toolbars/AbpToolbarOptions.cs

@ -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>();
}
}
}

29
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/Toolbars/IToolbarConfigurationContext.cs

@ -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);
}
}

9
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/Toolbars/IToolbarContributor.cs

@ -0,0 +1,9 @@
using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.Toolbars
{
public interface IToolbarContributor
{
Task ConfigureToolbarAsync(IToolbarConfigurationContext context);
}
}

9
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/Toolbars/IToolbarManager.cs

@ -0,0 +1,9 @@
using System.Threading.Tasks;
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.Toolbars
{
public interface IToolbarManager
{
Task<Toolbar> GetAsync(string name);
}
}

7
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/Toolbars/StandardToolbars.cs

@ -0,0 +1,7 @@
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.Toolbars
{
public static class StandardToolbars
{
public const string Main = "Main";
}
}

18
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/Toolbars/Toolbar.cs

@ -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>();
}
}
}

68
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/Toolbars/ToolbarConfigurationContext.cs

@ -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);
}
}
}

23
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/Toolbars/ToolbarItem.cs

@ -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));
}
}
}

39
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/Toolbars/ToolbarManager.cs

@ -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…
Cancel
Save