mirror of https://github.com/abpframework/abp.git
15 changed files with 361 additions and 197 deletions
@ -0,0 +1,8 @@ |
|||||
|
namespace Volo.Abp.BlazoriseUI.Components |
||||
|
{ |
||||
|
public enum ActionType |
||||
|
{ |
||||
|
Dropdown, |
||||
|
Button |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Blazorise.DataGrid; |
||||
|
using Localization.Resources.AbpUi; |
||||
|
using Microsoft.AspNetCore.Components; |
||||
|
using Microsoft.Extensions.Localization; |
||||
|
|
||||
|
namespace Volo.Abp.BlazoriseUI.Components |
||||
|
{ |
||||
|
public class DataGridEntityActionsColumn<TItem> : DataGridColumn<TItem> |
||||
|
{ |
||||
|
[Inject] |
||||
|
public IStringLocalizer<AbpUiResource> UiLocalizer { get; set; } |
||||
|
|
||||
|
protected override async Task OnInitializedAsync() |
||||
|
{ |
||||
|
await base.OnInitializedAsync(); |
||||
|
await SetDefaultValuesAsync(); |
||||
|
} |
||||
|
|
||||
|
protected virtual ValueTask SetDefaultValuesAsync() |
||||
|
{ |
||||
|
Caption = UiLocalizer["Actions"]; |
||||
|
Width = "150px"; |
||||
|
Sortable = false; |
||||
|
Field = typeof(TItem).GetProperties().First().Name; |
||||
|
return ValueTask.CompletedTask; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
@typeparam TItem |
||||
|
@using Blazorise |
||||
|
|
||||
|
@if (ParentActions.Type == ActionType.Dropdown) |
||||
|
{ |
||||
|
if (IsVisible && Primary == false) |
||||
|
{ |
||||
|
<DropdownItem Clicked="@ActionClickedAsync">@Text</DropdownItem> |
||||
|
} |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
if (IsVisible) |
||||
|
{ |
||||
|
<Blazorise.Button Block="true" |
||||
|
Color="@Color" |
||||
|
Clicked="@ActionClickedAsync"> |
||||
|
@Text |
||||
|
</Blazorise.Button> |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,75 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Blazorise; |
||||
|
using Localization.Resources.AbpUi; |
||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using Microsoft.AspNetCore.Components; |
||||
|
using Microsoft.Extensions.Localization; |
||||
|
using Volo.Abp.AspNetCore.Components.WebAssembly; |
||||
|
|
||||
|
namespace Volo.Abp.BlazoriseUI.Components |
||||
|
{ |
||||
|
public partial class EntityAction<TItem> : ComponentBase |
||||
|
{ |
||||
|
internal bool IsVisible = true; |
||||
|
|
||||
|
[Parameter] |
||||
|
public string Text { get; set; } |
||||
|
|
||||
|
[Parameter] |
||||
|
public bool Primary { get; set; } |
||||
|
|
||||
|
[Parameter] |
||||
|
public EventCallback Clicked { get; set; } |
||||
|
|
||||
|
[Parameter] |
||||
|
public string RequiredPolicy { get; set; } |
||||
|
|
||||
|
[Parameter] |
||||
|
public Color Color { get; set; } |
||||
|
|
||||
|
[Parameter] |
||||
|
public Func<string> ConfirmationMessage { get; set; } |
||||
|
|
||||
|
[CascadingParameter] |
||||
|
public EntityActions<TItem> ParentActions { get; set; } |
||||
|
|
||||
|
[Inject] |
||||
|
protected IAuthorizationService AuthorizationService { get; set; } |
||||
|
|
||||
|
[Inject] |
||||
|
protected IUiMessageService UiMessageService { get; set; } |
||||
|
|
||||
|
protected async override Task OnInitializedAsync() |
||||
|
{ |
||||
|
await base.OnInitializedAsync(); |
||||
|
await SetDefaultValuesAsync(); |
||||
|
if (!RequiredPolicy.IsNullOrEmpty()) |
||||
|
{ |
||||
|
IsVisible = await AuthorizationService.IsGrantedAsync(RequiredPolicy); |
||||
|
} |
||||
|
ParentActions.AddAction(this); |
||||
|
} |
||||
|
|
||||
|
protected internal virtual async Task ActionClickedAsync() |
||||
|
{ |
||||
|
if (ConfirmationMessage != null) |
||||
|
{ |
||||
|
if (await UiMessageService.ConfirmAsync(ConfirmationMessage())) |
||||
|
{ |
||||
|
await Clicked.InvokeAsync(); |
||||
|
} |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
await Clicked.InvokeAsync(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
protected virtual ValueTask SetDefaultValuesAsync() |
||||
|
{ |
||||
|
Color = Color.Primary; |
||||
|
return ValueTask.CompletedTask; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
@typeparam TItem |
||||
|
<CascadingValue Value="this"> |
||||
|
@if (Type == ActionType.Dropdown) |
||||
|
{ |
||||
|
<Dropdown> |
||||
|
@if (HasPrimaryAction) |
||||
|
{ |
||||
|
<Blazorise.Button Block="true" |
||||
|
Color="@PrimaryAction.Color" |
||||
|
Clicked="async ()=> await PrimaryAction.ActionClickedAsync()"> |
||||
|
@PrimaryAction.Text |
||||
|
</Blazorise.Button> |
||||
|
<DropdownToggle Color="@ToggleColor" Split="true" /> |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
<DropdownToggle Color="@ToggleColor"> |
||||
|
@ToggleText |
||||
|
</DropdownToggle> |
||||
|
} |
||||
|
<DropdownMenu> |
||||
|
@ChildContent |
||||
|
</DropdownMenu> |
||||
|
</Dropdown> |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
@ChildContent |
||||
|
} |
||||
|
</CascadingValue> |
||||
@ -0,0 +1,49 @@ |
|||||
|
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<TItem> : ComponentBase |
||||
|
{ |
||||
|
protected readonly List<EntityAction<TItem>> Actions = new List<EntityAction<TItem>>(); |
||||
|
protected bool HasPrimaryAction => Actions.Any(t => t.Primary); |
||||
|
protected EntityAction<TItem> PrimaryAction => Actions.FirstOrDefault(t => t.Primary); |
||||
|
protected internal ActionType Type => Actions.Count(t => t.IsVisible) > 1 ? ActionType.Dropdown : ActionType.Button; |
||||
|
|
||||
|
[Parameter] |
||||
|
public Color ToggleColor { get; set; } = Color.Primary; |
||||
|
|
||||
|
[Parameter] |
||||
|
public string ToggleText { get; set; } |
||||
|
|
||||
|
[Parameter] |
||||
|
public RenderFragment ChildContent { get; set; } |
||||
|
|
||||
|
[Parameter] |
||||
|
public DataGridEntityActionsColumn<TItem> EntityActionsColumn { get; set; } |
||||
|
|
||||
|
[Inject] |
||||
|
public IStringLocalizer<AbpUiResource> UiLocalizer { get; set; } |
||||
|
|
||||
|
internal void AddAction(EntityAction<TItem> action) |
||||
|
{ |
||||
|
Actions.Add(action); |
||||
|
if (EntityActionsColumn != null) |
||||
|
{ |
||||
|
EntityActionsColumn.Displayable = Actions.Any(t => t.IsVisible); |
||||
|
} |
||||
|
StateHasChanged(); |
||||
|
} |
||||
|
|
||||
|
protected override void OnInitialized() |
||||
|
{ |
||||
|
base.OnInitialized(); |
||||
|
ToggleText = UiLocalizer["Actions"]; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue