176 lines
5.2 KiB
C#
176 lines
5.2 KiB
C#
using GPW.CORE.Data.DbModels;
|
|
using GPW.CORE.Smart.Data;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace GPW.CORE.Smart.Components
|
|
{
|
|
public partial class CompProj
|
|
{
|
|
#region Public Properties
|
|
|
|
public int EndHour { get; set; } = 16;
|
|
|
|
[Parameter]
|
|
public int IdxDipCurr { get; set; } = 0;
|
|
|
|
[Parameter]
|
|
public List<RegAttivitaModel>? ListProgetti
|
|
{
|
|
get => listRA;
|
|
set
|
|
{
|
|
if (value == null)
|
|
{
|
|
value = new List<RegAttivitaModel>();
|
|
}
|
|
// calcolo la lista comprensiva di spazi vuoti da quella ricevuta...
|
|
listRA = ListRegAtt(value);
|
|
}
|
|
}
|
|
|
|
private async Task resetClone()
|
|
{
|
|
MService.clonedRA = null;
|
|
await Task.Delay(1);
|
|
//await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
[Inject]
|
|
private MessageService MService { get; set; } = null!;
|
|
|
|
public int StartHour { get; set; } = 8;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Aggiorno e riporto update
|
|
/// </summary>
|
|
protected async void DoUpdate(bool forceReload)
|
|
{
|
|
if (forceReload)
|
|
{
|
|
await ReloadData();
|
|
await Task.Delay(1);
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
}
|
|
|
|
protected async Task getCloned(RegAttivitaModel clonedRec)
|
|
{
|
|
currRec = clonedRec;
|
|
textDtAct = $"{DateTime.Now:ddd dd.MM.yyyy}";
|
|
lastAction = $"Clonato Attività";
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await ReloadData();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private string lastAction = "";
|
|
private string textDtAct = "";
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
[Inject]
|
|
private CoreSmartDataService CDService { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
/// Gestione ricezione evento + record RA clonato
|
|
/// </summary>
|
|
/// <param name="clonedRec"></param>
|
|
/// <returns></returns>
|
|
private RegAttivitaModel? currRec
|
|
{
|
|
get => MService.clonedRA;
|
|
set => MService.clonedRA = value;
|
|
}
|
|
|
|
private bool isLoading { get; set; } = false;
|
|
private List<RegAttivitaModel>? listRA { get; set; } = null;
|
|
|
|
private bool showToast
|
|
{
|
|
get => MService.clonedRA != null;
|
|
}
|
|
|
|
private string toastCss
|
|
{
|
|
get => showToast ? "show" : "";
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private List<RegAttivitaModel> ListRegAtt(List<RegAttivitaModel> ListOnlyRA)
|
|
{
|
|
// init
|
|
List<RegAttivitaModel> result = new List<RegAttivitaModel>();
|
|
if (ListOnlyRA != null && ListOnlyRA.Count > 0)
|
|
{
|
|
// prendo prima attività...
|
|
var firstRA = ListOnlyRA[0];
|
|
DateTime currHour = firstRA.Inizio.Date.AddHours(StartHour);
|
|
DateTime lastHour = firstRA.Inizio.Date.AddHours(EndHour);
|
|
// ciclo partendo dal primo evento ed aggiungendo eventuali periodi in testa / coda
|
|
// / intermedi
|
|
if (ListOnlyRA != null)
|
|
{
|
|
foreach (var item in ListOnlyRA)
|
|
{
|
|
// se evento > ora corrente --> aggiungo vuoto...
|
|
if (item.Inizio > currHour)
|
|
{
|
|
CORE.Data.DbModels.RegAttivitaModel? newItem = new CORE.Data.DbModels.RegAttivitaModel()
|
|
{
|
|
Inizio = currHour,
|
|
IdxFase = 0,
|
|
Descrizione = "-",
|
|
Fine = item.Inizio,
|
|
OreTot = (decimal)item.Inizio.Subtract(currHour).TotalHours
|
|
};
|
|
result.Add(newItem);
|
|
}
|
|
|
|
// ...altrimenti parto con lui...
|
|
result.Add(item);
|
|
currHour = item.Fine;
|
|
}
|
|
}
|
|
// se non sono in fondo --> aggiungo!
|
|
if (currHour < lastHour)
|
|
{
|
|
RegAttivitaModel? newItem = new RegAttivitaModel()
|
|
{
|
|
Inizio = currHour,
|
|
IdxFase = 0,
|
|
Descrizione = "-",
|
|
Fine = lastHour,
|
|
OreTot = (decimal)lastHour.Subtract(currHour).TotalHours
|
|
};
|
|
result.Add(newItem);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
await Task.Delay(1);
|
|
isLoading = true;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |