Gui stuff

This commit is contained in:
Holger Börchers 2020-08-22 21:37:24 +02:00
parent ca983c9d3a
commit f2932ad2e8
6 changed files with 60 additions and 30 deletions

View File

@ -3,20 +3,20 @@ using System.Collections.Generic;
using System.Linq;
using UserService.Infrastructure.DataModels;
namespace UserService.Infrastructure
namespace UserService.Infrastructure.DataModels
{
public static class NodeExtensions
{
public static void MapFields(this User user, Dictionary<string, object> values)
public static void MapFields(this Member member, Dictionary<string, object> values)
{
if (user == null) throw new ArgumentNullException(nameof(user));
if (member == null) throw new ArgumentNullException(nameof(member));
if (values == null) throw new ArgumentNullException(nameof(values));
var properties = user.GetType().GetProperties();
var properties = member.GetType().GetProperties();
foreach (var keyValuePair in values)
{
var propertyInfo = properties.FirstOrDefault(x => x.Name == keyValuePair.Key);
if (propertyInfo == null) continue;
propertyInfo.SetValue(user, keyValuePair.Value);
propertyInfo.SetValue(member, keyValuePair.Value);
}
}
}

Binary file not shown.

View File

@ -11,22 +11,24 @@ using UserService.Infrastructure.DataModels;
namespace UserService.Pages
{
public abstract class MembersBase<T> : ComponentBase where T : Member
public abstract class MembersBase<TMember> : ComponentBase where TMember : Member
{
[Inject] protected IJSRuntime JsRuntime { get; set; } = null!;
protected IReadOnlyList<OrganizationUnit>? OrganizationUnits { get; set; }
protected IReadOnlyList<T>? Members { get; set; }
protected IReadOnlyList<TMember>? Members { get; set; }
protected string? CustomFilterValue { get; set; }
protected abstract Task RowInsertingCallback(CancellableRowChange<T, Dictionary<string, object>> arg);
protected abstract Task RowInsertingCallback(CancellableRowChange<TMember, Dictionary<string, object>> arg);
protected abstract Task RowInsertedCallback(SavedRowItem<T, Dictionary<string, object>> arg);
protected abstract Task RowDeletingCallback(CancellableRowChange<T> arg);
protected abstract Task RowUpdatingCallback(CancellableRowChange<T, Dictionary<string, object>> arg);
protected abstract bool OnCustomFilter(T model);
protected abstract Task RowInsertedCallback(SavedRowItem<TMember, Dictionary<string, object>> arg);
protected abstract Task RowDeletingCallback(CancellableRowChange<TMember> arg);
protected abstract Task RowDeletedCallback(TMember user);
protected abstract Task RowUpdatingCallback(CancellableRowChange<TMember, Dictionary<string, object>> arg);
protected abstract bool OnCustomFilter(TMember model);
protected void ValidateCommonName(ValidatorEventArgs e)
{

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components;
@ -36,19 +37,18 @@ namespace UserService.Pages
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;
arg.Cancel = !confirmed;
}
/// <inheritdoc />
protected override async Task RowUpdatingCallback(CancellableRowChange<SecurityGroup, Dictionary<string, object>> arg)
{
if (arg == null) throw new ArgumentNullException(nameof(arg));
var securityGroup = arg.Item;
securityGroup.MapFields(arg.Values);
securityGroup.Parent = OrganizationUnits?.FirstOrDefault(x => x.Id == (int?)arg.Values[nameof(Node.ParentId)]);
var result = await SecurityGroupsRepository.UpdateAsync(securityGroup).ConfigureAwait(false);
arg.Cancel = !result;
}
protected async void OnButtonClicked(SecurityGroup securityGroup)
@ -67,5 +67,7 @@ namespace UserService.Pages
return model.CommonName.Contains(CustomFilterValue, StringComparison.OrdinalIgnoreCase);
}
protected override Task RowDeletedCallback(SecurityGroup item) => SecurityGroupsRepository.DeleteAsync(item);
}
}

View File

@ -22,6 +22,7 @@ else
Editable="true"
EditMode="DataGridEditMode.Inline"
RowRemoving="RowDeletingCallback"
RowRemoved="RowDeletedCallback"
Data="@Members"
RowInserted="RowInsertedCallback"
RowInserting="RowInsertingCallback"
@ -54,7 +55,6 @@ else
</CancelCommandTemplate>
</DataGridCommandColumn>
<DataGridColumn TItem="User" Field="@nameof(User.Id)" Caption="#" Sortable="false" />
<DataGridColumn TItem="User" Field="@nameof(User.CommonName)" Caption="CN" CellsEditableOnEditCommand="false" Editable="true">
<EditTemplate>
<Validation Validator="@ValidateCommonName">
@ -98,6 +98,35 @@ else
</Select>
</EditTemplate>
</DataGridSelectColumn>
<DataGridCheckColumn TItem="User" Field="@nameof(User.IsActive)" Caption="Active" Editable="true" />
<DataGridCheckColumn TItem="User" Field="@nameof(User.IsActive)" Caption="Active" Editable="true" >
<DisplayTemplate>
@{
if(((User) context ).IsActive){
<span style="color: green;">
<i class="far fa-check-circle"></i>
</span>
} else {
<span style="color: red;">
<i class="fas fa-ban"></i>
</span>
}
}
</DisplayTemplate>
<EditTemplate>
<Switch TValue="bool" Checked="@((bool)(context.CellValue))" CheckedChanged="@(v => context.CellValue = v)">
@{
if((bool)(context.CellValue)){
<span style="color: green;">
<i class="far fa-check-circle"></i>
</span>
} else {
<span style="color: red;">
<i class="fas fa-ban"></i>
</span>
}
}
</Switch>
</EditTemplate>
</DataGridCheckColumn>
</DataGrid>
}

View File

@ -7,8 +7,8 @@ using Blazorise;
using Blazorise.DataGrid;
using Microsoft.JSInterop;
using UserService.DatabaseLayer.Repository;
using UserService.Infrastructure;
using UserService.Infrastructure.DataModels;
using UserService.Infrastructure;
namespace UserService.Pages
{
@ -48,15 +48,12 @@ namespace UserService.Pages
if (arg == null) throw new ArgumentNullException(nameof(arg));
var confirmed = await JsRuntime.InvokeAsync<bool>("confirm",
$"You are about to delete the user {arg.Item.FullName}. Are you sure?").ConfigureAwait(false);
if (confirmed)
{
await UsersRepository.DeleteAsync(arg.Item).ConfigureAwait(false);
return;
}
arg.Cancel = true;
arg.Cancel = !confirmed;
}
protected override Task RowDeletedCallback(User user) => UsersRepository.DeleteAsync(user);
protected static void ValidateEmail(ValidatorEventArgs e)
{
if (e == null) throw new ArgumentNullException(nameof(e));