From d37ed441066e392a26a5dd0f35ae8a0057a6d5d0 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 16 Apr 2025 19:49:11 +0200 Subject: [PATCH 1/6] SPEC: - Update gestione cambio titolo automatico --- MP.Core/Utils.cs | 1 + MP.SPEC/Components/CmpTop.razor | 5 +- MP.SPEC/Components/CmpTop.razor.cs | 81 +++++++++++++------ .../Components/Reparti/ListReparti.razor.cs | 36 +++++---- MP.SPEC/Data/MsgServiceSpec.cs | 78 +++++++++++++++++- .../Extensions/NavigationManagerExtension.cs | 51 ++++++++++++ MP.SPEC/MP.SPEC.csproj | 2 +- MP.SPEC/Pages/GroupMacOprMan.razor.cs | 1 + MP.SPEC/Pages/Index.razor | 1 + MP.SPEC/Resources/ChangeLog.html | 2 +- MP.SPEC/Resources/VersNum.txt | 2 +- MP.SPEC/Resources/manifest.xml | 2 +- MP.SPEC/Shared/NavMenu.razor | 2 +- MP.SPEC/Shared/NavMenu.razor.cs | 6 +- 14 files changed, 219 insertions(+), 51 deletions(-) create mode 100644 MP.SPEC/Extensions/NavigationManagerExtension.cs diff --git a/MP.Core/Utils.cs b/MP.Core/Utils.cs index 0ae6198e..d4bfc95f 100644 --- a/MP.Core/Utils.cs +++ b/MP.Core/Utils.cs @@ -198,5 +198,6 @@ namespace MP.Core } #endregion Public Methods + } } \ No newline at end of file diff --git a/MP.SPEC/Components/CmpTop.razor b/MP.SPEC/Components/CmpTop.razor index 7d7009c8..c386b0a7 100644 --- a/MP.SPEC/Components/CmpTop.razor +++ b/MP.SPEC/Components/CmpTop.razor @@ -8,11 +8,14 @@
@userName
+
+ @PageName +
- +
diff --git a/MP.SPEC/Components/CmpTop.razor.cs b/MP.SPEC/Components/CmpTop.razor.cs index 74cd7038..9ea20a54 100644 --- a/MP.SPEC/Components/CmpTop.razor.cs +++ b/MP.SPEC/Components/CmpTop.razor.cs @@ -1,39 +1,51 @@ using Amazon.Runtime.Internal.Endpoints.StandardLibrary; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Authorization; +using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.JSInterop; using MP.AppAuth.Services; using MP.SPEC.Data; +using MP.SPEC.Extensions; using System; namespace MP.SPEC.Components { - public partial class CmpTop + public partial class CmpTop : IDisposable { #region Public Methods - public async Task flushCache() + public void Dispose() { - await Task.Delay(1); - await MDService.FlushRedisCache(); - await Task.Delay(1); - await ForceReload(); - // rimando a pagina corrente - NavManager.NavigateTo(NavManager.Uri, true); + MService.EA_PageUpdated -= OnPageUpdate; + NavManager.LocationChanged -= NavManager_LocationChanged; + } + + public void OnPageUpdate() + { + PageName = MService.PageName; + PageIcon = MService.PageIcon; + InvokeAsync(() => + { + StateHasChanged(); + }); } #endregion Public Methods #region Protected Properties + [Inject] + protected AppAuthService AAService { get; set; } = null!; + + [Inject] + protected AuthenticationStateProvider AuthStateProv { get; set; } = null!; + [Inject] protected IJSRuntime JSRuntime { get; set; } = null!; [Inject] protected MpDataService MDService { get; set; } = null!; - [Inject] - protected AuthenticationStateProvider AuthStateProv { get; set; } = null!; [Inject] protected MsgServiceSpec MService { get; set; } = null!; @@ -41,15 +53,44 @@ namespace MP.SPEC.Components #region Protected Methods + protected async Task FlushCache() + { + await MDService.FlushRedisCache(); + await ForceReload(); + // rimando a pagina corrente + NavManager.NavigateTo(NavManager.Uri, true); + } + protected override async Task OnInitializedAsync() { await ForceReload(); + MService.EA_PageUpdated += OnPageUpdate; + NavManager.LocationChanged += NavManager_LocationChanged; } + private void NavManager_LocationChanged(object? sender, Microsoft.AspNetCore.Components.Routing.LocationChangedEventArgs e) + { + // update testo pagina da URI + string pageUri = NavManager.Page(); + // verifica pagina x permessi + if (MService.ElencoLink != null) + { + var recLink = MService.ElencoLink.FirstOrDefault(x => x.NavigateUrl == pageUri); + if (recLink != null) + { + MService.PageIcon = recLink.Icona; + MService.PageName = recLink.Testo; + } + } + } + + #endregion Protected Methods #region Private Fields + private string PageIcon = ""; + private string PageName = ""; private string userName = ""; #endregion Private Fields @@ -58,11 +99,6 @@ namespace MP.SPEC.Components [Inject] private NavigationManager NavManager { get; set; } = null!; - [Inject] - private MsgServiceSpec MsgServ { get; set; } = null!; - [Inject] - protected AppAuthService AAService { get; set; } = null!; - #endregion Private Properties @@ -79,13 +115,13 @@ namespace MP.SPEC.Components var userData = userName.Split(@"\"); if (userData.Length > 1) { - MsgServ.DomainName = userData[0]; - MsgServ.UserName = userData[1]; + MService.DomainName = userData[0]; + MService.UserName = userData[1]; // recupero diritti e salvo... - var UserRightList = await AAService.DirittiGetByUser(MsgServ.UserName); + var UserRightList = await AAService.DirittiGetByUser(MService.UserName); if (UserRightList != null) { - MsgServ.UserRight = UserRightList.Select(x => x.Funzione).ToList(); + MService.UserRight = UserRightList.Select(x => x.Funzione).ToList(); } } } @@ -95,12 +131,7 @@ namespace MP.SPEC.Components } } - private async void MService_EA_ShowSearch() - { - await Task.Delay(1); - await InvokeAsync(() => StateHasChanged()); - } - #endregion Private Methods + } } \ No newline at end of file diff --git a/MP.SPEC/Components/Reparti/ListReparti.razor.cs b/MP.SPEC/Components/Reparti/ListReparti.razor.cs index 0b85388b..f95b835b 100644 --- a/MP.SPEC/Components/Reparti/ListReparti.razor.cs +++ b/MP.SPEC/Components/Reparti/ListReparti.razor.cs @@ -25,29 +25,23 @@ namespace MP.SPEC.Components.Reparti #region Protected Properties - [Inject] - protected IJSRuntime JSRuntime { get; set; } = null!; - - [Inject] - protected MpDataService MDService { get; set; } = null!; - [Inject] - protected MsgServiceSpec MsgService { get; set; } = null!; - - #endregion Protected Properties - protected bool IsSuperAdmin { get => HasRole(AppAuthService.RoleSuperAdmin); } - #region Protected Methods + [Inject] + protected IJSRuntime JSRuntime { get; set; } = null!; - protected override void OnInitialized() - { - SelRecord = null; - EditRec = null; - numRecord = 10; - } + [Inject] + protected MpDataService MDService { get; set; } = null!; + + [Inject] + protected MsgServiceSpec MsgService { get; set; } = null!; + + #endregion Protected Properties + + #region Protected Methods /// /// Verifica ruolo utente @@ -58,6 +52,14 @@ namespace MP.SPEC.Components.Reparti { return MsgService.HasRole(Ruolo); } + + protected override void OnInitialized() + { + SelRecord = null; + EditRec = null; + numRecord = 10; + } + protected override void OnParametersSet() { isLoading = true; diff --git a/MP.SPEC/Data/MsgServiceSpec.cs b/MP.SPEC/Data/MsgServiceSpec.cs index 559804e1..a6658de8 100644 --- a/MP.SPEC/Data/MsgServiceSpec.cs +++ b/MP.SPEC/Data/MsgServiceSpec.cs @@ -1,4 +1,5 @@ -using MP.AppAuth.Models; +using Microsoft.AspNetCore.Components; +using MP.AppAuth.Models; namespace MP.SPEC.Data { @@ -8,6 +9,8 @@ namespace MP.SPEC.Data public event Action EA_BroadCastMsg = null!; + public event Action EA_PageUpdated = null!; + #endregion Public Events #region Public Properties @@ -17,6 +20,11 @@ namespace MP.SPEC.Data /// public string DomainName { get; set; } = ""; + /// + /// Elenco link utente + /// + public List? ElencoLink { get; set; } = null; + public string newBCMsg { get => _newBCMsg; @@ -30,6 +38,32 @@ namespace MP.SPEC.Data } } + public string PageIcon + { + get => _pageIcon; + set + { + if (_pageIcon != value) + { + _pageIcon = value; + ReportPageUpd(); + } + } + } + + public string PageName + { + get => _pageName; + set + { + if (_pageName != value) + { + _pageName = value; + ReportPageUpd(); + } + } + } + /// /// Username utente /// @@ -40,6 +74,10 @@ namespace MP.SPEC.Data /// public List UserRight { get; set; } = new List(); + #endregion Public Properties + + #region Public Methods + /// /// Verifica ruolo utente /// @@ -57,7 +95,36 @@ namespace MP.SPEC.Data return answ; } - #endregion Public Properties + /// + /// Segnala cambio pagina + /// + /// + public void ReportPageUpd() + { + if (EA_PageUpdated != null) + { + EA_PageUpdated?.Invoke(); + } + } + + /// + /// Imposta i dati della pagina corrente dato l'url + /// + /// + public void SetPage(string pageUrl) + { + if (ElencoLink != null) + { + var recLink = ElencoLink.FirstOrDefault(x => x.NavigateUrl == pageUrl); + if (recLink != null) + { + _pageIcon = recLink.Icona; + PageName = recLink.Testo; + } + } + } + + #endregion Public Methods #region Protected Methods @@ -71,6 +138,13 @@ namespace MP.SPEC.Data #endregion Protected Methods + #region Private Fields + + private string _pageIcon = ""; + private string _pageName = ""; + + #endregion Private Fields + #region Private Properties private string _newBCMsg { get; set; } = ""; diff --git a/MP.SPEC/Extensions/NavigationManagerExtension.cs b/MP.SPEC/Extensions/NavigationManagerExtension.cs new file mode 100644 index 00000000..9383180a --- /dev/null +++ b/MP.SPEC/Extensions/NavigationManagerExtension.cs @@ -0,0 +1,51 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.WebUtilities; + +namespace MP.SPEC.Extensions +{ + public static class NavigationManagerExtension + { + #region Public Methods + + /// + /// Estensione metodo NavigationManager x recupero querystring + /// + /// https://code-maze.com/query-strings-blazor-webassembly/ + /// + /// + /// + /// + /// + public static T ExtractQueryStringByKey(this NavigationManager navManager, string key) + { + var uri = navManager.ToAbsoluteUri(navManager.Uri); + QueryHelpers.ParseQuery(uri.Query) + .TryGetValue(key, out var queryValue); + + if (typeof(T).Equals(typeof(int))) + { + int.TryParse(queryValue, out int result); + return (T)(object)result; + } + + if (typeof(T).Equals(typeof(string))) + return (T)(object)queryValue.ToString(); + + return default; + } + + /// + /// Recupero base page + /// + /// https://stackoverflow.com/questions/50102726/navigationmanager-get-current-url-in-a-blazor-component + /// + /// + /// + public static string Page(this NavigationManager navigation) + { + return navigation.Uri.Substring(navigation.BaseUri.Length); + } + + #endregion Public Methods + } +} diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj index c0036644..f0c0c372 100644 --- a/MP.SPEC/MP.SPEC.csproj +++ b/MP.SPEC/MP.SPEC.csproj @@ -5,7 +5,7 @@ enable enable MP.SPEC - 6.16.2504.1617 + 6.16.2504.1619 1800a78a-6ff1-40f9-b490-87fb8bfc1394 en diff --git a/MP.SPEC/Pages/GroupMacOprMan.razor.cs b/MP.SPEC/Pages/GroupMacOprMan.razor.cs index b1ccebeb..68566d90 100644 --- a/MP.SPEC/Pages/GroupMacOprMan.razor.cs +++ b/MP.SPEC/Pages/GroupMacOprMan.razor.cs @@ -2,6 +2,7 @@ using DnsClient.Protocol; using Microsoft.AspNetCore.Components; using MP.Core.DTO; using MP.Data.DbModels; +using MP.Data.Services; using MP.SPEC.Data; namespace MP.SPEC.Pages diff --git a/MP.SPEC/Pages/Index.razor b/MP.SPEC/Pages/Index.razor index eebb6da4..67cd4745 100644 --- a/MP.SPEC/Pages/Index.razor +++ b/MP.SPEC/Pages/Index.razor @@ -1,4 +1,5 @@ @page "/" +@page "/Home" @page "/Index" Index diff --git a/MP.SPEC/Resources/ChangeLog.html b/MP.SPEC/Resources/ChangeLog.html index bb81bb2b..6d4c500c 100644 --- a/MP.SPEC/Resources/ChangeLog.html +++ b/MP.SPEC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

Versione: 6.16.2504.1617

+

Versione: 6.16.2504.1619


Note di rilascio:
  • diff --git a/MP.SPEC/Resources/VersNum.txt b/MP.SPEC/Resources/VersNum.txt index 02219081..1873fc1a 100644 --- a/MP.SPEC/Resources/VersNum.txt +++ b/MP.SPEC/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2504.1617 +6.16.2504.1619 diff --git a/MP.SPEC/Resources/manifest.xml b/MP.SPEC/Resources/manifest.xml index 2bd31486..b00307ff 100644 --- a/MP.SPEC/Resources/manifest.xml +++ b/MP.SPEC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2504.1617 + 6.16.2504.1619 https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html false diff --git a/MP.SPEC/Shared/NavMenu.razor b/MP.SPEC/Shared/NavMenu.razor index e089c51b..081e58ae 100644 --- a/MP.SPEC/Shared/NavMenu.razor +++ b/MP.SPEC/Shared/NavMenu.razor @@ -21,7 +21,7 @@