Browse Source

visible parameter has been added.

pull/6647/head
Ilkay Ilknur 6 years ago
parent
commit
2ceeeff4ce
  1. 1
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/Extensibility/EntityActions/EntityAction.cs
  2. 2
      framework/src/Volo.Abp.BlazoriseUI/Components/AbpExtensibleDataGrid.razor
  3. 4
      framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor
  4. 11
      framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor.cs
  5. 4
      framework/src/Volo.Abp.BlazoriseUI/Components/EntityActions.razor.cs

1
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/Extensibility/EntityActions/EntityAction.cs

@ -12,6 +12,7 @@ namespace Volo.Abp.AspNetCore.Components.Extensibility.EntityActions
public bool Primary { get; set; } public bool Primary { get; set; }
public object Color { get; set; } public object Color { get; set; }
public string Icon { get; set; } public string Icon { get; set; }
public Func<object, Task<bool>> Visible { get; set; }
public bool Equals(EntityAction other) public bool Equals(EntityAction other)
{ {
return string.Equals(Text, other?.Text, StringComparison.OrdinalIgnoreCase); return string.Equals(Text, other?.Text, StringComparison.OrdinalIgnoreCase);

2
framework/src/Volo.Abp.BlazoriseUI/Components/AbpExtensibleDataGrid.razor

@ -30,6 +30,7 @@
Icon="@action.Icon" Icon="@action.Icon"
Clicked="async () => await action.Clicked(context)" Clicked="async () => await action.Clicked(context)"
ConfirmationMessage="() => action.ConfirmationMessage.Invoke(context)" ConfirmationMessage="() => action.ConfirmationMessage.Invoke(context)"
Visible="async () => await action.Visible?.Invoke(context)"
Text="@action.Text"> Text="@action.Text">
</EntityAction> </EntityAction>
} }
@ -40,6 +41,7 @@
Clicked="async () => await action.Clicked(context)" Clicked="async () => await action.Clicked(context)"
Color="@(action.Color!=null ? (Blazorise.Color)action.Color : Blazorise.Color.None)" Color="@(action.Color!=null ? (Blazorise.Color)action.Color : Blazorise.Color.None)"
Icon="@action.Icon" Icon="@action.Icon"
Visible="async () => await action.Visible?.Invoke(context)"
Text="@action.Text"> Text="@action.Text">
</EntityAction> </EntityAction>
} }

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

@ -3,14 +3,14 @@
@if (ParentActions.Type == ActionType.Dropdown) @if (ParentActions.Type == ActionType.Dropdown)
{ {
if (IsVisible && Primary == false) if (IsEntityActionVisible && Primary == false)
{ {
<DropdownItem Clicked="@ActionClickedAsync">@Text</DropdownItem> <DropdownItem Clicked="@ActionClickedAsync">@Text</DropdownItem>
} }
} }
else else
{ {
if (IsVisible) if (IsEntityActionVisible)
{ {
<Blazorise.Button Block="true" <Blazorise.Button Block="true"
Color="@Color" Color="@Color"

11
framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor.cs

@ -12,7 +12,7 @@ namespace Volo.Abp.BlazoriseUI.Components
{ {
public partial class EntityAction<TItem> : ComponentBase public partial class EntityAction<TItem> : ComponentBase
{ {
internal bool IsVisible = true; internal bool IsEntityActionVisible = true;
[Parameter] [Parameter]
public string Text { get; set; } public string Text { get; set; }
@ -35,6 +35,9 @@ namespace Volo.Abp.BlazoriseUI.Components
[Parameter] [Parameter]
public string Icon { get; set; } public string Icon { get; set; }
[Parameter]
public Func<Task<bool>> Visible { get; set; }
[CascadingParameter] [CascadingParameter]
public EntityActions<TItem> ParentActions { get; set; } public EntityActions<TItem> ParentActions { get; set; }
@ -48,9 +51,11 @@ namespace Volo.Abp.BlazoriseUI.Components
{ {
await base.OnInitializedAsync(); await base.OnInitializedAsync();
await SetDefaultValuesAsync(); await SetDefaultValuesAsync();
if (!RequiredPolicy.IsNullOrEmpty()) IsEntityActionVisible = await Visible?.Invoke();
if (!RequiredPolicy.IsNullOrEmpty() && !IsEntityActionVisible)
{ {
IsVisible = await AuthorizationService.IsGrantedAsync(RequiredPolicy); IsEntityActionVisible = await AuthorizationService.IsGrantedAsync(RequiredPolicy);
} }
ParentActions.AddAction(this); ParentActions.AddAction(this);
} }

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

@ -12,7 +12,7 @@ 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; protected internal ActionType Type => Actions.Count(t => t.IsEntityActionVisible) > 1 ? ActionType.Dropdown : ActionType.Button;
[Parameter] [Parameter]
public Color ToggleColor { get; set; } = Color.Primary; public Color ToggleColor { get; set; } = Color.Primary;
@ -34,7 +34,7 @@ namespace Volo.Abp.BlazoriseUI.Components
Actions.Add(action); Actions.Add(action);
if (EntityActionsColumn != null) if (EntityActionsColumn != null)
{ {
EntityActionsColumn.Displayable = Actions.Any(t => t.IsVisible); EntityActionsColumn.Displayable = Actions.Any(t => t.IsEntityActionVisible);
} }
StateHasChanged(); StateHasChanged();
} }

Loading…
Cancel
Save