From 17f3274abc23add29d8b073a40949ee1fc8a77b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20B=C3=B6rchers?= Date: Mon, 3 Aug 2020 22:15:25 +0200 Subject: [PATCH] Added Blazorise gui framework --- .../Repository/BaseRepository.cs | 25 ++--- .../Repository/IRepository.cs | 5 +- .../Repository/Repository.cs | 2 +- UserService/Pages/Directory.razor | 40 +++++--- UserService/Pages/Directory.razor.cs | 45 +++++++++ UserService/Pages/OrganizationUnits.razor | 67 +++++++------ UserService/Pages/SecurityGroups.razor | 82 ++++++++-------- UserService/Pages/Users.razor | 98 +++++++++---------- UserService/Pages/_Host.cshtml | 54 +++++----- UserService/Shared/NavMenu.razor | 61 ++++-------- UserService/Shared/SurveyPrompt.razor | 16 --- UserService/Startup.cs | 17 +++- UserService/UserService.csproj | 11 ++- UserService/_Imports.razor | 5 +- 14 files changed, 290 insertions(+), 238 deletions(-) create mode 100644 UserService/Pages/Directory.razor.cs delete mode 100644 UserService/Shared/SurveyPrompt.razor diff --git a/UserService.DatabaseLayer/Repository/BaseRepository.cs b/UserService.DatabaseLayer/Repository/BaseRepository.cs index aeb0dd7..7df73ec 100644 --- a/UserService.DatabaseLayer/Repository/BaseRepository.cs +++ b/UserService.DatabaseLayer/Repository/BaseRepository.cs @@ -1,8 +1,8 @@ -using System; +#nullable enable +using System; using System.Collections.Generic; +using System.Linq; using System.Linq.Expressions; -using System.Runtime.CompilerServices; -using System.Security.Cryptography.X509Certificates; using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; @@ -12,43 +12,46 @@ namespace UserService.DatabaseLayer.Repository { public class BaseRepository where T : Node { - protected readonly Func> _context; + protected readonly Func> Context; protected BaseRepository(Func> context) { - _context = context; + Context = context; } - public virtual async Task> GetAllAsync(CancellationToken token = default) + public virtual async Task> GetAllAsync(Expression>? predicate = null, CancellationToken token = default) { await using var db = new UserServiceDbContext(); - return await _context(db).Include(x => x.Parent).ToListAsync(token); + + IQueryable queryable = Context(db).Include(x => x.Parent); + if(queryable != null) queryable = queryable.Where(predicate); + return await queryable.ToListAsync(token); } public async Task GetAsync(Expression> predicate, CancellationToken token = default) { await using var db = new UserServiceDbContext(); - return await _context(db).FirstOrDefaultAsync(predicate, token); + return await Context(db).FirstOrDefaultAsync(predicate, token); } public async Task AddAsync(T entity, CancellationToken token = default) { await using var db = new UserServiceDbContext(); - await _context(db).AddAsync(@entity, token); + await Context(db).AddAsync(@entity, token); await db.SaveChangesAsync(token); } public async Task UpdateAsync(T entity, CancellationToken token = default) { await using var db = new UserServiceDbContext(); - _context(db).Update(entity); + Context(db).Update(entity); await db.SaveChangesAsync(token); } public async Task DeleteAsync(T entity, CancellationToken token = default) { await using var db = new UserServiceDbContext(); - _context(db).Remove(entity); + Context(db).Remove(entity); await db.SaveChangesAsync(token); } } diff --git a/UserService.DatabaseLayer/Repository/IRepository.cs b/UserService.DatabaseLayer/Repository/IRepository.cs index 19f8598..189c21a 100644 --- a/UserService.DatabaseLayer/Repository/IRepository.cs +++ b/UserService.DatabaseLayer/Repository/IRepository.cs @@ -1,4 +1,5 @@ -using System; +#nullable enable +using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Threading; @@ -9,7 +10,7 @@ namespace UserService.DatabaseLayer.Repository { public interface IRepository where T : Node { - Task> GetAllAsync(CancellationToken token = default); + Task> GetAllAsync(Expression>? predicate = null, CancellationToken token = default); Task GetAsync(Expression> predicate, CancellationToken token = default); Task AddAsync(T entity, CancellationToken token = default); Task UpdateAsync(T entity, CancellationToken token = default); diff --git a/UserService.DatabaseLayer/Repository/Repository.cs b/UserService.DatabaseLayer/Repository/Repository.cs index 2be88fd..86afdd3 100644 --- a/UserService.DatabaseLayer/Repository/Repository.cs +++ b/UserService.DatabaseLayer/Repository/Repository.cs @@ -23,7 +23,7 @@ namespace UserService.DatabaseLayer.Repository await using var db = new UserServiceDbContext(); var result = new List(); - var rootOus = await _context(db) + var rootOus = await Context(db) .Include(x => x.Parent) .ToListAsync(token); diff --git a/UserService/Pages/Directory.razor b/UserService/Pages/Directory.razor index 4ba6e41..39bb61c 100644 --- a/UserService/Pages/Directory.razor +++ b/UserService/Pages/Directory.razor @@ -1,11 +1,20 @@ @page "/directory" -@using UserService.DatabaseLayer.DataModels @using UserService.DatabaseLayer.Repository @inject IOrganizationUnitsRepository OuRepository +@inherits DirectoryBase -

TODO

+@functions { -@if (_organizationUnits == null) + + +} + + + +

TODO

+
+
+@if (OrganizationUnits == null) {

Loading... @@ -13,17 +22,20 @@ } else { + + + + + + @context?.CommonName + + + - -} -@code { - private IReadOnlyList _organizationUnits; - private OrganizationUnit _selectedOu; - - protected override async Task OnInitializedAsync() - { - _organizationUnits = (await OuRepository.GetAllAsync().ConfigureAwait(false)).Where(x=> x.Parent is null).ToList(); - } - + + } \ No newline at end of file diff --git a/UserService/Pages/Directory.razor.cs b/UserService/Pages/Directory.razor.cs new file mode 100644 index 0000000..4a7ac5c --- /dev/null +++ b/UserService/Pages/Directory.razor.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Components; +using UserService.DatabaseLayer.DataModels; +using UserService.DatabaseLayer.Repository; + +namespace UserService.Pages +{ + public class DirectoryBase : ComponentBase + { + private Node? _selectedNode; + public IReadOnlyList? OrganizationUnits { get; set; } + + public Node? SelectedNode + { + get => _selectedNode; + set + { + if(Equals(_selectedNode, value)) return; + _selectedNode = value; + OnSelectedNodeChanged(value); + } + } + + private async void OnSelectedNodeChanged(Node? value) + { + Members = await UsersRepository.GetAllAsync(); + } + + [Inject] public IOrganizationUnitsRepository OuRepository { get; set; } + + [Inject] public IUsersRepository UsersRepository { get; set; } + + + protected override async Task OnInitializedAsync() + { + OrganizationUnits = (await OuRepository.GetAllAsync().ConfigureAwait(false)) + .Where(x => x.Parent is null) + .ToList(); + } + + } +} \ No newline at end of file diff --git a/UserService/Pages/OrganizationUnits.razor b/UserService/Pages/OrganizationUnits.razor index c17c79e..ff8896c 100644 --- a/UserService/Pages/OrganizationUnits.razor +++ b/UserService/Pages/OrganizationUnits.razor @@ -12,33 +12,36 @@ } else { - - - Common Name - Description - Parent - Manager - - - - - @context.CommonName - @context.Description - @context.Parent - @context.Manager - - edit - - - delete - - - + + + + @* + + Common Name + Description + Parent + Manager + + + + + @context.CommonName + @context.Description + @context.Parent + @context.Manager + + edit + + + delete + + + *@ Create organization unit } - +@* @if (OuToEdit != null) { @(OuToEdit.Id == 0 ? "New" : "Edit") @OuToEdit.CommonName (@OuToEdit.Id) @@ -47,16 +50,16 @@ else

@**@ -

- - - } - else - { - No securityGroup selected - } +@*

+ + + } + else + { + No securityGroup selected + } No Thanks OK - \ No newline at end of file + *@ \ No newline at end of file diff --git a/UserService/Pages/SecurityGroups.razor b/UserService/Pages/SecurityGroups.razor index fdbfba0..0904a02 100644 --- a/UserService/Pages/SecurityGroups.razor +++ b/UserService/Pages/SecurityGroups.razor @@ -13,47 +13,47 @@ } else { - - - Common Name - Description - E-Mail - Parent - - - - - @context.CommonName - @context.Description - @context.EMail - @context.Parent - edit - delete + @* + + Common Name + Description + E-Mail + Parent + + + + + @context.CommonName + @context.Description + @context.EMail + @context.Parent + edit + delete - - - Create new group + + + Create new group*@ } - - @if (SecurityGroupToEdit != null) - { - @(SecurityGroupToEdit.Id == 0 ? "New" : "Edit") @SecurityGroupToEdit.CommonName (@SecurityGroupToEdit.Id) - - -

- - -

- - - } - else - { - No securityGroup selected - } - - No Thanks - OK - - \ No newline at end of file +@* + @if (SecurityGroupToEdit != null) + { + @(SecurityGroupToEdit.Id == 0 ? "New" : "Edit") @SecurityGroupToEdit.CommonName (@SecurityGroupToEdit.Id) + + +

+ + +

+ + + } + else + { + No securityGroup selected + } + + No Thanks + OK + + *@ \ No newline at end of file diff --git a/UserService/Pages/Users.razor b/UserService/Pages/Users.razor index 6bc2fd3..77ac95a 100644 --- a/UserService/Pages/Users.razor +++ b/UserService/Pages/Users.razor @@ -12,55 +12,55 @@ } else { - - - Common Name - Full name - Description - E-Mail - Parent - Is active - - - - - @context.CommonName - @context.FullName - @context.Description - @context.EMail - @context.Parent - @context.IsActive - edit - delete - - + @* + + Common Name + Full name + Description + E-Mail + Parent + Is active + + + + + @context.CommonName + @context.FullName + @context.Description + @context.EMail + @context.Parent + @context.IsActive + edit + delete + + - Create user + Create user*@ } - - @if (UserToEdit != null) - { - @(UserToEdit.Id == 0 ? "New" : "Edit") @UserToEdit.CommonName (@UserToEdit.Id) - - - -

- - -

- - -

- - - } - else - { - No securityGroup selected - } - - No Thanks - OK - - \ No newline at end of file +@* + @if (UserToEdit != null) + { + @(UserToEdit.Id == 0 ? "New" : "Edit") @UserToEdit.CommonName (@UserToEdit.Id) + + + +

+ + +

+ + +

+ + + } + else + { + No securityGroup selected + } + + No Thanks + OK + + *@ \ No newline at end of file diff --git a/UserService/Pages/_Host.cshtml b/UserService/Pages/_Host.cshtml index 8b3f80a..b5f61a9 100644 --- a/UserService/Pages/_Host.cshtml +++ b/UserService/Pages/_Host.cshtml @@ -8,33 +8,41 @@ - - + + UserService - + + - - - + + + + + + + - - - + + + -

- - An error has occurred. This application may no longer respond until reloaded. - - - An unhandled exception has occurred. See browser dev tools for details. - - Reload - 🗙 -
- - - - +
+ + An error has occurred. This application may no longer respond until reloaded. + + + An unhandled exception has occurred. See browser dev tools for details. + + Reload + 🗙 +
+ + + + + + + \ No newline at end of file diff --git a/UserService/Shared/NavMenu.razor b/UserService/Shared/NavMenu.razor index d1a68c0..5e569fa 100644 --- a/UserService/Shared/NavMenu.razor +++ b/UserService/Shared/NavMenu.razor @@ -1,49 +1,26 @@ - - - -
- -
+ @code { - private bool _collapseNavMenu = true; + private SidebarInfo _sidebarInfo; - private string NavMenuCssClass => _collapseNavMenu ? "collapse" : null; - - private void ToggleNavMenu() + protected override void OnInitialized() { - _collapseNavMenu = !_collapseNavMenu; + _sidebarInfo = new SidebarInfo + { + Brand = new SidebarBrandInfo + { + Text = "SidebarBrand", + To = "/" + }, Items = new List + { + new SidebarItemInfo + { + Text = "Directory", + Icon = IconName.Folder, + To = "/directory" + } + } + }; } } \ No newline at end of file diff --git a/UserService/Shared/SurveyPrompt.razor b/UserService/Shared/SurveyPrompt.razor deleted file mode 100644 index e9706c8..0000000 --- a/UserService/Shared/SurveyPrompt.razor +++ /dev/null @@ -1,16 +0,0 @@ - - -@code { - // Demonstrates how a parent component can supply parameters - [Parameter] - public string Title { get; set; } -} diff --git a/UserService/Startup.cs b/UserService/Startup.cs index e43811c..b3c667e 100644 --- a/UserService/Startup.cs +++ b/UserService/Startup.cs @@ -1,4 +1,7 @@ using System.Net.Http; +using Blazorise; +using Blazorise.Bootstrap; +using Blazorise.Icons.FontAwesome; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; @@ -26,7 +29,13 @@ namespace UserService services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - services.AddScoped(); + services + .AddBlazorise(options => + { + options.ChangeTextOnKeyPress = true; // optional + }) + .AddBootstrapProviders() + .AddFontAwesomeIcons(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -48,6 +57,10 @@ namespace UserService app.UseRouting(); + app.ApplicationServices + .UseBootstrapProviders() + .UseFontAwesomeIcons(); + app.UseEndpoints(endpoints => { endpoints.MapBlazorHub(); @@ -55,4 +68,4 @@ namespace UserService }); } } -} +} \ No newline at end of file diff --git a/UserService/UserService.csproj b/UserService/UserService.csproj index 1217d5d..990bac0 100644 --- a/UserService/UserService.csproj +++ b/UserService/UserService.csproj @@ -5,12 +5,15 @@ enable - - - - + + + + + + + diff --git a/UserService/_Imports.razor b/UserService/_Imports.razor index 2e8ba2a..ea8639c 100644 --- a/UserService/_Imports.razor +++ b/UserService/_Imports.razor @@ -7,4 +7,7 @@ @using Microsoft.JSInterop @using UserService @using UserService.Shared -@using MatBlazor \ No newline at end of file +@using Blazorise +@using Blazorise.Sidebar +@using Blazorise.TreeView +