using Microsoft.AspNetCore.Components; using MP.Data.DbModels; using MP.SPEC.Components.Reparti; using MP.SPEC.Data; using NLog.LayoutRenderers; using static MP.Core.Objects.Enums; using static MP.Data.Services.ExecStatsCollector; namespace MP.SPEC.Pages { public partial class RepStop { #region Protected Properties protected List CurrList { get; set; } = new List(); [Inject] protected MpDataService MDService { get; set; } = null!; protected int numSel { get => CurrList.Count(); } #endregion Protected Properties #region Protected Methods protected string CheckSelect(MacchineModel currRec) { string answ = ""; if (CurrList.Contains(currRec.CodMacchina)) { answ = "table-info"; } return answ; } protected override void OnInitialized() { var rawList = MDService.MacchineGetFilt("*"); // prendo solo macchine VALIDE SearchRecords = rawList.Where(x => !string.IsNullOrEmpty(x.locazione)).ToList(); totalCount = SearchRecords.Count; } protected override async Task OnParametersSetAsync() { await ReloadData(); } protected async Task SetNumRec(int newNum) { numRecord = newNum; currPage = 1; await ReloadData(); } protected async Task SetPage(int newNum) { currPage = newNum; await ReloadData(); } /// /// Esegue toggle selezione fino a numMax in aggiunta e rimuovendo tutti se era true /// protected async Task ToggleAllSel() { AllSelected = !AllSelected; if (AllSelected) { if (ListRecords != null) { foreach (var record in ListRecords) { if (!CurrList.Contains(record.CodMacchina)) { CurrList.Add(record.CodMacchina); } } } } else { CurrList.Clear(); } await Task.Delay(1); #if false await EC_ListUpdated.InvokeAsync(CurrList); #endif } protected void ToggleSel(string newVal) { if (!CurrList.Contains(newVal)) { CurrList.Add(newVal); } else { CurrList.Remove(newVal); } // riordino CurrList = CurrList.OrderBy(x => x).ToList(); } #endregion Protected Methods #region Private Fields private bool AllSelected = false; private int currPage = 1; private bool isLoading = false; private List ListRecords = new(); private int numRecord = 10; private List SearchRecords = new(); private int totalCount = 0; #endregion Private Fields #region Private Methods private async Task ReloadData() { if (SearchRecords != null) { // filtro x display ListRecords = SearchRecords .Skip(numRecord * (currPage - 1)) .Take(numRecord) .ToList(); } await Task.Delay(1); } #endregion Private Methods } }