From f760b487853a653e63df0eb488f961ed9bb578d2 Mon Sep 17 00:00:00 2001 From: Ilkay Ilknur Date: Fri, 11 Dec 2020 12:27:24 +0300 Subject: [PATCH] AbpDataGrid implementation. --- .../Extensibility/EntityActions/EntityAction.cs | 6 +++++- .../Extensibility/TableColumns/TableColumn.cs | 8 +++++++- .../TableColumns/TableColumnsConfiguration.cs | 10 ++++++++-- .../src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs | 12 ++++++++++++ .../Components/AbpDataGrid.razor | 3 ++- .../Components/AbpDataGrid.razor.cs | 7 ++++--- 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/Extensibility/EntityActions/EntityAction.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/Extensibility/EntityActions/EntityAction.cs index 74bf28157f..245edfd04c 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/Extensibility/EntityActions/EntityAction.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/Extensibility/EntityActions/EntityAction.cs @@ -3,12 +3,16 @@ using System.Threading.Tasks; namespace Volo.Abp.AspNetCore.Components.Extensibility.EntityActions { - public class EntityAction + public class EntityAction:IEquatable { public string Text { get; set; } public Func Clicked { get; set; } public string RequiredPolicy { get; set; } public Func ConfirmationMessage { get; set; } public bool Primary { get; set; } + public bool Equals(EntityAction other) + { + return string.Equals(Text, other?.Text, StringComparison.OrdinalIgnoreCase); + } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/Extensibility/TableColumns/TableColumn.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/Extensibility/TableColumns/TableColumn.cs index 9a50860c99..0aff01674c 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/Extensibility/TableColumns/TableColumn.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/Extensibility/TableColumns/TableColumn.cs @@ -6,7 +6,7 @@ using Volo.Abp.AspNetCore.Components.Extensibility.EntityActions; namespace Volo.Abp.AspNetCore.Components.Extensibility.TableColumns { - public class TableColumn + public class TableColumn : IEquatable { public string Title { get; set; } public string Data { get; set; } @@ -18,5 +18,11 @@ namespace Volo.Abp.AspNetCore.Components.Extensibility.TableColumns { Actions = new List(); } + + public bool Equals(TableColumn other) + { + return string.Equals(Title, other?.Title, StringComparison.OrdinalIgnoreCase) && + string.Equals(Data, other?.Data, StringComparison.OrdinalIgnoreCase); + } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/Extensibility/TableColumns/TableColumnsConfiguration.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/Extensibility/TableColumns/TableColumnsConfiguration.cs index d2a9f78fd1..2668b5c583 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/Extensibility/TableColumns/TableColumnsConfiguration.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/Extensibility/TableColumns/TableColumnsConfiguration.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace Volo.Abp.AspNetCore.Components.Extensibility.TableColumns { @@ -13,7 +14,12 @@ namespace Volo.Abp.AspNetCore.Components.Extensibility.TableColumns public List Get() { - return TableColumns.GetOrAdd(typeof(T).FullName, () => new List()); + return Get(typeof(T)); + } + + public List Get(Type type) + { + return TableColumns.GetOrAdd(type.FullName, () => new List()); } } } diff --git a/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs b/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs index 30a5c8ad26..04aecf1f5f 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs @@ -206,6 +206,8 @@ namespace Volo.Abp.BlazoriseUI protected override async Task OnInitializedAsync() { + await SetEntityActionsAsync(); + await SetTableColumnsAsync(); await SetBreadcrumbItemsAsync(); await SetPermissionsAsync(); } @@ -450,5 +452,15 @@ namespace Volo.Abp.BlazoriseUI { return ValueTask.CompletedTask; } + + protected virtual ValueTask SetEntityActionsAsync() + { + return ValueTask.CompletedTask; + } + + protected virtual ValueTask SetTableColumnsAsync() + { + return ValueTask.CompletedTask; + } } } diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/AbpDataGrid.razor b/framework/src/Volo.Abp.BlazoriseUI/Components/AbpDataGrid.razor index 8b6fabe294..52e1a374b0 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/AbpDataGrid.razor +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/AbpDataGrid.razor @@ -1,5 +1,6 @@ @typeparam TItem @using Blazorise.DataGrid; +@using Volo.Abp.AspNetCore.Components.Extensibility - @foreach (var column in Columns) + @foreach (var column in UIExtensions.Instance.TableColumns.Get(Page)) { if (column.Actions.Any()) { diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/AbpDataGrid.razor.cs b/framework/src/Volo.Abp.BlazoriseUI/Components/AbpDataGrid.razor.cs index 14e517c0ba..c3e0d767ad 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/AbpDataGrid.razor.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/AbpDataGrid.razor.cs @@ -1,4 +1,5 @@ -using Blazorise.DataGrid; +using System; +using Blazorise.DataGrid; using Microsoft.AspNetCore.Components; using System.Collections.Generic; using Volo.Abp.AspNetCore.Components.Extensibility.TableColumns; @@ -24,8 +25,8 @@ namespace Volo.Abp.BlazoriseUI.Components [Parameter] public int PageSize { get; set; } - [Parameter] - public List Columns { get; set; } + [Parameter] + public Type Page { get; set; } } }