Files
mapo-core/MP.SPEC/Components/FolderBrowser.razor.cs
Samuele Locatelli 6806f7ffe5 SPEC:
- Fix gestione paginazione x elenco files
- Fix reload
2024-10-15 11:27:28 +02:00

99 lines
2.9 KiB
C#

using Microsoft.AspNetCore.Components;
using MP.Data;
namespace MP.SPEC.Components
{
public partial class FolderBrowser
{
#region Public Properties
[Parameter]
public string LogicalPath { get; set; } = "";
#endregion Public Properties
#region Protected Properties
[Inject]
protected IConfiguration ConfMan { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
/// <summary>
/// Restituisce size calcolata
/// </summary>
/// <param name="origSize"></param>
/// <returns></returns>
protected string CalcSize(long origSize)
{
return MeasureUtils.SizeSuffix(origSize, 1);
}
protected string FileLink(string fName)
{
return $"RET_DATA/{LogicalPath}/{fName}";
}
/// <summary>
/// Eseguo browsing directory...
/// </summary>
/// <returns></returns>
protected override void OnParametersSet()
{
ReloadData();
}
private void ReloadData()
{
// calcolo phisical path...
string BasePathOdlReturn = ConfMan.GetValue<string>("ServerConf:BasePathOdlReturn") ?? ConfMan.GetValue<string>("OptConf:BasePathOdlReturn") ?? "";
PhysicalPath = Path.Combine(BasePathOdlReturn, LogicalPath);
// controllo esista
if (Directory.Exists(PhysicalPath))
{
// recupero come DirectoryInfo x avere tutte le informazioni su nome, tipo, size...
DirectoryInfo dirInfo = new DirectoryInfo(PhysicalPath);
SearchRecords = dirInfo.GetFiles().ToList();
}
totalCount = SearchRecords.Count;
// filtro x display
ListRecords = SearchRecords
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToList();
}
private int totalCount { get; set; } = 0;
#endregion Protected Methods
#region Private Properties
private List<FileInfo> ListRecords { get; set; } = new List<FileInfo>();
private List<FileInfo> SearchRecords { get; set; } = new List<FileInfo>();
private string PhysicalPath { get; set; } = "";
#endregion Private Properties
private int currPage { get; set; } = 1;
private bool isLoading { get; set; } = false;
private int numRecord { get; set; } = 10;
protected async Task SetNumRec(int newNum)
{
numRecord = newNum;
currPage = 1;
ReloadData();
await InvokeAsync(ReloadData);
}
protected async Task SetPage(int newNum)
{
ReloadData();
currPage = newNum;
await InvokeAsync(ReloadData);
}
}
}