193 lines
5.1 KiB
C#
193 lines
5.1 KiB
C#
namespace Lux.UI.Components.Pages
|
|
{
|
|
public partial class JobRoute
|
|
{
|
|
#region Protected Methods
|
|
|
|
protected override Task OnInitializedAsync()
|
|
{
|
|
return ReloadDataAsync();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private bool addVisible = false;
|
|
|
|
private bool isLoading = false;
|
|
|
|
private List<CostDriverModel> ListCostDrivers = new List<CostDriverModel>();
|
|
|
|
private List<JobTaskModel> ListJobTask = new List<JobTaskModel>();
|
|
|
|
private List<PhaseModel> ListPhases = new List<PhaseModel>();
|
|
|
|
private List<ResourceModel> ListResources = new List<ResourceModel>();
|
|
|
|
private List<JobStepModel>? ListStep = null;
|
|
|
|
private List<string> ListTagsAvailable = new List<string>();
|
|
|
|
private JobTaskModel? selRecord = null;
|
|
|
|
private JobTaskModel newRecord = null!;
|
|
|
|
private string errorMsg = "";
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
[Inject]
|
|
private ICostDriverService CDService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IDataLayerServices DLService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IJobStepService JStService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IJobTaskService JTaService { get; set; } = null!;
|
|
|
|
private string mainCss
|
|
{
|
|
get => selRecord == null ? "col-12" : "col-4";
|
|
}
|
|
|
|
[Inject]
|
|
private IPhaseService PhService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IResourceService ResService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IJobTaskService JTService { get; set; } = null!;
|
|
|
|
private string searchVal { get; set; } = string.Empty;
|
|
|
|
[Inject]
|
|
private ITagService TagService { get; set; } = null!;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private Task ForceReloadAsync()
|
|
{
|
|
return ReloadDataAsync();
|
|
}
|
|
|
|
private async Task ReloadDataAsync()
|
|
{
|
|
isLoading = true;
|
|
var rawTags = await TagService.GetAllAsync();
|
|
ListTagsAvailable = rawTags.Select(x => x.CodTag).ToList();
|
|
ListCostDrivers = await CDService.GetAllAsync();
|
|
ListPhases = await PhService.GetAllAsync();
|
|
ListResources = await ResService.GetAllAsync();
|
|
ListJobTask = await JTaService.GetAllAsync();
|
|
ListStep = null;
|
|
isLoading = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reload dettagli ciclo
|
|
/// </summary>
|
|
/// <param name="args"></param>
|
|
/// <returns></returns>
|
|
private async Task ReloadDetail(bool args)
|
|
{
|
|
if (selRecord != null)
|
|
{
|
|
ListStep = await JStService.GetByParentAsync(selRecord.JobID);
|
|
}
|
|
else
|
|
{
|
|
ListStep = null;
|
|
}
|
|
}
|
|
|
|
private void ResetSearch()
|
|
{
|
|
searchVal = "";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salva ID sel e mostra dettagli JobTask
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
private async Task ShowDetail(JobTaskModel? selRec)
|
|
{
|
|
selRecord = selRec;
|
|
// ricarico dal DB
|
|
if (selRec != null)
|
|
{
|
|
ListStep = await JStService.GetByParentAsync(selRec.JobID);
|
|
}
|
|
else
|
|
{
|
|
ListStep = null;
|
|
}
|
|
}
|
|
|
|
private string SearchVal
|
|
{
|
|
get => searchVal;
|
|
set
|
|
{
|
|
if (searchVal != value)
|
|
{
|
|
searchVal = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private string btnResetCss
|
|
{
|
|
get => string.IsNullOrEmpty(searchVal) ? "btn-outline-secondary" : "btn-primary";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Genera nuovo record e lo salva
|
|
/// </summary>
|
|
private async Task DoAdd()
|
|
{
|
|
if (newRecord != null)
|
|
{
|
|
// verifico non sia duplicato...
|
|
var recExist = ListJobTask.Count(x => x.Description == newRecord.Description);
|
|
if (recExist > 0)
|
|
{
|
|
errorMsg = $"Errore: record gia' esistente | {newRecord.Description}";
|
|
}
|
|
else
|
|
{
|
|
errorMsg = "";
|
|
// faccio upsert record...
|
|
await JTService.UpsertAsync(newRecord);
|
|
// segnalo update x reload
|
|
await ForceReloadAsync();
|
|
newRecord = new();
|
|
addVisible = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ToggleAdd()
|
|
{
|
|
addVisible = !addVisible;
|
|
if (addVisible)
|
|
{
|
|
newRecord = new JobTaskModel()
|
|
{
|
|
Description = $"Nuovo Ciclo-{DateTime.Now:yyyy.MM.dd-HH.mm.ss}",
|
|
Index = ListJobTask.Count + 1
|
|
};
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |