using Microsoft.AspNetCore.Components; using MP.TaskMan.Models; using MP.TaskMan.Services; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using NLog; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace MP.TaskMan { public partial class TaskExeList { #region Public Properties [Parameter] public TaskListModel? CurrRecord { get; set; } = null; #endregion Public Properties #region Protected Fields protected bool isLoading = false; #endregion Protected Fields #region Protected Properties [Inject] protected NavigationManager NavManager { get; set; } = null!; /// /// Show error mode: 0 = tutti 1 = solo errori 2 = solo ok /// protected int ShowErrorMode { get => showErrorMode; set { if (showErrorMode != value) { showErrorMode = value; var pUpd = Task.Run(async () => await ReloadData()); pUpd.Wait(); } } } protected int totalCount { get; set; } = 0; [Inject] protected TaskService TService { get; set; } = null!; #endregion Protected Properties #region Protected Methods protected string alCss(TaskExecModel TaskRec) { return TaskRec.IsError ? "alert-danger" : "alert-success"; } protected async Task ForceReload(int newNum) { numRecord = newNum; await ReloadData(); } protected async Task ForceReloadPage(int newNum) { currPage = newNum; await ReloadData(); } protected override async Task OnInitializedAsync() { await ReloadData(); } protected string TextReduce(string textOriginal, int maxChar) { string answ = textOriginal; if (answ.Length > maxChar) { answ = $"{textOriginal.Substring(0, maxChar / 2)} ... {textOriginal.Substring(answ.Length - maxChar / 2)}"; } return answ; } #endregion Protected Methods #region Private Fields private static Logger Log = LogManager.GetCurrentClassLogger(); private List ListRecords; private List SearchRecords; #endregion Private Fields #region Private Properties private int currPage { get; set; } = 1; private int numRecord { get; set; } = 10; private int showErrorMode { get; set; } = 0; #endregion Private Properties #region Private Methods private async Task ReloadData() { SearchRecords = await TService.TaskExecGetFilt(CurrRecord.TaskId, 1000, ""); // se non tutti filtro... if (ShowErrorMode != 0) { if (ShowErrorMode == 1) { SearchRecords = SearchRecords.FindAll(x => x.IsError); } else if (ShowErrorMode == 2) { SearchRecords = SearchRecords.FindAll(x => !x.IsError); } } totalCount = SearchRecords.Count; ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); } #endregion Private Methods } }