using Microsoft.AspNetCore.Components; using MP.Core.DTO; namespace MP.IOC.Components.Compo { public partial class ParetoDetail { #region Public Properties [Parameter] public EventCallback EC_Selected { get; set; } [Parameter] public List ParetoList { get; set; } = null!; [Parameter] public string Title { get; set; } = ""; #endregion Public Properties #region Protected Methods protected override void OnParametersSet() { //base.OnParametersSet(); totalCount = ParetoList.Count(); grandTotal = ParetoList.Sum(x => x.Value); if (grandTotal == 0) { grandTotal = 1; } if (_title != Title) { _title = Title; currSelect = ""; } UpdateTable(); } protected double valPerc(double valore) { return valore / grandTotal; } #endregion Protected Methods #region Private Fields private string currSelect = ""; private double grandTotal = 1; private List ListPaged = new(); private int numRecPage = 10; private int pageNum = 1; private int totalCount = 0; #endregion Private Fields #region Private Properties private string _title { get; set; } = null!; #endregion Private Properties #region Private Methods private string CheckSelect(string curKey) { return !string.IsNullOrEmpty(currSelect) && currSelect == curKey ? "bg-dark text-light bg-gradient" : ""; } private async Task DoReset() { currSelect = ""; await EC_Selected.InvokeAsync(""); } private async Task DoSelect(string reqKey) { if (ParetoList.Any(x => x.Label == reqKey)) { currSelect = reqKey; await EC_Selected.InvokeAsync(reqKey); } } private void SaveNumRec(int newNum) { numRecPage = newNum; UpdateTable(); } private void SavePage(int newNum) { pageNum = newNum; UpdateTable(); } private void UpdateTable() { // esegue paginazione if (totalCount > numRecPage) { ListPaged = ParetoList.Skip((pageNum - 1) * numRecPage).Take(numRecPage).ToList(); } else { ListPaged = ParetoList; } } #endregion Private Methods } }