refactor usages.

pull/7686/head
Ilkay Ilknur 5 years ago
parent b704cac314
commit 9591c23f1f

@ -26,23 +26,24 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.Layout
[Parameter]
public List<BlazoriseUI.BreadcrumbItem> BreadcrumbItems { get; set; }
[Parameter]
public PageToolbar Toolbar { get; set; }
[Parameter]
public string PageName { get; set; }
public PageHeader(IPageToolbarManager pageToolbarManager)
public PageHeader()
{
BreadcrumbItems = new List<BlazoriseUI.BreadcrumbItem>();
ToolbarItemRenders = new List<RenderFragment>();
PageToolbarManager = pageToolbarManager;
}
protected override async Task OnInitializedAsync()
{
if (!PageName.IsNullOrEmpty())
if (Toolbar!=null)
{
var toolbarItems = await PageToolbarManager.GetItemsAsync(PageName);
var toolbarItems = await PageToolbarManager.GetItemsAsync(Toolbar);
ToolbarItemRenders.Clear();

@ -1,30 +0,0 @@
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);
}
}
}

@ -4,6 +4,6 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.PageToolbars
{
public interface IPageToolbarManager
{
Task<PageToolbarItem[]> GetItemsAsync(string pageName);
Task<PageToolbarItem[]> GetItemsAsync(PageToolbar toolbar);
}
}

@ -4,13 +4,10 @@ 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)
public PageToolbar()
{
PageName = Check.NotNullOrEmpty(pageName, nameof(pageName));
Contributors = new PageToolbarContributorList();
}
}

@ -5,9 +5,6 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.PageToolbars
{
public class PageToolbarContributionContext
{
[NotNull]
public string PageName { get; }
[NotNull]
public IServiceProvider ServiceProvider { get; }
@ -15,12 +12,9 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.PageToolbars
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();
}
}

@ -9,20 +9,16 @@ 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)
public virtual async Task<PageToolbarItem[]> GetItemsAsync(PageToolbar toolbar)
{
var toolbar = Options.Toolbars.GetOrDefault(pageName);
if (toolbar == null || !toolbar.Contributors.Any())
{
return Array.Empty<PageToolbarItem>();
@ -30,7 +26,7 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming.PageToolbars
using (var scope = ServiceScopeFactory.CreateScope())
{
var context = new PageToolbarContributionContext(pageName, scope.ServiceProvider);
var context = new PageToolbarContributionContext(scope.ServiceProvider);
foreach (var contributor in toolbar.Contributors)
{

@ -4,6 +4,9 @@ namespace Volo.Abp.AspNetCore.Components.Extensibility.EntityActions
{
public class EntityActionDictionary : Dictionary<string, List<EntityAction>>
{
public List<EntityAction> Get<T>()
{
return this.GetOrAdd(typeof(T).FullName, () => new List<EntityAction>());
}
}
}

@ -1,19 +0,0 @@
using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Components.Extensibility.EntityActions
{
public class EntityActionsConfiguration
{
protected EntityActionDictionary EntityActions { get; set; }
public EntityActionsConfiguration()
{
EntityActions = new EntityActionDictionary();
}
public List<EntityAction> Get<T>()
{
return EntityActions.GetOrAdd(typeof(T).FullName, () => new List<EntityAction>());
}
}
}

@ -1,9 +1,13 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Components.Extensibility.TableColumns
{
public class TableColumnDictionary : Dictionary<string, List<TableColumn>>
{
public List<TableColumn> Get<T>()
{
return this.GetOrAdd(typeof(T).FullName, () => new List<TableColumn>());
}
}
}

@ -1,25 +0,0 @@
using System;
using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Components.Extensibility.TableColumns
{
public class TableColumnsConfiguration
{
protected TableColumnDictionary TableColumns { get; set; }
public TableColumnsConfiguration()
{
TableColumns = new TableColumnDictionary();
}
public List<TableColumn> Get<T>()
{
return Get(typeof(T));
}
public List<TableColumn> Get(Type type)
{
return TableColumns.GetOrAdd(type.FullName, () => new List<TableColumn>());
}
}
}

@ -1,20 +0,0 @@
using Volo.Abp.AspNetCore.Components.Extensibility.EntityActions;
using Volo.Abp.AspNetCore.Components.Extensibility.TableColumns;
namespace Volo.Abp.AspNetCore.Components.Extensibility
{
public class UIExtensions
{
public static UIExtensions Instance { get; protected set; } = new UIExtensions();
public EntityActionsConfiguration EntityActions { get; }
public TableColumnsConfiguration TableColumns { get; }
private UIExtensions()
{
EntityActions = new EntityActionsConfiguration();
TableColumns = new TableColumnsConfiguration();
}
}
}

@ -14,6 +14,8 @@ using Microsoft.Extensions.Options;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.AspNetCore.Components;
using Volo.Abp.AspNetCore.Components.Extensibility.EntityActions;
using Volo.Abp.AspNetCore.Components.Extensibility.TableColumns;
using Volo.Abp.AspNetCore.Components.WebAssembly;
using Volo.Abp.Authorization;
using Volo.Abp.BlazoriseUI.Components;
@ -190,6 +192,8 @@ namespace Volo.Abp.BlazoriseUI
protected Validations EditValidationsRef;
protected List<BreadcrumbItem> BreadcrumbItems = new List<BreadcrumbItem>(2);
protected DataGridEntityActionsColumn<TListViewModel> EntityActionsColumn;
protected EntityActionDictionary EntityActions { get; set; }
protected TableColumnDictionary TableColumns { get; set; }
protected string CreatePolicyName { get; set; }
protected string UpdatePolicyName { get; set; }
@ -203,13 +207,15 @@ namespace Volo.Abp.BlazoriseUI
{
NewEntity = new TCreateViewModel();
EditingEntity = new TUpdateViewModel();
TableColumns = new TableColumnDictionary();
EntityActions = new EntityActionDictionary();
}
protected override async Task OnInitializedAsync()
{
await SetToolbarItemsAsync();
await SetEntityActionsAsync();
await SetTableColumnsAsync();
await SetToolbarItemsAsync();
await SetBreadcrumbItemsAsync();
await SetPermissionsAsync();
}
@ -420,6 +426,7 @@ namespace Volo.Abp.BlazoriseUI
await AppService.DeleteAsync(entity.Id);
await GetEntitiesAsync();
await InvokeAsync(() => StateHasChanged());
}
protected virtual string GetDeleteConfirmationMessage(TListViewModel entity)

@ -10,48 +10,51 @@
ShowPager="@ShowPager"
PageSize="@PageSize">
<DataGridColumns>
@foreach (var column in UIExtensions.Instance.TableColumns.Get(Page))
@if (Columns != null)
{
if (column.Actions.Any())
@foreach (var column in Columns)
{
<DataGridEntityActionsColumn TItem="TItem" @ref="ActionColumns[column.Title]" Caption="@column.Title">
<DisplayTemplate>
<EntityActions TItem="TItem" EntityActionsColumn="ActionColumns[column.Title]">
@foreach (var action in column.Actions)
{
if (action.ConfirmationMessage != null)
{
<EntityAction TItem="TItem"
RequiredPolicy="@action.RequiredPolicy"
Clicked="async () => await action.Clicked(context)"
ConfirmationMessage="() => action.ConfirmationMessage.Invoke(context)"
Text="@action.Text"></EntityAction>
}
else
{
<EntityAction TItem="TItem"
RequiredPolicy="@action.RequiredPolicy"
Clicked="async () => await action.Clicked(context)"
Text="@action.Text"></EntityAction>
}
}
</EntityActions>
</DisplayTemplate>
</DataGridEntityActionsColumn>
}
else
{
@if (column.Render != null)
if (column.Actions.Any())
{
<DataGridColumn TItem="TItem" Field="@column.Data" Caption="@column.Title">
<DataGridEntityActionsColumn TItem="TItem" @ref="ActionColumns[column.Title]" Caption="@column.Title">
<DisplayTemplate>
@column.Render.Invoke(context)
<EntityActions TItem="TItem" EntityActionsColumn="ActionColumns[column.Title]">
@foreach (var action in column.Actions)
{
if (action.ConfirmationMessage != null)
{
<EntityAction TItem="TItem"
RequiredPolicy="@action.RequiredPolicy"
Clicked="async () => await action.Clicked(context)"
ConfirmationMessage="() => action.ConfirmationMessage.Invoke(context)"
Text="@action.Text"></EntityAction>
}
else
{
<EntityAction TItem="TItem"
RequiredPolicy="@action.RequiredPolicy"
Clicked="async () => await action.Clicked(context)"
Text="@action.Text"></EntityAction>
}
}
</EntityActions>
</DisplayTemplate>
</DataGridColumn>
</DataGridEntityActionsColumn>
}
else
{
<DataGridColumn TItem="TItem" Field="@column.Data" Caption="@column.Title" />
@if (column.Render != null)
{
<DataGridColumn TItem="TItem" Field="@column.Data" Caption="@column.Title">
<DisplayTemplate>
@column.Render.Invoke(context)
</DisplayTemplate>
</DataGridColumn>
}
else
{
<DataGridColumn TItem="TItem" Field="@column.Data" Caption="@column.Title"/>
}
}
}
}

@ -26,7 +26,7 @@ namespace Volo.Abp.BlazoriseUI.Components
public int PageSize { get; set; }
[Parameter]
public Type Page { get; set; }
public IEnumerable<TableColumn> Columns { get; set; }
}
}

@ -15,18 +15,18 @@
@* ************************* PAGE HEADER ************************* *@
<Volo.Abp.AspNetCore.Components.WebAssembly.Theming.Layout.PageHeader Title="@L["Roles"]"
BreadcrumbItems="@BreadcrumbItems"
PageName="@typeof(RoleManagement).FullName">
Toolbar="@Toolbar">
</Volo.Abp.AspNetCore.Components.WebAssembly.Theming.Layout.PageHeader>
</CardHeader>
<CardBody>
@* ************************* DATA GRID ************************* *@
<AbpExtensibleDataGrid TItem="IdentityRoleDto"
Data="Entities"
ReadData="OnDataGridReadAsync"
TotalItems="TotalCount"
Data="@Entities"
ReadData="@OnDataGridReadAsync"
TotalItems="@TotalCount"
ShowPager="true"
PageSize="PageSize"
Page="typeof(RoleManagement)">
PageSize="@PageSize"
Columns="@RoleManagementTableColumns">
</AbpExtensibleDataGrid>
</CardBody>
</Card>

@ -26,8 +26,9 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
protected bool HasManagePermissionsPermission { get; set; }
[Inject]
protected IOptions<AbpPageToolbarOptions> ToolbarOptions { get; set; }
protected PageToolbar Toolbar { get; set; }
private List<TableColumn> RoleManagementTableColumns => TableColumns.Get<RoleManagement>();
public RoleManagement()
{
@ -38,23 +39,26 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
UpdatePolicyName = IdentityPermissions.Roles.Update;
DeletePolicyName = IdentityPermissions.Roles.Delete;
ManagePermissionsPolicyName = IdentityPermissions.Roles.ManagePermissions;
Toolbar = new PageToolbar();
}
protected override ValueTask SetEntityActionsAsync()
{
UIExtensions.Instance
.EntityActions
EntityActions
.Get<RoleManagement>()
.AddIfNotContains(new EntityAction[]
.AddRange(new EntityAction[]
{
new EntityAction
{
Text = L["Edit"],
RequiredPolicy = UpdatePolicyName,
Clicked = async (data) => await OpenEditModalAsync(data.As<IdentityRoleDto>())
Clicked = async (data) =>
{
await OpenEditModalAsync(data.As<IdentityRoleDto>());
}
},
new EntityAction
{
{
Text = L["Permissions"],
RequiredPolicy = ManagePermissionsPolicyName,
Clicked = async (data) =>
@ -77,15 +81,14 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
protected override ValueTask SetTableColumnsAsync()
{
UIExtensions.Instance
.TableColumns
TableColumns
.Get<RoleManagement>()
.AddIfNotContains(new TableColumn[]
.AddRange(new TableColumn[]
{
new TableColumn
{
Title = L["Actions"],
Actions = UIExtensions.Instance.EntityActions.Get<RoleManagement>()
Actions = EntityActions.Get<RoleManagement>()
},
new TableColumn
{
@ -151,10 +154,8 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
protected override ValueTask SetToolbarItemsAsync()
{
ToolbarOptions.Value.Configure<RoleManagement>(toolbar =>
{
toolbar.AddButton(L["NewRole"], OpenCreateModalAsync, IconName.Add, requiredPolicyName: CreatePolicyName);
});
Toolbar.AddButton(L["NewRole"], OpenCreateModalAsync, IconName.Add,
requiredPolicyName: CreatePolicyName);
return base.SetToolbarItemsAsync();
}

@ -12,7 +12,7 @@
@* ************************* PAGE HEADER ************************* *@
<Volo.Abp.AspNetCore.Components.WebAssembly.Theming.Layout.PageHeader Title="@L["Users"]"
BreadcrumbItems="@BreadcrumbItems"
PageName="@typeof(UserManagement).FullName">
Toolbar="@Toolbar">
</Volo.Abp.AspNetCore.Components.WebAssembly.Theming.Layout.PageHeader>
</CardHeader>
<CardBody>
@ -23,7 +23,7 @@
TotalItems="TotalCount"
ShowPager="true"
PageSize="PageSize"
Page="typeof(UserManagement)">
Columns="@UserManagementTableColumns">
</AbpExtensibleDataGrid>
</CardBody>
</Card>

@ -30,15 +30,16 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
protected AssignedRoleViewModel[] EditUserRoles;
protected string ManagePermissionsPolicyName;
protected bool HasManagePermissionsPermission { get; set; }
protected string CreateModalSelectedTab = DefaultSelectedTab;
protected string EditModalSelectedTab = DefaultSelectedTab;
[Inject]
protected IOptions<AbpPageToolbarOptions> ToolbarOptions { get; set; }
protected PageToolbar Toolbar { get; set; }
private List<TableColumn> UserManagementTableColumns => TableColumns.Get<UserManagement>();
public UserManagement()
{
@ -49,6 +50,7 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
UpdatePolicyName = IdentityPermissions.Users.Update;
DeletePolicyName = IdentityPermissions.Users.Delete;
ManagePermissionsPolicyName = IdentityPermissions.Users.ManagePermissions;
Toolbar = new PageToolbar();
}
protected override async Task OnInitializedAsync()
@ -62,7 +64,8 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
{
await base.SetPermissionsAsync();
HasManagePermissionsPermission = await AuthorizationService.IsGrantedAsync(IdentityPermissions.Users.ManagePermissions);
HasManagePermissionsPermission =
await AuthorizationService.IsGrantedAsync(IdentityPermissions.Users.ManagePermissions);
}
protected override Task OpenCreateModalAsync()
@ -116,10 +119,9 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
protected override ValueTask SetEntityActionsAsync()
{
UIExtensions.Instance
.EntityActions
EntityActions
.Get<UserManagement>()
.AddIfNotContains(new EntityAction[]
.AddRange(new EntityAction[]
{
new EntityAction
{
@ -151,15 +153,14 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
protected override ValueTask SetTableColumnsAsync()
{
UIExtensions.Instance
.TableColumns
TableColumns
.Get<UserManagement>()
.AddIfNotContains(new TableColumn[]
.AddRange(new TableColumn[]
{
new TableColumn
{
Title = L["Actions"],
Actions = UIExtensions.Instance.EntityActions.Get<UserManagement>()
Actions = EntityActions.Get<UserManagement>()
},
new TableColumn
{
@ -189,11 +190,9 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
protected override ValueTask SetToolbarItemsAsync()
{
ToolbarOptions.Value.Configure<UserManagement>(toolbar =>
{
toolbar.AddButton(L["NewUser"], OpenCreateModalAsync, IconName.Add, requiredPolicyName: CreatePolicyName);
});
Toolbar.AddButton(L["NewUser"], OpenCreateModalAsync, IconName.Add,
requiredPolicyName: CreatePolicyName);
return base.SetToolbarItemsAsync();
}
}
@ -204,4 +203,4 @@ namespace Volo.Abp.Identity.Blazor.Pages.Identity
public bool IsAssigned { get; set; }
}
}
}
Loading…
Cancel
Save