using EgwCoreLib.Lux.Data.DbModel.Task; using EgwCoreLib.Lux.Data.Services; using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; namespace Lux.UI.Components.Compo.JobTask { public partial class JobStepMan { #region Public Properties [Parameter] public List CurrRecords { get; set; } [Parameter] public string CurrSearch { get; set; } = string.Empty; [Parameter] public EventCallback EC_Selected { get; set; } [Parameter] public EventCallback EC_Updated { get; set; } #endregion Public Properties #region Protected Fields protected List FiltRecords = new List(); protected List ListRecords = new List(); #endregion Protected Fields #region Protected Methods [Inject] protected IJSRuntime JSRuntime { get; set; } = null!; [Inject] protected DataLayerServices DLService { get; set; } = null!; /// /// Eliminazione record /// /// protected async Task DoDelete(JobStepModel rec2del) { if (!await JSRuntime.InvokeAsync("confirm", $"Sicuro di voler eliminare il record? {rec2del.Description} ({rec2del.JobStepID})")) return; // esegue eliminazione del record... await DLService.JobStepDeleteAsync(rec2del); // segnalo update x reload await EC_Updated.InvokeAsync(true); // rileggo ReloadData(); } /// /// Edit articolo selezionato /// /// protected async void DoEdit(JobStepModel curRec) { editRecord = curRec; selRecord = curRec; #if false await EC_Selected.InvokeAsync(curRec); #endif await Task.Delay(1); } /// /// Check selezione riga item /// /// /// private string checkSel(JobStepModel curRec) { string answ = ""; if (selRecord != null) { answ = curRec.JobStepID == selRecord.JobStepID ? "table-info" : ""; } return answ; } /// /// Reset selezione /// protected async void DoReset() { editRecord = null; selRecord = null; await EC_Selected.InvokeAsync(selRecord); } /// /// Selezione articolo x display info /// /// protected async void DoSelect(JobStepModel curRec) { selRecord = curRec; await EC_Selected.InvokeAsync(curRec); } protected override void OnParametersSet() { ReloadData(); } protected void ToggleAdd() { addVisible = !addVisible; if (addVisible) { newRecord = new JobStepModel() { Index = totalCount + 1, Description = $"Fase {totalCount + 1} | {DateTime.Now:yyyy.MM.dd-HH.mm.ss}" }; } } #endregion Protected Methods #region Private Fields private bool addVisible = false; private int currPage = 1; private JobStepModel? editRecord = null; private JobStepModel? newRecord = null; private int numRecord = 10; private JobStepModel? selRecord = null; private int totalCount = 0; #endregion Private Fields #region Private Methods private void ReloadData() { if (CurrRecords != null) { // se ho ricerca testuale faccio filtro ulteriore... if (!string.IsNullOrEmpty(CurrSearch)) { FiltRecords = CurrRecords .Where(x => x.Description.Contains(CurrSearch, StringComparison.InvariantCultureIgnoreCase)) .ToList(); } else { FiltRecords = CurrRecords; } totalCount = FiltRecords.Count; // fix paginazione ListRecords = CurrRecords .OrderBy(x => x.Index) .Skip(numRecord * (currPage - 1)) .Take(numRecord) .ToList(); } } #endregion Private Methods } }