using EgwCoreLib.Razor; using Microsoft.AspNetCore.SignalR.Protocol; namespace Lux.UI.Components.Compo.Templates { public partial class TemplateList { #region Public Properties /// /// Ricerca libera da parent /// [Parameter] public string CurrSearchVal { get; set; } = ""; /// /// Callback invocato al select /// [Parameter] public EventCallback EC_Selected { get; set; } /// /// Callback invocato al modifica /// [Parameter] public EventCallback EC_Edit { get; set; } [Parameter] public TemplateModel? SelRecord { get; set; } = null; #endregion Public Properties #region Protected Methods protected override async Task OnParametersSetAsync() { await ReloadDataAsync(); UpdateTable(); } #endregion Protected Methods #region Private Fields private List AllRecords = new List(); private EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS CurrEnvir = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW; private int currPage = 1; private Enums.ItemSourceType CurrSourceType = Enums.ItemSourceType.Jwd; private TemplateModel? EditRecord = null; private bool isLoading = false; private List ListFilt = new List(); private List ListRecords = new List(); private int numRecord = 10; private int totalCount = 0; private BootstrapModal Modal = new(); private string mTitle = ""; private string mMessage = ""; private BootstrapModal.ModalMode mMode = BootstrapModal.ModalMode.ND; private Dictionary modalOpt = new Dictionary(); #endregion Private Fields #region Private Properties /// /// Servizi di accesso ai dati iniettati dal framework. /// [Inject] private IDataLayerServices DLService { get; set; } = null!; [Inject] private IJSRuntime JSRuntime { get; set; } = null!; [Inject] private ITemplateService TService { get; set; } = default!; #endregion Private Properties #region Private Methods private string CheckSelect(TemplateModel curRec) { string answ = ""; if (SelRecord != null) { answ = curRec.TemplateID == SelRecord.TemplateID ? "table-info" : ""; } return answ; } private void DoAdd() { DateTime adesso = DateTime.Now; EditRecord = new TemplateModel() { Name = $"New Template {adesso.Year}", Description = $"Nuovo Template {adesso:ddd yyyy.MM.dd HH:mm:ss}", Envir = CurrEnvir, SourceType = CurrSourceType }; } private async Task DoClone(TemplateModel rec2clone) { mTitle = "Attenzione"; mMessage = $"Confermi di voler duplicare interamente il Gruppo Template selezionato?\n" + $"Env: {rec2clone.Envir} | {rec2clone.Name}\n " + $"{rec2clone.Description}\n " + $"Articoli: {rec2clone.NumItems}"; mMode = BootstrapModal.ModalMode.Confirm; modalOpt = new(); modalOpt.Add(true, "Si"); modalOpt.Add(false, "No"); if (!await Modal!.ShowAsync()) return; // clona intero template + tutte le righe... rec2clone.Name += " - clone"; rec2clone.Description += $" - cloned {DateTime.Now:yyyy.MM.dd HH:mm:ss}"; await TService.CloneAsync(rec2clone); await ReloadDataAsync(); UpdateTable(); } //private void DoClose() //{ // SelRecord = null; // EditRecord = null; //} private async Task DoDelete(TemplateModel curRec) { mTitle = "Eliminazione"; mMessage = $"Confermi di voler eliminare il Gruppo Template selezionato?\n" + $"Env: {curRec.Envir} | {curRec.Name}\n " + $"{curRec.Description}\n " + $"Articoli: {curRec.NumItems}"; mMode = BootstrapModal.ModalMode.Confirm; modalOpt = new(); modalOpt.Add(true, "Si"); modalOpt.Add(false, "No"); if (!await Modal!.ShowAsync()) return; // elimina intero template (anche le sue righe) await TService.DeleteAsync(curRec); await ReloadDataAsync(); UpdateTable(); } private Task DoEdit(TemplateModel curRec) { SelRecord = null; return EC_Edit.InvokeAsync(curRec); // EditRecord = curRec; } private async Task DoReset() { //EditRecord = null; SelRecord = null; await ReloadDataAsync(); UpdateTable(); await EC_Selected.InvokeAsync(null); } ///// ///// Salva record ed avanza compilazione ///// ///// ///// //private async Task DoSave(TemplateModel updRec) //{ // // salvo record // await TService.UpsertAsync(updRec); // EditRecord = null; // SelRecord = null; // await ReloadDataAsync(); // UpdateTable(); //} private Task DoSelect(TemplateModel curRec) { SelRecord = curRec; return EC_Selected.InvokeAsync(curRec); } private async Task ReloadDataAsync() { AllRecords = await TService.GetAllAsync(); } private void SaveNumRec(int newNum) { numRecord = newNum; UpdateTable(); } private void SavePage(int newNum) { currPage = newNum; UpdateTable(); } private void UpdateTable() { //ListFilt.Clear(); ListFilt = AllRecords; if (!string.IsNullOrEmpty(CurrSearchVal)) { ListFilt = AllRecords .Where(x => x.Name.Contains(CurrSearchVal, StringComparison.InvariantCultureIgnoreCase) || x.Description.Contains(CurrSearchVal, StringComparison.InvariantCultureIgnoreCase)) .ToList(); } totalCount = ListFilt.Count; // gestione paginazione ListRecords = ListFilt .Skip(numRecord * (currPage - 1)) .Take(numRecord) .ToList(); } #endregion Private Methods } }