working on group members list

This commit is contained in:
Holger Börchers 2020-09-01 22:36:33 +02:00
parent 256bb47dfe
commit e9a7c37931
5 changed files with 64 additions and 22 deletions

View File

@ -3,12 +3,12 @@ using Microsoft.JSInterop;
public static class JSInteropExtensions
{
public static ValueTask<bool> Confirm(this IJSRuntime jsRuntime, string message)
public static ValueTask<bool> ConfirmAsync(this IJSRuntime jsRuntime, string message)
{
return jsRuntime.InvokeAsync<bool>("confirm", message);
}
public static ValueTask Alert(this IJSRuntime jsRuntime, string message)
public static ValueTask AlertAsync(this IJSRuntime jsRuntime, string message)
{
return jsRuntime.InvokeVoidAsync("alert", message);
}

View File

@ -99,12 +99,49 @@ else
<CloseButton Clicked="@HideModal"/>
</ModalHeader>
<ModalBody>
<Autocomplete Data="@AvailableMembers" TItem="Member"
TextField="@((item)=>item.CommonName)"
ValueField="@((item)=>item)"
SelectedValueChanged="@MySearchHandler"
SearchChanged="@OnSearchChanged"
Placeholder="Search..." />
<Row >
<Addons>
<Addon AddonType="AddonType.Start">
<AddonLabel>@@</AddonLabel>
</Addon>
<Addon AddonType="AddonType.Body">
<Autocomplete Data="@AvailableMembers" TItem="Member"
TextField="@((item) => item.CommonName)"
ValueField="@((item) => item)"
SelectedValueChanged="@MySearchHandler"
SearchChanged="@OnSearchChanged"
Placeholder="Username"/>
</Addon>
</Addons>
</Row>
<Row>
<Table Narrow="true" FullWidth="true">
<TableHeader>
<TableRow>
<TableHeaderCell>#</TableHeaderCell>
<TableHeaderCell>Common Name</TableHeaderCell>
<TableHeaderCell></TableHeaderCell>
</TableRow>
</TableHeader>
<TableBody>
<TableRow>
<TableRowHeader>1</TableRowHeader>
<TableRowCell>Mark</TableRowCell>
<TableRowCell><Button>Delete</Button></TableRowCell>
</TableRow>
<TableRow>
<TableRowHeader>2</TableRowHeader>
<TableRowCell>Jacob</TableRowCell>
<TableRowCell><Button>Delete</Button></TableRowCell>
</TableRow>
<TableRow>
<TableRowHeader>3</TableRowHeader>
<TableRowCell>Larry</TableRowCell>
<TableRowCell><Button>Delete</Button></TableRowCell>
</TableRow>
</TableBody>
</Table>
</Row>
</ModalBody>
<ModalFooter>
<Button Color="Color.Primary" Clicked="@HideModal">Close</Button>

View File

@ -5,7 +5,6 @@ using System.Threading.Tasks;
using Blazorise;
using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using UserService.DatabaseLayer.Repositories;
using UserService.Infrastructure.DataModels;
@ -22,7 +21,7 @@ namespace UserService.Pages
// reference to the modal component
protected Modal ModalRef { get; set; } = null!;
protected IEnumerable<Member> AvailableMembers { get; set; }
protected IEnumerable<Member>? AvailableMembers { get; set; }
protected override async Task OnInitializedAsync()
{
@ -45,7 +44,7 @@ namespace UserService.Pages
protected override async Task RowDeletingCallback(CancellableRowChange<SecurityGroup> arg)
{
if (arg == null) throw new ArgumentNullException(nameof(arg));
var confirmed = await JsRuntime.Confirm($"You are about to delete the security group {arg.Item.CommonName}. Are you sure?")
var confirmed = await JsRuntime.ConfirmAsync($"You are about to delete the security group {arg.Item.CommonName}. Are you sure?")
.ConfigureAwait(false);
arg.Cancel = !confirmed;
}
@ -65,20 +64,28 @@ namespace UserService.Pages
protected async Task MySearchHandler(object arg)
{
var addedMember = arg as Member;
if(addedMember is null) return;
var confirmed = await JsRuntime.InvokeAsync<bool>("confirm", addedMember?.CommonName ?? "Fuck")
.ConfigureAwait(false);
if (!(arg is Member addedMember)) return;
await JsRuntime.AlertAsync(addedMember?.CommonName ?? "Fuck").ConfigureAwait(false);
}
protected async Task OnSearchChanged(string arg)
{
AvailableMembers = await GetAvailableMembers(arg).ConfigureAwait(false);
}
private async Task<IReadOnlyList<Member>?> GetAvailableMembers(string arg)
{
var result = new List<Member>();
if (string.IsNullOrWhiteSpace(arg)) return null;
var users = await UsersRepository.GetAllAsync().ConfigureAwait(false);
var securityGroups = await SecurityGroupsRepository.GetAllAsync().ConfigureAwait(false);
result.AddRange(users.Where(x=> x.CommonName.StartsWith(arg, StringComparison.InvariantCultureIgnoreCase) || x.FullName.StartsWith(arg, StringComparison.InvariantCultureIgnoreCase)));
result.AddRange(securityGroups.Where(x=> x.CommonName.StartsWith(arg, StringComparison.InvariantCultureIgnoreCase)).Where(x=> x.Id != SelectedSecurityGroup?.Id));
AvailableMembers = result;
result.AddRange(users.Where(x =>
x.CommonName.StartsWith(arg, StringComparison.InvariantCultureIgnoreCase) ||
x.FullName.StartsWith(arg, StringComparison.InvariantCultureIgnoreCase)));
result.AddRange(securityGroups
.Where(x => x.CommonName.StartsWith(arg, StringComparison.InvariantCultureIgnoreCase))
.Where(x => x.Id != SelectedSecurityGroup?.Id));
return result.Count == 0 ? null : result;
}
protected void OnButtonClicked(SecurityGroup securityGroup)

View File

@ -5,7 +5,6 @@ using System.Linq;
using System.Threading.Tasks;
using Blazorise;
using Blazorise.DataGrid;
using Microsoft.JSInterop;
using UserService.DatabaseLayer.Repositories;
using UserService.Infrastructure.DataModels;
using UserService.Infrastructure;
@ -31,7 +30,7 @@ namespace UserService.Pages
Members ?? Enumerable.Empty<User>());
if (mailValidation == true && commonNameValidation == true) return;
await JsRuntime.Alert("User could not be added").ConfigureAwait(false);
await JsRuntime.AlertAsync("User could not be added").ConfigureAwait(false);
arg.Cancel = true;
}
@ -46,7 +45,7 @@ namespace UserService.Pages
protected override async Task RowDeletingCallback(CancellableRowChange<User> arg)
{
if (arg == null) throw new ArgumentNullException(nameof(arg));
var confirmed = await JsRuntime.Confirm($"You are about to delete the user {arg.Item.FullName}. Are you sure?").ConfigureAwait(false);
var confirmed = await JsRuntime.ConfirmAsync($"You are about to delete the user {arg.Item.FullName}. Are you sure?").ConfigureAwait(false);
arg.Cancel = !confirmed;
}

View File

@ -4,6 +4,5 @@
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="devexpress" value="https://nuget.devexpress.com/3zXs42uzzGPeHmfH1Bl7ERGp2eJ2t3ppmS2wZumhP3vJedKtPB/api" />
</packageSources>
</configuration>