Working on edit button for Members of Security groups

This commit is contained in:
Holger Börchers 2020-08-22 20:30:05 +02:00
parent e6822e0491
commit ca983c9d3a
5 changed files with 35 additions and 8 deletions

View File

@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace UserService.Infrastructure.DataModels namespace UserService.Infrastructure.DataModels
{ {

View File

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using Blazorise; using Blazorise;
using Blazorise.DataGrid; using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using UserService.Infrastructure; using UserService.Infrastructure;
using UserService.Infrastructure.DataModels; using UserService.Infrastructure.DataModels;
@ -12,6 +13,8 @@ namespace UserService.Pages
{ {
public abstract class MembersBase<T> : ComponentBase where T : Member public abstract class MembersBase<T> : ComponentBase where T : Member
{ {
[Inject] protected IJSRuntime JsRuntime { get; set; } = null!;
protected IReadOnlyList<OrganizationUnit>? OrganizationUnits { get; set; } protected IReadOnlyList<OrganizationUnit>? OrganizationUnits { get; set; }
protected IReadOnlyList<T>? Members { get; set; } protected IReadOnlyList<T>? Members { get; set; }

View File

@ -83,5 +83,10 @@ else
</Select> </Select>
</EditTemplate> </EditTemplate>
</DataGridSelectColumn> </DataGridSelectColumn>
<DataGridColumn TItem="SecurityGroup" Field="@nameof(SecurityGroup.Members)" Caption="Members" Editable="true">
<DisplayTemplate>
<Button Color="Color.Success" Block="true" Clicked="@(() => OnButtonClicked((SecurityGroup) context ))">Edit</Button>
</DisplayTemplate>
</DataGridColumn>
</DataGrid> </DataGrid>
} }

View File

@ -1,7 +1,9 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Blazorise.DataGrid; using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using UserService.DatabaseLayer.Repository; using UserService.DatabaseLayer.Repository;
using UserService.Infrastructure.DataModels; using UserService.Infrastructure.DataModels;
@ -31,7 +33,16 @@ namespace UserService.Pages
/// <inheritdoc /> /// <inheritdoc />
protected override async Task RowDeletingCallback(CancellableRowChange<SecurityGroup> arg) protected override async Task RowDeletingCallback(CancellableRowChange<SecurityGroup> arg)
{ {
if (arg == null) throw new ArgumentNullException(nameof(arg));
var confirmed = await JsRuntime.InvokeAsync<bool>("confirm",
$"You are about to delete the security group {arg.Item.CommonName}. Are you sure?").ConfigureAwait(false);
if (confirmed)
{
await SecurityGroupsRepository.DeleteAsync(arg.Item).ConfigureAwait(false);
return;
}
arg.Cancel = true;
} }
@ -40,10 +51,21 @@ namespace UserService.Pages
{ {
} }
protected async void OnButtonClicked(SecurityGroup securityGroup)
{
var confirmed = await JsRuntime.InvokeAsync<bool>("confirm",
$"You are about to delete the security group {securityGroup.CommonName}. Are you sure?").ConfigureAwait(false);
}
/// <inheritdoc /> /// <inheritdoc />
protected override bool OnCustomFilter(SecurityGroup model) protected override bool OnCustomFilter(SecurityGroup model)
{ {
return true; if (model == null) throw new ArgumentNullException(nameof(model));
// We want to accept empty value as valid or otherwise
// datagrid will not show anything.
if (string.IsNullOrEmpty(CustomFilterValue)) return true;
return model.CommonName.Contains(CustomFilterValue, StringComparison.OrdinalIgnoreCase);
} }
} }
} }

View File

@ -17,8 +17,6 @@ namespace UserService.Pages
[Inject] private IUsersRepository UsersRepository { get; set; } = null!; [Inject] private IUsersRepository UsersRepository { get; set; } = null!;
[Inject] private IOrganizationUnitsRepository OrganizationUnitsRepository { get; set; } = null!; [Inject] private IOrganizationUnitsRepository OrganizationUnitsRepository { get; set; } = null!;
[Inject] private IJSRuntime JsRuntime { get; set; } = null!;
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
Members = await UsersRepository.GetAllAsync().ConfigureAwait(false); Members = await UsersRepository.GetAllAsync().ConfigureAwait(false);