Browse Source

Introduce DataGridActionsColumn and add policy check, default value setting

pull/5890/head
İlkay İlknur 6 years ago
parent
commit
f7a3955e36
  1. 23
      framework/src/Volo.Abp.BlazoriseUI/Components/DataGridEntityActionsColumn.cs
  2. 5
      framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor
  3. 57
      framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor.cs
  4. 7
      framework/src/Volo.Abp.BlazoriseUI/Components/EntityActions.razor
  5. 30
      framework/src/Volo.Abp.BlazoriseUI/Components/EntityActions.razor.cs

23
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<TItem> : DataGridColumn<TItem>
{
[Inject]
public IStringLocalizer<AbpUiResource> UiLocalizer { get; set; }
protected override void OnInitialized()
{
base.OnInitialized();
Caption = UiLocalizer["Actions"];
Width = "150px";
Sortable = false;
Field = typeof(TItem).GetProperties().First().Name;
}
}
}

5
framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor

@ -1,5 +1,4 @@
@typeparam TItem @using Blazorise
@using Blazorise
@if (ParentActions.Type == ActionType.Dropdown) @if (ParentActions.Type == ActionType.Dropdown)
{ {
@ -13,7 +12,7 @@ else
if (IsVisible) if (IsVisible)
{ {
<Blazorise.Button Block="true" <Blazorise.Button Block="true"
Color="Color.Primary" Color="@Color"
Clicked="@ActionClickedAsync"> Clicked="@ActionClickedAsync">
@Text @Text
</Blazorise.Button> </Blazorise.Button>

57
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 Microsoft.AspNetCore.Components;
using Volo.Abp.AspNetCore.Components.WebAssembly;
namespace Volo.Abp.BlazoriseUI.Components namespace Volo.Abp.BlazoriseUI.Components
{ {
public partial class EntityAction<TItem> : ComponentBase public partial class EntityAction : ComponentBase
{ {
[Parameter] internal bool IsVisible;
public bool IsVisible { get; set; }
[Parameter] [Parameter]
public string Text { get; set; } public string Text { get; set; }
@ -14,20 +18,53 @@ namespace Volo.Abp.BlazoriseUI.Components
public bool Primary { get; set; } public bool Primary { get; set; }
[Parameter] [Parameter]
public EventCallback<TItem> 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] [CascadingParameter]
public EntityActions<TItem> 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); 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;
} }
} }
} }

7
framework/src/Volo.Abp.BlazoriseUI/Components/EntityActions.razor

@ -1,13 +1,12 @@
@typeparam TItem <CascadingValue Value="this">
<CascadingValue Value="this">
@if (Type == ActionType.Dropdown) @if (Type == ActionType.Dropdown)
{ {
<Dropdown> <Dropdown>
@if (HasPrimaryAction) @if (HasPrimaryAction)
{ {
<Blazorise.Button Block="true" <Blazorise.Button Block="true"
Color="Color.Primary" Color="@PrimaryAction.Color"
Clicked="async ()=> await PrimaryAction.Clicked.InvokeAsync(Entity)"> Clicked="async ()=> await PrimaryAction.ActionClickedAsync()">
@PrimaryAction.Text @PrimaryAction.Text
</Blazorise.Button> </Blazorise.Button>
<DropdownToggle Color="@ToggleColor" Split="true" /> <DropdownToggle Color="@ToggleColor" Split="true" />

30
framework/src/Volo.Abp.BlazoriseUI/Components/EntityActions.razor.cs

@ -1,15 +1,18 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using Blazorise; using Blazorise;
using Localization.Resources.AbpUi;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
namespace Volo.Abp.BlazoriseUI.Components namespace Volo.Abp.BlazoriseUI.Components
{ {
public partial class EntityActions<TItem> : ComponentBase public partial class EntityActions : ComponentBase
{ {
protected List<EntityAction<TItem>> Actions = new List<EntityAction<TItem>>(); protected readonly List<EntityAction> Actions = new List<EntityAction>();
protected bool HasPrimaryAction => Actions.Any(t => t.Primary); protected bool HasPrimaryAction => Actions.Any(t => t.Primary);
protected EntityAction<TItem> 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; protected internal ActionType Type => Actions.Count(t => t.IsVisible) > 1 ? ActionType.Dropdown : ActionType.Button;
[Parameter] [Parameter]
@ -18,17 +21,30 @@ namespace Volo.Abp.BlazoriseUI.Components
[Parameter] [Parameter]
public string ToggleText { get; set; } public string ToggleText { get; set; }
[Parameter]
public TItem Entity { get; set; }
[Parameter] [Parameter]
public RenderFragment ChildContent { get; set; } public RenderFragment ChildContent { get; set; }
internal void AddAction(EntityAction<TItem> action) [Inject]
public IStringLocalizer<AbpUiResource> UiLocalizer { get; set; }
internal void AddAction(EntityAction action)
{ {
Actions.Add(action); Actions.Add(action);
StateHasChanged(); 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 public enum ActionType

Loading…
Cancel
Save