Files

177 lines
4.6 KiB
C#

using Lux.Report.Data.DbModel;
using Lux.Report.Data.Services;
using Microsoft.AspNetCore.Components;
using Newtonsoft.Json;
namespace Lux.Report.Manager.Components.Pages
{
public partial class ReportMan
{
#region Protected Methods
protected string FileName(string fullName)
{
return Path.GetFileName(fullName);
}
protected override async Task OnInitializedAsync()
{
GetQueryParams();
await ReloadDataAsync();
UpdateTable();
}
#endregion Protected Methods
#region Private Fields
private List<ReportModel> AllRecords = new List<ReportModel>();
private int currPage = 1;
private string currRepFile = "";
private ReportModel? EditRecord = null;
private bool isAuth = false;
private bool isLoading = false;
private List<ReportModel> ListRecords = new List<ReportModel>();
private int numRecord = 10;
private ReportModel? SelRecord = null;
private int totalCount = 0;
#endregion Private Fields
#region Private Properties
[Inject]
private IFileService FService { get; set; } = null!;
private string mainCss
{
get => SelRecord == null ? "col-12" : "col-8";
}
[Inject]
private NavigationManager NavManager { get; set; } = null!;
[Inject]
private IReportService RepService { get; set; } = default!;
#endregion Private Properties
#region Private Methods
private string CheckSelect(ReportModel curRec)
{
string answ = "";
if (SelRecord != null)
{
answ = curRec.ReportID == SelRecord.ReportID ? "table-info" : "";
}
return answ;
}
/// <summary>
/// Conteggio dei file rep disponibili
/// </summary>
/// <param name="repName"></param>
/// <returns></returns>
private int CountNumRep(string repName)
{
string repPath = Path.Combine("reports", repName);
// numero file esclusi quelli nascosti (template)
return FService.CountFile(repPath, "*.repx", true);
}
private void DoCloseEditRep()
{
currRepFile = "";
}
private async Task DoEdit(ReportModel curRec)
{
SelRecord = null;
EditRecord = curRec;
await Task.Delay(10);
//return EC_Selected.InvokeAsync(curRec);
//await InvokeAsync(StateHasChanged);
}
private void DoEditReport(string repFullPath)
{
// chiama editing x il report richiesto
currRepFile = repFullPath;
}
private async Task DoReloadParent(bool args)
{
await ReloadDataAsync();
UpdateTable();
}
private async Task DoReset()
{
EditRecord = null;
SelRecord = null;
await ReloadDataAsync();
UpdateTable();
}
private async Task DoSelect(ReportModel curRec)
{
EditRecord = null;
SelRecord = curRec;
await Task.Delay(10);
//return EC_Selected.InvokeAsync(curRec);
//await InvokeAsync(StateHasChanged);
}
private void GetQueryParams()
{
var uri = NavManager.ToAbsoluteUri(NavManager.Uri);
var query = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(uri.Query);
if (query.TryGetValue("edit", out var param))
{
isAuth = param.ToString() == "enabled";
}
}
private async Task ReloadDataAsync()
{
AllRecords = await RepService.GetAllAsync();
}
private void UpdateTable()
{
totalCount = AllRecords.Count;
// gestione paginazione
ListRecords = AllRecords
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToList();
}
#endregion Private Methods
private async Task DoSaveDict(Dictionary<string, string> currDict)
{
if (SelRecord != null)
{
// serializzo nel record corrente
string rawDict = JsonConvert.SerializeObject(currDict);
SelRecord.FileConfDataRaw = rawDict;
// salvo!
await RepService.UpsertAsync(SelRecord);
}
await ReloadDataAsync();
UpdateTable();
}
}
}