using Microsoft.AspNetCore.Components;
using System.Drawing;
namespace Egw.Core.Razor.Comp
{
public partial class CalendarWeek
{
#region Public Properties
///
/// Periodo da mostrare (tipicamente 1 settimana)
///
[Parameter]
public List DateList { get; set; } = new List();
///
/// Eventi da inserire
///
[Parameter]
public List EventList { get; set; } = new List();
///
/// Evento selezione data valida (= entro il periodo selezionato)
///
[Parameter]
public EventCallback DateSelected { get; set; }
[Parameter]
public EventCallback backToCalendar{ get; set; }
[Parameter]
public int EndHour { get; set; } = 20;
///
/// Css titolo
/// default: color: red
///
[Parameter]
public string HeadStyle { get; set; } = "color: #E67E22";
///
/// Altezza di ogni blocco ora da mostrare
///
[Parameter]
public int HeightHour { get; set; } = 20;
///
/// Larghezza calcolata delle etichette, minimo tra
///
[Parameter]
public int labelWidth { get; set; } = 15;
[Parameter]
public int StartHour { get; set; } = 8;
///
/// Dimensioni viewbox GLOBALE
///
[Parameter]
public Size vBox { get; set; } = new Size(1200, 1600);
///
/// Evento richiesta modifica settimana
///
[Parameter]
public EventCallback WeekChanged { get; set; }
#endregion Public Properties
#region Protected Fields
protected List HourSlot = new List();
#endregion Protected Fields
#region Protected Properties
protected int calcColSpan
{
get => numDays + 1;
}
protected DateTime DtRif
{
get
{
DateTime answ = DateTime.Today;
if (DateList != null && DateList.Count > 0)
{
answ = DateList[0];
}
return answ;
}
}
protected int numDays
{
get => DateList.Count;
}
protected int contWidth
{
get => (vBox.Width * 2) / (2 * numDays + 1);
}
private string lblWidth
{
get => $"{(double)(vBox.Width - (contWidth * numDays)) / vBox.Width:P2}".Replace(",", ".");
}
private string dataWidth
{
get => $"{(double)contWidth / vBox.Width:P2}".Replace(",", ".");
}
protected Size vBoxLabel
{
get
{
// label � MENO di 1/tot columns
Size answ = new Size(contWidth / 2, vBox.Height);
return answ;
}
}
protected Size vBoxCont
{
get
{
// label � MENO di 1/tot columns
Size answ = new Size(contWidth, vBox.Height);
return answ;
}
}
//protected Size vBoxLabel
//{
// get
// {
// // label � MENO di 1/tot columns
// Size answ = new Size(labelWidth, vBox.Height);
// return answ;
// }
//}
#endregion Protected Properties
#region Protected Methods
///
/// Richiesta cambio sett di riferimento --> riporta evento
///
///
///
protected async Task changeWeek(int delta)
{
await WeekChanged.InvokeAsync(delta);
}
protected override async Task OnParametersSetAsync()
{
HourSlot = new List();
for (int i = StartHour; i <= EndHour; i++)
{
HourSlot.Add(i);
}
await InvokeAsync(StateHasChanged);
}
///
/// GetIso8601WeekOfYear
///
///
///
protected int weekNum(DateTime DtReq)
{
int wNum = WeekData.GetIso8601WeekOfYear(DtReq);
return wNum;
}
protected List DayEvent(DateTime DtReq)
{
List answ = new List();
if (EventList != null)
{
answ = EventList.Where(x => x.Inizio.Date == DtReq.Date).ToList();
}
return answ;
}
///
/// Genera etichette orarie (1 x ora)
///
///
protected List LabelList()
{
int idx = 0;
List answ = HourSlot.Select(x => new CalendarEvent()
{
id = idx++,
Inizio = DtRif.AddHours(x),
Fine = DtRif.AddHours(x),
CssClass = "text-light",
Title = $"{x:00}:00",
Description = $"{x:00}:00"
}).ToList();
return answ;
}
protected async Task openCalendarMonth()
{
await backToCalendar.InvokeAsync(true);
}
#endregion Protected Methods
}
}