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

235 lines
6.5 KiB
C#

using EgwCoreLib.Lux.Data.DbModel.Task;
using EgwCoreLib.Lux.Data.DbModel.Utils;
using EgwCoreLib.Lux.Data.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
namespace Lux.UI.Components.Compo.JobTask
{
public partial class JobTaskListMan
{
#region Public Properties
[Parameter]
public List<JobTaskModel> CurrRecords { get; set; }
[Parameter]
public string CurrSearch { get; set; } = string.Empty;
[Parameter]
public EventCallback<JobTaskModel?> EC_Selected { get; set; }
[Parameter]
public EventCallback<bool> EC_Updated { get; set; }
#endregion Public Properties
#region Protected Fields
protected List<JobTaskModel> FiltRecords = new List<JobTaskModel>();
protected List<JobTaskModel> ListRecords = new List<JobTaskModel>();
#endregion Protected Fields
#region Protected Properties
[Inject]
protected DataLayerServices DLService { get; set; } = null!;
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
/// <summary>
/// Genera nuovo record e lo salva
/// </summary>
protected async Task DoAdd()
{
if (newRecord != null)
{
// verifico non sia duplicato...
var recExist = CurrRecords.Count(x => x.Description == newRecord.Description);
if (recExist > 0)
{
errorMsg = $"Errore: record già esistente | {newRecord.Description}";
}
else
{
errorMsg = "";
// faccio upsert record...
await DLService.JobTaskUpsertAsync(newRecord);
// segnalo update x reload
await EC_Updated.InvokeAsync(true);
newRecord = null;
addVisible = false;
// rileggo
ReloadData();
}
}
}
/// <summary>
/// Eliminazione record
/// </summary>
/// <param name="rec2del"></param>
protected async Task DoDelete(JobTaskModel rec2del)
{
// controlo che NON abbia child obj... altrimenti esco
if (rec2del.NumChild > 0)
return;
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Sicuro di voler eliminare il record? {rec2del.Description} ({rec2del.JobID})"))
return;
// esegue eliminazione del record...
await DLService.JobTaskDeleteAsync(rec2del);
// segnalo update x reload
await EC_Updated.InvokeAsync(true);
// rileggo
ReloadData();
}
/// <summary>
/// Edit articolo selezionato
/// </summary>
/// <param name="curRec"></param>
protected async void DoEdit(JobTaskModel curRec)
{
editRecord = curRec;
selRecord = curRec;
#if false
await EC_Selected.InvokeAsync(curRec);
#endif
await Task.Delay(1);
}
/// <summary>
/// Reset selezione
/// </summary>
protected async void DoReset()
{
editRecord = null;
selRecord = null;
await EC_Selected.InvokeAsync(null);
await EC_Updated.InvokeAsync(true);
}
/// <summary>
/// Selezione articolo x display info
/// </summary>
/// <param name="curRec"></param>
protected async void DoSelect(JobTaskModel curRec)
{
selRecord = curRec;
await EC_Selected.InvokeAsync(curRec);
}
protected override void OnParametersSet()
{
ReloadData();
}
protected void ToggleAdd()
{
addVisible = !addVisible;
if (addVisible)
{
newRecord = new JobTaskModel()
{
Description = $"Nuovo Ciclo-{DateTime.Now:yyyy.MM.dd-HH.mm.ss}",
Index = totalCount + 1
};
}
}
#endregion Protected Methods
#region Private Fields
private bool addVisible = false;
private int currPage = 1;
private JobTaskModel? editRecord = null;
private string errorMsg = "";
private bool isLoading = false;
private JobTaskModel? newRecord = null;
private int numRecord = 10;
private JobTaskModel? selRecord = null;
private int totalCount = 0;
#endregion Private Fields
#region Private Methods
/// <summary>
/// Check selezione riga item
/// </summary>
/// <param name="curRec"></param>
/// <returns></returns>
private string checkSel(JobTaskModel curRec)
{
string answ = "";
if (selRecord != null)
{
answ = curRec.JobID == selRecord.JobID ? "table-info" : "";
}
return answ;
}
/// <summary>
/// Esegue spostamento
/// </summary>
/// <param name="curRec"></param>
/// <param name="moveUp"></param>
/// <returns></returns>
private async Task MoveRec(JobTaskModel curRec, bool moveUp)
{
await DLService.JobTaskMoveAsync(curRec, moveUp);
ResetEdit();
}
private void ReloadData()
{
isLoading = true;
// se ho ricerca testuale faccio filtro ulteriore...
if (!string.IsNullOrEmpty(CurrSearch))
{
FiltRecords = CurrRecords
.Where(x => x.Description.Contains(CurrSearch, StringComparison.InvariantCultureIgnoreCase))
.ToList();
}
else
{
FiltRecords = CurrRecords;
}
totalCount = FiltRecords.Count;
// fix paginazione
ListRecords = CurrRecords
.OrderBy(x => x.Index)
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToList();
isLoading = false;
}
private void ResetEdit()
{
// reset edit
editRecord = null;
ReloadData();
}
#endregion Private Methods
}
}