Inizio gestione con unico obj filtro

This commit is contained in:
Samuele Locatelli
2022-09-15 15:30:48 +02:00
parent 6790088950
commit 673eb62d8c
8 changed files with 267 additions and 297 deletions
+95 -57
View File
@@ -10,33 +10,18 @@ namespace MP.SPEC.Components
{
#region Public Properties
[Parameter]
public EventCallback<bool> PagerResetReq { get; set; }
[Parameter]
public EventCallback<int> TotRecordChanged { get; set; }
[Parameter]
public bool LiveUpdate
public SelectFluxParams SelFilter
{
get => _liveUpdate;
get => _selFilter;
set
{
_liveUpdate = value;
// var pUpd = Task.Run(async () => await reloadData(false));
// pUpd.Wait();
}
}
private bool _liveUpdate { get; set; }
[Parameter]
public int MaxRecord
{
get => _maxRecord;
set
{
if (_maxRecord != value)
if (!_selFilter.Equals(value))
{
_maxRecord = value;
_selFilter = value;
var pUpd = Task.Run(async () => await reloadData(true));
pUpd.Wait();
}
@@ -44,37 +29,7 @@ namespace MP.SPEC.Components
}
[Parameter]
public EventCallback<bool> PagerResetReq { get; set; }
[Parameter]
public string SelFlux
{
get => _selFlux;
set
{
if (_selFlux != value)
{
_selFlux = value;
//var pUpd = Task.Run(async () => await reloadData(false));
//pUpd.Wait();
}
}
}
[Parameter]
public string SelMacchina
{
get => _selMacchina;
set
{
if (_selMacchina != value)
{
_selMacchina = value;
//var pUpd = Task.Run(async () => await reloadData(false));
//pUpd.Wait();
}
}
}
public EventCallback<int> TotRecordChanged { get; set; }
#endregion Public Properties
@@ -138,8 +93,6 @@ namespace MP.SPEC.Components
isLoading = false;
}
private int tOutPeriod { get; set; } = 2000;
public void StartTimer()
{
//int.TryParse(Configuration["ReloadStatusTimer"], out tOutPeriod);
@@ -201,16 +154,17 @@ namespace MP.SPEC.Components
private int _maxRecord = 100;
private string _selFlux = "*";
private string _selMacchina = "*";
private int _totalCount = 0;
private FluxLog? currRecord = null;
private List<FluxLog>? ListRecords;
private List<FluxLog>? SearchRecords;
#endregion Private Fields
#region Private Properties
private SelectFluxParams _selFilter { get; set; } = new SelectFluxParams();
private int currPage
{
get => MessageService.currPage;
@@ -219,14 +173,96 @@ namespace MP.SPEC.Components
private bool isLoading { get; set; } = false;
private bool LiveUpdate
{
get => SelFilter.LiveUpdate;
}
private int MaxRecord
{
get => _selFilter.MaxRecord;
}
#if false
[Parameter]
public bool LiveUpdate
{
get => _liveUpdate;
set
{
_liveUpdate = value;
// var pUpd = Task.Run(async () => await reloadData(false)); pUpd.Wait();
}
}
private bool _liveUpdate { get; set; }
#endif
#if false
[Parameter]
public int MaxRecord
{
get => _maxRecord;
set
{
if (_maxRecord != value)
{
_maxRecord = value;
var pUpd = Task.Run(async () => await reloadData(true));
pUpd.Wait();
}
}
}
#endif
private int numRecord
{
get => MessageService.numRecord;
set => MessageService.numRecord = value;
}
private string SelFlux
{
get => _selFilter.CodFlux;
}
private string SelMacchina
{
get => _selFilter.IdxMacchina;
}
#if false
[Parameter]
public string SelFlux
{
get => _selFlux;
set
{
if (_selFlux != value)
{
_selFlux = value;
//var pUpd = Task.Run(async () => await reloadData(false));
//pUpd.Wait();
}
}
}
[Parameter]
public string SelMacchina
{
get => _selMacchina;
set
{
if (_selMacchina != value)
{
_selMacchina = value;
//var pUpd = Task.Run(async () => await reloadData(false));
//pUpd.Wait();
}
}
}
#endif
private int _totalCount = 0;
private int totalCount
{
get => _totalCount;
@@ -240,6 +276,8 @@ namespace MP.SPEC.Components
}
}
private int tOutPeriod { get; set; } = 5000;
#endregion Private Properties
#region Private Methods
+48 -30
View File
@@ -1,36 +1,54 @@
<div class="d-flex justify-content-end">
<div class="px-2">
<select @bind="@selMacchina" class="form-select">
<option value="*">--- Tutti ---</option>
@if (ListMacchine != null)
{
foreach (var item in ListMacchine)
{
<option value="@item">@item</option>
}
}
</select>
</div>
<div class="px-2">
@if (isLoading)
<div class="d-flex justify-content-between">
<div class="px-0">
@if (!liveUpdate)
{
<select disabled>
<option value="*">...loading</option>
</select>
<button class="btn btn-secondary" type="button" @onclick="() => toggleUpdate()">
<small>@lastUpdate</small>
</button>
}
else
{
<select @bind="@selFlux" class="form-select">
<option value="*">--- Tutti ---</option>
@if (ListFlux != null)
{
foreach (var item in ListFlux)
{
<option value="@item">@item</option>
}
}
</select>
{
<button class="btn btn-primary" type="button" @onclick="() => toggleUpdate()">
<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
Valori live
</button>
}
</div>
<div class="px-0">
<div class="d-flex justify-content-end">
<div class="px-2">
<select @bind="@selMacchina" class="form-select">
<option value="*">--- Tutti ---</option>
@if (ListMacchine != null)
{
foreach (var item in ListMacchine)
{
<option value="@item">@item</option>
}
}
</select>
</div>
<div class="px-2">
@if (isLoading)
{
<select disabled>
<option value="*">...loading</option>
</select>
}
else
{
<select @bind="@selFlux" class="form-select">
<option value="*">--- Tutti ---</option>
@if (ListFlux != null)
{
foreach (var item in ListFlux)
{
<option value="@item">@item</option>
}
}
</select>
}
</div>
</div>
</div>
</div>
+74 -40
View File
@@ -1,31 +1,63 @@
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.SPEC;
using MP.SPEC.Shared;
using MP.SPEC.Components;
using MP.SPEC.Data;
namespace MP.SPEC.Components
{
public partial class ParamsFilter
{
[Parameter]
public SelectFluxParams SelFilter { get; set; }
#region Public Properties
[Parameter]
public EventCallback<SelectFluxParams> FilterChanged { get; set; }
[Parameter]
public SelectFluxParams SelFilter { get; set; } = null!;
#endregion Public Properties
#region Protected Fields
protected string lastUpdate = "-";
#endregion Protected Fields
#region Protected Properties
protected bool liveUpdate
{
get => SelFilter.LiveUpdate;
set
{
if (!SelFilter.LiveUpdate.Equals(value))
{
isLoading = true;
SelFilter.LiveUpdate = value;
reportChange();
isLoading = false;
}
}
}
[Inject]
protected MpDataService MDService { get; set; }
protected string selFlux
{
get
{
return SelFilter.CodFlux;
}
set
{
if (!SelFilter.CodFlux.Equals(value))
{
SelFilter.CodFlux = value;
reportChange();
}
}
}
protected string selMacchina
{
get
@@ -45,34 +77,16 @@ namespace MP.SPEC.Components
ListFlux = MDService.ParametriGetFilt(selMacchina).Result;
Task.Delay(1);
StateHasChanged();
Task.Delay(1);
Task.Delay(1);
reportChange();
isLoading = false;
}
}
}
protected string selFlux
{
get
{
return SelFilter.CodFlux;
}
#endregion Protected Properties
set
{
if (!SelFilter.CodFlux.Equals(value))
{
SelFilter.CodFlux = value;
reportChange();
}
}
}
private void reportChange()
{
FilterChanged.InvokeAsync(SelFilter);
}
#region Protected Methods
protected override async Task OnInitializedAsync()
{
@@ -81,6 +95,19 @@ namespace MP.SPEC.Components
ListFlux = await MDService.ParametriGetFilt(selMacchina);
}
protected async Task toggleUpdate()
{
liveUpdate = !liveUpdate;
if (!liveUpdate)
{
lastUpdate = $"Last Snapshot: {DateTime.Now:yyyy/MM/dd HH:mm:ss}";
}
await Task.Delay(1);
}
#endregion Protected Methods
#region Private Fields
private bool isLoading = false;
@@ -88,9 +115,9 @@ namespace MP.SPEC.Components
private List<string>? ListMacchine;
[Inject]
protected MpDataService MDService { get; set; }
#endregion Private Fields
#region Private Methods
private async Task reloadFiltFlux()
{
@@ -98,5 +125,12 @@ namespace MP.SPEC.Components
ListFlux = await MDService.ParametriGetFilt(selMacchina);
await InvokeAsync(() => StateHasChanged());
}
private void reportChange()
{
FilterChanged.InvokeAsync(SelFilter);
}
#endregion Private Methods
}
}
+7 -8
View File
@@ -446,15 +446,14 @@ namespace MP.SPEC.Data
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
string readType = "DB";
result = await Task.FromResult(dbController.ParametriGetFilt(IdxMacchina));
#if false
// 2 minuti valore cache
int maxAgeMin = 5;
string currKey = $"{redisFluxByMac}:{IdxMacchina}";
// cerco in redis dato valore sel macchina...
RedisValue rawData = await redisDb.StringGetAsync(currKey);
if (!string.IsNullOrEmpty($"{rawData}"))
@@ -474,11 +473,11 @@ namespace MP.SPEC.Data
if (result == null)
{
result = new List<string>();
}
}
#endif
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"ParametriGetFilt | Read from {readType}: {ts.TotalMilliseconds}ms");
TimeSpan ts = stopWatch.Elapsed;
Log.Debug($"ParametriGetFilt | Read from {readType}: {ts.TotalMilliseconds}ms");
return result;
}
@@ -535,10 +534,10 @@ namespace MP.SPEC.Data
/// </summary>
private IDatabase redisDb = null!;
private string redisFluxByMac = "MP:MON:Cache:FluxByMac";
private string redisMseKey = "MP:MON:Cache:MSE";
private string redisStatoCom = "MP:MON:Cache:StatoCom";
private string redisTipoArt = "MP:MON:Cache:TipoArt";
private string redisFluxByMac = "MP:MON:Cache:FluxByMac";
#endregion Private Fields
+19 -4
View File
@@ -2,17 +2,25 @@
{
public class SelectFluxParams
{
#region Public Constructors
public SelectFluxParams()
{ }
#endregion Public Constructors
#region Public Properties
public string IdxMacchina { get; set; } = "*";
public string CodFlux { get; set; } = "*";
public string IdxMacchina { get; set; } = "*";
public bool LiveUpdate { get; set; } = true;
public int MaxRecord { get; set; } = 100;
#endregion Public Properties
#region Public Methods
public override bool Equals(object obj)
{
if (!(obj is SelectFluxParams item))
@@ -20,9 +28,16 @@
if (IdxMacchina != item.IdxMacchina)
return false;
if (CodFlux != item.CodFlux)
return false;
if (LiveUpdate != item.LiveUpdate)
return false;
if (MaxRecord != item.MaxRecord)
return false;
return true;
}
@@ -33,4 +48,4 @@
#endregion Public Methods
}
}
}
+5 -58
View File
@@ -2,64 +2,11 @@
<div class="card">
<div class="card-header table-primary">
<div class="row">
<div class="col-5">
<div class="d-flex justify-content-around">
<div class="px-2">
<h3><b>PARAMETERS</b></h3>
</div>
@if (!liveUpdate)
{
<button class="btn btn-secondary" type="button" @onclick="() => toggleUpdate()">
<small>@lastUpdate</small>
</button>
}
else
{
<button class="btn btn-primary" type="button" @onclick="() => toggleUpdate()">
<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
Valori live
</button>
}
<div class="px-2">
</div><div class="px-2">
</div>
</div>
<div class="d-flex">
<div class="px-0">
<h3><b>PARAMETERS</b></h3>
</div>
<div class="col-2">
</div>
<div class="col-5">
@*<div class="d-flex justify-content-between">
<div class="px-2">
</div>
<div class="px-2">
<select @bind="@selMacchina" class="form-select">
<option value="*">--- Tutti ---</option>
@if (ListMacchine != null)
{
foreach (var item in ListMacchine)
{
<option value="@item">@item</option>
}
}
</select>
</div>
<div class="px-2">
@if (!isLoading)
{
<select @bind="@selFlux" class="form-select">
<option value="*">--- Tutti ---</option>
@if (ListFlux != null)
{
foreach (var item in ListFlux)
{
<option value="@item">@item</option>
}
}
</select>
}
</div>
</div>*@
<div class="px-2 flex-fill">
<ParamsFilter FilterChanged="updateFilter"></ParamsFilter>
</div>
</div>
@@ -71,7 +18,7 @@
}
else
{
<ListPARAMS SelMacchina="@selMacchina" SelFlux="@selFlux" LiveUpdate="@liveUpdate" MaxRecord="@maxRecord" TotRecordChanged="@updateTotal"></ListPARAMS>
<ListPARAMS SelFilter="@currFilter" TotRecordChanged="@updateTotal"></ListPARAMS>
}
</div>
<div class="card-footer py-1">
+17 -98
View File
@@ -7,18 +7,11 @@ namespace MP.SPEC.Pages
{
public partial class PARAMS
{
#region Public Methods
#endregion Public Methods
#region Protected Fields
protected string _selFlux = "*";
protected string _selMacchina = "*";
protected string lastUpdate = "-";
protected bool liveUpdate = true;
protected DataPager pagerODL;
protected bool reqNew = false;
@@ -29,6 +22,8 @@ namespace MP.SPEC.Pages
[Inject]
protected IJSRuntime JSRuntime { get; set; }
protected bool liveUpdate { get; set; } = true;
[Inject]
protected MpDataService MDService { get; set; }
@@ -53,12 +48,6 @@ namespace MP.SPEC.Pages
currPage = newNum;
}
protected void updateTotal(int newTotCount)
{
//await Task.Delay(1);
totalCount = newTotCount;
}
protected override async Task OnInitializedAsync()
{
isLoading = true;
@@ -67,10 +56,11 @@ namespace MP.SPEC.Pages
// resetto search
MsgService.SearchVal = "";
ListMacchine = await MDService.MacchineWithFlux();
// carico dati
lastUpdate = $"Updated: {DateTime.Now:yyyy/MM/dd HH:mm:ss}";
#if false
await reloadFilters();
#endif
await reloadData();
isLoading = false;
}
@@ -83,35 +73,24 @@ namespace MP.SPEC.Pages
}
}
/// <summary>
/// Crea nuovo record e va in editing...
/// </summary>
/// <returns></returns>
protected async Task reqNewPODL()
protected void updateTotal(int newTotCount)
{
reqNew = !reqNew;
await Task.Delay(1);
}
protected async Task toggleUpdate()
{
liveUpdate = !liveUpdate;
await reloadData();
//await Task.Delay(1);
totalCount = newTotCount;
}
#endregion Protected Methods
#region Private Fields
private List<string>? ListFlux;
private List<string>? ListMacchine;
private int _totalCount = 0;
#endregion Private Fields
#region Private Properties
private SelectFluxParams currFilter { get; set; } = new SelectFluxParams();
private int currPage
{
@@ -121,56 +100,13 @@ namespace MP.SPEC.Pages
private bool isLoading { get; set; } = false;
private int numRecord
{
get => MsgService.numRecord;
set => MsgService.numRecord = value;
}
private string selFlux
{
get => _selFlux;
set
{
if (_selFlux != value)
{
isLoading = true;
_selFlux = value;
ForceReloadPage(1);
isLoading = false;
liveUpdate = false;
}
}
}
private string selMacchina
{
get => _selMacchina;
set
{
if (_selMacchina != value)
{
isLoading = true;
_selMacchina = value;
//var pUpd = Task.Run(async () =>
//{
// await reloadFilters();
// await InvokeAsync(() => StateHasChanged());
//}
//);
//pUpd.Wait();
//reloadFilters();
ForceReloadPage(1);
isLoading = false;
liveUpdate = false;
}
}
}
private int _totalCount = 0;
private int totalCount
{
get => _totalCount;
@@ -179,26 +115,10 @@ namespace MP.SPEC.Pages
//set => MsgService.totalCount = value;
}
private int maxRecord
{
get => _maxRecord;
set
{
_maxRecord = value;
if (value > 100 && liveUpdate)
{
liveUpdate = false;
}
}
}
private int _maxRecord = 100;
#endregion Private Properties
#region Private Methods
private async Task reloadData()
{
isLoading = true;
@@ -211,22 +131,21 @@ namespace MP.SPEC.Pages
await Task.Delay(1);
}
private async Task reloadFilters()
{
await Task.Delay(1);
selFlux = "*";
ListFlux = await MDService.ParametriGetFilt(selMacchina);
await InvokeAsync(() => StateHasChanged());
}
private async Task updateFilter(SelectFluxParams newParams)
{
isLoading = true;
currFilter = newParams;
liveUpdate = newParams.LiveUpdate;
await Task.Delay(1);
await InvokeAsync(() => StateHasChanged());
//await Task.Delay(1);
#if false
selMacchina = newParams.IdxMacchina;
selFlux = newParams.CodFlux;
//ForceReloadPage();
await InvokeAsync(() => StateHasChanged());
#endif
isLoading = false;
}
+2 -2
View File
@@ -260,14 +260,14 @@ namespace MP.SPEC.Pages
#endregion Private Properties
#region Private Methods
//private async Task navToODL()
//{
// await Task.Delay(1);
// NavManager.NavigateTo("/ODL");
//}
#region Private Methods
private async Task reloadData()
{
isLoading = true;