From 91591aaae8df7e236e7dc7e54d5173939e72e42a Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Sat, 30 Sep 2023 11:49:50 +0200 Subject: [PATCH] Aggiunta memorystorage x dati ripetuti --- .../Components/TcHistoryFilter.razor | 22 +++++-- MP-TAB/MP-TAB.Client/Pages/StatusMap.razor | 4 +- MP-TAB/MP-TAB.Client/Program.cs | 5 ++ MP-TAB/MP-TAB/Components/App.razor | 3 +- .../MP-TAB/Components/Layout/MainLayout.razor | 22 +++++-- MP-TAB/MP-TAB/Components/Layout/NavMenu.razor | 3 +- .../MP-TAB/Components/Layout/SlideMenu.razor | 15 +++++ .../MP-TAB/Components/Pages/StatusMap.razor | 6 +- MP-TAB/MP-TAB/Components/_Imports.razor | 4 ++ MP-TAB/MP-TAB/Controllers/ODLController.cs | 2 +- MP-TAB/MP-TAB/MP-TAB.csproj | 6 ++ MP-TAB/MP-TAB/Program.cs | 1 + MP-TAB/MP-TAB/wwwroot/favicon.png | Bin 1148 -> 0 bytes .../MP-TAB/wwwroot/{ => images}/favicon.ico | Bin MP.Data/Controllers/MpSpecController.cs | 10 ++-- MP.Data/Services/MemStorUtil.cs | 55 ++++++++++++++++++ 16 files changed, 133 insertions(+), 25 deletions(-) create mode 100644 MP-TAB/MP-TAB/Components/Layout/SlideMenu.razor delete mode 100644 MP-TAB/MP-TAB/wwwroot/favicon.png rename MP-TAB/MP-TAB/wwwroot/{ => images}/favicon.ico (100%) create mode 100644 MP.Data/Services/MemStorUtil.cs diff --git a/MP-TAB/MP-TAB.Client/Components/TcHistoryFilter.razor b/MP-TAB/MP-TAB.Client/Components/TcHistoryFilter.razor index c59af214..7e82ac44 100644 --- a/MP-TAB/MP-TAB.Client/Components/TcHistoryFilter.razor +++ b/MP-TAB/MP-TAB.Client/Components/TcHistoryFilter.razor @@ -1,7 +1,9 @@ -@using NLog; +@using MP.Data.Services; +@using NLog; @using System.Net.Http @using System.Net.Http.Json @inject HttpClient Http +@inject MemStorUtil CIServ
@@ -141,11 +143,14 @@ } protected async Task ReloadMacchine() { - string ApiUrl = $"{BaseAddr}api/ListSelect/GetDictMacc?MatrOpr={MatrOpr}"; - var rawData = await Http.GetFromJsonAsync>(ApiUrl); - if (rawData != null) + if (ListMacchineAll == null || ListMacchineAll.Count == 0) { - ListMacchineAll = rawData; + string ApiUrl = $"{BaseAddr}api/ListSelect/GetDictMacc?MatrOpr={MatrOpr}"; + var rawData = await Http.GetFromJsonAsync>(ApiUrl); + if (rawData != null) + { + ListMacchineAll = rawData; + } } } @@ -194,7 +199,12 @@ } protected string IdxMaccSel { get; set; } = ""; - protected Dictionary ListMacchineAll { get; set; } = new Dictionary(); + protected Dictionary ListMacchineAll + { + get => MemStorUtil.DictMacchine; + set => MemStorUtil.DictMacchine = value; + } + protected Dictionary ListArticoliAll { get; set; } = new Dictionary(); protected Dictionary? ListArticoli { get; set; } = null; protected int TotalCount { get; set; } = 0; diff --git a/MP-TAB/MP-TAB.Client/Pages/StatusMap.razor b/MP-TAB/MP-TAB.Client/Pages/StatusMap.razor index d8e54b27..8c086c66 100644 --- a/MP-TAB/MP-TAB.Client/Pages/StatusMap.razor +++ b/MP-TAB/MP-TAB.Client/Pages/StatusMap.razor @@ -1,5 +1,5 @@ -@* @attribute [RenderModeAuto] *@ -@attribute [RenderModeServer] +@attribute [RenderModeAuto] +@* @attribute [RenderModeServer] *@ @using MP.Data.Services; @using MP.Data; diff --git a/MP-TAB/MP-TAB.Client/Program.cs b/MP-TAB/MP-TAB.Client/Program.cs index 7eeaa159..6d829ac2 100644 --- a/MP-TAB/MP-TAB.Client/Program.cs +++ b/MP-TAB/MP-TAB.Client/Program.cs @@ -1,7 +1,11 @@ using Microsoft.AspNetCore.Components.WebAssembly.Hosting; +using MP.Data.Services; var builder = WebAssemblyHostBuilder.CreateDefault(args); +// servizio cache locale dati +builder.Services.AddScoped(); + // aggiunto x gestione chiamate WebAPI builder.Services.AddScoped(sp => new HttpClient @@ -9,4 +13,5 @@ builder.Services.AddScoped(sp => BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); + await builder.Build().RunAsync(); diff --git a/MP-TAB/MP-TAB/Components/App.razor b/MP-TAB/MP-TAB/Components/App.razor index 040d30a9..2f9c30df 100644 --- a/MP-TAB/MP-TAB/Components/App.razor +++ b/MP-TAB/MP-TAB/Components/App.razor @@ -9,9 +9,8 @@ - + - @* *@ diff --git a/MP-TAB/MP-TAB/Components/Layout/MainLayout.razor b/MP-TAB/MP-TAB/Components/Layout/MainLayout.razor index 4584de42..c11f0962 100644 --- a/MP-TAB/MP-TAB/Components/Layout/MainLayout.razor +++ b/MP-TAB/MP-TAB/Components/Layout/MainLayout.razor @@ -1,5 +1,8 @@ @inherits LayoutComponentBase + +@inject NavigationManager NavMan @inject ListSelectDataSrv MDataService +@inject MemStorUtil MStor
@@ -21,7 +24,7 @@ @*
*@
- +
@@ -32,7 +35,7 @@ @Body
@@ -50,10 +53,11 @@ /// Elenco items da menù per pagina corrente... /// protected List CurrMenuItems { get; set; } = new List(); + /// /// Livello corrente del menu /// - protected string CurrLevel = "T2H"; + protected string CurrLevel { get; set; } = ""; /// /// Init struttura dati @@ -61,8 +65,16 @@ /// protected override async Task OnInitializedAsync() { + CurrLevel = MemStorUtil.PageLevel(NavMan.Uri); + if (MemStorUtil.DictMenu.ContainsKey(CurrLevel)) + { + CurrMenuItems = MemStorUtil.DictMenu[CurrLevel]; + } + else + { + CurrMenuItems = await MDataService.ListLinkFilt(CurrLevel); + MemStorUtil.DictMenu.Add(CurrLevel, CurrMenuItems); + } await Task.Delay(1); - CurrMenuItems = await MDataService.ListLinkFilt(CurrLevel); - // return base.OnInitializedAsync(); } } \ No newline at end of file diff --git a/MP-TAB/MP-TAB/Components/Layout/NavMenu.razor b/MP-TAB/MP-TAB/Components/Layout/NavMenu.razor index ad904f29..8cf6091f 100644 --- a/MP-TAB/MP-TAB/Components/Layout/NavMenu.razor +++ b/MP-TAB/MP-TAB/Components/Layout/NavMenu.razor @@ -1,4 +1,5 @@ -@inject ListSelectDataSrv MDataService +@inject NavigationManager NavMan +@inject ListSelectDataSrv MDataService @*
*@ @*
diff --git a/MP-TAB/MP-TAB/Components/Layout/SlideMenu.razor b/MP-TAB/MP-TAB/Components/Layout/SlideMenu.razor new file mode 100644 index 00000000..f569bac8 --- /dev/null +++ b/MP-TAB/MP-TAB/Components/Layout/SlideMenu.razor @@ -0,0 +1,15 @@ +@inject NavigationManager NavMan +@inject ListSelectDataSrv MDataService +@inject MemStorUtil MStor + +@* @attribute [StreamRendering(true)] *@ + + + + +@code { + + [Parameter] + public List MenuItems { get; set; } = new List(); + +} diff --git a/MP-TAB/MP-TAB/Components/Pages/StatusMap.razor b/MP-TAB/MP-TAB/Components/Pages/StatusMap.razor index 81c3810e..43783059 100644 --- a/MP-TAB/MP-TAB/Components/Pages/StatusMap.razor +++ b/MP-TAB/MP-TAB/Components/Pages/StatusMap.razor @@ -4,9 +4,6 @@ @* @attribute [StreamRendering(true)] *@ - - - @* @if (listMSE == null || listMSE.Count == 0) {
@@ -21,4 +18,7 @@ else { } *@ + + + diff --git a/MP-TAB/MP-TAB/Components/_Imports.razor b/MP-TAB/MP-TAB/Components/_Imports.razor index 40a1a57c..8bb2ba63 100644 --- a/MP-TAB/MP-TAB/Components/_Imports.razor +++ b/MP-TAB/MP-TAB/Components/_Imports.razor @@ -12,3 +12,7 @@ @using MP.Data.Services @using MP_TAB @using MP_TAB.Components +@* +@using MP_TAB.Client.Components +@using MP_TAB.Client.Pages +*@ \ No newline at end of file diff --git a/MP-TAB/MP-TAB/Controllers/ODLController.cs b/MP-TAB/MP-TAB/Controllers/ODLController.cs index 3e62d12a..a6a0b3eb 100644 --- a/MP-TAB/MP-TAB/Controllers/ODLController.cs +++ b/MP-TAB/MP-TAB/Controllers/ODLController.cs @@ -20,7 +20,7 @@ namespace MP_TAB.Controllers Log.Info("Starting ODLController"); _configuration = configuration; CtrDataServ = DataService; - Log.Info("Avviato ODLController"); + Log.Trace("Avviato ODLController"); } #endregion Public Constructors diff --git a/MP-TAB/MP-TAB/MP-TAB.csproj b/MP-TAB/MP-TAB/MP-TAB.csproj index 09aa5521..614b03dd 100644 --- a/MP-TAB/MP-TAB/MP-TAB.csproj +++ b/MP-TAB/MP-TAB/MP-TAB.csproj @@ -110,6 +110,12 @@ Always + + Always + + + Always + Always diff --git a/MP-TAB/MP-TAB/Program.cs b/MP-TAB/MP-TAB/Program.cs index 8228ff64..862cc434 100644 --- a/MP-TAB/MP-TAB/Program.cs +++ b/MP-TAB/MP-TAB/Program.cs @@ -19,6 +19,7 @@ builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddScoped(); +builder.Services.AddScoped(); // nuova versione contenuti... builder.Services.AddRazorComponents() diff --git a/MP-TAB/MP-TAB/wwwroot/favicon.png b/MP-TAB/MP-TAB/wwwroot/favicon.png deleted file mode 100644 index 8422b59695935d180d11d5dbe99653e711097819..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1148 zcmV-?1cUpDP)9h26h2-Cs%i*@Moc3?#6qJID|D#|3|2Hn7gTIYEkr|%Xjp);YgvFmB&0#2E2b=| zkVr)lMv9=KqwN&%obTp-$<51T%rx*NCwceh-E+=&e(oLO`@Z~7gybJ#U|^tB2Pai} zRN@5%1qsZ1e@R(XC8n~)nU1S0QdzEYlWPdUpH{wJ2Pd4V8kI3BM=)sG^IkUXF2-j{ zrPTYA6sxpQ`Q1c6mtar~gG~#;lt=s^6_OccmRd>o{*=>)KS=lM zZ!)iG|8G0-9s3VLm`bsa6e ze*TlRxAjXtm^F8V`M1%s5d@tYS>&+_ga#xKGb|!oUBx3uc@mj1%=MaH4GR0tPBG_& z9OZE;->dO@`Q)nr<%dHAsEZRKl zedN6+3+uGHejJp;Q==pskSAcRcyh@6mjm2z-uG;s%dM-u0*u##7OxI7wwyCGpS?4U zBFAr(%GBv5j$jS@@t@iI8?ZqE36I^4t+P^J9D^ELbS5KMtZ z{Qn#JnSd$15nJ$ggkF%I4yUQC+BjDF^}AtB7w348EL>7#sAsLWs}ndp8^DsAcOIL9 zTOO!!0!k2`9BLk25)NeZp7ev>I1Mn={cWI3Yhx2Q#DnAo4IphoV~R^c0x&nw*MoIV zPthX?{6{u}sMS(MxD*dmd5rU(YazQE59b|TsB5Tm)I4a!VaN@HYOR)DwH1U5y(E)z zQqQU*B%MwtRQ$%x&;1p%ANmc|PkoFJZ%<-uq%PX&C!c-7ypis=eP+FCeuv+B@h#{4 zGx1m0PjS~FJt}3mdt4c!lel`1;4W|03kcZRG+DzkTy|7-F~eDsV2Tx!73dM0H0CTh zl)F-YUkE1zEzEW(;JXc|KR5{ox%YTh{$%F$a36JP6Nb<0%#NbSh$dMYF-{ z1_x(Vx)}fs?5_|!5xBTWiiIQHG<%)*e=45Fhjw_tlnmlixq;mUdC$R8v#j( zhQ$9YR-o%i5Uc`S?6EC51!bTRK=Xkyb<18FkCKnS2;o*qlij1YA@-nRpq#OMTX&RbL<^2q@0qja!uIvI;j$6>~k@IMwD42=8$$!+R^@5o6HX(*n~ x.TipoLink == tipoLink) - .AsNoTracking() - .OrderBy(x => x.ordine) - .ToList(); + .DbSetLinkMenu + .Where(x => x.TipoLink == tipoLink) + .AsNoTracking() + .OrderBy(x => x.ordine) + .ToList(); } return dbResult; } diff --git a/MP.Data/Services/MemStorUtil.cs b/MP.Data/Services/MemStorUtil.cs new file mode 100644 index 00000000..c605d146 --- /dev/null +++ b/MP.Data/Services/MemStorUtil.cs @@ -0,0 +1,55 @@ +using MP.Data.DatabaseModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MP.Data.Services +{ + public class MemStorUtil + { + + /// + /// Matricola operatore corrente (x filtraggio dati) + /// ToDo: gestire login!!! + /// + public static int MatrOpr = 102; + + /// + /// Dizionario macchine + /// + public static Dictionary DictMacchine { get; set; } = new Dictionary(); + + /// + /// Dizionario Menu + /// + public static Dictionary> DictMenu {get;set;} = new Dictionary>(); + + /// + /// Reset cache memory + /// + public void ResetCache() + { + DictMacchine = new Dictionary(); + DictMenu = new Dictionary>(); + } + + /// + /// Restituisce il livello pagina dato URL + /// - se contiene ?IdxMacc --> T2D (detail) + /// - altrimenti --> T2H + /// + /// + /// + public static string PageLevel(string pageUrl) + { + string answ = "T2H"; + if(pageUrl.Contains("?IdxMacc=")) + { + answ = "T2D"; + } + return answ; + } + } +}