294 lines
9.1 KiB
C#
294 lines
9.1 KiB
C#
using EgwCoreLib.Razor;
|
|
|
|
namespace Lux.UI.Components.Compo.JobTask
|
|
{
|
|
public partial class JobTaskListMan
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public List<CostDriverModel> CostDriverLists { get; set; } = new List<CostDriverModel>();
|
|
|
|
[Parameter]
|
|
public List<JobTaskModel> CurrRecords { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public string CurrSearch { get; set; } = string.Empty;
|
|
|
|
[Parameter]
|
|
public EventCallback<JobTaskModel?> EC_Selected { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> EC_Updated { get; set; }
|
|
|
|
[Parameter]
|
|
public List<string> ListAllTags { get; set; } = new List<string>();
|
|
|
|
[Parameter]
|
|
public List<ResourceModel> ResourceLists { get; set; } = new List<ResourceModel>();
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
ReloadData();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private bool addVisible = false;
|
|
private int currPage = 1;
|
|
private JobTaskModel? editRecord = null;
|
|
private string errorMsg = "";
|
|
private List<JobTaskModel> FiltRecords = new List<JobTaskModel>();
|
|
private bool isLoading = false;
|
|
private List<JobTaskModel> ListRecords = new List<JobTaskModel>();
|
|
|
|
private JobTaskModel? newRecord = null;
|
|
|
|
private int numRecord = 10;
|
|
|
|
private JobTaskModel? selRecord = null;
|
|
|
|
private int totalCount = 0;
|
|
|
|
private BootstrapModal Modal = new();
|
|
private string mTitle = "";
|
|
private string mMessage = "";
|
|
private BootstrapModal.ModalMode mMode = BootstrapModal.ModalMode.ND;
|
|
private Dictionary<bool, string> modalOpt = new Dictionary<bool, string>();
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
[Inject]
|
|
private IDataLayerServices DLService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IJobTaskService JTService { get; set; } = null!;
|
|
|
|
private List<string> ListCostDrivers
|
|
{
|
|
get => CostDriverLists
|
|
.Select(x => x.Name)
|
|
.Distinct()
|
|
.ToList();
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#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>
|
|
/// Genera nuovo record e lo salva
|
|
/// </summary>
|
|
private 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 JTService.UpsertAsync(newRecord);
|
|
// segnalo update x reload
|
|
await EC_Updated.InvokeAsync(true);
|
|
newRecord = null;
|
|
addVisible = false;
|
|
// rileggo
|
|
ReloadData();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Eliminazione record
|
|
/// </summary>
|
|
/// <param name="rec2del"></param>
|
|
private async Task DoDelete(JobTaskModel rec2del)
|
|
{
|
|
// controlo che NON abbia child obj... altrimenti esco
|
|
if (rec2del.NumChild > 0)
|
|
return;
|
|
|
|
mTitle = "Attenzione";
|
|
mMessage = $"Sicuro di voler eliminare il record? {rec2del.Description} ({rec2del.JobID})";
|
|
mMode = BootstrapModal.ModalMode.Confirm;
|
|
modalOpt = new();
|
|
modalOpt.Add(true, "Si");
|
|
modalOpt.Add(false, "No");
|
|
if (!await Modal!.ShowAsync<bool>())
|
|
return;
|
|
|
|
// esegue eliminazione del record...
|
|
await JTService.DeleteAsync(rec2del);
|
|
|
|
// segnalo update x reload
|
|
await EC_Updated.InvokeAsync(true);
|
|
// rileggo
|
|
ReloadData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Edit articolo selezionato
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
private Task DoEdit(JobTaskModel curRec)
|
|
{
|
|
editRecord = curRec;
|
|
selRecord = curRec;
|
|
return Task.Delay(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset selezione
|
|
/// </summary>
|
|
private async Task DoReset()
|
|
{
|
|
editRecord = null;
|
|
selRecord = null;
|
|
await EC_Selected.InvokeAsync(null);
|
|
await EC_Updated.InvokeAsync(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update record x elenco tags
|
|
/// </summary>
|
|
/// <param name="args"></param>
|
|
/// <returns></returns>
|
|
private async Task DoSaveTags(TagDisplay.SavePayload args)
|
|
{
|
|
// chiamo update
|
|
await JTService.MergeTagsAsync(args.Id, args.Tags);
|
|
await EC_Updated.InvokeAsync(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Selezione articolo x display info
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
private Task DoSelect(JobTaskModel curRec)
|
|
{
|
|
selRecord = curRec;
|
|
return EC_Selected.InvokeAsync(curRec);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituice elenco CostDrivers per il record (con cache...)
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
/// <returns></returns>
|
|
private List<string> ListDriversName(JobTaskModel curRec)
|
|
{
|
|
List<string> result = new List<string>();
|
|
if (CostDriverLists != null && ResourceLists != null)
|
|
{
|
|
// faccio distinct delle risorse...
|
|
List<ResourceModel> distResource = ResourceLists
|
|
.Where(x => curRec.ResourcesList.Contains(x.ResourceID))
|
|
.Distinct()
|
|
.ToList();
|
|
var listCostId = distResource
|
|
.Select(x => x.CostDriverID)
|
|
.Distinct()
|
|
.ToList();
|
|
// ora recupero elenco cost drivers...
|
|
var distCostDrv = CostDriverLists
|
|
.Where(x => listCostId.Contains(x.CostDriverID))
|
|
.Distinct()
|
|
.ToList();
|
|
// proiezione!
|
|
result = distCostDrv.Select(x => x.Name).ToList();
|
|
// salvo in dizionario
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Esegue spostamento
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
/// <param name="moveUp"></param>
|
|
/// <returns></returns>
|
|
private async Task MoveRec(JobTaskModel curRec, bool moveUp)
|
|
{
|
|
await JTService.MoveAsync(curRec, moveUp);
|
|
await EC_Updated.InvokeAsync(true);
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
private void ToggleAdd()
|
|
{
|
|
addVisible = !addVisible;
|
|
if (addVisible)
|
|
{
|
|
newRecord = new JobTaskModel()
|
|
{
|
|
Description = $"Nuovo Ciclo-{DateTime.Now:yyyy.MM.dd-HH.mm.ss}",
|
|
Index = totalCount + 1
|
|
};
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |