diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/DataGridEntityActionsColumn.cs b/framework/src/Volo.Abp.BlazoriseUI/Components/DataGridEntityActionsColumn.cs new file mode 100644 index 0000000000..316c01370b --- /dev/null +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/DataGridEntityActionsColumn.cs @@ -0,0 +1,23 @@ +using System.Linq; +using Blazorise.DataGrid; +using Localization.Resources.AbpUi; +using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Localization; + +namespace Volo.Abp.BlazoriseUI.Components +{ + public class DataGridEntityActionsColumn : DataGridColumn + { + [Inject] + public IStringLocalizer UiLocalizer { get; set; } + + protected override void OnInitialized() + { + base.OnInitialized(); + Caption = UiLocalizer["Actions"]; + Width = "150px"; + Sortable = false; + Field = typeof(TItem).GetProperties().First().Name; + } + } +} diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor b/framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor index c36620f195..4988af6725 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor @@ -1,5 +1,4 @@ -@typeparam TItem -@using Blazorise +@using Blazorise @if (ParentActions.Type == ActionType.Dropdown) { @@ -13,7 +12,7 @@ else if (IsVisible) { @Text diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor.cs b/framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor.cs index 8dc4dcb5a0..872a735f83 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor.cs @@ -1,12 +1,16 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; +using Blazorise; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Components; +using Volo.Abp.AspNetCore.Components.WebAssembly; namespace Volo.Abp.BlazoriseUI.Components { - public partial class EntityAction : ComponentBase + public partial class EntityAction : ComponentBase { - [Parameter] - public bool IsVisible { get; set; } + internal bool IsVisible; + [Parameter] public string Text { get; set; } @@ -14,20 +18,53 @@ namespace Volo.Abp.BlazoriseUI.Components public bool Primary { get; set; } [Parameter] - public EventCallback Clicked { get; set; } + public EventCallback Clicked { get; set; } + + [Parameter] + public string Policy { get; set; } + + [Parameter] + public Color Color { get; set; } + + [Parameter] + public string ConfirmationMessage { get; set; } [CascadingParameter] - public EntityActions ParentActions { get; set; } + public EntityActions ParentActions { get; set; } - protected override void OnInitialized() + [Inject] + protected IAuthorizationService AuthorizationService { get; set; } + + [Inject] + protected IUiMessageService UiMessageService { get; set; } + + protected async override Task OnInitializedAsync() { - base.OnInitialized(); + await base.OnInitializedAsync(); + await SetDefaultValuesAsync(); ParentActions.AddAction(this); + IsVisible = await AuthorizationService.IsGrantedAsync(Policy); + } + + protected internal virtual async Task ActionClickedAsync() + { + if (!ConfirmationMessage.IsNullOrEmpty()) + { + if (await UiMessageService.ConfirmAsync(ConfirmationMessage)) + { + await Clicked.InvokeAsync(); + } + } + else + { + await Clicked.InvokeAsync(); + } } - protected virtual async Task ActionClickedAsync() + protected virtual ValueTask SetDefaultValuesAsync() { - await Clicked.InvokeAsync(ParentActions.Entity); + Color = Color.Primary; + return ValueTask.CompletedTask; } } } diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/EntityActions.razor b/framework/src/Volo.Abp.BlazoriseUI/Components/EntityActions.razor index b5afcdbadf..16e4889490 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/EntityActions.razor +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/EntityActions.razor @@ -1,13 +1,12 @@ -@typeparam TItem - + @if (Type == ActionType.Dropdown) { @if (HasPrimaryAction) { + Color="@PrimaryAction.Color" + Clicked="async ()=> await PrimaryAction.ActionClickedAsync()"> @PrimaryAction.Text diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/EntityActions.razor.cs b/framework/src/Volo.Abp.BlazoriseUI/Components/EntityActions.razor.cs index d24c7125a7..9024bf0d4b 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/EntityActions.razor.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/EntityActions.razor.cs @@ -1,15 +1,18 @@ using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Blazorise; +using Localization.Resources.AbpUi; using Microsoft.AspNetCore.Components; +using Microsoft.Extensions.Localization; namespace Volo.Abp.BlazoriseUI.Components { - public partial class EntityActions : ComponentBase + public partial class EntityActions : ComponentBase { - protected List> Actions = new List>(); + protected readonly List Actions = new List(); protected bool HasPrimaryAction => Actions.Any(t => t.Primary); - protected EntityAction PrimaryAction => Actions.FirstOrDefault(t => t.Primary); + protected EntityAction PrimaryAction => Actions.FirstOrDefault(t => t.Primary); protected internal ActionType Type => Actions.Count(t => t.IsVisible) > 1 ? ActionType.Dropdown : ActionType.Button; [Parameter] @@ -18,17 +21,30 @@ namespace Volo.Abp.BlazoriseUI.Components [Parameter] public string ToggleText { get; set; } - [Parameter] - public TItem Entity { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } - internal void AddAction(EntityAction action) + [Inject] + public IStringLocalizer UiLocalizer { get; set; } + + internal void AddAction(EntityAction action) { Actions.Add(action); StateHasChanged(); } + + protected override async Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + await SetDefaultValuesAsync(); + } + + protected virtual ValueTask SetDefaultValuesAsync() + { + ToggleColor = Color.Primary; + ToggleText = UiLocalizer["Actions"]; + return ValueTask.CompletedTask; + } } public enum ActionType