260 lines
8.5 KiB
C#
260 lines
8.5 KiB
C#
using EgwCoreLib.Lux.Core.Generic;
|
|
using Radzen;
|
|
using Radzen.Blazor;
|
|
|
|
namespace Lux.UI.Components.Compo.Planner
|
|
{
|
|
public partial class CalendarPlanner
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public DtUtils.Periodo CurrPeriodo { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public EventCallback<DateTime> EC_DtReq { get; set; }
|
|
|
|
[Parameter]
|
|
public List<EventDto> EvDtoList { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public DateTime firstDate { get; set; } = new DateTime(DateTime.Today.Year, 1, 1);
|
|
|
|
[Parameter]
|
|
public DateTime maxDate { get; set; } = new DateTime(DateTime.Today.Year + 1, 1, 1);
|
|
|
|
[Parameter]
|
|
public DateTime minDate { get; set; } = new DateTime(DateTime.Today.Year, 1, 1);
|
|
|
|
[Parameter]
|
|
public int MonthDispl
|
|
{
|
|
get => cMonth;
|
|
set => cMonth = value;
|
|
}
|
|
|
|
[Parameter]
|
|
public EventCallback<int> MonthReq { get; set; }
|
|
|
|
[Parameter]
|
|
public bool ShowNeedConf { get; set; } = false;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Fields
|
|
|
|
protected RadzenScheduler<EventDto> scheduler = null!;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected DialogService DialogService { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
numEvAll = 0;
|
|
numEvFilt = 0;
|
|
if (EvDtoList != null && EvDtoList.Count > 0)
|
|
{
|
|
numEvAll = EvDtoList.Count();
|
|
FilterData();
|
|
try
|
|
{
|
|
await scheduler.Reload();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante OnParametersSet{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
|
private int selectedIndex = 2;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int cMonth { get; set; } = 3;
|
|
|
|
private string currView { get; set; } = "";
|
|
private List<EventDto> EvDtoFilt { get; set; } = new List<EventDto>();
|
|
|
|
private int numEvAll { get; set; } = 0;
|
|
private int numEvFilt { get; set; } = 0;
|
|
private string schedHeight { get; set; } = "height: 50rem;";
|
|
|
|
private DateTime SelDate { get; set; } = DateTime.Today;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private void FilterData()
|
|
{
|
|
// in primis copio tutto
|
|
EvDtoFilt = EvDtoList;
|
|
#if false
|
|
if (ShowNeedConf)
|
|
{
|
|
EvDtoFilt = EvDtoFilt.Where(x => !x.Conf).ToList();
|
|
}
|
|
// controllo ogni toggle...
|
|
if (!showChiu)
|
|
{
|
|
EvDtoFilt = EvDtoFilt
|
|
.Where(x => !x.IsCompany || (x.IsCompany && !x.CodTipo.Equals("FER", StringComparison.InvariantCultureIgnoreCase)))
|
|
.ToList();
|
|
}
|
|
if (!showFer)
|
|
{
|
|
EvDtoFilt = EvDtoFilt
|
|
.Where(x => !x.CodTipo.Equals("FER", StringComparison.InvariantCultureIgnoreCase) || (x.CodTipo.Equals("FER", StringComparison.InvariantCultureIgnoreCase) && x.IsCompany))
|
|
.ToList();
|
|
}
|
|
if (!showFest)
|
|
{
|
|
EvDtoFilt = EvDtoFilt
|
|
.Where(x => !x.CodTipo.Equals("FEST", StringComparison.InvariantCultureIgnoreCase))
|
|
.ToList();
|
|
}
|
|
if (!showMal)
|
|
{
|
|
EvDtoFilt = EvDtoFilt
|
|
.Where(x => !x.CodTipo.Equals("MAL", StringComparison.InvariantCultureIgnoreCase))
|
|
.ToList();
|
|
}
|
|
if (!showPer)
|
|
{
|
|
EvDtoFilt = EvDtoFilt
|
|
.Where(x => !x.CodTipo.Equals("PERM", StringComparison.InvariantCultureIgnoreCase) && !x.CodTipo.Equals("104", StringComparison.InvariantCultureIgnoreCase))
|
|
.ToList();
|
|
}
|
|
#endif
|
|
numEvFilt = EvDtoFilt.Count();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sistemazione colore sfonto di ogni evento mostrato
|
|
/// </summary>
|
|
/// <param name="args"></param>
|
|
private void OnAppointmentRender(SchedulerAppointmentRenderEventArgs<EventDto> args)
|
|
{
|
|
// Never call StateHasChanged in AppointmentRender - would lead to infinite loop
|
|
args.Attributes["style"] = $"background: {args.Data.Color}; color: {args.Data.ForeColor};";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Selezione evento per display
|
|
/// </summary>
|
|
/// <param name="selEv"></param>
|
|
/// <returns></returns>
|
|
private async Task OnAppointmentSelect(SchedulerAppointmentSelectEventArgs<EventDto> selEv)
|
|
{
|
|
var copy = selEv.Data.Clone();
|
|
await Task.Delay(1);
|
|
var data = await DialogService.OpenAsync<TaskDetail>("", new Dictionary<string, object> { { "ThisTask", copy } });
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gestione richeista caricamento dati dal controllo x avere nuovo set da mostrare
|
|
/// </summary>
|
|
/// <param name="args"></param>
|
|
/// <returns></returns>
|
|
private async Task OnLoadData(SchedulerLoadDataEventArgs args)
|
|
{
|
|
await Task.Delay(1);
|
|
currView = scheduler.SelectedView.Text.ToLowerInvariant();
|
|
DateTime dtMid = args.Start.AddDays(args.End.Subtract(args.Start).TotalDays / 2);
|
|
// controllo se sia cambiata data anno precedente...
|
|
if (dtMid.Year != SelDate.Year)
|
|
{
|
|
SelDate = dtMid;
|
|
await EC_DtReq.InvokeAsync(SelDate);
|
|
}
|
|
// di almeno 1 anno in questo caso...
|
|
else if (SelDate != scheduler.Date || Math.Abs(scheduler.Date.Subtract(args.Start).TotalDays) > 365)
|
|
{
|
|
SelDate = args.Start.AddDays(4);
|
|
await EC_DtReq.InvokeAsync(SelDate);
|
|
}
|
|
|
|
//schedHeight = (currView == "year" || currView == "planner") ? "height: 60rem;" : "height: 50rem;";
|
|
// // Get the appointments for between the Start and End
|
|
// data = await MyAppointmentService.GetData(selEv.Start, selEv.End);
|
|
}
|
|
|
|
private void OnSlotRender(SchedulerSlotRenderEventArgs args)
|
|
{
|
|
// Highlight today in month view
|
|
if (args.View.Text == "Month" && args.Start.Date == DateTime.Today)
|
|
{
|
|
args.Attributes["style"] = "background: var(--rz-scheduler-highlight-background-color, rgba(255,220,40,.2));";
|
|
}
|
|
|
|
// Highlight working hours (9-18)
|
|
if ((args.View.Text == "Week" || args.View.Text == "Day") && args.Start.Hour > 8 && args.Start.Hour < 19)
|
|
{
|
|
args.Attributes["style"] = "background: var(--rz-scheduler-highlight-background-color, rgba(255,220,40,.2));";
|
|
}
|
|
}
|
|
|
|
private async Task OnSlotSelect(SchedulerSlotSelectEventArgs args)
|
|
{
|
|
int prevIdx = selectedIndex;
|
|
await Task.Delay(1);
|
|
// verifico indice corretto della vista...
|
|
switch (args.View.Text)
|
|
{
|
|
case "Day":
|
|
selectedIndex = 0;
|
|
break;
|
|
|
|
case "Week":
|
|
selectedIndex = 1;
|
|
break;
|
|
|
|
case "Month":
|
|
selectedIndex = 2;
|
|
break;
|
|
|
|
case "Planner":
|
|
selectedIndex = 3;
|
|
break;
|
|
|
|
case "Year":
|
|
selectedIndex = 4;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
if (prevIdx != selectedIndex)
|
|
{
|
|
await scheduler.Reload();
|
|
}
|
|
await Task.Delay(1);
|
|
if (selectedIndex > 0)
|
|
{
|
|
selectedIndex--;
|
|
}
|
|
// imposto al data selezionata
|
|
SelDate = args.Start;
|
|
// riporto data al controller parent...
|
|
await EC_DtReq.InvokeAsync(SelDate);
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |