565c20e396
- spostamento sel calendario inDataLayer - Fix display info personali in dettaglio DTO - Fix selettore mese - Clòeanup vari
343 lines
10 KiB
C#
343 lines
10 KiB
C#
using BlazorCalendar;
|
|
using BlazorCalendar.Models;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.Identity.Client;
|
|
using Radzen.Blazor.Rendering;
|
|
using Radzen.Blazor;
|
|
using static EgwCoreLib.Razor.Toggler;
|
|
using Radzen;
|
|
using System;
|
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
using GPW.CORE.Data.DTO;
|
|
using System.Diagnostics;
|
|
using GPW.CORE.WRKLOG.Data;
|
|
|
|
namespace GPW.CORE.WRKLOG.Components.Compo
|
|
{
|
|
public partial class CalendarioAziendale
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public List<EventDTO> EvDtoList { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public DateTime firstDate { get; set; } = new DateTime(DateTime.Today.Year, 1, 1);
|
|
|
|
[Parameter]
|
|
public int IdxDip { get; set; } = 0;
|
|
|
|
[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 DisplayedView ModoDisplay { get; set; } = DisplayedView.Annual;
|
|
|
|
[Parameter]
|
|
public int MonthDispl
|
|
{
|
|
get => cMonth;
|
|
set => cMonth = value;
|
|
}
|
|
|
|
[Parameter]
|
|
public EventCallback<int> MonthReq { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<DateTime> DtReq { get; set; }
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Fields
|
|
|
|
protected RadzenScheduler<EventDTO> scheduler = null!;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Enums
|
|
|
|
protected enum Viste
|
|
{
|
|
Day,
|
|
Week,
|
|
Month,
|
|
Planner,
|
|
Year
|
|
}
|
|
|
|
#endregion Protected Enums
|
|
|
|
#region Protected Properties
|
|
|
|
protected string CalModeText
|
|
{
|
|
get => ModoDisplay == DisplayedView.Annual ? "Mensile" : "Multi Mese";
|
|
}
|
|
|
|
protected int currMonth
|
|
{
|
|
get => cMonth;
|
|
set
|
|
{
|
|
if (cMonth != value)
|
|
{
|
|
cMonth = value;
|
|
MonthReq.InvokeAsync(value);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected string CurrMonth
|
|
{
|
|
get => ModoDisplay == DisplayedView.Monthly ? $"{firstDate:MMMM}" : "Multi";
|
|
}
|
|
|
|
[Inject]
|
|
protected DialogService DialogService { get; set; } = null!;
|
|
|
|
protected bool UseRadz { get; set; } = true;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected async Task addMonth(int numMesi)
|
|
{
|
|
firstDate = firstDate.AddMonths(numMesi);
|
|
// verifico limiti...
|
|
if (numMesi > 0)
|
|
{
|
|
firstDate = firstDate > maxDate ? maxDate : firstDate;
|
|
}
|
|
else
|
|
{
|
|
firstDate = firstDate < minDate ? minDate : firstDate;
|
|
}
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await Task.Delay(1);
|
|
if (UseRadz)
|
|
{
|
|
// il mese viene preimpostato sul trimestre corrente...
|
|
startMonth = (Month)((DateTime.Today.Month / 6) * 6);
|
|
ToggleData = new SelectGlobalToggle()
|
|
{
|
|
leftString = "Personali",
|
|
rightString = "Tutti",
|
|
placardCss = "bg-dark border-dark text-light"
|
|
};
|
|
}
|
|
else
|
|
{
|
|
ToggleData = new SelectGlobalToggle()
|
|
{
|
|
leftString = "Mensile",
|
|
rightString = "Multi Mese",
|
|
placardCss = "bg-dark border-dark text-light"
|
|
};
|
|
}
|
|
}
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
FilterData();
|
|
TaskList = EvDtoList.Select(x => Converter.ToBlazorCalTask(x)).ToList();
|
|
scheduler.Reload();
|
|
}
|
|
|
|
protected void ResetCal()
|
|
{
|
|
FixCalendar();
|
|
}
|
|
|
|
protected void SetWeek(ClickTaskParameter taskVal)
|
|
{
|
|
firstDate = taskVal.Day;
|
|
ModoDisplay = DisplayedView.Weekly;
|
|
}
|
|
|
|
protected void SetWeek(ClickEmptyDayParameter taskVal)
|
|
{
|
|
firstDate = taskVal.Day;
|
|
ModoDisplay = DisplayedView.Weekly;
|
|
}
|
|
|
|
protected async Task StartMonthChange()
|
|
{
|
|
await scheduler.Reload();
|
|
}
|
|
|
|
protected async Task ToggleMode()
|
|
{
|
|
ModoDisplay = ModoDisplay == DisplayedView.Annual ? DisplayedView.Monthly : DisplayedView.Annual;
|
|
await Task.Delay(1);
|
|
// se annuale --> riporto firstDate
|
|
if (ModoDisplay == DisplayedView.Annual)
|
|
{
|
|
firstDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
|
|
}
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
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 string schedHeight { get; set; } = "height: 50rem;";
|
|
private Month startMonth { get; set; } = Month.January;// = DateTime.Today.Month <= 6 ? Month.January : Month.July;
|
|
private List<Tasks> TaskList { get; set; } = new List<Tasks>();
|
|
private SelectGlobalToggle ToggleData { get; set; } = new SelectGlobalToggle();
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async Task evToggled(SelectGlobalToggle newTogData)
|
|
{
|
|
ToggleData = newTogData;
|
|
if (UseRadz)
|
|
{
|
|
FilterData();
|
|
}
|
|
else
|
|
{
|
|
FixCalendar();
|
|
await Task.Delay(1);
|
|
}
|
|
}
|
|
|
|
private void FilterData()
|
|
{
|
|
// filtro risultati richiesti...
|
|
if (ToggleData.isActive)
|
|
{
|
|
EvDtoFilt = EvDtoList;
|
|
}
|
|
else
|
|
{
|
|
EvDtoFilt = EvDtoList
|
|
.Where(x => x.IdxDipendente == IdxDip || x.IdxDipendente == 0)
|
|
.ToList();
|
|
}
|
|
}
|
|
|
|
private void FixCalendar()
|
|
{
|
|
ModoDisplay = ToggleData.isActive ? DisplayedView.Annual : DisplayedView.Monthly;
|
|
// se annuale --> riporto firstDate
|
|
if (ModoDisplay == DisplayedView.Annual)
|
|
{
|
|
firstDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
|
|
}
|
|
}
|
|
|
|
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};";
|
|
}
|
|
|
|
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 } });
|
|
}
|
|
|
|
private async Task OnLoadData(SchedulerLoadDataEventArgs args)
|
|
{
|
|
await Task.Delay(1);
|
|
currView = scheduler.SelectedView.Text.ToLowerInvariant();
|
|
|
|
// controllo se sia cambiata data... di almeno 1 anno in questo caso...
|
|
if (SelDate != scheduler.Date || Math.Abs(scheduler.Date.Subtract(args.Start).TotalDays) > 365)
|
|
{
|
|
SelDate = args.Start.AddMonths(1);
|
|
// riporto data al controller parent...
|
|
await 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 DtReq.InvokeAsync(SelDate);
|
|
}
|
|
|
|
private DateTime SelDate { get; set; } = DateTime.Today;
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |