working on group members list
This commit is contained in:
parent
256bb47dfe
commit
e9a7c37931
@ -3,12 +3,12 @@ using Microsoft.JSInterop;
|
|||||||
|
|
||||||
public static class JSInteropExtensions
|
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);
|
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);
|
return jsRuntime.InvokeVoidAsync("alert", message);
|
||||||
}
|
}
|
||||||
|
@ -99,12 +99,49 @@ else
|
|||||||
<CloseButton Clicked="@HideModal"/>
|
<CloseButton Clicked="@HideModal"/>
|
||||||
</ModalHeader>
|
</ModalHeader>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<Autocomplete Data="@AvailableMembers" TItem="Member"
|
<Row >
|
||||||
TextField="@((item)=>item.CommonName)"
|
<Addons>
|
||||||
ValueField="@((item)=>item)"
|
<Addon AddonType="AddonType.Start">
|
||||||
SelectedValueChanged="@MySearchHandler"
|
<AddonLabel>@@</AddonLabel>
|
||||||
SearchChanged="@OnSearchChanged"
|
</Addon>
|
||||||
Placeholder="Search..." />
|
<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>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button Color="Color.Primary" Clicked="@HideModal">Close</Button>
|
<Button Color="Color.Primary" Clicked="@HideModal">Close</Button>
|
||||||
|
@ -5,7 +5,6 @@ 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.DatabaseLayer.Repositories;
|
using UserService.DatabaseLayer.Repositories;
|
||||||
using UserService.Infrastructure.DataModels;
|
using UserService.Infrastructure.DataModels;
|
||||||
|
|
||||||
@ -22,7 +21,7 @@ namespace UserService.Pages
|
|||||||
// reference to the modal component
|
// reference to the modal component
|
||||||
protected Modal ModalRef { get; set; } = null!;
|
protected Modal ModalRef { get; set; } = null!;
|
||||||
|
|
||||||
protected IEnumerable<Member> AvailableMembers { get; set; }
|
protected IEnumerable<Member>? AvailableMembers { get; set; }
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
@ -45,7 +44,7 @@ namespace UserService.Pages
|
|||||||
protected override async Task RowDeletingCallback(CancellableRowChange<SecurityGroup> arg)
|
protected override async Task RowDeletingCallback(CancellableRowChange<SecurityGroup> arg)
|
||||||
{
|
{
|
||||||
if (arg == null) throw new ArgumentNullException(nameof(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);
|
.ConfigureAwait(false);
|
||||||
arg.Cancel = !confirmed;
|
arg.Cancel = !confirmed;
|
||||||
}
|
}
|
||||||
@ -65,20 +64,28 @@ namespace UserService.Pages
|
|||||||
|
|
||||||
protected async Task MySearchHandler(object arg)
|
protected async Task MySearchHandler(object arg)
|
||||||
{
|
{
|
||||||
var addedMember = arg as Member;
|
if (!(arg is Member addedMember)) return;
|
||||||
if(addedMember is null) return;
|
await JsRuntime.AlertAsync(addedMember?.CommonName ?? "Fuck").ConfigureAwait(false);
|
||||||
var confirmed = await JsRuntime.InvokeAsync<bool>("confirm", addedMember?.CommonName ?? "Fuck")
|
|
||||||
.ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async Task OnSearchChanged(string arg)
|
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>();
|
var result = new List<Member>();
|
||||||
|
if (string.IsNullOrWhiteSpace(arg)) return null;
|
||||||
var users = await UsersRepository.GetAllAsync().ConfigureAwait(false);
|
var users = await UsersRepository.GetAllAsync().ConfigureAwait(false);
|
||||||
var securityGroups = await SecurityGroupsRepository.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(users.Where(x =>
|
||||||
result.AddRange(securityGroups.Where(x=> x.CommonName.StartsWith(arg, StringComparison.InvariantCultureIgnoreCase)).Where(x=> x.Id != SelectedSecurityGroup?.Id));
|
x.CommonName.StartsWith(arg, StringComparison.InvariantCultureIgnoreCase) ||
|
||||||
AvailableMembers = result;
|
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)
|
protected void OnButtonClicked(SecurityGroup securityGroup)
|
||||||
|
@ -5,7 +5,6 @@ using System.Linq;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Blazorise;
|
using Blazorise;
|
||||||
using Blazorise.DataGrid;
|
using Blazorise.DataGrid;
|
||||||
using Microsoft.JSInterop;
|
|
||||||
using UserService.DatabaseLayer.Repositories;
|
using UserService.DatabaseLayer.Repositories;
|
||||||
using UserService.Infrastructure.DataModels;
|
using UserService.Infrastructure.DataModels;
|
||||||
using UserService.Infrastructure;
|
using UserService.Infrastructure;
|
||||||
@ -31,7 +30,7 @@ namespace UserService.Pages
|
|||||||
Members ?? Enumerable.Empty<User>());
|
Members ?? Enumerable.Empty<User>());
|
||||||
if (mailValidation == true && commonNameValidation == true) return;
|
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;
|
arg.Cancel = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +45,7 @@ namespace UserService.Pages
|
|||||||
protected override async Task RowDeletingCallback(CancellableRowChange<User> arg)
|
protected override async Task RowDeletingCallback(CancellableRowChange<User> arg)
|
||||||
{
|
{
|
||||||
if (arg == null) throw new ArgumentNullException(nameof(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;
|
arg.Cancel = !confirmed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,5 @@
|
|||||||
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
|
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
|
||||||
<clear />
|
<clear />
|
||||||
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
|
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
|
||||||
<add key="devexpress" value="https://nuget.devexpress.com/3zXs42uzzGPeHmfH1Bl7ERGp2eJ2t3ppmS2wZumhP3vJedKtPB/api" />
|
|
||||||
</packageSources>
|
</packageSources>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user