From 86acf9947c05dde5ceb0c1ac1e0c64d0ae2091f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20B=C3=B6rchers?= Date: Mon, 24 Aug 2020 21:27:15 +0200 Subject: [PATCH] Added Autocomplete component to view --- UserService/Pages/SecurityGroups.razor | 33 ++++++++++++++--- UserService/Pages/SecurityGroups.razor.cs | 43 +++++++++++++++++++---- UserService/Program.cs | 2 +- UserService/UserService.csproj | 1 + UserService/_Imports.razor | 1 + 5 files changed, 67 insertions(+), 13 deletions(-) diff --git a/UserService/Pages/SecurityGroups.razor b/UserService/Pages/SecurityGroups.razor index e407432..a33ae82 100644 --- a/UserService/Pages/SecurityGroups.razor +++ b/UserService/Pages/SecurityGroups.razor @@ -12,8 +12,7 @@ } else { - - + - @foreach (var item in OrganizationUnits ?? Enumerable.Empty()) { @item.CommonName } - + - + + + + + + @if (SelectedSecurityGroup != null) + { + + Members of @SelectedSecurityGroup.CommonName group + + + + + + + + + } + + } \ No newline at end of file diff --git a/UserService/Pages/SecurityGroups.razor.cs b/UserService/Pages/SecurityGroups.razor.cs index cfc3036..b0de0dd 100644 --- a/UserService/Pages/SecurityGroups.razor.cs +++ b/UserService/Pages/SecurityGroups.razor.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Blazorise; using Blazorise.DataGrid; using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; @@ -15,6 +16,11 @@ namespace UserService.Pages [Inject] private ISecurityGroupsRepository SecurityGroupsRepository { get; set; } = null!; [Inject] private IOrganizationUnitsRepository OrganizationUnitsRepository { get; set; } = null!; + // reference to the modal component + protected Modal ModalRef { get; set; } = null!; + + protected IEnumerable AvailableMembers { get; set; } + protected override async Task OnInitializedAsync() { Members = await SecurityGroupsRepository.GetAllAsync().ConfigureAwait(false); @@ -22,7 +28,8 @@ namespace UserService.Pages } /// - protected override async Task RowInsertingCallback(CancellableRowChange> arg) + protected override async Task RowInsertingCallback( + CancellableRowChange> arg) { } @@ -36,27 +43,44 @@ namespace UserService.Pages { if (arg == null) throw new ArgumentNullException(nameof(arg)); var confirmed = await JsRuntime.InvokeAsync("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); arg.Cancel = !confirmed; } /// - protected override async Task RowUpdatingCallback(CancellableRowChange> arg) + protected override async Task RowUpdatingCallback( + CancellableRowChange> 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)]); + 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 Task MySearchHandler(object arg) { - var confirmed = await JsRuntime.InvokeAsync("confirm", - $"You are about to delete the security group {securityGroup.CommonName}. Are you sure?").ConfigureAwait(false); + var addedMember = arg as Member; + var confirmed = await JsRuntime.InvokeAsync("confirm", addedMember?.CommonName ?? "Fuck") + .ConfigureAwait(false); } + protected async Task OnSearchChanged(string arg) + { + //TODO + } + + protected void OnButtonClicked(SecurityGroup securityGroup) + { + SelectedSecurityGroup = securityGroup; + ModalRef.Show(); + } + + public SecurityGroup? SelectedSecurityGroup { get; set; } + /// protected override bool OnCustomFilter(SecurityGroup model) { @@ -69,5 +93,10 @@ namespace UserService.Pages } protected override Task RowDeletedCallback(SecurityGroup item) => SecurityGroupsRepository.DeleteAsync(item); + + protected void HideModal() + { + ModalRef.Hide(); + } } } \ No newline at end of file diff --git a/UserService/Program.cs b/UserService/Program.cs index c911c91..8f2f812 100644 --- a/UserService/Program.cs +++ b/UserService/Program.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.Hosting; namespace UserService { - public class Program + public static class Program { public static void Main(string[] args) { diff --git a/UserService/UserService.csproj b/UserService/UserService.csproj index c104d48..dd8b7f7 100644 --- a/UserService/UserService.csproj +++ b/UserService/UserService.csproj @@ -17,6 +17,7 @@ + diff --git a/UserService/_Imports.razor b/UserService/_Imports.razor index 8a87504..96aec76 100644 --- a/UserService/_Imports.razor +++ b/UserService/_Imports.razor @@ -11,3 +11,4 @@ @using Blazorise.Sidebar @using Blazorise.TreeView @using Blazorise.DataGrid +@using Blazorise.Components \ No newline at end of file