Files
lux/Lux.UI/Components/Compo/JobTask/ResourcesMan.razor.cs
T
2025-10-30 18:32:17 +01:00

136 lines
3.6 KiB
C#

using EgwCoreLib.Lux.Data.DbModel.Cost;
using EgwCoreLib.Lux.Data.DbModel.Task;
using EgwCoreLib.Lux.Data.Services;
using Microsoft.AspNetCore.Components;
namespace Lux.UI.Components.Compo.JobTask
{
public partial class ResourcesMan
{
#region Public Properties
[Parameter]
public string CurrSearch { get; set; } = string.Empty;
#endregion Public Properties
#region Protected Fields
protected List<ResourceModel> AllRecords = new List<ResourceModel>();
protected List<ResourceModel> ListRecords = new List<ResourceModel>();
protected List<ResourceModel> SearchRecords = new List<ResourceModel>();
#endregion Protected Fields
#region Protected Properties
[Inject]
protected DataLayerServices DLService { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
/// <summary>
/// Reset selezione
/// </summary>
protected async void DoReset()
{
editRecord = null;
selRecord = null;
await ReloadBaseData();
ReloadData();
}
/// <summary>
/// Selezione articolo x display info
/// </summary>
/// <param name="curRec"></param>
protected void DoSelect(ResourceModel curRec)
{
selRecord = curRec;
}
protected override async Task OnInitializedAsync()
{
await ReloadBaseData();
ReloadData();
}
protected override void OnParametersSet()
{
ReloadData();
}
protected void ToggleAdd()
{
addVisible = !addVisible;
if (addVisible)
{
newRecord = new ResourceModel()
{
Name = $"Risorsa | {DateTime.Now:yyyy.MM.dd-HH.mm.ss}"
};
}
}
#endregion Protected Methods
#region Private Fields
private bool addVisible = false;
private int currPage = 1;
private ResourceModel? editRecord = null;
private bool isLoading = false;
private ResourceModel? newRecord = null;
private int numRecord = 10;
private ResourceModel? selRecord = null;
private int totalCount = 0;
#endregion Private Fields
#region Private Properties
private string mainCss
{
get => selRecord == null ? "col-6" : "col-4";
}
#endregion Private Properties
#region Private Methods
private async Task ReloadBaseData()
{
AllRecords = await DLService.ResourcesGetAllAsync();
}
private void ReloadData()
{
isLoading = true;
// se ho ricerca testuale faccio filtro ulteriore...
if (!string.IsNullOrEmpty(CurrSearch))
{
SearchRecords = AllRecords
.Where(x => x.Name.Contains(CurrSearch, StringComparison.InvariantCultureIgnoreCase))
.ToList();
}
else
{
SearchRecords = AllRecords;
}
totalCount = SearchRecords.Count;
// fix paginazione
ListRecords = SearchRecords
.OrderBy(x => x.CodResource)
.ThenBy(x => x.Name)
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToList();
isLoading = false;
}
#endregion Private Methods
}
}