using EgwCoreLib.Lux.Core.RestPayload; using EgwCoreLib.Lux.Data.DbModel.Config; using EgwCoreLib.Lux.Data.Services; using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using System.ComponentModel; namespace Lux.UI.Components.Compo.Config { 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!; [Inject] protected IJSRuntime JSRuntime { get; set; } = null!; protected string SearchVal { get => searchVal; set { if (searchVal != value) { searchVal = value; FullUpdate(); } } } #endregion Protected Properties #region Protected Methods /// /// Richiesta update elenco HW preferiti/configurati /// protected async Task DoReqUpdate() { // chiamata richiesta update da calc await callRefreshProfList(); } protected override void OnInitialized() { apiUrl = Config.GetValue("ServerConf:Prog.ApiUrl") ?? ""; genericBasePath = Config.GetValue("ServerConf:GenericBaseUrl") ?? ""; calcTag = Config.GetValue("ServerConf:CalcTag") ?? "calc"; DLService.PipeProfList.EA_NewMessage += PipeProfList_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"; /// /// Per eventuale gestione multi-profilo su multi tenant /// private string confProf = "Default"; 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 callRefreshProfList() { 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() { EnvType = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW, 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); } private void FullUpdate() { ReloadData(); UpdateTable(); } /// /// Ricevuto update da Calc x elenco profili: aggiorno! /// /// /// private void PipeProfList_EA_NewMessage(object? sender, EventArgs e) { FullUpdate(); _ = InvokeAsync(StateHasChanged); } private void ReloadData() { isLoading = true; 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) .ToList(); } else { AllRecords = AllRecords .Where(x => x.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase)) .OrderBy(x => x) .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 } }