239 lines
7.0 KiB
C#
239 lines
7.0 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using System.Drawing;
|
|
using EgwCoreLib.Razor.Data;
|
|
|
|
namespace EgwCoreLib.Razor
|
|
{
|
|
public partial class CalWeekColumn
|
|
{
|
|
#region Public Enums
|
|
|
|
public enum ColType
|
|
{
|
|
/// <summary>
|
|
/// Tipo etichetta Start (SX)
|
|
/// </summary>
|
|
labelStart,
|
|
|
|
/// <summary>
|
|
/// Tipo etichetta End (DX)
|
|
/// </summary>
|
|
labelEnd,
|
|
|
|
/// <summary>
|
|
/// Colonna dati
|
|
/// </summary>
|
|
dataContainer
|
|
}
|
|
|
|
#endregion Public Enums
|
|
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// Lista etichette da mostrare (richiede tipo label...)
|
|
/// </summary>
|
|
[Parameter]
|
|
public List<CalendarEvent> EventList { get; set; } = new List<CalendarEvent>();
|
|
|
|
/// <summary>
|
|
/// Modalit� di disegno
|
|
/// </summary>
|
|
[Parameter]
|
|
public ColType ItemMode { get; set; } = ColType.dataContainer;
|
|
|
|
/// <summary>
|
|
/// Fattore di shift in X, se 0 = nessuno shift, se > 0 è percentuale moltiplica il
|
|
/// gradino calcolato
|
|
/// Default: 100 (poi riportato a intero, quindi 100/100 = 1.0)
|
|
/// </summary>
|
|
[Parameter]
|
|
public int PercX { get; set; } = 100;
|
|
|
|
/// <summary>
|
|
/// Fattore di shift in Y, se 0 = nessuno shift, se > 0 è percentuale moltiplica il
|
|
/// gradino calcolato
|
|
/// Default: 90 (poi riportato a intero, quindi 90/100 = 0.9)
|
|
/// </summary>
|
|
[Parameter]
|
|
public int PercY { get; set; } = 90;
|
|
|
|
[Parameter]
|
|
public int ValMax { get; set; } = 19;
|
|
|
|
[Parameter]
|
|
public int ValMin { get; set; } = 9;
|
|
|
|
/// <summary>
|
|
/// Dimensioni viewbox
|
|
/// </summary>
|
|
[Parameter]
|
|
public Size vBox { get; set; } = new Size(1200, 3200);
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Fields
|
|
|
|
protected string Messaggio = "";
|
|
protected string titleDx = "";
|
|
protected string titleSx = "";
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
protected boxData? currData { get; set; } = null;
|
|
|
|
protected int hFO
|
|
{
|
|
get => 100;// EventList.Count > 0 ? vBox.Height / EventList.Count : vBox.Height;
|
|
}
|
|
|
|
protected int mFO
|
|
{
|
|
get => vBox.Width * 4 / 100;
|
|
}
|
|
|
|
protected bool showDetail { get; set; } = false;
|
|
|
|
protected int wFO
|
|
{
|
|
get => vBox.Width * 98 / 100;
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected List<boxData> BoxItems()
|
|
{
|
|
List<boxData> answ = new List<boxData>();
|
|
int step = vBox.Height / (ValMax - ValMin);
|
|
int numEv = EventList.Count;
|
|
int evWidth = numEv > 1 ? (int)(0.5 * vBox.Width) : (int)(0.9 * vBox.Width);
|
|
//int evWidth = numEv > 1 ? (int)(1.5 * vBox.Width / numEv) : (int)(0.9 * vBox.Width);
|
|
int offsetX = 1;
|
|
int offsetY = 0;// step / 2;
|
|
if (numEv > 0)
|
|
{
|
|
int xStep = evWidth / (EventList.Count + 1) * PercX / 100;
|
|
int yStep = evWidth * PercY / 100;
|
|
//int yStep = xStep * 5;
|
|
//int yStep = xStep * (EventList.Count + 50) / (EventList.Count + 6);
|
|
int deltaX = 0;
|
|
answ = EventList
|
|
.OrderBy(x => x.Inizio)
|
|
.ThenByDescending(x => x.Durata)
|
|
.Select(x => new boxData()
|
|
{
|
|
pX = offsetX + xStep * (deltaX),
|
|
pY = offsetY + yStep * (deltaX++) + (int)(x.Inizio.AddHours(-ValMin).TimeOfDay.TotalHours * step),
|
|
width = evWidth,
|
|
height = offsetY + (int)(x.Fine.Subtract(x.Inizio).TotalHours * step),
|
|
title = x.Type,
|
|
value = x.Description,
|
|
start = x.Inizio,
|
|
end = x.Fine,
|
|
cssClass = x.CssClass
|
|
})
|
|
.ToList();
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected async Task DetClosed(bool closed)
|
|
{
|
|
if (closed)
|
|
{
|
|
currData = null;
|
|
showDetail = false;
|
|
}
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converte la stringa in formato markup valido
|
|
/// </summary>
|
|
/// <param name="rawData"></param>
|
|
/// <returns></returns>
|
|
protected MarkupString getMarkup(string rawData)
|
|
{
|
|
return new MarkupString(rawData);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Genera una lista di etichette con corrdinate
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected List<labelData> LabelItems()
|
|
{
|
|
int step = vBox.Height / numEv;// (ValMax - ValMin);
|
|
int offset = 0;// step / 2;
|
|
|
|
List<labelData> answ = EventList
|
|
.OrderBy(x => x.Inizio)
|
|
.Select(x => new labelData()
|
|
{
|
|
pX = vBox.Width / 10,
|
|
pY = offset + (int)(x.Inizio.AddHours(-ValMin).TimeOfDay.TotalHours * step),
|
|
value = x.Title
|
|
})
|
|
.ToList();
|
|
return answ;
|
|
}
|
|
|
|
protected async void selItem(boxData item)
|
|
{
|
|
titleSx = $"{item.start:dddd dd}";
|
|
titleDx = $"{item.start:MMMM yyyy}";
|
|
|
|
currData = item;
|
|
showDetail = true;
|
|
await Task.Delay(1);
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Protected Classes
|
|
|
|
protected class boxData
|
|
{
|
|
#region Public Properties
|
|
|
|
public string cssClass { get; set; } = "";
|
|
public DateTime end { get; set; } = DateTime.Today;
|
|
public int height { get; set; } = 0;
|
|
public int pX { get; set; } = 0;
|
|
public int pY { get; set; } = 0;
|
|
public DateTime start { get; set; } = DateTime.Today;
|
|
public string title { get; set; } = "";
|
|
public string value { get; set; } = "";
|
|
public int width { get; set; } = 0;
|
|
|
|
#endregion Public Properties
|
|
}
|
|
|
|
protected class labelData
|
|
{
|
|
#region Public Properties
|
|
|
|
public int pX { get; set; } = 0;
|
|
public int pY { get; set; } = 0;
|
|
public string value { get; set; } = "";
|
|
|
|
#endregion Public Properties
|
|
}
|
|
|
|
#endregion Protected Classes
|
|
|
|
#region Private Properties
|
|
|
|
private int numEv
|
|
{
|
|
get => EventList.Count > 0 ? EventList.Count : 1;
|
|
}
|
|
|
|
#endregion Private Properties
|
|
}
|
|
} |