280 lines
8.5 KiB
C#
280 lines
8.5 KiB
C#
using EgwCoreLib.Lux.Core.RestPayload;
|
|
using EgwCoreLib.Lux.Data.DbModel.Config;
|
|
using EgwCoreLib.Lux.Data.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Cors.Infrastructure;
|
|
using Microsoft.JSInterop;
|
|
using System.ComponentModel;
|
|
|
|
namespace Lux.UI.Components.Compo.Config
|
|
{
|
|
public partial class ProfileMan : IDisposable
|
|
{
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Dispose sottoscrizione canale
|
|
/// </summary>
|
|
public void Dispose()
|
|
{
|
|
DLService.PipeProfList.EA_NewMessage -= PipeProfList_EA_NewMessage;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected ConfigDataService CDService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IConfiguration Config { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected CalcRuidService CRService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected CalcRequestService CService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected DataLayerServices DLService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
protected string SearchVal
|
|
{
|
|
get => searchVal;
|
|
set
|
|
{
|
|
if (searchVal != value)
|
|
{
|
|
searchVal = value;
|
|
FullUpdate();
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Richiesta update elenco HW preferiti/configurati
|
|
/// </summary>
|
|
protected async Task DoReqUpdate()
|
|
{
|
|
// chiamata richiesta update da calc
|
|
await callRefreshProfList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update soglie da elenco profili
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
|
|
protected async Task DoReqUpdateThresh()
|
|
{
|
|
// chiamata richiesta update da calc
|
|
await callRefreshProfThresh();
|
|
}
|
|
|
|
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.PipeProfList.EA_NewMessage += PipeProfList_EA_NewMessage;
|
|
}
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
ReloadData();
|
|
UpdateTable();
|
|
}
|
|
|
|
protected void ResetSearch()
|
|
{
|
|
SearchVal = "";
|
|
}
|
|
|
|
protected void SaveNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
UpdateTable();
|
|
}
|
|
|
|
protected void SavePage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
UpdateTable();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private List<string> AllRecords = new();
|
|
|
|
private string apiUrl = "";
|
|
|
|
private string calcTag = "calc";
|
|
|
|
private EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS cEnvir = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW;
|
|
|
|
/// <summary>
|
|
/// Per eventuale gestione multi-profilo su multi tenant
|
|
/// </summary>
|
|
private string confProf = "Default";
|
|
|
|
private int currPage = 1;
|
|
|
|
private string genericBasePath = "generic";
|
|
|
|
private bool isLoading = false;
|
|
|
|
private List<string> 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";
|
|
}
|
|
|
|
private string searchVal { get; set; } = string.Empty;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// Effettua vera richiesta elenco profili gestiti
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async Task callRefreshProfList()
|
|
{
|
|
Dictionary<string, string> DictExec = new Dictionary<string, string>();
|
|
var cMode = Egw.Window.Data.Enums.QuestionModes.CONFIG;
|
|
var cSubMode = Egw.Window.Data.Enums.QuestionConfSubModes.PROFILELIST;
|
|
// compongo righiesta
|
|
string reqUid = "Default";
|
|
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}");
|
|
CalcRequestDTO req = new CalcRequestDTO()
|
|
{
|
|
EnvType = cEnvir,
|
|
DictExec = DictExec
|
|
};
|
|
// svuotiamo cache dati...
|
|
AllRecords = new List<string>();
|
|
isLoading = true;
|
|
|
|
// chiamo la chiamata POST alla API, che manda la richiesta via REDIS
|
|
await CService.CallRestPost($"{apiUrl}/{genericBasePath}", $"{calcTag}/{reqUid}", req);
|
|
}
|
|
|
|
private string cssBtnThresh
|
|
{
|
|
get => ListRecords != null && ListRecords.Count > 0 ? "btn-info" : "btn-secondary disabled";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua richiesta delle soglie dati i profili
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async Task callRefreshProfThresh()
|
|
{
|
|
Dictionary<string, string> DictExec = new Dictionary<string, string>();
|
|
var cMode = Egw.Window.Data.Enums.QuestionModes.CONFIG;
|
|
var cSubMode = Egw.Window.Data.Enums.QuestionConfSubModes.THRESHOLDLIST;
|
|
DictExec.Add("UID", "");
|
|
DictExec.Add("RUID", "");
|
|
DictExec.Add("ProfileName", "");
|
|
DictExec.Add("Mode", $"{(int)cMode}");
|
|
DictExec.Add("SubMode", $"{(int)cSubMode}");
|
|
// ciclo x tutti i profili...
|
|
foreach (var profile in ListRecords)
|
|
{
|
|
string reqUid = profile;
|
|
DictExec["UID"] = reqUid;
|
|
DictExec["ProfileName"] = reqUid;
|
|
// creo registrazione richiesta...
|
|
var ruid = await CRService.AddRequestAsync($"{cEnvir}", $"{cMode}-{cSubMode}", reqUid);
|
|
// aggiungo RUID effettivo
|
|
DictExec["RUID"] = ruid;
|
|
CalcRequestDTO req = new CalcRequestDTO()
|
|
{
|
|
EnvType = cEnvir,
|
|
DictExec = DictExec
|
|
};
|
|
// chiamo la chiamata POST alla API, che manda la richiesta via REDIS
|
|
await CService.CallRestPost($"{apiUrl}/{genericBasePath}", $"{calcTag}/{reqUid}", req);
|
|
}
|
|
}
|
|
|
|
private void FullUpdate()
|
|
{
|
|
ReloadData();
|
|
UpdateTable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ricevuto update da Calc x elenco profili: aggiorno!
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void PipeProfList_EA_NewMessage(object? sender, EventArgs e)
|
|
{
|
|
FullUpdate();
|
|
_ = InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
private void ReloadData()
|
|
{
|
|
isLoading = true;
|
|
AllRecords = CDService.ProfileList(cEnvir, confProf);
|
|
// se ho ricerca testuale faccio filtro ulteriore...
|
|
if (string.IsNullOrEmpty(SearchVal))
|
|
{
|
|
AllRecords = AllRecords
|
|
.OrderBy(x => x)
|
|
.ToList();
|
|
}
|
|
else
|
|
{
|
|
AllRecords = AllRecords
|
|
.Where(x => x.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase))
|
|
.OrderBy(x => x)
|
|
.ToList();
|
|
}
|
|
totalCount = AllRecords.Count;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Filtro e paginazione
|
|
/// </summary>
|
|
private void UpdateTable()
|
|
{
|
|
// fix paginazione
|
|
ListRecords = AllRecords
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |