147 lines
3.6 KiB
C#
147 lines
3.6 KiB
C#
using GWMS.Data.DTO;
|
|
using GWMS.UI.Data;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace GWMS.UI.Pages
|
|
{
|
|
[AllowAnonymous]
|
|
public partial class Test : ComponentBase, IDisposable
|
|
{
|
|
#region Private Fields
|
|
|
|
private PlantDTO currRecord = null;
|
|
|
|
private List<PlantDTO> ListRecords;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Protected Fields
|
|
|
|
/// <summary>
|
|
/// Valore PlantId filtrato da claim
|
|
/// </summary>
|
|
protected int ClaimPlantId = -1;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Private Properties
|
|
|
|
private bool isLoading { get; set; } = false;
|
|
|
|
private bool ShowCharts { get; set; } = false;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected GWMSDataService DataService { get; set; }
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; }
|
|
|
|
[Inject]
|
|
protected MessageService MessageService { get; set; }
|
|
|
|
[Inject]
|
|
protected NavigationManager NavManager { get; set; }
|
|
|
|
protected int totalCount
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
if (ListRecords != null)
|
|
{
|
|
answ = ListRecords.Count;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// Recupero Claims dell'utente...
|
|
///
|
|
/// https://docs.microsoft.com/it-it/aspnet/core/blazor/security/?view=aspnetcore-5.0
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async Task GetClaimsData()
|
|
{
|
|
ClaimPlantId = 0;
|
|
}
|
|
|
|
private async Task ReloadAllData()
|
|
{
|
|
isLoading = true;
|
|
ListRecords = null;
|
|
await GetClaimsData();
|
|
// se ho un plantId valido --> altrimenti non abilitato
|
|
if (ClaimPlantId == 0)
|
|
{
|
|
ListRecords = await DataService.PlantsGetAll();
|
|
}
|
|
else if (ClaimPlantId > 0)
|
|
{
|
|
var rawData = await DataService.PlantsGetAll();
|
|
ListRecords = rawData.Where(x => x.PlantId == ClaimPlantId).ToList();
|
|
}
|
|
else
|
|
{
|
|
ListRecords = new List<PlantDTO>();
|
|
}
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
#region Protected Methods
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
MessageService.ShowSearch = false;
|
|
MessageService.PageName = "Impianti";
|
|
MessageService.PageIcon = "fas fa-gas-pump pr-2";
|
|
MessageService.EA_SearchUpdated += OnSeachUpdated;
|
|
await ReloadAllData();
|
|
}
|
|
|
|
protected void Select(PlantDTO selRecord)
|
|
{
|
|
// applico filtro da selezione
|
|
currRecord = selRecord;
|
|
}
|
|
|
|
protected async Task UpdateData()
|
|
{
|
|
currRecord = null;
|
|
await ReloadAllData();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
MessageService.EA_SearchUpdated -= OnSeachUpdated;
|
|
}
|
|
|
|
public async void OnSeachUpdated()
|
|
{
|
|
await UpdateData();
|
|
StateHasChanged();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |