Browse Source

add datagridentityactionscolumn reference to the entityactions component and code refactorings.

pull/5890/head
Ilkay Ilknur 6 years ago
parent
commit
a2643f3f28
  1. 11
      framework/src/Volo.Abp.BlazoriseUI/Components/DataGridEntityActionsColumn.cs
  2. 3
      framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor
  3. 6
      framework/src/Volo.Abp.BlazoriseUI/Components/EntityAction.razor.cs
  4. 3
      framework/src/Volo.Abp.BlazoriseUI/Components/EntityActions.razor
  5. 28
      framework/src/Volo.Abp.BlazoriseUI/Components/EntityActions.razor.cs

11
framework/src/Volo.Abp.BlazoriseUI/Components/DataGridEntityActionsColumn.cs

@ -1,4 +1,5 @@
using System.Linq;
using System.Threading.Tasks;
using Blazorise.DataGrid;
using Localization.Resources.AbpUi;
using Microsoft.AspNetCore.Components;
@ -11,13 +12,19 @@ namespace Volo.Abp.BlazoriseUI.Components
[Inject]
public IStringLocalizer<AbpUiResource> UiLocalizer { get; set; }
protected override void OnInitialized()
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
await SetDefaultValuesAsync();
}
protected virtual ValueTask SetDefaultValuesAsync()
{
base.OnInitialized();
Caption = UiLocalizer["Actions"];
Width = "150px";
Sortable = false;
Field = typeof(TItem).GetProperties().First().Name;
return ValueTask.CompletedTask;
}
}
}

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

@ -1,4 +1,5 @@
@using Blazorise
@typeparam TItem
@using Blazorise
@if (ParentActions.Type == ActionType.Dropdown)
{

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

@ -7,7 +7,7 @@ using Volo.Abp.AspNetCore.Components.WebAssembly;
namespace Volo.Abp.BlazoriseUI.Components
{
public partial class EntityAction : ComponentBase
public partial class EntityAction<TItem> : ComponentBase
{
internal bool IsVisible;
@ -30,7 +30,7 @@ namespace Volo.Abp.BlazoriseUI.Components
public string ConfirmationMessage { get; set; }
[CascadingParameter]
public EntityActions ParentActions { get; set; }
public EntityActions<TItem> ParentActions { get; set; }
[Inject]
protected IAuthorizationService AuthorizationService { get; set; }
@ -42,8 +42,8 @@ namespace Volo.Abp.BlazoriseUI.Components
{
await base.OnInitializedAsync();
await SetDefaultValuesAsync();
ParentActions.AddAction(this);
IsVisible = await AuthorizationService.IsGrantedAsync(Policy);
ParentActions.AddAction(this);
}
protected internal virtual async Task ActionClickedAsync()

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

@ -1,4 +1,5 @@
<CascadingValue Value="this">
@typeparam TItem
<CascadingValue Value="this">
@if (Type == ActionType.Dropdown)
{
<Dropdown>

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

@ -8,15 +8,15 @@ using Microsoft.Extensions.Localization;
namespace Volo.Abp.BlazoriseUI.Components
{
public partial class EntityActions : ComponentBase
public partial class EntityActions<TItem> : ComponentBase
{
protected readonly List<EntityAction> Actions = new List<EntityAction>();
protected readonly List<EntityAction<TItem>> Actions = new List<EntityAction<TItem>>();
protected bool HasPrimaryAction => Actions.Any(t => t.Primary);
protected EntityAction 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]
public Color ToggleColor { get; set; }
public Color ToggleColor { get; set; } = Color.Primary;
[Parameter]
public string ToggleText { get; set; }
@ -24,26 +24,26 @@ namespace Volo.Abp.BlazoriseUI.Components
[Parameter]
public RenderFragment ChildContent { get; set; }
[Parameter]
public DataGridEntityActionsColumn<TItem> EntityActionsColumn { get; set; }
[Inject]
public IStringLocalizer<AbpUiResource> UiLocalizer { get; set; }
internal void AddAction(EntityAction action)
internal void AddAction(EntityAction<TItem> action)
{
Actions.Add(action);
if (EntityActionsColumn != null)
{
EntityActionsColumn.Displayable = Actions.Any(t => t.IsVisible);
}
StateHasChanged();
}
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
await SetDefaultValuesAsync();
}
protected virtual ValueTask SetDefaultValuesAsync()
protected override void OnInitialized()
{
ToggleColor = Color.Primary;
base.OnInitialized();
ToggleText = UiLocalizer["Actions"];
return ValueTask.CompletedTask;
}
}

Loading…
Cancel
Save