Gui stuff
This commit is contained in:
parent
ca983c9d3a
commit
f2932ad2e8
@ -3,20 +3,20 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UserService.Infrastructure.DataModels;
|
using UserService.Infrastructure.DataModels;
|
||||||
|
|
||||||
namespace UserService.Infrastructure
|
namespace UserService.Infrastructure.DataModels
|
||||||
{
|
{
|
||||||
public static class NodeExtensions
|
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));
|
if (values == null) throw new ArgumentNullException(nameof(values));
|
||||||
var properties = user.GetType().GetProperties();
|
var properties = member.GetType().GetProperties();
|
||||||
foreach (var keyValuePair in values)
|
foreach (var keyValuePair in values)
|
||||||
{
|
{
|
||||||
var propertyInfo = properties.FirstOrDefault(x => x.Name == keyValuePair.Key);
|
var propertyInfo = properties.FirstOrDefault(x => x.Name == keyValuePair.Key);
|
||||||
if (propertyInfo == null) continue;
|
if (propertyInfo == null) continue;
|
||||||
propertyInfo.SetValue(user, keyValuePair.Value);
|
propertyInfo.SetValue(member, keyValuePair.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BIN
UserService.db
BIN
UserService.db
Binary file not shown.
@ -11,22 +11,24 @@ using UserService.Infrastructure.DataModels;
|
|||||||
|
|
||||||
namespace UserService.Pages
|
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!;
|
[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<TMember>? Members { get; set; }
|
||||||
|
|
||||||
protected string? CustomFilterValue { 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 RowInsertedCallback(SavedRowItem<TMember, Dictionary<string, object>> arg);
|
||||||
protected abstract Task RowDeletingCallback(CancellableRowChange<T> arg);
|
protected abstract Task RowDeletingCallback(CancellableRowChange<TMember> arg);
|
||||||
protected abstract Task RowUpdatingCallback(CancellableRowChange<T, Dictionary<string, object>> arg);
|
protected abstract Task RowDeletedCallback(TMember user);
|
||||||
protected abstract bool OnCustomFilter(T model);
|
|
||||||
|
protected abstract Task RowUpdatingCallback(CancellableRowChange<TMember, Dictionary<string, object>> arg);
|
||||||
|
protected abstract bool OnCustomFilter(TMember model);
|
||||||
|
|
||||||
protected void ValidateCommonName(ValidatorEventArgs e)
|
protected void ValidateCommonName(ValidatorEventArgs e)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Blazorise.DataGrid;
|
using Blazorise.DataGrid;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
@ -36,19 +37,18 @@ namespace UserService.Pages
|
|||||||
if (arg == null) throw new ArgumentNullException(nameof(arg));
|
if (arg == null) throw new ArgumentNullException(nameof(arg));
|
||||||
var confirmed = await JsRuntime.InvokeAsync<bool>("confirm",
|
var confirmed = await JsRuntime.InvokeAsync<bool>("confirm",
|
||||||
$"You are about to delete the security group {arg.Item.CommonName}. Are you sure?").ConfigureAwait(false);
|
$"You are about to delete the security group {arg.Item.CommonName}. Are you sure?").ConfigureAwait(false);
|
||||||
if (confirmed)
|
arg.Cancel = !confirmed;
|
||||||
{
|
|
||||||
await SecurityGroupsRepository.DeleteAsync(arg.Item).ConfigureAwait(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
arg.Cancel = true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override async Task RowUpdatingCallback(CancellableRowChange<SecurityGroup, Dictionary<string, object>> arg)
|
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)
|
protected async void OnButtonClicked(SecurityGroup securityGroup)
|
||||||
@ -67,5 +67,7 @@ namespace UserService.Pages
|
|||||||
|
|
||||||
return model.CommonName.Contains(CustomFilterValue, StringComparison.OrdinalIgnoreCase);
|
return model.CommonName.Contains(CustomFilterValue, StringComparison.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override Task RowDeletedCallback(SecurityGroup item) => SecurityGroupsRepository.DeleteAsync(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -22,6 +22,7 @@ else
|
|||||||
Editable="true"
|
Editable="true"
|
||||||
EditMode="DataGridEditMode.Inline"
|
EditMode="DataGridEditMode.Inline"
|
||||||
RowRemoving="RowDeletingCallback"
|
RowRemoving="RowDeletingCallback"
|
||||||
|
RowRemoved="RowDeletedCallback"
|
||||||
Data="@Members"
|
Data="@Members"
|
||||||
RowInserted="RowInsertedCallback"
|
RowInserted="RowInsertedCallback"
|
||||||
RowInserting="RowInsertingCallback"
|
RowInserting="RowInsertingCallback"
|
||||||
@ -54,7 +55,6 @@ else
|
|||||||
</CancelCommandTemplate>
|
</CancelCommandTemplate>
|
||||||
</DataGridCommandColumn>
|
</DataGridCommandColumn>
|
||||||
<DataGridColumn TItem="User" Field="@nameof(User.Id)" Caption="#" Sortable="false" />
|
<DataGridColumn TItem="User" Field="@nameof(User.Id)" Caption="#" Sortable="false" />
|
||||||
|
|
||||||
<DataGridColumn TItem="User" Field="@nameof(User.CommonName)" Caption="CN" CellsEditableOnEditCommand="false" Editable="true">
|
<DataGridColumn TItem="User" Field="@nameof(User.CommonName)" Caption="CN" CellsEditableOnEditCommand="false" Editable="true">
|
||||||
<EditTemplate>
|
<EditTemplate>
|
||||||
<Validation Validator="@ValidateCommonName">
|
<Validation Validator="@ValidateCommonName">
|
||||||
@ -98,6 +98,35 @@ else
|
|||||||
</Select>
|
</Select>
|
||||||
</EditTemplate>
|
</EditTemplate>
|
||||||
</DataGridSelectColumn>
|
</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>
|
</DataGrid>
|
||||||
}
|
}
|
@ -7,8 +7,8 @@ using Blazorise;
|
|||||||
using Blazorise.DataGrid;
|
using Blazorise.DataGrid;
|
||||||
using Microsoft.JSInterop;
|
using Microsoft.JSInterop;
|
||||||
using UserService.DatabaseLayer.Repository;
|
using UserService.DatabaseLayer.Repository;
|
||||||
using UserService.Infrastructure;
|
|
||||||
using UserService.Infrastructure.DataModels;
|
using UserService.Infrastructure.DataModels;
|
||||||
|
using UserService.Infrastructure;
|
||||||
|
|
||||||
namespace UserService.Pages
|
namespace UserService.Pages
|
||||||
{
|
{
|
||||||
@ -48,14 +48,11 @@ namespace UserService.Pages
|
|||||||
if (arg == null) throw new ArgumentNullException(nameof(arg));
|
if (arg == null) throw new ArgumentNullException(nameof(arg));
|
||||||
var confirmed = await JsRuntime.InvokeAsync<bool>("confirm",
|
var confirmed = await JsRuntime.InvokeAsync<bool>("confirm",
|
||||||
$"You are about to delete the user {arg.Item.FullName}. Are you sure?").ConfigureAwait(false);
|
$"You are about to delete the user {arg.Item.FullName}. Are you sure?").ConfigureAwait(false);
|
||||||
if (confirmed)
|
arg.Cancel = !confirmed;
|
||||||
{
|
|
||||||
await UsersRepository.DeleteAsync(arg.Item).ConfigureAwait(false);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
arg.Cancel = true;
|
protected override Task RowDeletedCallback(User user) => UsersRepository.DeleteAsync(user);
|
||||||
}
|
|
||||||
|
|
||||||
protected static void ValidateEmail(ValidatorEventArgs e)
|
protected static void ValidateEmail(ValidatorEventArgs e)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user