Files
lux/Lux.UI/Components/Compo/Config/HardwareMan.razor.cs
T
2026-03-24 12:55:16 +01:00

226 lines
6.8 KiB
C#

using EgwCoreLib.Lux.Core.RestPayload;
using EgwCoreLib.Lux.Data.DbModel.Config;
using EgwCoreLib.Lux.Data.Services.General;
using EgwMultiEngineManager.Data;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
namespace Lux.UI.Components.Compo.Config
{
public partial class HardwareMan : IDisposable
{
#region Public Methods
/// <summary>
/// Dispose sottoscrizione canale
/// </summary>
public void Dispose()
{
DLService.PipeHwList.EA_NewMessage -= PipeHwList_EA_NewMessage;
}
#endregion Public Methods
#region Protected Methods
protected override void OnInitialized()
{
apiUrl = Config.GetValue<string>("ServerConf:Prog.ApiUrl") ?? "";
genericBasePath = Config.GetValue<string>("ServerConf:GenericBaseUrl") ?? "";
calcTag = Config.GetValue<string>("ServerConf:CalcTag") ?? "calc";
DLService.PipeHwList.EA_NewMessage += PipeHwList_EA_NewMessage;
}
protected override async Task OnParametersSetAsync()
{
await ReloadDataAsync();
UpdateTable();
}
#endregion Protected Methods
#region Private Fields
private List<HardwareModel> AllRecords = new();
private string apiUrl = "";
private string calcTag = "calc";
private Constants.EXECENVIRONMENTS cEnvir = Constants.EXECENVIRONMENTS.WINDOW;
/// <summary>
/// Conf HW corrente (produttore) - gestire con conf?
/// </summary>
private string confHw = "HW.AGB";
private int currPage = 1;
private string genericBasePath = "generic";
private bool isLoading = false;
private List<HardwareModel> ListRecords = new();
private int numRecord = 5;
private int totalCount = 0;
#endregion Private Fields
#region Private Properties
private string btnResetCss
{
get => string.IsNullOrEmpty(searchVal) ? "btn-outline-light" : "btn-primary";
}
[Inject]
private IConfigDataService CDService { get; set; } = null!;
[Inject]
private IConfiguration Config { get; set; } = null!;
[Inject]
private ICalcRuidService CRService { get; set; } = null!;
[Inject]
private ICalcRequestService CService { get; set; } = null!;
[Inject]
private IDataLayerServices DLService { get; set; } = null!;
[Inject]
private IJSRuntime JSRuntime { get; set; } = null!;
private string searchVal { get; set; } = string.Empty;
private string SearchVal
{
get => searchVal;
set
{
if (searchVal != value)
{
searchVal = value;
currPage = 1;
ReloadDataAsync().ConfigureAwait(false);
UpdateTable();
}
}
}
#endregion Private Properties
#region Private Methods
/// <summary>
/// Effettua vera richiesta della BOM
/// </summary>
/// <param name="reqUid"></param>
/// <returns></returns>
private async Task callRefreshHwList(string reqUid)
{
Dictionary<string, string> DictExec = new Dictionary<string, string>();
var cMode = Egw.Window.Data.Enums.QuestionModes.HARDWARE;
var cSubMode = Egw.Window.Data.Enums.QuestionHwSubModes.LIST;
var cManufact = Egw.Window.Data.Enums.HardwareManufacturers.AGB;
// compongo righiesta
DictExec.Add("Mode", $"{(int)cMode}");
DictExec.Add("UID", reqUid);
// creo registrazione richiesta...
var ruid = await CRService.AddRequestAsync($"{cEnvir}", $"{cMode}-{cSubMode}", reqUid);
// aggiungo RUID effettivo
DictExec.Add("RUID", ruid);
DictExec.Add("SubMode", $"{(int)cSubMode}");
DictExec.Add("Manufacturer", $"{(int)cManufact}");
CalcRequestDTO req = new CalcRequestDTO()
{
EnvType = cEnvir,
DictExec = DictExec
};
// svuotiamo cache dati...
AllRecords = new List<HardwareModel>();
isLoading = true;
// chiamo la chiamata POST alla API, che manda la richiesta via REDIS
await CService.CallRestPost($"{apiUrl}/{genericBasePath}", $"{calcTag}/{reqUid}", req);
}
/// <summary>
/// Richiesta update elenco HW preferiti/configurati
/// </summary>
private Task DoReqUpdate()
{
// chiamata richiesta update da calc
return callRefreshHwList(confHw);
}
/// <summary>
/// Ricevuto update da Calc x elenco HW: aggiorno!
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void PipeHwList_EA_NewMessage(object? sender, EventArgs e)
{
await ReloadDataAsync();
UpdateTable();
await InvokeAsync(StateHasChanged);
}
private async Task ReloadDataAsync()
{
isLoading = true;
AllRecords = await CDService.HwModelListAsync(cEnvir, confHw);
}
private void ResetSearch()
{
SearchVal = "";
}
private void SaveNumRec(int newNum)
{
numRecord = newNum;
UpdateTable();
}
private void SavePage(int newNum)
{
currPage = newNum;
UpdateTable();
}
/// <summary>
/// Filtro e paginazione
/// </summary>
private void UpdateTable()
{
// se ho ricerca testuale faccio filtro ulteriore...
if (string.IsNullOrEmpty(SearchVal))
{
AllRecords = AllRecords
.OrderBy(x => x.Description)
.ToList();
}
else
{
AllRecords = AllRecords
.Where(x =>
x.Description.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase) ||
x.FamilyName.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase))
.OrderBy(x => x.Description)
.ToList();
}
totalCount = AllRecords.Count;
// fix paginazione
ListRecords = AllRecords
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToList();
isLoading = false;
}
#endregion Private Methods
}
}