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 ListCostDrivers = new List(); private List ListJobTask = new List(); private List ListPhases = new List(); private List ListResources = new List(); private List? ListStep = null; private List ListTagsAvailable = new List(); 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; } /// /// Reload dettagli ciclo /// /// /// private async Task ReloadDetail(bool args) { if (selRecord != null) { ListStep = await JStService.GetByParentAsync(selRecord.JobID); } else { ListStep = null; } } private void ResetSearch() { searchVal = ""; } /// /// Salva ID sel e mostra dettagli JobTask /// /// 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"; } /// /// Genera nuovo record e lo salva /// 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 } }