// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this // file to you under the MIT license. using EgwCoreLib.Razor; using MagMan.Core.Services; using MagMan.Data.Admin.DbModels; using MagMan.Data.Admin.Services; using MagMan.Data.Tenant.DbModels; using MagMan.Data.Tenant.Services; using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; namespace MagMan.UI.Components { public partial class MacStatusMan { #region Public Properties [Parameter] public int CustomerId { get; set; } = 0; [Parameter] public int KeyNum { get; set; } = 0; #endregion Public Properties #region Protected Properties [Inject] protected MessageService AppMService { get; set; } = null!; [Inject] protected IConfiguration Configuration { get; set; } = null!; [Inject] protected IJSRuntime JSRuntime { get; set; } = null!; [Inject] protected MTAdminService MTService { get; set; } = null!; protected int totalCount { get; set; } = 0; [Inject] protected TenantService TService { get; set; } = null!; #endregion Protected Properties private List MachineList = new List(); private List? SearchRecords = null; private List? ListRecords = null; private string currSearch = ""; private bool sortAsc = true; private string sortField = ""; private int currPage { get; set; } = 1; private bool isLoading { get; set; } = false; private int machIdSel = 0; private int MachineIdSel { get => machIdSel; set { if (machIdSel != value) { machIdSel = value; InvokeAsync(ReloadData); } } } private int numRecord { get; set; } = 10; protected override void OnInitialized() { currSearch = ""; AppMService.EA_SearchUpdated += AppMService_EA_SearchUpdated; } protected override async Task OnParametersSetAsync() { await ReloadData(); } protected void SetNumRec(int newNum) { numRecord = newNum; currPage = 1; InvokeAsync(ReloadData); } protected void SetPage(int newNum) { currPage = newNum; DoSelect(null); InvokeAsync(ReloadData); } protected async Task SortRequested(Sorter.SortCallBack e) { sortField = e.ParamName; sortAsc = e.IsAscending; await ReloadData(); } protected void DoSelect(LogMachineModel? selItem) { #if false if (selItem != null) { ProjDbId = selItem.ProjDbId; } else { ProjDbId = 0; } E_ProjSel.InvokeAsync(selItem); #endif } protected async Task ForceReload(bool force) { #if false CurrItem = null; #endif await ReloadData(); } protected string CheckSel(LogMachineModel curItem) { string answ = ""; #if false if (CurrItem != null) { answ = curItem.ProjDbId == CurrItem.ProjDbId ? "table-info" : ""; } else { answ = curItem.ProjDbId == ProjDbId ? "table-info" : ""; } #endif return answ; } private async void AppMService_EA_SearchUpdated() { currSearch = AppMService.SearchVal; await ReloadData(); } protected int maxRec { get; set; } = 1000; private async Task ReloadData() { isLoading = true; //await InvokeAsync(StateHasChanged); ListRecords = null; if (KeyNum > 0) { MachineList = await MTService.MachineGetByCustId(CustomerId); // mettere var x maxNum? SearchRecords = await TService.LogMacGetLast(KeyNum, MachineIdSel, maxRec); // verifico filtro per ricerca if (!string.IsNullOrEmpty(currSearch)) { SearchRecords = SearchRecords.Where(x => x.VarValue.Contains(currSearch, StringComparison.InvariantCultureIgnoreCase)).ToList(); } totalCount = SearchRecords.Count; } SortTable(); isLoading = false; await InvokeAsync(StateHasChanged); } private void SortTable() { if (SearchRecords != null) { // se ho ordinamento riordino... if (!string.IsNullOrEmpty(sortField)) { #if false switch (sortField) { case "ID": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.ProjExtId).ToList(); } else { SearchRecords = SearchRecords.OrderByDescending(x => x.ProjExtId).ToList(); } break; case "ProjDescription": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.ProjDescription).ToList(); } else { SearchRecords = SearchRecords.OrderByDescending(x => x.ProjDescription).ToList(); } break; case "Machine": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.Machine).ToList(); } else { SearchRecords = SearchRecords.OrderByDescending(x => x.Machine).ToList(); } break; case "DtCreated": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.DtCreated).ToList(); } else { SearchRecords = SearchRecords.OrderByDescending(x => x.DtCreated).ToList(); } break; case "DtSchedule": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.DtSchedule).ToList(); } else { SearchRecords = SearchRecords.OrderByDescending(x => x.DtSchedule).ToList(); } break; case "DtStartProd": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.DtStartProd).ToList(); } else { SearchRecords = SearchRecords.OrderByDescending(x => x.DtStartProd).ToList(); } break; case "DtLastAction": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.DtLastAction).ToList(); } else { SearchRecords = SearchRecords.OrderByDescending(x => x.DtLastAction).ToList(); } break; case "ListName": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.ListName).ToList(); } else { SearchRecords = SearchRecords.OrderByDescending(x => x.ListName).ToList(); } break; case "IsActive": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.IsActive).ToList(); } else { SearchRecords = SearchRecords.OrderByDescending(x => x.IsActive).ToList(); } break; case "IsArchived": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.IsArchived).ToList(); } else { SearchRecords = SearchRecords.OrderByDescending(x => x.IsArchived).ToList(); } break; case "ProcTimeEst": if (sortAsc) { SearchRecords = SearchRecords.OrderBy(x => x.ProcTimeEst).ToList(); } else { SearchRecords = SearchRecords.OrderByDescending(x => x.ProcTimeEst).ToList(); } break; default: break; } #endif } // filtro x display ListRecords = SearchRecords .Skip(numRecord * (currPage - 1)) .Take(numRecord) .ToList(); } else { ListRecords = new List(); } } } }