using Liman.CadCam.DbModel; using Liman.CadCam.Services; using LiMan.UI.Data; using Microsoft.AspNetCore.Components; using System.Collections.Generic; using System.Threading.Tasks; using System; using System.Linq; using LiMan.DB; using LiMan.DB.DBModels; namespace LiMan.UI.Components { public partial class SearchEnroll : IDisposable { #region Public Properties public string searchVal { get; set; } = ""; #endregion Public Properties #region Public Methods public void Dispose() { AppMessages.EA_SearchUpdated -= AppMessages_EA_SearchUpdated; LMDService.EnrollMessPipe.EA_NewMessage -= async (sender, e) => await EnrollMessPipe_EA_NewMessage(sender, e); } #endregion Public Methods #region Protected Properties [Inject] protected MessageService AppMessages { get; set; } = null!; [Inject] protected LiManDataService LMDService { get; set; } = null!; #endregion Protected Properties #region Protected Methods protected override async Task OnInitializedAsync() { AppMessages.EA_SearchUpdated += AppMessages_EA_SearchUpdated; LMDService.EnrollMessPipe.EA_NewMessage += async (sender, e) => await EnrollMessPipe_EA_NewMessage(sender, e); await ReloadLicData(); } /// /// Rimozione richieste scadute /// /// protected async Task RemoveOld() { await LMDService.EnrollReqPurgeInvalid(); await LMDService.FlushEnrollCache(); LMDService.EnrollMessPipe.sendMessage("PurgedOld"); searchVal = ""; } /// /// Idx licenza selezionata /// private int SelIdxLic = 0; private List ListLicenze; private async Task ReloadLicData() { SelectNext currFilt = new SelectNext() { ApplicazioneSel = "UpdateManager" }; var rawList = await LMDService.LicenzeNextGetFilt(currFilt); ListLicenze = rawList .OrderBy(x => x.CodApp) .ThenBy(x => x.CodInst) .ToList(); } /// /// formattazione opzione licenza da mostrare in select /// /// /// /// protected string formatLic(LicenzaModel licItem, bool doShort) { string answ = $"{licItem.CodApp} | {licItem.CodInst} | {licItem.Attivazioni.Count} / {licItem.NumLicenze}"; if (doShort) { answ = $"{licItem.CodApp.Substring(0, 5)}...{licItem.CodApp.Substring(licItem.CodApp.Length - 3)} | {licItem.CodInst} | {licItem.Attivazioni.Count} / {licItem.NumLicenze}"; } return answ; } private DateTime dtStart = new DateTime(2024, 1, 1); private DateTime dtEnd = DateTime.Today.AddDays(1); #endregion Protected Methods #region Private Fields private bool isLoading = false; /// /// Indica se mostrare tutte le richieste o solo quelle Attive(aperte/non confermate) /// private bool showAll = false; #endregion Private Fields #region Private Properties private bool hasUpdate { get; set; } = false; private List ListProd { get; set; } = new List(); /// /// Testo associato al toogle button delle richieste Attive / Tutte /// private string selMessage { get => showAll ? "Mostra tutte" : "Solo Attive"; } #endregion Private Properties #region Private Methods private void AppMessages_EA_SearchUpdated() { ReloadData(); } /// /// Evento refresh legato a ricezione evento da MessagePipe /// /// /// private async Task EnrollMessPipe_EA_NewMessage(object sender, EventArgs e) { PubSubEventArgs currArgs = (PubSubEventArgs)e; // qualsiasi messaggio fa scattare reload data if (!string.IsNullOrEmpty(currArgs.newMessage)) { hasUpdate = true; await InvokeAsync(StateHasChanged); await Task.Delay(2500); hasUpdate = false; await InvokeAsync(StateHasChanged); } } private void ReloadData() { isLoading = true; if (searchVal != AppMessages.SearchVal) { searchVal = AppMessages.SearchVal; } isLoading = false; InvokeAsync(StateHasChanged); } #endregion Private Methods } }