175 lines
4.3 KiB
C#
175 lines
4.3 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.Extensions.Configuration;
|
|
using MP.AppAuth.Models;
|
|
using MP.AppAuth.Services;
|
|
using MP.Land.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MP.Land.Pages
|
|
{
|
|
public partial class UserQr : IDisposable
|
|
{
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
AppMService.EA_SearchUpdated -= OnSeachUpdated;
|
|
AppMService.EA_FilterUpdated -= OnFilterUpdated;
|
|
ListRecords = null;
|
|
GC.Collect();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Fields
|
|
|
|
protected string CardMessage = "User Card";
|
|
protected int totalCount = 0;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected LMessageService AppMService { get; set; }
|
|
|
|
protected string BaseUrlTab
|
|
{
|
|
get => $"{Configuration["ServerConf:BaseUrl"]}{Configuration["QrJumpPath"]}";
|
|
}
|
|
|
|
[Inject]
|
|
protected AppAuthService DataService { get; set; }
|
|
|
|
protected string Environment
|
|
{
|
|
get => Configuration["Environment"];
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
AppMService.ShowSearch = true;
|
|
AppMService.PageName = "User Card";
|
|
AppMService.PageIcon = "fas fa-qrcode pe-2";
|
|
await ReloadData();
|
|
AppMService.EA_SearchUpdated += OnSeachUpdated;
|
|
AppMService.EA_FilterUpdated += OnFilterUpdated;
|
|
}
|
|
|
|
protected async Task PagerReloadNum(int newNum)
|
|
{
|
|
ListRecords = null;
|
|
numRecord = newNum;
|
|
await ReloadData();
|
|
isLoading = false;
|
|
}
|
|
|
|
protected async Task PagerReloadPage(int newNum)
|
|
{
|
|
ListRecords = null;
|
|
currPage = newNum;
|
|
await ReloadData();
|
|
isLoading = false;
|
|
}
|
|
|
|
protected MarkupString traduci(string lemma)
|
|
{
|
|
MarkupString answ;
|
|
string rawHtml = DataService.Traduci(lemma, "IT");
|
|
answ = new MarkupString(rawHtml);
|
|
return answ;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private List<AnagraficaOperatori> ListRecords;
|
|
|
|
private List<AnagraficaOperatori> SearchRecords;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
[Inject]
|
|
private IConfiguration Configuration { get; set; }
|
|
|
|
private int currPage
|
|
{
|
|
get
|
|
{
|
|
return AppMService.SelFilter.PageNum;
|
|
}
|
|
set
|
|
{
|
|
AppMService.SelFilter.PageNum = value;
|
|
}
|
|
}
|
|
|
|
private string groupName
|
|
{
|
|
get
|
|
{
|
|
return AppMService.CodGruppo;
|
|
}
|
|
}
|
|
|
|
private bool isLoading { get; set; } = false;
|
|
|
|
private int numRecord
|
|
{
|
|
get
|
|
{
|
|
return AppMService.SelFilter.PageSize;
|
|
}
|
|
set
|
|
{
|
|
AppMService.SelFilter.PageSize = value;
|
|
}
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async void OnFilterUpdated()
|
|
{
|
|
isLoading = true;
|
|
await InvokeAsync(StateHasChanged);
|
|
ListRecords = null;
|
|
currPage = 1;
|
|
await ReloadData();
|
|
}
|
|
|
|
private async void OnSeachUpdated()
|
|
{
|
|
isLoading = true;
|
|
await Task.Delay(1);
|
|
await InvokeAsync(StateHasChanged);
|
|
ListRecords = null;
|
|
currPage = 1;
|
|
await ReloadData();
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
// importante altrimenti NON mostra update UI
|
|
SearchRecords = await DataService.AnagOperByGroupList(groupName, AppMService.SearchVal);
|
|
ListRecords = SearchRecords.Skip((currPage - 1) * numRecord).Take(numRecord).ToList();
|
|
totalCount = SearchRecords.Count();
|
|
isLoading = false;
|
|
StateHasChanged();
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |