From 7b8fab7146775b28d1cf3486228387b2b6b8149f Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 22 Oct 2025 10:57:36 +0200 Subject: [PATCH] Completato test gestione profile list da configurazioni --- .../Services/ConfigDataService.cs | 41 ++++- .../Services/ImageCacheService.cs | 1 + Lux.API/Controllers/WindowController.cs | 2 +- .../Compo/Config/HardwareMan.razor.cs | 7 +- .../Components/Compo/Config/ProfileMan.razor | 33 +--- .../Compo/Config/ProfileMan.razor.cs | 164 ++++++++++-------- Lux.UI/Components/Compo/OfferRowMan.razor.cs | 2 +- 7 files changed, 136 insertions(+), 114 deletions(-) diff --git a/EgwCoreLib.Lux.Data/Services/ConfigDataService.cs b/EgwCoreLib.Lux.Data/Services/ConfigDataService.cs index c7be39bf..2458baa7 100644 --- a/EgwCoreLib.Lux.Data/Services/ConfigDataService.cs +++ b/EgwCoreLib.Lux.Data/Services/ConfigDataService.cs @@ -16,6 +16,7 @@ namespace EgwCoreLib.Lux.Data.Services { public class ConfigDataService : BaseServ { + #region Public Constructors public ConfigDataService(IConfiguration configuration, IConnectionMultiplexer RedisConn) : base(configuration, RedisConn) { @@ -23,11 +24,15 @@ namespace EgwCoreLib.Lux.Data.Services Log.Info($"ConfigDataService | Init OK"); } + #endregion Public Constructors + + #region Public Methods + /// - /// restituisce l'elenco dell'HW valido in memoria + /// Restituisce l'elenco dell'HW valido da cache REDIS /// /// - public List ElencoHw(Constants.EXECENVIRONMENTS execEnvironment, string HwReq = "HW.AGB") + public List HwModelList(Constants.EXECENVIRONMENTS execEnvironment, string HwReq = "HW.AGB") { List result = new List(); // leggo obj da redis cache @@ -38,16 +43,36 @@ namespace EgwCoreLib.Lux.Data.Services { var currList = JsonConvert.DeserializeObject>($"{rawData}"); result = currList ?? new List(); - //var currList = JsonConvert.DeserializeObject($"{rawData}"); - //if (currList != null && currList.ListItem != null) - //{ - // result = currList.ListItem; - //} } return result; } + /// + /// Restituisce l'elenco dei profili da cache REDIS + /// + /// + public List ProfileList(Constants.EXECENVIRONMENTS execEnvironment, string ProfReq = "Default") + { + List result = new List(); + // leggo obj da redis cache + var currKey = $"{redisBaseKey}:{execEnvironment}:PROFLIST:{ProfReq}"; + RedisValue rawData = redisDb.StringGet(currKey); + // prendo solo i valori validi (Description <> FamilyName) + if (rawData.HasValue) + { + var currList = JsonConvert.DeserializeObject>($"{rawData}"); + result = currList ?? new List(); + } + return result; + } + + #endregion Public Methods + + #region Private Fields + private static Logger Log = LogManager.GetCurrentClassLogger(); private string redisBaseKey = "Lux"; + + #endregion Private Fields } -} +} \ No newline at end of file diff --git a/EgwCoreLib.Lux.Data/Services/ImageCacheService.cs b/EgwCoreLib.Lux.Data/Services/ImageCacheService.cs index f3aa2c83..8f3fbb5d 100644 --- a/EgwCoreLib.Lux.Data/Services/ImageCacheService.cs +++ b/EgwCoreLib.Lux.Data/Services/ImageCacheService.cs @@ -27,6 +27,7 @@ namespace EgwCoreLib.Lux.Data.Services calcTag = _config.GetValue("ServerConf:ImageCalcTag") ?? "svg-preview"; bomChannel = _config.GetValue("ServerConf:BomChannel") ?? "Egw:bom"; hmlChannel = _config.GetValue("ServerConf:HwListChannel") ?? "Egw:hml"; + profListChannel = _config.GetValue("ServerConf:ProfListChannel") ?? "Egw:prof"; updateChannel = _config.GetValue("ServerConf:UpdateChannel") ?? "Egw:update"; // verifico la url base apiUrl = _config.GetValue("ServerConf:Prog.ApiUrl") ?? "https://iis01.egalware.com/lux/srv/api"; diff --git a/Lux.API/Controllers/WindowController.cs b/Lux.API/Controllers/WindowController.cs index a076ceb5..479b52aa 100644 --- a/Lux.API/Controllers/WindowController.cs +++ b/Lux.API/Controllers/WindowController.cs @@ -128,7 +128,7 @@ namespace Lux.API.Controllers Stopwatch sw = new Stopwatch(); sw.Start(); string hwReq = id ?? "HW.AGB"; - var answ = _confService.ElencoHw(EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW, hwReq); + var answ = _confService.HwModelList(EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW, hwReq); if (answ == null || answ.Count == 0) { await sendHwReq(); diff --git a/Lux.UI/Components/Compo/Config/HardwareMan.razor.cs b/Lux.UI/Components/Compo/Config/HardwareMan.razor.cs index e37b68fc..98252058 100644 --- a/Lux.UI/Components/Compo/Config/HardwareMan.razor.cs +++ b/Lux.UI/Components/Compo/Config/HardwareMan.razor.cs @@ -59,7 +59,7 @@ namespace Lux.UI.Components.Compo.Config #region Protected Methods /// - /// Reset selezione + /// Richiesta update elenco HW preferiti/configurati /// protected async Task DoReqUpdate() { @@ -143,7 +143,7 @@ namespace Lux.UI.Components.Compo.Config /// /// Effettua vera richiesta della BOM /// - /// + /// /// private async Task callRefreshHwList(string reqUid) { @@ -171,7 +171,6 @@ namespace Lux.UI.Components.Compo.Config /// /// /// - /// private void PipeHwList_EA_NewMessage(object? sender, EventArgs e) { ReloadData(); @@ -182,7 +181,7 @@ namespace Lux.UI.Components.Compo.Config private void ReloadData() { isLoading = true; - AllRecords = CDService.ElencoHw(EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW, confHw); + AllRecords = CDService.HwModelList(EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW, confHw); // se ho ricerca testuale faccio filtro ulteriore... if (string.IsNullOrEmpty(SearchVal)) { diff --git a/Lux.UI/Components/Compo/Config/ProfileMan.razor b/Lux.UI/Components/Compo/Config/ProfileMan.razor index 40a2a35e..af861de3 100644 --- a/Lux.UI/Components/Compo/Config/ProfileMan.razor +++ b/Lux.UI/Components/Compo/Config/ProfileMan.razor @@ -1,8 +1,13 @@ 
-
-
Conf. Profilo
+
+
+
Conf. Profilo
+
+
+ +
@@ -31,16 +36,7 @@ - - @* *@ - - - @@ -48,20 +44,7 @@ @foreach (var item in ListRecords) { - - - - - + } diff --git a/Lux.UI/Components/Compo/Config/ProfileMan.razor.cs b/Lux.UI/Components/Compo/Config/ProfileMan.razor.cs index e32869a3..4f2def61 100644 --- a/Lux.UI/Components/Compo/Config/ProfileMan.razor.cs +++ b/Lux.UI/Components/Compo/Config/ProfileMan.razor.cs @@ -1,3 +1,4 @@ +using EgwCoreLib.Lux.Core.RestPayload; using EgwCoreLib.Lux.Data.DbModel.Config; using EgwCoreLib.Lux.Data.Services; using Microsoft.AspNetCore.Components; @@ -6,10 +7,31 @@ using System.ComponentModel; namespace Lux.UI.Components.Compo.Config { - public partial class ProfileMan + public partial class ProfileMan : IDisposable { + #region Public Methods + + /// + /// Dispose sottoscrizione canale + /// + public void Dispose() + { + DLService.PipeProfList.EA_NewMessage -= PipeProfList_EA_NewMessage; + } + + #endregion Public Methods + #region Protected Properties + [Inject] + protected ConfigDataService CDService { get; set; } = null!; + + [Inject] + protected IConfiguration Config { get; set; } = null!; + + [Inject] + protected CalcRequestService CService { get; set; } = null!; + [Inject] protected DataLayerServices DLService { get; set; } = null!; @@ -24,7 +46,7 @@ namespace Lux.UI.Components.Compo.Config if (searchVal != value) { searchVal = value; - _ = FullUpdate(); + FullUpdate(); } } } @@ -34,52 +56,25 @@ namespace Lux.UI.Components.Compo.Config #region Protected Methods /// - /// impossta record x eliminazione + /// Richiesta update elenco HW preferiti/configurati /// - /// - protected async Task DoDelete(ProfileModel selRec) + protected async Task DoReqUpdate() { - if (!await JSRuntime.InvokeAsync("confirm", $"Sicuro di voler eliminare il record? Dettagli: {selRec.ProfileID} | {selRec.Description} | {selRec.Thickness}")) - return; - - // esegue eliminazione del record... - await DLService.ConfProfileDeleteAsync(selRec); - - EditRecord = null; - SelRecord = null; - await ReloadData(); - UpdateTable(); + // chiamata richiesta update da calc + await callRefreshProfList(); } - /// - /// Edit articolo selezionato - /// - /// - protected void DoEdit(ProfileModel curRec) + protected override void OnInitialized() { - EditRecord = curRec; + apiUrl = Config.GetValue("ServerConf:Prog.ApiUrl") ?? ""; + genericBasePath = Config.GetValue("ServerConf:GenericBaseUrl") ?? ""; + calcTag = Config.GetValue("ServerConf:CalcTag") ?? "calc"; + DLService.PipeProfList.EA_NewMessage += PipeProfList_EA_NewMessage; } - /// - /// Reset selezione - /// - protected void DoReset() + protected override void OnParametersSet() { - EditRecord = null; - } - - /// - /// Selezione articolo x display info - /// - /// - protected void DoSelect(ProfileModel curRec) - { - SelRecord = curRec; - } - - protected override async Task OnParametersSetAsync() - { - await ReloadData(); + ReloadData(); UpdateTable(); } @@ -104,13 +99,27 @@ namespace Lux.UI.Components.Compo.Config #region Private Fields - private List AllRecords = new(); + private List AllRecords = new(); + + private string apiUrl = ""; + + private string calcTag = "calc"; + + /// + /// Per eventuale gestione multi-profilo su multi tenant + /// + private string confProf = "Default"; + private int currPage = 1; - private ProfileModel? EditRecord = null; + + private string genericBasePath = "generic"; + private bool isLoading = false; - private List ListRecords = new(); + + private List ListRecords = new(); + private int numRecord = 5; - private ProfileModel? SelRecord = null; + private int totalCount = 0; #endregion Private Fields @@ -128,65 +137,70 @@ namespace Lux.UI.Components.Compo.Config #region Private Methods - private async Task DoAdd() + /// + /// Effettua vera richiesta della BOM + /// + /// + private async Task callRefreshProfList() { - // aggiungo un nuovo record in coda... - EditRecord = new ProfileModel() + Dictionary DictExec = new Dictionary(); + DictExec.Add("Mode", $"{(int)Egw.Window.Data.Enums.QuestionModes.CONFIG}"); + // preparo args + string reqUid = "Default"; + DictExec.Add("UID", reqUid); + DictExec.Add("SubMode", $"{(int)Egw.Window.Data.Enums.QuestionConfSubModes.PROFILELIST}"); + CalcRequestDTO req = new CalcRequestDTO() { - Description = "New Glass", - Code = "", - Thickness = 30 + EnvType = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW, + DictExec = DictExec }; - await DoSave(EditRecord); + // svuotiamo cache dati... + AllRecords = new List(); + isLoading = true; + + // chiamo la chiamata POST alla API, che manda la richiesta via REDIS + await CService.CallRestPost($"{apiUrl}/{genericBasePath}", $"{calcTag}/{reqUid}", req); } - private async Task DoSave(ProfileModel currRec) + private void FullUpdate() { - // salvo - await DLService.ConfProfileUpsertAsync(currRec); - await ResetEdit(); + ReloadData(); UpdateTable(); - EditRecord = null; - SelRecord = null; } - private async Task FullUpdate() + /// + /// Ricevuto update da Calc x elenco profili: aggiorno! + /// + /// + /// + private void PipeProfList_EA_NewMessage(object? sender, EventArgs e) { - await ReloadData(); - UpdateTable(); - await InvokeAsync(StateHasChanged); + FullUpdate(); + _ = InvokeAsync(StateHasChanged); } - private async Task ReloadData() + private void ReloadData() { isLoading = true; - AllRecords = await DLService.ConfProfileGetAllAsync(); + + AllRecords = CDService.ProfileList(EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW, confProf); // se ho ricerca testuale faccio filtro ulteriore... if (string.IsNullOrEmpty(SearchVal)) { AllRecords = AllRecords - .OrderBy(x => x.Description) + .OrderBy(x => x) .ToList(); } else { AllRecords = AllRecords - .Where(x => - x.Description.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase) || - x.Code.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase)) - .OrderBy(x => x.Description) + .Where(x => x.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase)) + .OrderBy(x => x) .ToList(); } totalCount = AllRecords.Count; } - private async Task ResetEdit() - { - // reset edit - EditRecord = null; - await ReloadData(); - } - /// /// Filtro e paginazione /// diff --git a/Lux.UI/Components/Compo/OfferRowMan.razor.cs b/Lux.UI/Components/Compo/OfferRowMan.razor.cs index 00ce3ebc..e48d11f8 100644 --- a/Lux.UI/Components/Compo/OfferRowMan.razor.cs +++ b/Lux.UI/Components/Compo/OfferRowMan.razor.cs @@ -892,7 +892,7 @@ namespace Lux.UI.Components.Compo // lettura config setup varie da DB/Cache Redis AllConfEnvir = await DLService.ConfEnvirParamGetAllAsync(); AllConfGlass = await DLService.ConfGlassGetAllAsync(); - var rawHw = CDService.ElencoHw(EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW, "HW.AGB"); + var rawHw = CDService.HwModelList(EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW, "HW.AGB"); // hw filtro solo validi... AllConfHardware = rawHw .Where(x => !x.FamilyName.Equals(x.Description, StringComparison.OrdinalIgnoreCase))
- - IDCod.DescrizioneSize mm - -
@item.ProfileID@item.Code@item.Description@($"{item.Thickness:N2}") - @if (false) - { - - } - else - { - - } - @item