Bozza apgina dettaglio allarmi

This commit is contained in:
Samuele Locatelli
2022-03-17 13:13:47 +01:00
parent ee8e994996
commit fa26f22663
8 changed files with 496 additions and 129 deletions
-40
View File
@@ -1,40 +0,0 @@
@using MP.MONO.Data
@using MP.MONO.UI.Components
@using MP.MONO.Core.DTO
@using MP.MONO.UI.Data
@inject CurrentDataService MMDataService
@if (@ListRecords != null)
{
if (@ListRecords.Count == 0)
{
<i>waiting for data:</i>
<ul>
<li>Current State</li>
<li>Alarms Log</li>
<li>Messages State</li>
</ul>
}
else
{
<ul class="list-group">
@foreach (var item in ListRecords)
{
<li class="list-group-item list-group-item-action">
<div class="d-flex w-100 justify-content-between" title="order">
<div class="small">@item.Title</div>
<div>
<b>@item.Value</b>
</div>
</div>
</li>
}
</ul>
}
}
else
{
<LoadingDataSmall></LoadingDataSmall>
}
@@ -1,71 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using 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.MONO.Core.DTO;
using MP.MONO.Data;
using MP.MONO.UI;
using MP.MONO.UI.Shared;
using MP.MONO.UI.Components;
using MP.MONO.UI.Data;
using Newtonsoft.Json;
namespace MP.MONO.UI.Components
{
public partial class AlarmsHistory
{
private List<DisplayDataDTO>? ListRecords { get; set; } = new List<DisplayDataDTO>();
protected override async Task OnInitializedAsync()
{
await ReloadData();
MMDataService.alarmPipe.EA_NewMessage += AlarmPipe_EA_NewMessage;
}
private void AlarmPipe_EA_NewMessage(object? sender, EventArgs e)
{
PubSubEventArgs currArgs = (PubSubEventArgs)e;
// conversione on-the-fly List<string> --> allarmi
if (!string.IsNullOrEmpty(currArgs.newMessage))
{
try
{
var alarmList = JsonConvert.DeserializeObject<List<string>>(currArgs.newMessage);
ListRecords = alarmList.Select(x => new DisplayDataDTO()
{
IsNumeric = false,
Title = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}",
Value = x,
Order = ListRecords == null ? 0 : ListRecords.Count
}).ToList();
}
catch
{ }
}
InvokeAsync(() =>
{
StateHasChanged();
});
}
protected async Task ReloadData()
{
var alarmList = await MMDataService.getAlarms();
ListRecords = alarmList.Select(x => new DisplayDataDTO()
{
IsNumeric = false,
Title = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss}",
Value = x,
Order = ListRecords == null ? 0 : ListRecords.Count
}).ToList();
}
}
}
+1 -6
View File
@@ -9,12 +9,7 @@
{
if (@ListRecords.Count == 0)
{
<i>waiting for data:</i>
<ul>
<li>Current State</li>
<li>Alarms Log</li>
<li>Messages State</li>
</ul>
<div class="alert alert-success text-center display-4">All OK</div>
}
else
{
+77
View File
@@ -0,0 +1,77 @@
<div class="row">
<div class="col-12 col-lg-9 text-left">
<div class="row">
<div class="col-12 small">
@if (totalCount > 0)
{
<Pagination Class="mb-0">
<PaginationItem>
<PaginationLink Clicked="@HandlePaginationItemClick" Page="1">
<i class="fas fa-angle-double-left"></i>
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink Clicked="@HandlePaginationItemClick" Page="@prevBlock.ToString()">
<span aria-hidden="true"><i class="fas fa-angle-left"></i></span>
</PaginationLink>
</PaginationItem>
@for (int i = @startPage; i <= endPage; ++i)
{
var pageNum = i;
<PaginationItem Active="@(currPage.Equals(pageNum))">
<PaginationLink Clicked="@HandlePaginationItemClick" Page="@pageNum.ToString()">
@pageNum
</PaginationLink>
</PaginationItem>
}
<PaginationItem>
<PaginationLink Clicked="@HandlePaginationItemClick" Page="@nextBlock.ToString()">
<i class="fas fa-angle-right"></i>
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink Clicked="@HandlePaginationItemClick" Page="@LastPage.ToString()">
<i class="fas fa-angle-double-right"></i>
</PaginationLink>
</PaginationItem>
</Pagination>
}
</div>
</div>
<div class="row">
<div class="col-12 small">
@if (showLoading)
{
<Progress>
<ProgressBar Value="@percLoading" Striped="true" Animated="true" />
</Progress>
}
</div>
</div>
</div>
<div class="col-12 col-lg-3">
<div class="d-flex">
<div class="p-1 flex-fill text-right">
@if (!showLoading)
{
<span>@totalCount records</span>
}
</div>
<div class="p-1 flex-fill text-right small">
@if (totalCount > 0)
{
<div class="input-group input-group-sm">
<select @bind="@PageSize" class="form-control form-control-sm">
<option value="5">5</option>
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
</div>
}
</div>
</div>
</div>
</div>
+177
View File
@@ -0,0 +1,177 @@
using Microsoft.AspNetCore.Components;
namespace MP.MONO.UI.Components
{
public partial class DataPager : ComponentBase
{
#region Protected Fields
protected bool _showLoading = false;
#endregion Protected Fields
#region Private Properties
private int endPage
{
get
{
int answ = (int)(currPage / numPages) * numPages + numPages;
answ = answ < LastPage ? answ : LastPage;
return answ;
}
}
private int LastPage
{
get
{
return Math.Max((int)Math.Ceiling(totalCount / (double)PageSize), 1);
}
}
private int nextBlock
{
get
{
int answ = currPage + numPages;
answ = answ < LastPage ? answ : LastPage;
return answ;
}
}
private int numPages { get; set; } = 10;
private int prevBlock
{
get
{
int answ = currPage - numPages;
answ = answ > 0 ? answ : 1;
return answ;
}
}
// calcola un set 1 .. numPages centrato sulla pagina corrente...
private int startPage
{
get
{
int answ = (int)(currPage / numPages) * numPages;
answ = answ > 0 ? answ : 1;
return answ;
}
}
#endregion Private Properties
#region Protected Properties
protected int _numPage { get; set; } = 1;
protected int _numRecord { get; set; } = 10;
protected int percLoading { get; set; } = 0;
#endregion Protected Properties
#region Public Properties
[Parameter]
public int currPage
{
get
{
return _numPage;
}
set
{
bool doReport = !_numPage.Equals(value);
if (doReport)
{
_numPage = value;
reportChangePage();
}
}
}
[Parameter]
public EventCallback<int> numPageChanged { get; set; }
[Parameter]
public EventCallback<int> numRecordChanged { get; set; }
[Parameter]
public int PageSize
{
get
{
return _numRecord;
}
set
{
bool doReport = !_numRecord.Equals(value);
if (doReport)
{
_numRecord = value;
reportChange();
}
}
}
[Parameter]
public bool showLoading
{
get
{
return _showLoading;
}
set
{
if (value)
{
Random random = new Random();
percLoading = random.Next(30, 90);
}
else
{
percLoading = 5;
}
_showLoading = value;
}
}
[Parameter]
public int totalCount { get; set; } = 0;
#endregion Public Properties
#region Private Methods
private void reportChange()
{
numRecordChanged.InvokeAsync(PageSize);
}
private void reportChangePage()
{
numPageChanged.InvokeAsync(currPage);
}
#endregion Private Methods
#region Protected Methods
protected void HandlePaginationItemClick(string page)
{
currPage = int.Parse(page);
}
protected override async Task OnInitializedAsync()
{
await Task.Run(() => showLoading = false);
}
#endregion Protected Methods
}
}
+13
View File
@@ -3,9 +3,11 @@ using MP.MONO.Core.CONF;
using MP.MONO.Core.DTO;
using MP.MONO.Data;
using MP.MONO.Data.Controllers;
using MP.MONO.Data.DbModels;
using Newtonsoft.Json;
using NLog;
using StackExchange.Redis;
using System.Diagnostics;
namespace MP.MONO.UI.Data
{
@@ -281,6 +283,17 @@ namespace MP.MONO.UI.Data
return await Task.FromResult(dbResult);
}
public async Task<List<AlarmLogModel>> AlarmLogGetFilt(int machineId, int skipRec, int numRec)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
List<AlarmLogModel>? dbResult = dbController.AlarmLogGetFilt(machineId, skipRec, numRec);
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Trace($"Effettuata lettura da DB AlarmLogGetFilt: {ts.TotalMilliseconds} ms");
return await Task.FromResult(dbResult);
}
#endregion Public Methods
}
}
+107 -12
View File
@@ -1,25 +1,120 @@
@page "/Alarms"
<div class="row">
<div class="col-4">
<div class="card">
<div class="card-header">
@using MP.MONO.Data
@using MP.MONO.UI.Components
@using MP.MONO.Core.DTO
@using MP.MONO.UI.Data
@inject CurrentDataService MMDataService
<div class="card">
<div class="card-header">
<div class="row">
<div class="col-12 col-md-6 col-lg-3 h3">
<h3>Alarms</h3>
</div>
<div class="card-body">
<div class="row">
<div class="col-4">
<AlarmsOverview></AlarmsOverview>
<div class="col-12 col-md-6 col-lg-9 text-right">
<div class="d-flex flex-row-reverse">
<div class="p-2">
<div class="form-group mb-0">
<Button id="btnReset" class="btn btn-info btn-sm btn-block" Clicked="DoRefresh" title="Reset Filter"><span class="oi oi-loop-circular"></span></Button>
</div>
</div>
<div class="col-8">
<AlarmsHistory></AlarmsHistory>
<div class="p-2">
<div class="input-group input-group-sm">
<div class="input-group-prepend">
<span class="input-group-text">Max Record:</span>
</div>
<input class="form-control form-control-sm" @bind-value="@MaxRecord" title="Max number of record to show" />
</div>
</div>
@*<div class="p-2">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="fas fa-gas-pump" aria-hidden="true"></span>
</span>
</div>
<select @bind="@SelPlantId" class="form-control form-control-sm">
<option value="0">--- Tutti ---</option>
@if (PlantsList != null)
{
foreach (var item in PlantsList)
{
<option value="@item.PlantId">@item.PlantCode | @item.PlantDesc</option>
}
}
</select>
</div>
</div>*@
</div>
</div>
</div>
</div>
<div class="card-body">
<div class="row">
<div class="col-4">
<h5>Current alarms</h5>
<AlarmsOverview></AlarmsOverview>
</div>
<div class="col-8">
@if (ListRecords == null)
{
<LoadingData></LoadingData>
}
else if (totalCount == 0)
{
<div class="alert alert-warning text-center display-4">No record found</div>
}
else
{
<table class="table table-sm table-striped table-responsive-lg">
<thead>
<tr>
<th>Data</th>
<th>Ora</th>
<th>Codice Area</th>
<th class="text-right">Codice</th>
<th class="text-right">Stato</th>
</tr>
</thead>
<tbody>
@foreach (var record in ListRecords)
{
<tr>
<td>
@record.DtRif.ToString("ddd yyyy.MM.dd")
</td>
<td>
@record.DtRif.ToString("HH:mm:ss")
</td>
<td><b>@record.MemAddress</b> / @record.Index</td>
<td class="text-right">
@record.Status
</td>
<td class="text-right">
@if (record.Status == 0)
{
<span class="text-success">@record.ValDecoded <i class="fas fa-certificate"></i></span>
}
else
{
<span class="text-danger">@record.ValDecoded <i class="fas fa-exclamation-triangle"></i></span>
}
</td>
</tr>
}
</tbody>
</table>
}
</div>
</div>
</div>
<div class="card-footer p-1">
<DataPager PageSize="numRecord" currPage="currPage" numRecordChanged="ForceReload" numPageChanged="ForceReloadPage" totalCount="totalCount" showLoading="isLoading" />
</div>
</div>
@code {
}
+121
View File
@@ -0,0 +1,121 @@
using MP.MONO.Data.DbModels;
namespace MP.MONO.UI.Pages
{
public partial class Alarms
{
#region Private Fields
private List<AlarmLogModel>? ListRecords = null;
// FARE!!! filtro macchina
private int MachineId = 1;
private List<AlarmLogModel>? SearchRecords = null;
#endregion Private Fields
#region Protected Fields
protected int _MaxRecord = 100;
#endregion Protected Fields
#region Private Properties
private int _currPage { get; set; } = 1;
private int _numRecord { get; set; } = 10;
private int currPage
{
get => _currPage;
set
{
if (_currPage != value)
{
_currPage = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
private bool isLoading { get; set; } = false;
private int numRecord
{
get => _numRecord;
set
{
if (_numRecord != value)
{
_numRecord = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
#endregion Private Properties
#region Protected Properties
protected int MaxRecord
{
get
{
return _MaxRecord;
}
set
{
if (_MaxRecord != value)
{
_MaxRecord = value;
var pUpd = Task.Run(async () => await ReloadData());
pUpd.Wait();
}
}
}
protected int totalCount
{
get
{
int answ = 0;
if (SearchRecords != null)
{
answ = SearchRecords.Count;
}
return answ;
}
}
#endregion Protected Properties
#region Protected Methods
protected void ForceReload(int newNum)
{
numRecord = newNum;
}
protected void ForceReloadPage(int newNum)
{
currPage = newNum;
}
protected override async Task OnInitializedAsync()
{
await ReloadData();
}
protected async Task ReloadData()
{
SearchRecords = await MMDataService.AlarmLogGetFilt(MachineId, 0, MaxRecord);
ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
}
#endregion Protected Methods
}
}