From c00de7d839c707530a4907c4b3bf8d0dfe5e7c19 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 31 Jan 2024 13:02:39 +0100 Subject: [PATCH] Update gestione admin utenti --- MagMan.UI/Components/UserMan.razor | 73 +++++- MagMan.UI/Components/UserMan.razor.cs | 357 +++++++++++++++++++++----- MagMan.UI/MagMan.UI.csproj | 2 +- Resources/ChangeLog.html | 2 +- Resources/VersNum.txt | 2 +- Resources/manifest.xml | 2 +- 6 files changed, 372 insertions(+), 66 deletions(-) diff --git a/MagMan.UI/Components/UserMan.razor b/MagMan.UI/Components/UserMan.razor index 2d164d2..8879839 100644 --- a/MagMan.UI/Components/UserMan.razor +++ b/MagMan.UI/Components/UserMan.razor @@ -32,6 +32,75 @@ *@ -
Content
- +
+ + + + + + + + + + + + + + @foreach (var user in UsersList) + { + + + + + + + + + } + +
IdUser / EmailRuoloPermessi
+ @if (!ShowPopup) + { + + } + else + { + + } + @user.Identity.Id.Substring(0, 8)... + @if (user.Identity.EmailConfirmed) + { + + } + else + { + + } +  @user.Identity.Email + + @ShowRoles(user.Roles) + + @ShowClaims(user.Claims) + + @if (!ShowPopup) + { + + } + else + { + + } +
+
+ \ No newline at end of file diff --git a/MagMan.UI/Components/UserMan.razor.cs b/MagMan.UI/Components/UserMan.razor.cs index 143d5f9..4818e14 100644 --- a/MagMan.UI/Components/UserMan.razor.cs +++ b/MagMan.UI/Components/UserMan.razor.cs @@ -1,13 +1,228 @@ using MagMan.Core.Services; using MagMan.Data.Admin; using MagMan.Data.Admin.Services; +using MagMan.Data.Tenant.DbModels; using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Identity; using Microsoft.Data.SqlClient; +using Microsoft.JSInterop; namespace MagMan.UI.Components { - public partial class UserMan:IDisposable + public partial class UserMan : IDisposable { + #region Public Methods + + public List ConvertClaim(List ClaimList) + { + List answ = new List(); + +#if false + var pUpd = Task.Run(async () => + { + await refreshLists(); + }); + pUpd.Wait(); + + // ciclo sui claims + foreach (var claim in ClaimList) + { + string claimStr = claim.ToString(); + // verifico che in OGNI claim ci siaun valore ammissibile... + if (claimStr.Contains(":")) + { + // splitto chiave/valore + var splitClaim = claimStr.Split(':'); + switch (splitClaim[0]) + { + case "PlantId": + if (plantList != null) + { + var plantRec = plantList + .Where(x => x.PlantId.ToString() == splitClaim[1].Trim()) + .FirstOrDefault(); + if (plantRec != null) + { + answ.Add($"{splitClaim[0]}: {plantRec.PlantDesc}"); + } + else + { + answ.Add($"{claim}"); + } + } + break; + + case "SupplierId": + if (suppList != null) + { + var plantRec = suppList + .Where(x => x.SupplierId.ToString() == splitClaim[1].Trim()) + .FirstOrDefault(); + if (plantRec != null) + { + answ.Add($"{splitClaim[0]}: {plantRec.SupplierDesc}"); + } + else + { + answ.Add($"{claim}"); + } + } + break; + + case "TransporterId": + if (transpList != null) + { + var plantRec = transpList + .Where(x => x.TransporterId.ToString() == splitClaim[1].Trim()) + .FirstOrDefault(); + if (plantRec != null) + { + answ.Add($"{splitClaim[0]}: {plantRec.TransporterDesc}"); + } + else + { + answ.Add($"{claim}"); + } + } + break; + + case "None": + default: + break; + } + } + } +#endif + + return answ; + } + + public void Dispose() + { + AppMService.EA_SearchUpdated -= AppMService_EA_SearchUpdated; + } + + /// + /// Recupera elenco utenti + /// + public async Task GetUsers() + { + // clear any error messages + strError = ""; + + UsersAll = await MTService.UserDataGetFilt(currSearch); + + // filtro visualizzazione x tipo SE richeisto + if (FiltUserRole != "0") + { + UsersAll = UsersAll.Where(x => x.Roles.Contains(FiltUserRole)).ToList(); + } + totalCount = UsersAll.Count; + + UsersList = UsersAll + .Skip(numRecord * (currPage - 1)).Take(numRecord) + .ToList(); + } + + public string ShowClaims(List ClaimList) + { + //string answ = string.Join(",", ClaimList); + string answ = string.Join(",", ConvertClaim(ClaimList)); + return answ; + } + + public string ShowRoles(List RoleList) + { + string answ = string.Join(",", RoleList); + return answ; + } + + #endregion Public Methods + + #region Protected Properties + + [Inject] + protected MessageService AppMService { get; set; } = null!; + + [Inject] + protected MTAdminService MTService { get; set; } = null!; + + protected int totalCount { get; set; } = 0; + + #endregion Protected Properties + + #region Protected Methods + + protected void DoSelect(UserData? selItem) + { +#if false + if (selItem != null) + { + ProjDbId = selItem.ProjDbId; + } + else + { + ProjDbId = 0; + } + E_ProjSel.InvokeAsync(selItem); +#endif + } + + protected override void OnInitialized() + { + currSearch = ""; + AppMService.EA_SearchUpdated += AppMService_EA_SearchUpdated; + } + + protected void SetNumRec(int newNum) + { + numRecord = newNum; + currPage = 1; + InvokeAsync(ReloadData); + } + + protected void SetPage(int newNum) + { + currPage = newNum; + DoSelect(null); + InvokeAsync(ReloadData); + } + + #endregion Protected Methods + + #region Private Fields + + private string currSearch = ""; + + /// + /// Elenco ROLES da mostrare in dropdown durante editing (1 solo? usare DB?!?) + /// + private List RolesList = new List() { "Undef", "User", "Admin", "SuperAdmin" }; + + // To enable showing the Popup + private bool ShowPopup = false; + + // To hold any possible errors + private string strError = ""; + + /// + /// Collezione utenti (totale) + /// + private List UsersAll = new List(); + + /// + /// Collezione utenti + /// + private List UsersList = new List(); + + #endregion Private Fields + + #region Private Properties + + private string _filtUserRole { get; set; } = "0"; + + private int currPage { get; set; } = 1; + /// /// Gestione filtraggio dati /// @@ -28,82 +243,104 @@ namespace MagMan.UI.Components } } - /// - /// Elenco ROLES da mostrare in dropdown durante editing (1 solo? usare DB?!?) - /// - private List RolesList = new List() { "Undef", "User", "Admin", "SuperAdmin" }; - - private string _filtUserRole { get; set; } = "0"; - - private int currPage { get; set; } = 1; - private bool isLoading { get; set; } = false; private int numRecord { get; set; } = 10; - private async Task ReloadData() - { - isLoading = true; - await GetUsers(); - isLoading = false; - } - // To enable showing the Popup - private bool ShowPopup = false; - // To hold any possible errors - private string strError = ""; + #endregion Private Properties - /// - /// Collezione utenti (totale) - /// - private List UsersAll = new List(); + #region Private Methods - /// - /// Collezione utenti - /// - private List UsersList = new List(); - [Inject] - protected MTAdminService MTService { get; set; } = null!; - - [Inject] - protected MessageService AppMService { get; set; } = null!; private async void AppMService_EA_SearchUpdated() { currSearch = AppMService.SearchVal; await ReloadData(); } - protected override void OnInitialized() + private async Task DeleteUser(IdentityUser _IdentityUser) { - currSearch = ""; - AppMService.EA_SearchUpdated += AppMService_EA_SearchUpdated; - } +#if false + // Close the Popup + ShowPopup = false; - public void Dispose() - { - AppMService.EA_SearchUpdated -= AppMService_EA_SearchUpdated; - } + if (!await JSRuntime.InvokeAsync("confirm", "Sicuro di voler eliminare l'utente selezionato??")) + return; - private string currSearch = ""; - - /// - /// Recupera elenco utenti - /// - public async Task GetUsers() - { - // clear any error messages - strError = ""; - - UsersAll = await MTService.UserDataGetFilt(currSearch); - - // filtro visualizzazione x tipo SE richeisto - if (FiltUserRole != "0") + // Get the user + var user = await _UserManager.FindByIdAsync(_IdentityUser.Id); + if (user != null) { - UsersAll = UsersAll.Where(x => x.Roles.Contains(FiltUserRole)).ToList(); + // Delete the user + await _UserManager.DeleteAsync(user); } - - UsersList = UsersAll - .Skip(numRecord * (currPage - 1)).Take(numRecord) - .ToList(); +#endif + // Refresh Users + await GetUsers(); } + + private void EditUser(IdentityUser _IdentityUser) + { +#if false + // selezione come current user + objUser = _IdentityUser; + var pUpd = Task.Run(async () => + { + // Get the user + var user = await _UserManager.FindByIdAsync(objUser.Id); + if (user != null) + { + // salvo role + var UserRoles = await _UserManager.GetRolesAsync(user); + if (UserRoles != null) + { + CurrentUserRole = UserRoles.FirstOrDefault(); + } + else + { + CurrentUserRole = UNDEF_ROLE; + } + + // salvo claim + var UserClaims = await _UserManager.GetClaimsAsync(user); + if (UserClaims != null && UserClaims.Count > 0) + { + var CurrentUserClaim = UserClaims.FirstOrDefault(); + CurrentUserClaimType = CurrentUserClaim.Type; + CurrentUserClaimVal = CurrentUserClaim.Value; + } + else + { + CurrentUserClaimType = STD_CLAIM; + CurrentUserClaimVal = "0"; + } + + string baseUrl = Configuration["BaseUrl"]; + string baseAppPath = Configuration["BaseAppPath"]; + string redirPage = Configuration["QrRedirPage"]; + if (!string.IsNullOrEmpty(baseAppPath)) + { + if (baseUrl.EndsWith("/")) + { + baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); + } + baseUrl = $"{baseUrl}{baseAppPath}"; + } + qrCodeVal = $"{baseUrl}Identity/Account/LogIn?uid={user.Id}&uem={user.Email}&pag={redirPage}"; + } + }); + pUpd.Wait(); + // Open the Popup + ShowPopup = true; +#endif + } + + private async Task ReloadData() + { + isLoading = true; + await GetUsers(); + isLoading = false; + } + + #endregion Private Methods } } \ No newline at end of file diff --git a/MagMan.UI/MagMan.UI.csproj b/MagMan.UI/MagMan.UI.csproj index 1bfae20..7c6eb96 100644 --- a/MagMan.UI/MagMan.UI.csproj +++ b/MagMan.UI/MagMan.UI.csproj @@ -2,7 +2,7 @@ net6.0 - 1.0.2401.3112 + 1.0.2401.3113 enable enable true diff --git a/Resources/ChangeLog.html b/Resources/ChangeLog.html index 90902bf..f064269 100644 --- a/Resources/ChangeLog.html +++ b/Resources/ChangeLog.html @@ -1,6 +1,6 @@ MagMan - Wood Warehouse Management System -

Versione: 1.0.2401.3112

+

Versione: 1.0.2401.3113


Note di rilascio:
  • diff --git a/Resources/VersNum.txt b/Resources/VersNum.txt index 9e2480b..ef50388 100644 --- a/Resources/VersNum.txt +++ b/Resources/VersNum.txt @@ -1 +1 @@ -1.0.2401.3112 +1.0.2401.3113 diff --git a/Resources/manifest.xml b/Resources/manifest.xml index 489645a..117156d 100644 --- a/Resources/manifest.xml +++ b/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.0.2401.3112 + 1.0.2401.3113 http://nexus.steamware.net/repository/SWS/MagMan/stable/0/MagMan.UI.zip http://nexus.steamware.net/repository/SWS/MagMan/stable/0/ChangeLog.html false