171 lines
4.9 KiB
C#
171 lines
4.9 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using MP.MONO.Core.DTO;
|
|
using MP.MONO.Data;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace MP.MONO.UI.Components
|
|
{
|
|
public partial class ToolsOverview : IDisposable
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public EventCallback<string> EC_AddValue { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<string> EC_RemValue { get; set; }
|
|
|
|
[Parameter]
|
|
public bool selectAll { get; set; } = false;
|
|
|
|
[Parameter]
|
|
public List<string> SelVal { get; set; } = new List<string>();
|
|
|
|
[Parameter]
|
|
public bool ShowReduced { get; set; } = false;
|
|
|
|
[Parameter]
|
|
public double sampleSecMin { get; set; } = 1;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
MMDataService.toolsPipe.EA_NewMessage -= ToolsPipe_EA_NewMessage;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Methods
|
|
|
|
protected string cssActive(string toolName)
|
|
{
|
|
string answ = SelVal.Contains(toolName) ? "bg-dark text-light" : "";
|
|
return answ;
|
|
}
|
|
|
|
protected string cssLast(string toolName)
|
|
{
|
|
string answ = SelVal.Contains(toolName) ? "bg-dark text-light" : "";
|
|
// se è ultima testo giallo...
|
|
if (SelVal != null && SelVal.Count > 0)
|
|
{
|
|
var ultimo = SelVal.LastOrDefault();
|
|
if (ultimo != null && ultimo.Equals(toolName))
|
|
{
|
|
answ = "bg-dark text-warning";
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await ReloadData();
|
|
MMDataService.toolsPipe.EA_NewMessage += ToolsPipe_EA_NewMessage;
|
|
}
|
|
|
|
protected string percProgress(double num, double minVal, double maxVal)
|
|
{
|
|
string answ = "width: 0%;";
|
|
double den = (maxVal - minVal) != 0 ? (maxVal - minVal) : 1;
|
|
double ratio = ((double)num) / den;
|
|
answ = $"width: {ratio:P0};";
|
|
return answ;
|
|
}
|
|
|
|
protected async Task ReloadData()
|
|
{
|
|
SelVal = new List<string>();
|
|
var allData = await MMDataService.getTools();
|
|
// se modalità reduced --> mostro solo il subset dati filtrati...
|
|
FilterData(allData);
|
|
}
|
|
|
|
protected void toggleSelect(string SelectedValue)
|
|
{
|
|
// se contiene rimuovo
|
|
if (SelVal.Contains(SelectedValue))
|
|
{
|
|
//SelVal.Remove(SelectedValue);
|
|
EC_RemValue.InvokeAsync(SelectedValue);
|
|
}
|
|
// altrimenti aggiungo
|
|
else
|
|
{
|
|
//SelVal.Add(SelectedValue);
|
|
EC_AddValue.InvokeAsync(SelectedValue);
|
|
}
|
|
}
|
|
|
|
protected void toggleSelectAll()
|
|
{
|
|
if (selectAll == true && ListRecords != null)
|
|
{
|
|
foreach (var item in ListRecords)
|
|
{
|
|
EC_AddValue.InvokeAsync(item.Title);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Properties
|
|
|
|
private List<DisplayDataDTO>? ListRecords { get; set; } = null;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void FilterData(List<DisplayDataDTO> allData)
|
|
{
|
|
if (ShowReduced)
|
|
{
|
|
ListRecords = allData
|
|
.Where(x => x.HLShow)
|
|
.OrderBy(x => x.Order)
|
|
.ToList();
|
|
}
|
|
else
|
|
{
|
|
ListRecords = allData
|
|
.OrderBy(x => x.Order)
|
|
.ToList();
|
|
}
|
|
}
|
|
|
|
protected DateTime lastRec = DateTime.Now.AddMinutes(-1);
|
|
|
|
private void ToolsPipe_EA_NewMessage(object? sender, EventArgs e)
|
|
{
|
|
DateTime adesso = DateTime.Now;
|
|
if (lastRec.AddSeconds(sampleSecMin) < adesso)
|
|
{
|
|
PubSubEventArgs currArgs = (PubSubEventArgs)e;
|
|
if (!string.IsNullOrEmpty(currArgs.newMessage))
|
|
{
|
|
lastRec = adesso;
|
|
try
|
|
{
|
|
var rawData = JsonConvert.DeserializeObject<List<DisplayDataDTO>>(currArgs.newMessage);
|
|
var allData = rawData == null ? new List<DisplayDataDTO>() : rawData;
|
|
FilterData(allData);
|
|
}
|
|
catch
|
|
{ }
|
|
InvokeAsync(() =>
|
|
{
|
|
StateHasChanged();
|
|
});
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |