diff --git a/MP-TAB-SERV/Components/MachineBlock.razor b/MP-TAB-SERV/Components/MachineBlock.razor index 9d1d4c05..5ff8d645 100644 --- a/MP-TAB-SERV/Components/MachineBlock.razor +++ b/MP-TAB-SERV/Components/MachineBlock.razor @@ -1,4 +1,4 @@ -@if (RecMSE == null) +@if (isLoading) {
@@ -166,139 +166,4 @@ else } } -@code { - [Parameter] - public MappaStatoExpl? RecMSE { get; set; } = null; - - - [Parameter] - public int keepAliveMin { get; set; } = 5; - - - [Parameter] - public bool FullMode { get; set; } = true; - - [Inject] - protected NavigationManager NavMan { get; set; } = null!; - - - protected int kaFactor = 60 / 2; - - protected override void OnInitialized() - { - // se configurata uso cartella virtuale... altrimenti cartella processo - imgBasePath = Environment.CurrentDirectory;// @"C:\Steamware\macchine"; - } - - private string imgBasePath = ""; - - protected ProdAdvDispl.ProdCounter CurrCount - { - get - { - ProdAdvDispl.ProdCounter answ = new ProdAdvDispl.ProdCounter() - { - numPzConf = (int)RecMSE.PezziConf, - numPzOrd= (int)RecMSE.NumPezzi, - numPzProd= (int)RecMSE.PezziProd - }; - return answ; - } - } - - protected async Task ShowDetail() - { - NavMan.NavigateTo($"machine-detail/?IdxMacc={RecMSE!.IdxMacchina}"); - } - - /// - /// url completo immagine - /// - /// - /// - public string ImgUrlMacc(string url) - { - string answ = ""; - if (string.IsNullOrEmpty(url.ToString())) - { - url = "Steamware.png"; - } - // verifico esistenza macchina SMALL... - answ = $"images/macchine/small/{url}"; - string fullPath = Path.Combine(imgBasePath, "wwwroot", answ); - if (!File.Exists(fullPath)) - { - // se non ci fosse cerco immagine fullsize - answ = $"images/macchine/{url}"; - fullPath = Path.Combine(imgBasePath, "wwwroot", answ); - } - // altrimenti metto default Steamware - if (!File.Exists(fullPath)) - { - answ = "images/macchine/Steamware.png"; - } - return answ; - } - - /// - /// formatta la durata in minuti in un modo "human readable" gg/ore/min - /// - /// minuti - /// - public static string formatDurata(double? minuti) - { - string answ = "??"; - if (minuti != null) - { - DateTime tempo = new DateTime(); - tempo = tempo.AddMinutes((double)minuti); - - if (minuti < 60) - { - answ = $"{tempo.Minute:00}:{tempo.Second:00}"; - } - else if (minuti < 1440) - { - answ = $"{tempo.Hour}h {tempo.Minute}m"; - } - else - { - answ = $"{tempo.DayOfYear}g {tempo.Hour}h"; - } - } - return answ; - } - - private string cssComStatus(string semaforo, DateTime? lastUpdateN) - { - DateTime lastUpdate = lastUpdateN.HasValue ? (DateTime)lastUpdateN : DateTime.Now.AddHours(-1); - string answ = cssStatus(semaforo); - if (DateTime.Now.Subtract(lastUpdate).TotalSeconds > (keepAliveMin * kaFactor)) - { - answ = $"{baseCss}Ro"; - // blink se secondo pari... - DateTime adesso = DateTime.Now; - int resto = 0; - Math.DivRem(adesso.Second, 2, out resto); - if (resto == 0) - { - answ += "_b"; - } - } - return answ; - } - - private string cssStatus(string codSemaforo) - { - // se vuoto --> mostra nero! - if (string.IsNullOrEmpty(codSemaforo)) - { - codSemaforo = "sNe"; - } - string codColore = codSemaforo.Substring(1, 2); - string answ = $"{baseCss}{codColore}"; - return answ; - } - protected string baseCss = "sem"; -} diff --git a/MP-TAB-SERV/Components/MachineBlock.razor.cs b/MP-TAB-SERV/Components/MachineBlock.razor.cs new file mode 100644 index 00000000..f1f05400 --- /dev/null +++ b/MP-TAB-SERV/Components/MachineBlock.razor.cs @@ -0,0 +1,197 @@ +using global::Microsoft.AspNetCore.Components; +using MP.Data.DatabaseModels; +using MP.Data.Services; + +namespace MP_TAB_SERV.Components +{ + public partial class MachineBlock + { + #region Public Properties + + [Parameter] + public bool FullMode { get; set; } = true; + + [Parameter] + public int keepAliveMin { get; set; } = 5; + + [Parameter] + public MappaStatoExpl? RecMSE { get; set; } = null; + + #endregion Public Properties + + #region Public Methods + + /// + /// formatta la durata in minuti in un modo "human readable" gg/ore/min + /// + /// minuti + /// + public static string formatDurata(double? minuti) + { + string answ = "??"; + if (minuti != null) + { + DateTime tempo = new DateTime(); + tempo = tempo.AddMinutes((double)minuti); + if (minuti < 60) + { + answ = $"{tempo.Minute:00}:{tempo.Second:00}"; + } + else if (minuti < 1440) + { + answ = $"{tempo.Hour}h {tempo.Minute}m"; + } + else + { + answ = $"{tempo.DayOfYear}g {tempo.Hour}h"; + } + } + + return answ; + } + + /// + /// url completo immagine + /// + /// + /// + public string ImgUrlMacc(string url) + { + string answ = ""; + if (string.IsNullOrEmpty(url.ToString())) + { + url = "Steamware.png"; + } + + // verifico esistenza macchina SMALL... + answ = $"images/macchine/small/{url}"; + string fullPath = Path.Combine(imgBasePath, "wwwroot", answ); + if (!File.Exists(fullPath)) + { + // se non ci fosse cerco immagine fullsize + answ = $"images/macchine/{url}"; + fullPath = Path.Combine(imgBasePath, "wwwroot", answ); + } + + // altrimenti metto default Steamware + if (!File.Exists(fullPath)) + { + answ = "images/macchine/Steamware.png"; + } + + return answ; + } + + #endregion Public Methods + + #region Protected Fields + + protected string baseCss = "sem"; + + protected int kaFactor = 60 / 2; + + #endregion Protected Fields + + #region Protected Properties + + protected ProdAdvDispl.ProdCounter CurrCount + { + get + { + ProdAdvDispl.ProdCounter answ = new ProdAdvDispl.ProdCounter() + { + numPzConf = (int)RecMSE.PezziConf, + numPzOrd = (int)RecMSE.NumPezzi, + numPzProd = (int)RecMSE.PezziProd + }; + return answ; + } + } + + [Inject] + protected MessageService MServ { get; set; } = null!; + + [Inject] + protected NavigationManager NavMan { get; set; } = null!; + + #endregion Protected Properties + + #region Protected Methods + + protected override void OnInitialized() + { + isLoading = true; + // se configurata uso cartella virtuale... altrimenti cartella processo + imgBasePath = Environment.CurrentDirectory; // @"C:\Steamware\macchine"; + } + + protected override async Task OnParametersSetAsync() + { + isLoading = RecMSE == null; + await Task.Delay(1); + } + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + isLoading = RecMSE == null; + await Task.Delay(1); + //return base.OnAfterRenderAsync(firstRender); + } + + + protected async Task ShowDetail() + { + // salvo idxMacch + await MServ.IdxMaccSet(RecMSE!.IdxMacchina); + // navigo! + NavMan.NavigateTo($"machine-detail"); + } + + private bool isLoading = false; + + #endregion Protected Methods + + #region Private Fields + + private string imgBasePath = ""; + + #endregion Private Fields + + #region Private Methods + + private string cssComStatus(string semaforo, DateTime? lastUpdateN) + { + DateTime lastUpdate = lastUpdateN.HasValue ? (DateTime)lastUpdateN : DateTime.Now.AddHours(-1); + string answ = cssStatus(semaforo); + if (DateTime.Now.Subtract(lastUpdate).TotalSeconds > (keepAliveMin * kaFactor)) + { + answ = $"{baseCss}Ro"; + // blink se secondo pari... + DateTime adesso = DateTime.Now; + int resto = 0; + Math.DivRem(adesso.Second, 2, out resto); + if (resto == 0) + { + answ += "_b"; + } + } + + return answ; + } + + private string cssStatus(string codSemaforo) + { + // se vuoto --> mostra nero! + if (string.IsNullOrEmpty(codSemaforo)) + { + codSemaforo = "sNe"; + } + + string codColore = codSemaforo.Substring(1, 2); + string answ = $"{baseCss}{codColore}"; + return answ; + } + + #endregion Private Methods + } +} \ No newline at end of file diff --git a/MP-TAB-SERV/Pages/MachineDetail.razor b/MP-TAB-SERV/Pages/MachineDetail.razor index 66b50e9c..30634109 100644 --- a/MP-TAB-SERV/Pages/MachineDetail.razor +++ b/MP-TAB-SERV/Pages/MachineDetail.razor @@ -3,32 +3,12 @@ @using MP.Data.Services; @inject MessageService MsgServ -

Machine Detail

-

@IdxMacc

-@if (CurrMSE == null) +@if (string.IsNullOrEmpty(IdxMacc) || CurrMSE == null) { - + loading... } else { } -@code { - - [Parameter] - [SupplyParameterFromQuery(Name = "IdxMacc")] - public string? IdxMacc { get; set; } - - protected override async Task OnAfterRenderAsync(bool firstRender) - { - // recupero MSE macchina.... - if (!string.IsNullOrEmpty(IdxMacc)) - { - CurrMSE = await MsgServ.GetMachineMse(IdxMacc); - } - //await InvokeAsync(StateHasChanged); - // return base.OnAfterRenderAsync(firstRender); - } - protected MappaStatoExpl? CurrMSE { get; set; } = null; -} diff --git a/MP-TAB-SERV/Pages/MachineDetail.razor.cs b/MP-TAB-SERV/Pages/MachineDetail.razor.cs new file mode 100644 index 00000000..e4845ec2 --- /dev/null +++ b/MP-TAB-SERV/Pages/MachineDetail.razor.cs @@ -0,0 +1,43 @@ +using global::System; +using global::System.Collections.Generic; +using global::System.Linq; +using global::System.Threading.Tasks; +using global::Microsoft.AspNetCore.Components; +using System.Net.Http; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Components.Authorization; +using Microsoft.AspNetCore.Components.Forms; +using Microsoft.AspNetCore.Components.Routing; +using Microsoft.AspNetCore.Components.Web; +using Microsoft.AspNetCore.Components.Web.Virtualization; +using Microsoft.JSInterop; +using MP_TAB_SERV; +using MP_TAB_SERV.Shared; +using MP_TAB_SERV.Components; +using MP.Data; +using MP.Data.DatabaseModels; +using MP.Data.DTO; +using NLog; +using MP.Data.Services; + +namespace MP_TAB_SERV.Pages +{ + public partial class MachineDetail + { + protected string IdxMacc { get; set; } = ""; + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + IdxMacc = await MsgServ.IdxMaccGet(); + // recupero MSE macchina.... + if (!string.IsNullOrEmpty(IdxMacc)) + { + CurrMSE = await MsgServ.GetMachineMse(IdxMacc); + } + //await InvokeAsync(StateHasChanged); + // return base.OnAfterRenderAsync(firstRender); + } + + protected MappaStatoExpl? CurrMSE { get; set; } = null; + } +} \ No newline at end of file diff --git a/MP-TAB-SERV/Pages/StatusMap.razor b/MP-TAB-SERV/Pages/StatusMap.razor index 297c5377..cd5bea4b 100644 --- a/MP-TAB-SERV/Pages/StatusMap.razor +++ b/MP-TAB-SERV/Pages/StatusMap.razor @@ -1,4 +1,4 @@ -@*@page "/"*@ +@page "/" @page "/home" @page "/status-map" diff --git a/MP.Data/Services/MessageService.cs b/MP.Data/Services/MessageService.cs index e2acba95..26afdf92 100644 --- a/MP.Data/Services/MessageService.cs +++ b/MP.Data/Services/MessageService.cs @@ -107,6 +107,21 @@ namespace MP.Data.Services pUpd.Wait(); } } + /// + /// Macchine attualmente selezionata + /// + public async Task IdxMaccGet() + { + return await localStorage.GetItemAsync("CurrMach"); + } + + /// + /// Macchine attualmente selezionata + /// + public async Task IdxMaccSet(string machSel) + { + await localStorage.SetItemAsync("CurrMach", machSel); + } #if false public bool IsActive @@ -188,19 +203,19 @@ namespace MP.Data.Services public RegAttivitaModel? recordRA { get; set; } = null; #endif - public AnagOperatoriModel? RigaOper + public AnagOperatoriModel? RigaOper + { + get => _rigaOper; + set { - get => _rigaOper; - set + // salvo + _rigaOper = value; + if (EA_OperUpdated != null) { - // salvo - _rigaOper = value; - if (EA_OperUpdated != null) - { - EA_OperUpdated?.Invoke(); - } + EA_OperUpdated?.Invoke(); } } + } #if false public string SearchVal @@ -239,42 +254,42 @@ namespace MP.Data.Services public DateTime targetDateMancTimb { get; set; } #endif - #endregion Public Properties + #endregion Public Properties - protected const string KeyMacDict = "MachineDict"; - protected const string KeyDevSec = "DevSec"; - protected const string KeyDevIp4 = "DevIpv4"; + protected const string KeyMacDict = "MachineDict"; + protected const string KeyDevSec = "DevSec"; + protected const string KeyDevIp4 = "DevIpv4"; - #region Public Methods + #region Public Methods - /// - /// Restituisce il valore di DeviceSecret da localstorage - /// - /// - public async Task getDevSecretAsync() + /// + /// Restituisce il valore di DeviceSecret da localstorage + /// + /// + public async Task getDevSecretAsync() + { + string answ = ""; + var result = await localStorage.GetItemAsync(KeyDevSec); + if (result != null) { - string answ = ""; - var result = await localStorage.GetItemAsync(KeyDevSec); - if (result != null) - { - answ = result; - } - return answ; + answ = result; } - /// - /// Restituisce il valore Ipv4 del Device da localstorage - /// - /// - public async Task getDevIpAsync() + return answ; + } + /// + /// Restituisce il valore Ipv4 del Device da localstorage + /// + /// + public async Task getDevIpAsync() + { + string answ = ""; + var result = await localStorage.GetItemAsync(KeyDevIp4); + if (result != null) { - string answ = ""; - var result = await localStorage.GetItemAsync(KeyDevIp4); - if (result != null) - { - answ = result; - } - return answ; + answ = result; } + return answ; + } #if false public void ReportDateChange() @@ -344,112 +359,112 @@ namespace MP.Data.Services } #endif - /// - /// Scrive il valore di DeviceSecret nel localstoragee - /// - /// - /// - public async Task setDevSecretAsync(string newVal) + /// + /// Scrive il valore di DeviceSecret nel localstoragee + /// + /// + /// + public async Task setDevSecretAsync(string newVal) + { + bool answ = false; + try { - bool answ = false; - try - { - await localStorage.SetItemAsync(KeyDevSec, newVal); - answ = true; - } - catch (Exception ex) - { - Log.Error($"Eccezione in setDevSecretAsync{Environment.NewLine}{ex}"); - } - return answ; + await localStorage.SetItemAsync(KeyDevSec, newVal); + answ = true; } - /// - /// Scrive il valore di IPV4 del device nel localstoragee - /// - /// - /// - public async Task setDevIpv4Async(string newVal) + catch (Exception ex) { - bool answ = false; - try - { - await localStorage.SetItemAsync(KeyDevIp4, newVal); - answ = true; - } - catch (Exception ex) - { - Log.Error($"Eccezione in setDevIpv4Async{Environment.NewLine}{ex}"); - } - return answ; + Log.Error($"Eccezione in setDevSecretAsync{Environment.NewLine}{ex}"); } - - private string machineMse(string idxMacc) + return answ; + } + /// + /// Scrive il valore di IPV4 del device nel localstoragee + /// + /// + /// + public async Task setDevIpv4Async(string newVal) + { + bool answ = false; + try { - return $"MSE_{idxMacc}"; + await localStorage.SetItemAsync(KeyDevIp4, newVal); + answ = true; } - - /// - /// Effettua salvataggio in localstorage dei dati MSE correnti - /// - /// - /// - /// - public async Task SaveMse(List currListMSE) + catch (Exception ex) { - foreach (var item in currListMSE) - { - string serVal = JsonSerializer.Serialize(item); - await localStorage.SetItemAsync(machineMse(item.IdxMacchina), serVal); - } + Log.Error($"Eccezione in setDevIpv4Async{Environment.NewLine}{ex}"); } + return answ; + } - /// - /// Recupero dati MSE x macchina - /// - /// - /// - public async Task GetMachineMse(string idxMacchina) + private string machineMse(string idxMacc) + { + return $"MSE_{idxMacc}"; + } + + /// + /// Effettua salvataggio in localstorage dei dati MSE correnti + /// + /// + /// + /// + public async Task SaveMse(List currListMSE) + { + foreach (var item in currListMSE) { - MappaStatoExpl answ = new MappaStatoExpl(); - //answ = await localStorage.GetItemAsync(machineMse(idxMacchina)); - string tryString = await localStorage.GetItemAsync(machineMse(idxMacchina)); - if(tryString != "") - { - answ = JsonSerializer.Deserialize(tryString); - } - return answ; + string serVal = JsonSerializer.Serialize(item); + await localStorage.SetItemAsync(machineMse(item.IdxMacchina), serVal); } + } - #endregion Public Methods + /// + /// Recupero dati MSE x macchina + /// + /// + /// + public async Task GetMachineMse(string idxMacchina) + { + MappaStatoExpl answ = new MappaStatoExpl(); + //answ = await localStorage.GetItemAsync(machineMse(idxMacchina)); + string tryString = await localStorage.GetItemAsync(machineMse(idxMacchina)); + if (tryString != "") + { + answ = JsonSerializer.Deserialize(tryString); + } + return answ; + } - #region Protected Properties + #endregion Public Methods - protected ILocalStorageService localStorage { get; set; } = null!; + #region Protected Properties - protected ISessionStorageService sessionStore { get; set; } = null!; + protected ILocalStorageService localStorage { get; set; } = null!; - #endregion Protected Properties + protected ISessionStorageService sessionStore { get; set; } = null!; - #region Private Fields + #endregion Protected Properties + + #region Private Fields #if false private string _pageIcon = ""; private string _pageName = ""; #endif - private AnagOperatoriModel? _rigaOper; + private AnagOperatoriModel? _rigaOper; - private Logger Log = LogManager.GetCurrentClassLogger(); + private Logger Log = LogManager.GetCurrentClassLogger(); #if false private string _searchVal = ""; private bool showSearch; #endif - #endregion Private Fields + #endregion Private Fields - #region Private Properties + #region Private Properties #if false @@ -457,9 +472,9 @@ namespace MP.Data.Services private bool nextIsEntrata { get; set; } = true; #endif - #endregion Private Properties + #endregion Private Properties - #region Private Methods + #region Private Methods #if false private void ReportPageUpd() @@ -479,6 +494,6 @@ namespace MP.Data.Services } #endif - #endregion Private Methods - } + #endregion Private Methods +} }