179 lines
4.6 KiB
C#
179 lines
4.6 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using MP.Data.DbModels;
|
|
|
|
namespace MP.SPEC.Components
|
|
{
|
|
public partial class ListMacc
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public List<MappaStatoExplModel> ListMSE { get; set; } = null!;
|
|
|
|
|
|
[Parameter]
|
|
public EventCallback<List<string>> EC_Selected { get; set; }
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Properties
|
|
|
|
/// <summary>
|
|
/// Elenco selezione corrente
|
|
/// </summary>
|
|
protected List<string> CurrList { get; set; } = new List<string>();
|
|
|
|
/// <summary>
|
|
/// Conteggio elementi selezionati
|
|
/// </summary>
|
|
protected int numSel
|
|
{
|
|
get => CurrList.Count();
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected string CheckSelect(MappaStatoExplModel currRec)
|
|
{
|
|
string answ = "";
|
|
if (CurrList.Contains(currRec.CodMacchina))
|
|
{
|
|
answ = "table-info";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// CSS Class bordo da stato macchina
|
|
/// </summary>
|
|
protected string cssClassBorder(string semaforo)
|
|
{
|
|
string answ = "";
|
|
if (!string.IsNullOrEmpty(semaforo))
|
|
{
|
|
switch (semaforo)
|
|
{
|
|
case "sGi":
|
|
answ += " text-bg-warning";
|
|
break;
|
|
|
|
case "sRo":
|
|
answ += " text-bg-danger";
|
|
break;
|
|
|
|
case "sGr":
|
|
answ += " text-bg-dark";
|
|
break;
|
|
|
|
case "sBl":
|
|
answ += " text-bg-rimary";
|
|
break;
|
|
|
|
case "sVe":
|
|
answ += " text-bg-success";
|
|
break;
|
|
|
|
default:
|
|
answ += " text-bg-secondary";
|
|
break;
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
totalCount = ListMSE.Count();
|
|
await ReloadData();
|
|
}
|
|
|
|
protected async Task SetNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
currPage = 1;
|
|
await ReloadData();
|
|
}
|
|
|
|
protected async Task SetPage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
await ReloadData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue toggle selezione fino a numMax in aggiunta e rimuovendo tutti se era true
|
|
/// </summary>
|
|
protected async Task ToggleAllSel()
|
|
{
|
|
AllSelected = !AllSelected;
|
|
if (AllSelected)
|
|
{
|
|
if (ListRecords != null)
|
|
{
|
|
foreach (var record in ListRecords)
|
|
{
|
|
if (!CurrList.Contains(record.CodMacchina))
|
|
{
|
|
CurrList.Add(record.CodMacchina);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CurrList.Clear();
|
|
}
|
|
await Task.Delay(1);
|
|
await EC_Selected.InvokeAsync(CurrList);
|
|
}
|
|
|
|
protected async Task ToggleSel(string newVal)
|
|
{
|
|
if (!CurrList.Contains(newVal))
|
|
{
|
|
CurrList.Add(newVal);
|
|
}
|
|
else
|
|
{
|
|
CurrList.Remove(newVal);
|
|
}
|
|
// riordino
|
|
CurrList = CurrList.OrderBy(x => x).ToList();
|
|
// invio selezione!
|
|
await EC_Selected.InvokeAsync(CurrList);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private bool AllSelected = false;
|
|
private int currPage = 1;
|
|
private bool isLoading = false;
|
|
|
|
private List<MappaStatoExplModel> ListRecords = new();
|
|
private int numRecord = 10;
|
|
private int totalCount = 0;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Methods
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
if (ListMSE != null)
|
|
{
|
|
// filtro x display
|
|
ListRecords = ListMSE
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
}
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |