Files
2025-06-21 11:53:07 +02:00

136 lines
3.5 KiB
C#

using GPW.CORE.Data.DbModels;
using GPW.CORE.Data.DTO;
using GPW.CORE.Data.Services;
using Microsoft.AspNetCore.Components;
using static EgwCoreLib.Razor.Toggler;
namespace GPW.CORE.ADM.Components.Pages
{
public partial class RichiesteDip
{
#region Protected Fields
protected int anno = DateTime.Today.Year;
protected DateTime dtMax = DateTime.Today.AddMonths(1);
protected DateTime dtMin = DateTime.Today;
protected int numMesi = 6;
#endregion Protected Fields
#region Protected Properties
[Inject]
protected MessageService AppMServ { get; set; } = null!;
[Inject]
protected GpwDataService DataService { get; set; } = null!;
protected int idxDipendente
{
get => AppMServ.IdxDipendente;
}
#endregion Protected Properties
#region Protected Methods
protected override async Task OnInitializedAsync()
{
initToggler();
// recupero mesi da gestire
var monthConf = await DataService.ConfigGetKeyAsync("NumMesiCalAzienda");
if (monthConf != null)
{
int intVal = 0;
int.TryParse(monthConf.valore, out intVal);
numMesi = intVal > 0 ? intVal : numMesi;
}
dtRif = DateTime.Today;
dtMin = new DateTime(dtRif.Year, 1, 1);
dtMax = dtMin.AddYears(1);
ReloadData();
}
private DateTime dtRif = DateTime.Today;
#endregion Protected Methods
#region Private Fields
private bool isLoading = false;
#endregion Private Fields
#region Private Properties
private bool OnlyNeedConf { get; set; } = false;
/// <summary>
/// Elenco eventi formato originale (EventDTO)
/// </summary>
private List<EventDTO> SchedEvList { get; set; } = new List<EventDTO>();
private SelectGlobalToggle ToggleData { get; set; } = new SelectGlobalToggle();
#endregion Private Properties
#region Private Methods
private async Task evToggled(SelectGlobalToggle newTogData)
{
ToggleData = newTogData;
OnlyNeedConf = !ToggleData.isActive;
await Task.Delay(1);
}
private void ForceReloadCal()
{
ReloadData();
}
private void initToggler()
{
ToggleData = new SelectGlobalToggle()
{
leftString = "Da approvare",
rightString = "Tutti",
placardCss = "bg-light border-light text-dark",
};
}
private void ReloadData()
{
isLoading = true;
// recupero direttamente da oggetto DB
SchedEvList = DataService.EventListPeriodo(idxDipendente, dtMin, dtMax);
isLoading = false;
}
private void SetDate(DateTime newDate)
{
// se la data fosse esterna all'intervallo considerato...)
if (newDate < dtMin || newDate > dtMax)
{
dtRif = newDate;
// ricalcolo periodo
dtMin = new DateTime(dtRif.Year, 1, 1);
dtMax = new DateTime(dtRif.Year + 1, 1, 1);
ReloadData();
}
}
private void SetMonth(int newNum)
{
if (numMesi != newNum)
{
numMesi = newNum;
}
ReloadData();
}
#endregion Private Methods
}
}