Files
egwcapp/EgwControlCenter.App/Components/Compo/TargetSetup.razor.cs
T
Samuele Locatelli 8b73e7dca6 EgwACC:
- update condizioni visibilità dataPager
- update display lista valori setup
- test debug locale
2025-04-03 16:29:16 +02:00

220 lines
5.5 KiB
C#

using EgwControlCenter.Core;
using EgwControlCenter.Core.Models;
using EgwCoreLib.Utils;
using Microsoft.AspNetCore.Components;
namespace EgwControlCenter.App.Components.Compo
{
public partial class TargetSetup : IDisposable
{
#region Public Properties
[Parameter]
public EventCallback<bool> EC_GotoSetup { get; set; }
#endregion Public Properties
#region Public Methods
public void Dispose()
{
ACService.EA_ConfigUpdated -= ACService_EA_ConfigUpdated;
ACService.EA_RemoteCalling -= ACService_EA_RemoteCalling;
}
#endregion Public Methods
#region Protected Properties
[Inject]
protected AppControlService ACService { get; set; } = null!;
protected string AppKey
{
get => ACService.AppKey;
}
protected string MainKey
{
get => ACService.MainKey;
set => ACService.MainKey = value;
}
protected int RefreshPeriod
{
get => ACService.RefreshPeriod;
set => ACService.RefreshPeriod = value;
}
protected bool RemoteCallActive { get; set; } = false;
#endregion Protected Properties
#region Protected Methods
protected void DoCancel()
{
ACService.DoReloadConfig();
}
protected void DoReset()
{
ACService.ResetConf();
}
protected async Task DoSave()
{
ACService.DoSaveConfig();
ACService.DoReloadConfig();
// invio update in remoto
await ACService.SendConfTarget();
}
protected override void OnInitialized()
{
CodImpiego = SLicManager.CodImpiego();
ACService.EA_ConfigUpdated += ACService_EA_ConfigUpdated;
ACService.EA_RemoteCalling += ACService_EA_RemoteCalling;
}
protected override void OnParametersSet()
{
ForceReload();
}
protected void SetNumRec(int newNum)
{
numRecord = newNum;
currPage = 1;
ForceReload();
}
protected void SetPage(int newNum)
{
currPage = newNum;
ForceReload();
}
protected async void ToggleSetup()
{
ReqSetup = !ReqSetup;
await EC_GotoSetup.InvokeAsync(ReqSetup);
}
#endregion Protected Methods
#region Private Fields
private bool remoteCalling = false;
private bool ReqSetup = true;
#endregion Private Fields
#region Private Properties
private string btnSyncClass
{
get
{
string answ = "";
if (remoteCalling)
{
answ = "btn-info";
}
else
{
answ = ChannelAuth ? "btn-outline-success" : "btn-warning";
}
return answ;
}
}
private bool ChannelAuth
{
get => ACService.ChannelAuth;
}
private string CodImpiego { get; set; } = "";
private int currPage { get; set; } = 1;
private bool isLoading { get; set; } = false;
private List<ControlTarget> ListRecords { get; set; } = new List<ControlTarget>();
private int numRecord { get; set; } = 5;
private bool PwdOk
{
get => !string.IsNullOrEmpty(SetupPwd) && SetupPwd == EgwControlCenter.Core.Const.EditPwd;
}
private List<ControlTarget> SearchRecords
{
get => ACService.TargetList;
set => ACService.TargetList = value;
}
private string SetupPwd { get; set; } = "";
private SubLicManager SLicManager { get; set; } = new SubLicManager();
private int totalCount { get; set; } = 0;
private int VetoCheck
{
get => ACService.VetoCheck;
set => ACService.VetoCheck = value;
}
#endregion Private Properties
#region Private Methods
private void ACService_EA_ConfigUpdated()
{
ForceReload();
}
/// <summary>
/// Gestione evento chiamata verso server
/// </summary>
private async void ACService_EA_RemoteCalling()
{
RemoteCallActive = ACService.CloudCallActive;
await InvokeAsync(StateHasChanged);
}
private void ForceReload()
{
totalCount = SearchRecords.Count;
ListRecords = SearchRecords
.OrderBy(x => x.Idx)
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToList();
}
private async Task TrySync()
{
remoteCalling = true;
// verifico se ho CodImpiego
bool setCodImp = string.IsNullOrEmpty(CodImpiego);
bool setAppKey = string.IsNullOrEmpty(AppKey);
if (setCodImp || setAppKey)
{
ACService.ResetSubLic(setAppKey);
}
await Task.Delay(10);
bool fatto = await ACService.CheckAttivazioni();
if (fatto)
{
ACService.DoSaveConfig();
}
await Task.Delay(10);
remoteCalling = false;
}
#endregion Private Methods
}
}