using EgwMultiEngineManager.Data; 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 Methods 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 async Task OnParametersSetAsync() { await ReloadDataAsync(); 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"; } [Inject] private IConfigDataService CDService { get; set; } = null!; [Inject] private IConfiguration Config { get; set; } = null!; [Inject] private ICalcRuidService CRService { get; set; } = null!; [Inject] private ICalcRequestService CService { get; set; } = null!; [Inject] private IDataLayerServices DLService { get; set; } = null!; [Inject] private IJSRuntime JSRuntime { get; set; } = null!; private string searchVal { get; set; } = string.Empty; private string SearchVal { get => searchVal; set { if (searchVal != value) { searchVal = value; currPage = 1; ReloadDataAsync().ConfigureAwait(false); UpdateTable(); } } } #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); } /// /// Richiesta update elenco HW preferiti/configurati /// private Task DoReqUpdate() { // chiamata richiesta update da calc return callRefreshHwList(confHw); } /// /// Ricevuto update da Calc x elenco HW: aggiorno! /// /// /// private async void PipeHwList_EA_NewMessage(object? sender, EventArgs e) { await ReloadDataAsync(); UpdateTable(); await InvokeAsync(StateHasChanged); } private async Task ReloadDataAsync() { isLoading = true; AllRecords = await CDService.HwModelListAsync(cEnvir, confHw); } private void ResetSearch() { SearchVal = ""; } private void SaveNumRec(int newNum) { numRecord = newNum; UpdateTable(); } private void SavePage(int newNum) { currPage = newNum; UpdateTable(); } /// /// Filtro e paginazione /// private void UpdateTable() { // 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; // fix paginazione ListRecords = AllRecords .Skip(numRecord * (currPage - 1)) .Take(numRecord) .ToList(); isLoading = false; } #endregion Private Methods } }