5d72d21fb1
Update gestione paginazione (visibile solo dove serve) + fix calcolo di alcuni intems male filtrati
359 lines
12 KiB
C#
359 lines
12 KiB
C#
using Liman.CadCam.Services;
|
|
using LiMan.DB;
|
|
using LiMan.DB.DBModels;
|
|
using LiMan.UI.Data;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
using Microsoft.JSInterop;
|
|
using Newtonsoft.Json;
|
|
using NLog.LayoutRenderers;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using static Core.Enum;
|
|
|
|
namespace LiMan.UI.Components
|
|
{
|
|
public partial class EnrollList : IDisposable
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public DateTime DtEnd { get; set; } = DateTime.Today.AddDays(1);
|
|
|
|
[Parameter]
|
|
public DateTime DtStart { get; set; } = DateTime.Today.AddMonths(-1);
|
|
|
|
[Parameter]
|
|
public int IdxLicSel { get; set; } = 0;
|
|
|
|
[Parameter]
|
|
public bool OnlyActive { get; set; } = true;
|
|
|
|
[Parameter]
|
|
public string SearchVal { get; set; } = "";
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Metodo dispose
|
|
/// </summary>
|
|
public virtual void Dispose()
|
|
{
|
|
LMDService.EnrollMessPipe.EA_NewMessage -= async (sender, e) => await EnrollMessPipe_EA_NewMessage(sender, e);
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected AuthenticationStateProvider AuthStateProvider { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected LiManDataService LMDService { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Aggiunge all licenza selezionata altri 10 slot...
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected async Task AddActivations()
|
|
{
|
|
// chiedo conferma...
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Sicuro di voler aggiungere 10 ulteriori slot alla licenza {SelCodInst}? L'operazione non è reversibile"))
|
|
return;
|
|
|
|
var currLic = LMDService.LicenzaNextGetByIdx(SelIdxLic);
|
|
currLic.NumLicenze += 10;
|
|
// aggiorno chiave calcolata
|
|
currLic.Chiave = currLic.ChiaveCalc;
|
|
await LMDService.LicenzeNextUpdate(currLic);
|
|
LMDService.EnrollMessPipe.sendMessage("LicUpdated");
|
|
ShowAddLic = false;
|
|
ShowEditLic = false;
|
|
await ReloadLicData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiunge la licenza selezionata x 10 slot...
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected async Task AddLicense()
|
|
{
|
|
// chiedo conferma...
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Sicuro di voler aggiungere la richiesta per l'installazione {SelCodInst}? L'operazione non è reversibile"))
|
|
return;
|
|
|
|
LicenzaModel newLic = new LicenzaModel()
|
|
{
|
|
CodApp = "UpdateManager",
|
|
CodInst = SelCodInst,
|
|
NumLicenze = 10,
|
|
Tipo = TipoLicenza.MasterKey,
|
|
Scadenza = new DateTime(2099, 12, 31),
|
|
Descrizione = "Licenza per Richieste Enroll Applicativi",
|
|
Enigma = "",
|
|
Payload = "",
|
|
};
|
|
// aggiungo chiave calcolata
|
|
newLic.Chiave = newLic.ChiaveCalc;
|
|
await LMDService.LicenzeNextUpdate(newLic);
|
|
LMDService.EnrollMessPipe.sendMessage("LicAdded");
|
|
ShowAddLic = false;
|
|
ShowEditLic = false;
|
|
await ReloadLicData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera info licenza dato Idx x indicare licenza di assegnazione dell'enroll
|
|
/// </summary>
|
|
/// <param name="idxLic"></param>
|
|
/// <returns></returns>
|
|
protected string DescrLic(int idxLic)
|
|
{
|
|
string answ = "NA";
|
|
if (idxLic > 0 && ListLicenze != null && ListLicenze.Count > 0)
|
|
{
|
|
var sRec = ListLicenze.FirstOrDefault(x => x.IdxLic == idxLic);
|
|
if (sRec != null)
|
|
{
|
|
answ = $"{sRec.CodInst}";
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected async Task DoApprove()
|
|
{
|
|
// chiedo conferma...
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler confermare la richiesta?"))
|
|
return;
|
|
|
|
var authState = await AuthStateProvider.GetAuthenticationStateAsync();
|
|
var user = authState.User;
|
|
|
|
if (user.Identity.IsAuthenticated && !string.IsNullOrEmpty(user.Identity.Name))
|
|
{
|
|
// registra approvazione
|
|
SelRecord.DtAppr = DateTime.Now;
|
|
SelRecord.UserAppr = user.Identity.Name;
|
|
SelRecord.IdxLic = SelIdxLic;
|
|
await LMDService.EnrollReqUpsert(SelRecord);
|
|
LMDService.EnrollMessPipe.sendMessage("AppApproved");
|
|
SelRecord = null;
|
|
await ReloadData();
|
|
}
|
|
}
|
|
|
|
protected async Task DoDelete()
|
|
{
|
|
if (SelRecord != null)
|
|
{
|
|
// chiedo conferma...
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler eliminare il record?"))
|
|
return;
|
|
|
|
// cerca l'attivazione collegata x DeviceID (contenuto nel payload) e se lo trova la elimina
|
|
List<SubLicenzaModel> listAtt = await LMDService.AttivazioniGetByLic(SelRecord.IdxLic);
|
|
// se ne ho trovate cerco...
|
|
if (listAtt.Count > 0)
|
|
{
|
|
var dictPayload = JsonConvert.DeserializeObject<Dictionary<string, string>>(SelRecord.ReqPayload);
|
|
if (dictPayload != null && dictPayload.Count > 0)
|
|
{
|
|
string DeviceID = "";
|
|
if (dictPayload.ContainsKey("DeviceID"))
|
|
{
|
|
DeviceID = dictPayload["DeviceID"];
|
|
}
|
|
// cerco attivazioni correlate (tutte)
|
|
var rec2del = listAtt.Where(x => x.CodImpiego == DeviceID).ToList();
|
|
if (rec2del != null)
|
|
{
|
|
foreach (var rec in rec2del)
|
|
{
|
|
// elimino InstRel data
|
|
int numDel = LMDService.InstallRelDelBySubLic(rec.IdxSubLic);
|
|
// elimino attivazioni
|
|
await LMDService.AttivazioneDelete(rec.IdxSubLic);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
await LMDService.EnrollReqDelete(SelRecord.IdReq);
|
|
await Task.Delay(10);
|
|
SelRecord = null;
|
|
await ReloadData();
|
|
}
|
|
}
|
|
|
|
protected async Task DoSelect(EnrollRequestModel curRec)
|
|
{
|
|
SelRecord = curRec;
|
|
await ReloadLicData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// init sottoscrizione messaggi + refresh dati
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
LMDService.EnrollMessPipe.EA_NewMessage += async (sender, e) => await EnrollMessPipe_EA_NewMessage(sender, e);
|
|
await ReloadData();
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await ReloadLicData();
|
|
await ReloadData();
|
|
}
|
|
|
|
protected async Task ResetSel()
|
|
{
|
|
SelRecord = null;
|
|
await ReloadData();
|
|
}
|
|
|
|
protected async Task setNumPage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
await ReloadData();
|
|
isLoading = false;
|
|
}
|
|
|
|
protected async Task setNumRec(int newNum)
|
|
{
|
|
currPage = 1;
|
|
numRecord = newNum;
|
|
await ReloadData();
|
|
isLoading = false;
|
|
}
|
|
|
|
protected void ToggleAddNew()
|
|
{
|
|
ShowAddLic = !ShowAddLic;
|
|
}
|
|
|
|
protected void ToggleEditLic()
|
|
{
|
|
ShowEditLic = !ShowEditLic;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private List<InstallazioneModel> ListInstall;
|
|
private List<LicenzaModel> ListLicenze;
|
|
|
|
/// <summary>
|
|
/// num max di dettagli KVP da mostrare
|
|
/// </summary>
|
|
private int nShort = 3;
|
|
|
|
private List<int> PageList = new List<int>() { 4, 8, 12, 16, 24, 48 };
|
|
|
|
/// <summary>
|
|
/// Codice installazione selezionata
|
|
/// </summary>
|
|
private string SelCodInst = "";
|
|
|
|
/// <summary>
|
|
/// Idx licenza selezionata
|
|
/// </summary>
|
|
private int SelIdxLic = 0;
|
|
|
|
private bool ShowAddLic = false;
|
|
private bool ShowEditLic = false;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int currPage { get; set; } = 1;
|
|
|
|
private bool isLoading { get; set; } = false;
|
|
|
|
[Inject]
|
|
private IJSRuntime JSRuntime { get; set; }
|
|
|
|
private List<EnrollRequestModel> ListRecords { get; set; } = new List<EnrollRequestModel>();
|
|
|
|
private int numRecord { get; set; } = 8;
|
|
|
|
private List<EnrollRequestModel> SearchRecords { get; set; } = new List<EnrollRequestModel>();
|
|
|
|
private EnrollRequestModel? SelRecord { get; set; } = null;
|
|
|
|
private int totalCount { get; set; } = 0;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// Evento refresh legato a ricezione evento da MessagePipe
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private async Task EnrollMessPipe_EA_NewMessage(object sender, EventArgs e)
|
|
{
|
|
PubSubEventArgs currArgs = (PubSubEventArgs)e;
|
|
// qualsiasi messaggio fa scattare reload data
|
|
if (!string.IsNullOrEmpty(currArgs.newMessage))
|
|
{
|
|
isLoading = true;
|
|
//await InvokeAsync(StateHasChanged);
|
|
await LMDService.FlushEnrollCache();
|
|
//await Task.Delay(50);
|
|
await ReloadData();
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
SearchRecords = await LMDService.EnrollReqGetFilt(OnlyActive, DtStart, DtEnd);
|
|
if (IdxLicSel > 0)
|
|
{
|
|
SearchRecords = SearchRecords.Where(x => x.IdxLic == IdxLicSel).ToList();
|
|
}
|
|
if (!string.IsNullOrEmpty(SearchVal))
|
|
{
|
|
SearchRecords = SearchRecords.Where(x => $"{x.Passcode}".Contains(SearchVal)).ToList();
|
|
}
|
|
totalCount = SearchRecords.Count;
|
|
ListRecords = SearchRecords
|
|
.Skip((currPage - 1) * numRecord)
|
|
.Take(numRecord)
|
|
.ToList();
|
|
isLoading = false;
|
|
}
|
|
|
|
private async Task ReloadLicData()
|
|
{
|
|
SelectNext currFilt = new SelectNext()
|
|
{
|
|
ApplicazioneSel = "UpdateManager"
|
|
};
|
|
var rawList = await LMDService.LicenzeNextGetFilt(currFilt);
|
|
ListLicenze = rawList
|
|
.OrderBy(x => x.CodApp)
|
|
.ThenBy(x => x.CodInst)
|
|
.ToList();
|
|
|
|
ListInstall = await LMDService.InstallazioniNextGetAll();
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |