using Microsoft.AspNetCore.Components; using MP.MONO.Data; using MP.MONO.Data.DTO; using MP.MONO.UI.Data; using static MP.MONO.Core.Enums; namespace MP.MONO.UI.Components { public partial class ParamPlot { #region Public Properties [Parameter] public int MachineId { get; set; } = 1; public string ParamId { get => _selParam.Replace(" ", "_"); } [Parameter] public string SelectedParam { get => _selParam; set => _selParam = 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 _selParam { get; set; } = ""; protected string? MaxVal { get { string answ = "0"; if (listMaxVal != null && listMaxVal.Count > 0) { answ = listMaxVal[SelectedParam] ?? "0"; } return answ; } } protected string? MinVal { get { string answ = "0"; if (listMinVal != null && listMinVal.Count > 0) { answ = listMinVal[SelectedParam] ?? "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; } protected override async Task OnInitializedAsync() { await ReloadData(); await Task.Delay(1); } 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.Parameter, SelectedParam, 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 } }