using EgwCoreLib.Lux.Core.RestPayload; using EgwCoreLib.Lux.Data.DbModel.Config; using EgwCoreLib.Lux.Data.DbModel.Sales; using EgwCoreLib.Lux.Data.Services; using EgwMultiEngineManager.Data; using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using System.Threading.Tasks; namespace Lux.UI.Components.Compo.Config { public partial class HardwareMan : IDisposable { #region Public Methods /// /// Dispose sottoscrizione canale /// public void Dispose() { DLService.PipeHwList.EA_NewMessage -= PipeHwList_EA_NewMessage; } #endregion Public Methods #region Protected Properties [Inject] protected ConfigDataService CDService { get; set; } = null!; [Inject] protected IConfiguration Config { get; set; } = null!; [Inject] protected CalcRuidService CRService { get; set; } = null!; [Inject] protected CalcRequestService CService { get; set; } = null!; [Inject] protected DataLayerServices DLService { get; set; } = null!; [Inject] protected IJSRuntime JSRuntime { get; set; } = null!; protected string SearchVal { get => searchVal; set { if (searchVal != value) { searchVal = value; ReloadData(); UpdateTable(); } } } #endregion Protected Properties #region Protected Methods /// /// Richiesta update elenco HW preferiti/configurati /// protected async Task DoReqUpdate() { // chiamata richiesta update da calc await callRefreshHwList(confHw); } protected override void OnInitialized() { apiUrl = Config.GetValue("ServerConf:Prog.ApiUrl") ?? ""; genericBasePath = Config.GetValue("ServerConf:GenericBaseUrl") ?? ""; calcTag = Config.GetValue("ServerConf:CalcTag") ?? "calc"; DLService.PipeHwList.EA_NewMessage += PipeHwList_EA_NewMessage; } protected override void OnParametersSet() { ReloadData(); UpdateTable(); } protected void ResetSearch() { SearchVal = ""; } protected void SaveNumRec(int newNum) { numRecord = newNum; UpdateTable(); } protected void SavePage(int newNum) { currPage = newNum; UpdateTable(); } #endregion Protected Methods #region Private Fields private List AllRecords = new(); private string apiUrl = ""; private string calcTag = "calc"; private Constants.EXECENVIRONMENTS cEnvir = Constants.EXECENVIRONMENTS.WINDOW; /// /// Conf HW corrente (produttore) - gestire con conf? /// private string confHw = "HW.AGB"; private int currPage = 1; private string genericBasePath = "generic"; private bool isLoading = false; private List ListRecords = new(); private int numRecord = 5; private int totalCount = 0; #endregion Private Fields #region Private Properties private string btnResetCss { get => string.IsNullOrEmpty(searchVal) ? "btn-outline-light" : "btn-primary"; } private string searchVal { get; set; } = string.Empty; #endregion Private Properties #region Private Methods /// /// Effettua vera richiesta della BOM /// /// /// private async Task callRefreshHwList(string reqUid) { Dictionary DictExec = new Dictionary(); var cMode = Egw.Window.Data.Enums.QuestionModes.HARDWARE; var cSubMode = Egw.Window.Data.Enums.QuestionHwSubModes.LIST; var cManufact = Egw.Window.Data.Enums.HardwareManufacturers.AGB; // compongo righiesta DictExec.Add("Mode", $"{(int)cMode}"); DictExec.Add("UID", reqUid); // creo registrazione richiesta... var ruid = await CRService.AddRequestAsync($"{cEnvir}", $"{cMode}-{cSubMode}", reqUid); // aggiungo RUID effettivo DictExec.Add("RUID", ruid); DictExec.Add("SubMode", $"{(int)cSubMode}"); DictExec.Add("Manufacturer", $"{(int)cManufact}"); CalcRequestDTO req = new CalcRequestDTO() { EnvType = cEnvir, DictExec = DictExec }; // 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); } /// /// Ricevuto update da Calc x elenco HW: aggiorno! /// /// /// private void PipeHwList_EA_NewMessage(object? sender, EventArgs e) { ReloadData(); UpdateTable(); _ = InvokeAsync(StateHasChanged); } private void ReloadData() { isLoading = true; AllRecords = CDService.HwModelList(cEnvir, confHw); // se ho ricerca testuale faccio filtro ulteriore... if (string.IsNullOrEmpty(SearchVal)) { AllRecords = AllRecords .OrderBy(x => x.Description) .ToList(); } else { AllRecords = AllRecords .Where(x => x.Description.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase) || x.FamilyName.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase)) .OrderBy(x => x.Description) .ToList(); } totalCount = AllRecords.Count; } /// /// Filtro e paginazione /// private void UpdateTable() { // fix paginazione ListRecords = AllRecords .Skip(numRecord * (currPage - 1)) .Take(numRecord) .ToList(); isLoading = false; } #endregion Private Methods } }