416 lines
12 KiB
C#
416 lines
12 KiB
C#
using global::Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using MP.Data;
|
|
using MP.Data.DbModels;
|
|
using MP.Data.Services;
|
|
using Newtonsoft.Json;
|
|
using NLog;
|
|
|
|
namespace MP_TAB3.Pages
|
|
{
|
|
public partial class StatusMap : IDisposable
|
|
{
|
|
#region Protected Fields
|
|
|
|
protected bool _showCard = false;
|
|
|
|
protected string showArt = "";
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Private Fields
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
private bool doBlink = false;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected IConfiguration config { get; set; } = null!;
|
|
|
|
protected int Height { get; set; } = 0;
|
|
|
|
protected bool isCalcSize { get; set; } = false;
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
/// Numero colonne mappa: calcolato larghezza riga...
|
|
/// </summary>
|
|
protected int mapNCol
|
|
{
|
|
get
|
|
{
|
|
int answ = 2;
|
|
if (Width > 450)
|
|
{
|
|
if (Width < 1024)
|
|
{
|
|
answ = (int)Math.Floor((decimal)Width / 200);
|
|
}
|
|
else
|
|
{
|
|
answ = (int)Math.Floor((decimal)Width / 220) - 1;
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Numero righe mappa: calcolato da num elementi e numMax x riga...
|
|
/// </summary>
|
|
protected int mapNRow
|
|
{
|
|
get
|
|
{
|
|
int answ = 1;
|
|
int numElems = ListMSE != null ? ListMSE.Count : 1;
|
|
answ = (int)Math.Ceiling((double)numElems / mapNCol);
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
[Inject]
|
|
protected StatusData MDataService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected MessageService MsgServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected NavigationManager NavMan { get; set; } = null!;
|
|
|
|
protected bool ShowCard
|
|
{
|
|
get => _showCard;
|
|
set
|
|
{
|
|
_showCard = value;
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
|
|
[Inject]
|
|
protected TabDataService TabDServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected TabDataFeeder TDFeeder { get; set; } = null!;
|
|
|
|
protected int Width { get; set; } = 0;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Private Properties
|
|
|
|
private List<MappaStatoExplModel>? AllDataMSE { get; set; } = null;
|
|
|
|
private string baseLang { get; set; } = "";
|
|
|
|
private List<MacchineModel>? ListMachineEnabled { get; set; } = null;
|
|
|
|
private List<MappaStatoExplModel>? ListMSE { get; set; } = null;
|
|
|
|
private int MatrOpr
|
|
{
|
|
get => MsgServ.MatrOpr;
|
|
}
|
|
|
|
private string tcMode { get; set; } = "";
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
TDFeeder.dataPipe.EA_NewMessage -= DataPipe_EA_NewMessage;
|
|
TDFeeder.blinkPipe.EA_NewMessage -= BlinkPipe_EA_NewMessage;
|
|
ListMSE = null;
|
|
ListMachineEnabled = null;
|
|
AllDataMSE = null;
|
|
GC.Collect();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// calcola num blocchi max data dimensione larghezza
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected int calcMaxBlock()
|
|
{
|
|
int answ = 2;
|
|
if (Width > 450)
|
|
{
|
|
if (Width < 1024)
|
|
{
|
|
answ = (int)Math.Floor((decimal)Width / 200);
|
|
}
|
|
else
|
|
{
|
|
answ = (int)Math.Floor((decimal)Width / 220) - 1;
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected async Task DoLogout()
|
|
{
|
|
string tgtUrl = "logout";
|
|
await Task.Delay(1);
|
|
if (tgtUrl.Contains("status-map"))
|
|
{
|
|
await MsgServ.IdxMaccSet("");
|
|
}
|
|
await MsgServ.LastOpenedPageSet(tgtUrl);
|
|
NavMan.NavigateTo(tgtUrl, true);
|
|
}
|
|
|
|
protected async Task getWDim()
|
|
{
|
|
var dimension = await JSRuntime.InvokeAsync<WindowDimension>("getWindowDimensions");
|
|
Height = dimension.Height;
|
|
Width = dimension.Width;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifica se la macchina sia abilitata per l'operatore
|
|
/// </summary>
|
|
/// <param name="idxMacc"></param>
|
|
/// <returns></returns>
|
|
protected bool MachineIsOprEnab(string idxMacc)
|
|
{
|
|
bool answ = false;
|
|
if (ListMachineEnabled != null && !string.IsNullOrEmpty(idxMacc))
|
|
{
|
|
var macRec = ListMachineEnabled
|
|
.Where(x => x.IdxMacchina == idxMacc)
|
|
.FirstOrDefault();
|
|
answ = macRec != null && macRec.IdxMacchina == idxMacc;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// restituisce MSE dato indice
|
|
/// </summary>
|
|
/// <param name="mseIdx">Indice MSE richiesto</param>
|
|
/// <returns></returns>
|
|
protected MappaStatoExplModel? MseById(int mseIdx)
|
|
{
|
|
MappaStatoExplModel? answ = null;
|
|
if (ListMSE != null && ListMSE.Count > mseIdx)
|
|
{
|
|
answ = ListMSE[mseIdx];
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
await getWDim();
|
|
isCalcSize = false;
|
|
// rileggo elenco macchine operatore...
|
|
if (ListMachineEnabled == null || ListMachineEnabled.Count == 0)
|
|
{
|
|
ListMachineEnabled = await TabDServ.MacchineByMatrOper(MatrOpr);
|
|
}
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
// rileggo macchina e pagina
|
|
await RestoreMaccPage();
|
|
if (ListMSE != null)
|
|
{
|
|
// salvo in LocalStorage...
|
|
await MsgServ.SaveMse(ListMSE);
|
|
}
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
// ora resetto il resto
|
|
ListMSE = null;
|
|
setDefaults();
|
|
await LoadMseData();
|
|
SetupConf();
|
|
TDFeeder.dataPipe.EA_NewMessage += DataPipe_EA_NewMessage;
|
|
TDFeeder.blinkPipe.EA_NewMessage += BlinkPipe_EA_NewMessage;
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
// x prima cosa elenco macchine operatore... se mancasse
|
|
if (ListMachineEnabled == null || ListMachineEnabled.Count == 0)
|
|
{
|
|
ListMachineEnabled = await TabDServ.MacchineByMatrOper(MatrOpr);
|
|
}
|
|
}
|
|
|
|
protected async Task SaveData(List<MappaStatoExplModel> newList)
|
|
{
|
|
// rileggo elenco macchine operatore...
|
|
if (ListMachineEnabled == null || ListMachineEnabled.Count == 0)
|
|
{
|
|
ListMachineEnabled = await TabDServ.MacchineByMatrOper(MatrOpr);
|
|
}
|
|
// salvo valori ricevuti
|
|
AllDataMSE = newList;
|
|
// filtro!
|
|
FiltOprMse();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// Ricezione evento blink
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void BlinkPipe_EA_NewMessage(object? sender, EventArgs e)
|
|
{
|
|
PubSubEventArgs currArgs = (PubSubEventArgs)e;
|
|
// conversione on-the-fly List<string> --> allarmi
|
|
if (!string.IsNullOrEmpty(currArgs.newMessage))
|
|
{
|
|
try
|
|
{
|
|
var dataRaw = JsonConvert.DeserializeObject<string>(currArgs.newMessage);
|
|
if (dataRaw != null)
|
|
{
|
|
bool.TryParse($"{dataRaw}", out doBlink);
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
InvokeAsync(() =>
|
|
{
|
|
StateHasChanged();
|
|
});
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ricevuto nuovi dati da mostrare!
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
private void DataPipe_EA_NewMessage(object? sender, EventArgs e)
|
|
{
|
|
#if false
|
|
// se fossi in update resetto...
|
|
if (MsgServ.IsReloading)
|
|
{
|
|
AllDataMSE = null;
|
|
}
|
|
else
|
|
{
|
|
}
|
|
#endif
|
|
PubSubEventArgs currArgs = (PubSubEventArgs)e;
|
|
// conversione on-the-fly List<string> --> allarmi
|
|
if (!string.IsNullOrEmpty(currArgs.newMessage))
|
|
{
|
|
try
|
|
{
|
|
List<MappaStatoExplModel>? dataList = JsonConvert.DeserializeObject<List<MappaStatoExplModel>>(currArgs.newMessage);
|
|
if (dataList != null)
|
|
{
|
|
InvokeAsync(() => SaveData(dataList));
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
InvokeAsync(() =>
|
|
{
|
|
StateHasChanged();
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// Filtro dati operatore tra macchine visualizzabili e elenco MSE ricevuto
|
|
/// </summary>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
private void FiltOprMse()
|
|
{
|
|
ListMSE = new List<MappaStatoExplModel>();
|
|
if (AllDataMSE != null)
|
|
{
|
|
foreach (var item in AllDataMSE)
|
|
{
|
|
if (MachineIsOprEnab(item.IdxMacchina))
|
|
{
|
|
ListMSE.Add(item);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private async Task LoadMseData()
|
|
{
|
|
AllDataMSE = await MDataService.MseGetAll(true);
|
|
FiltOprMse();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restore della macchina + pagina selezionate da info di sessione browser
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async Task RestoreMaccPage()
|
|
{
|
|
var LastOpenedPage = await MsgServ.LastOpenedPageGet();
|
|
var currMacc = await MsgServ.IdxMaccGet();
|
|
if (currMacc != "" && currMacc != null)
|
|
{
|
|
await MsgServ.IdxMaccSet(currMacc);
|
|
if (LastOpenedPage != "" && LastOpenedPage != null)
|
|
{
|
|
NavMan.NavigateTo(LastOpenedPage);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void setDefaults()
|
|
{
|
|
string df = MsgServ.UserPrefSetup("DefCardMode", "full");
|
|
baseLang = MsgServ.UserPrefSetup("Lang", "IT");
|
|
tcMode = MsgServ.UserPrefSetup("TcMode", "ms");
|
|
ShowCard = df == "shrink" ? false : true;
|
|
isCalcSize = true;
|
|
}
|
|
|
|
private void SetupConf()
|
|
{
|
|
// sistemo i parametri opzionali...
|
|
TabDServ.ConfigGetVal("sART", ref showArt);
|
|
Log.Info($"setupConf | Effettuato setup parametri | showArt: {showArt}");
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
#region Public Classes
|
|
|
|
public class WindowDimension
|
|
{
|
|
#region Public Properties
|
|
|
|
public int Height { get; set; }
|
|
public int Width { get; set; }
|
|
|
|
#endregion Public Properties
|
|
}
|
|
|
|
#endregion Public Classes
|
|
}
|
|
} |