Browse Source

Explicitely define EntityActions Type

pull/8074/head
Mladen Macanovic 6 years ago
parent
commit
f6ef4be30a
  1. 8
      framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor
  2. 14
      framework/src/Volo.Abp.BlazoriseUI/Components/EntityActions.razor
  3. 28
      framework/src/Volo.Abp.BlazoriseUI/Components/EntityActions.razor.cs

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

@ -12,10 +12,10 @@ else
{ {
if (IsVisible) if (IsVisible)
{ {
<Blazorise.Button Block="true" <Button Block="true"
Color="@Color" Color="@Color"
Clicked="@ActionClickedAsync"> Clicked="@ActionClickedAsync">
@Text @Text
</Blazorise.Button> </Button>
} }
} }

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

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

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

@ -1,5 +1,6 @@
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 Localization.Resources.AbpUi;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
@ -12,7 +13,6 @@ namespace Volo.Abp.BlazoriseUI.Components
protected readonly List<EntityAction<TItem>> Actions = new List<EntityAction<TItem>>(); protected readonly List<EntityAction<TItem>> Actions = new List<EntityAction<TItem>>();
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<TItem> PrimaryAction => Actions.FirstOrDefault(t => t.Primary);
protected internal ActionType Type => Actions.Count(t => t.IsVisible) > 1 ? ActionType.Dropdown : ActionType.Button;
[Parameter] [Parameter]
public Color ToggleColor { get; set; } = Color.Primary; public Color ToggleColor { get; set; } = Color.Primary;
@ -26,17 +26,18 @@ namespace Volo.Abp.BlazoriseUI.Components
[Parameter] [Parameter]
public DataGridEntityActionsColumn<TItem> EntityActionsColumn { get; set; } public DataGridEntityActionsColumn<TItem> EntityActionsColumn { get; set; }
[Parameter]
public ActionType Type { get; set; } = ActionType.Dropdown;
[CascadingParameter]
public DataGridEntityActionsColumn<TItem> ParentEntityActionsColumn { get; set; }
[Inject] [Inject]
public IStringLocalizer<AbpUiResource> UiLocalizer { get; set; } public IStringLocalizer<AbpUiResource> UiLocalizer { get; set; }
internal void AddAction(EntityAction<TItem> action) internal void AddAction(EntityAction<TItem> action)
{ {
Actions.Add(action); Actions.Add(action);
if (EntityActionsColumn != null)
{
EntityActionsColumn.Displayable = Actions.Any(t => t.IsVisible);
}
InvokeAsync(StateHasChanged);
} }
protected override void OnInitialized() protected override void OnInitialized()
@ -44,5 +45,20 @@ namespace Volo.Abp.BlazoriseUI.Components
base.OnInitialized(); base.OnInitialized();
ToggleText = UiLocalizer["Actions"]; ToggleText = UiLocalizer["Actions"];
} }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
if (ParentEntityActionsColumn != null)
{
ParentEntityActionsColumn.Displayable = Actions.Any(t => t.IsVisible);
}
await InvokeAsync(StateHasChanged);
}
await base.OnAfterRenderAsync(firstRender);
}
} }
} }

Loading…
Cancel
Save