using Microsoft.AspNetCore.Components; using MP.MONO.Core.DTO; using MP.MONO.Data; using MP.MONO.Data.DTO; using MP.MONO.UI.Data; using Newtonsoft.Json; using static MP.MONO.Core.Enums; namespace MP.MONO.UI.Components { public partial class ToolsPlot { #region Public Properties [Parameter] public int MachineId { get; set; } = 1; public string ToolId { get => _selTool.Replace(" ", "_"); } [Parameter] public string SelectedTool { get => _selTool; set => _selTool = value; } [Parameter] public DataLogFilter SelFilter { get => _SelFilter; set => _SelFilter = value; } #endregion Public Properties #region Protected Fields protected DateTime lastRec = DateTime.Now.AddMinutes(-1); protected List LevelVal = new List(); protected Dictionary listMaxVal = new Dictionary(); protected Dictionary listMinVal = new Dictionary(); #endregion Protected Fields #region Protected Properties protected DataLogFilter _SelFilter { get; set; } = new DataLogFilter(); protected string _selTool { get; set; } = ""; protected string? MaxVal { get { string answ = "0"; if (listMaxVal != null && listMaxVal.Count > 0) { answ = listMaxVal[SelectedTool] ?? "0"; } return answ; } } protected string? MinVal { get { string answ = "0"; if (listMinVal != null && listMinVal.Count > 0) { answ = listMinVal[SelectedTool] ?? "0"; } return answ; } } #endregion Protected Properties #region Protected Methods protected List getFillColors(string alpha) { List answ = new List(); answ.Add($"rgba(108, 214, 164, {alpha})"); return answ; } protected List getLineColors(string alpha) { List answ = new List(); answ.Add($"rgba(54, 204, 82, {alpha})"); return answ; } protected List getPointColors(string alpha) { List answ = new List(); answ.Add($"rgba(108, 158, 118, {alpha})"); return answ; } #if false protected override async Task OnInitializedAsync() { //await ReloadData(); //await Task.Delay(1); } #endif protected override async Task OnParametersSetAsync() { isLoading = true; await ReloadData(); await Task.Delay(1); } protected async Task ReloadData() { isLoading = true; ListRecords = null; await Task.Delay(1); ListRecords = await MMDataService.DataLogDtoGetFilt(MachineId, DataLogType.Tools, SelectedTool, StartDate, EndDate); await Task.Delay(1); // converto in plotdata LevelVal = ListRecords.Select(l => new chartJsData.chartJsTSerie() { x = l.DtRif, y = l.ValNum }).ToList(); await Task.Delay(1); isLoading = false; } #endregion Protected Methods #region Private Fields private List? ListRecords = null; #endregion Private Fields #region Private Properties private DateTime EndDate { get => _SelFilter.DtEnd; } private bool isLoading { get; set; } = false; private DateTime StartDate { get => _SelFilter.DtStart; } #endregion Private Properties } }