diff --git a/EgwCoreLib.BlazorTest/Pages/TestCalendario.razor b/EgwCoreLib.BlazorTest/Pages/TestCalendario.razor index 5620a7b..fdab007 100644 --- a/EgwCoreLib.BlazorTest/Pages/TestCalendario.razor +++ b/EgwCoreLib.BlazorTest/Pages/TestCalendario.razor @@ -10,7 +10,7 @@
- +
diff --git a/EgwCoreLib.BlazorTest/Pages/TestCalendario.razor.cs b/EgwCoreLib.BlazorTest/Pages/TestCalendario.razor.cs index 9b39d1d..0bb98c8 100644 --- a/EgwCoreLib.BlazorTest/Pages/TestCalendario.razor.cs +++ b/EgwCoreLib.BlazorTest/Pages/TestCalendario.razor.cs @@ -45,30 +45,9 @@ namespace EgwCoreLib.BlazorTest.Pages protected void SetDayDetail(DateTime selDate) { - var tmpDays = new List(); - var tmpEv = new List(); - tmpDays.Add(selDate); - // genero qualche evento da 0 a 6... - int numEv = rnd.Next(0, 8); - if (numEv > 0) - { - for (int e = 0; e < numEv; e++) - { - double duration = 9 + 8 * rnd.NextDouble(); - CalendarEvent newEv = new CalendarEvent() - { - CssClass = "bg-success opacity-25", - Description = $"Permesso #{e}", - Type = "PERM", - Inizio = selDate.AddHours(8), - Fine = selDate.AddHours(duration), - Title = "O.S.", - ToolTip = $"O.S. {selDate.AddHours(8)} - {selDate.AddHours(duration)}" - }; - tmpEv.Add(newEv); - } - } + var tmpDays = ListDate.Where(x => x.Equals(selDate)).ToList(); + var tmpEv = EventListWeek.Where(x => x.Inizio.Date.Equals(selDate)).ToList(); // salvo valori simulati ListDate = tmpDays; EventListWeek = tmpEv; @@ -89,15 +68,17 @@ namespace EgwCoreLib.BlazorTest.Pages { for (int e = 0; e < numEv; e++) { + int inizio = rnd.Next(8, 12); + int fine = inizio + rnd.Next(2,8); CalendarEvent newEv = new CalendarEvent() { CssClass = "bg-success opacity-25", Description = $"Permesso #{e}", Type = "PERM", - Inizio = oggi.AddDays(i).AddHours(8), - Fine = oggi.AddDays(i).AddHours(9 + 8 * rnd.NextDouble()), + Inizio = oggi.AddDays(i).AddHours(inizio), + Fine = oggi.AddDays(i).AddHours(fine), Title = "O.S.", - ToolTip = $"O.S. {oggi.AddDays(i).AddHours(8)} - {oggi.AddDays(i).AddHours(17)}" + ToolTip = $"O.S. {oggi.AddDays(i).AddHours(inizio)} - {oggi.AddDays(i).AddHours(fine)}" }; tmpEv.Add(newEv); } diff --git a/EgwCoreLib.Razor/CalWeekColumn.razor.cs b/EgwCoreLib.Razor/CalWeekColumn.razor.cs index c266cbf..b678ff1 100644 --- a/EgwCoreLib.Razor/CalWeekColumn.razor.cs +++ b/EgwCoreLib.Razor/CalWeekColumn.razor.cs @@ -42,6 +42,14 @@ namespace EgwCoreLib.Razor [Parameter] public ColType ItemMode { get; set; } = ColType.dataContainer; + /// + /// 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) + /// + [Parameter] + public int PercX { get; set; } = 100; + /// /// Fattore di shift in Y, se 0 = nessuno shift, se > 0 è percentuale moltiplica il /// gradino calcolato @@ -102,19 +110,20 @@ namespace EgwCoreLib.Razor List answ = new List(); int step = vBox.Height / (ValMax - ValMin); int numEv = EventList.Count; - int evWidth = numEv > 1 ? (int)(0.7 * vBox.Width) : (int)(0.9 * vBox.Width); + 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); + 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), diff --git a/EgwCoreLib.Razor/CalendarWeek.razor b/EgwCoreLib.Razor/CalendarWeek.razor index 63b6e39..7e473c5 100644 --- a/EgwCoreLib.Razor/CalendarWeek.razor +++ b/EgwCoreLib.Razor/CalendarWeek.razor @@ -6,7 +6,7 @@ else { - + @foreach (var item in DateList) { @@ -29,7 +29,7 @@ else @foreach (var item in DateList) { } diff --git a/EgwCoreLib.Razor/CalendarWeek.razor.cs b/EgwCoreLib.Razor/CalendarWeek.razor.cs index a61afa8..144d6c1 100644 --- a/EgwCoreLib.Razor/CalendarWeek.razor.cs +++ b/EgwCoreLib.Razor/CalendarWeek.razor.cs @@ -8,40 +8,24 @@ namespace EgwCoreLib.Razor { #region Public Properties + /// + /// Evento x ritorno click + /// + [Parameter] + public EventCallback backToCalendar { get; set; } + /// /// 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; } - - /// - /// 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) - /// - [Parameter] - public int PercY { get; set; } = 90; - - /// - /// Evento x ritorno click - /// - [Parameter] - public EventCallback backToCalendar{ get; set; } - - /// /// Evento selezione data singola giornata da header /// @@ -54,6 +38,12 @@ namespace EgwCoreLib.Razor [Parameter] public int EndHour { get; set; } = 20; + /// + /// Eventi da inserire + /// + [Parameter] + public List EventList { get; set; } = new List(); + /// /// Css titolo /// default: color: red @@ -73,6 +63,22 @@ namespace EgwCoreLib.Razor [Parameter] public int labelWidth { get; set; } = 15; + /// + /// 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) + /// + [Parameter] + public int PercX { get; set; } = 100; + + /// + /// 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) + /// + [Parameter] + public int PercY { get; set; } = 90; + [Parameter] public int StartHour { get; set; } = 8; @@ -103,6 +109,12 @@ namespace EgwCoreLib.Razor get => numDays + 1; } + protected int contWidth + { + get => (vBox.Width * 2) / (2 * numDays + 1); + //get => numDays > 1 ? (vBox.Width * 2) / (2 * numDays + 1) : vBox.Width * 90 / 100; + } + protected DateTime DtRif { get @@ -121,48 +133,26 @@ namespace EgwCoreLib.Razor get => DateList.Count; } - protected int contWidth + protected Size vBoxCont { - 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(",", "."); + get + { + // label e' MENO di 1/tot columns + Size answ = new Size(contWidth, vBox.Height); + return answ; + } } protected Size vBoxLabel { get { - // label � MENO di 1/tot columns + // label e' MENO di 1/tot columns Size answ = new Size(contWidth / 2, vBox.Height); + //Size answ = new Size(labelWidth, 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 @@ -178,27 +168,6 @@ namespace EgwCoreLib.Razor 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(); @@ -228,17 +197,51 @@ namespace EgwCoreLib.Razor return answ; } + protected override async Task OnParametersSetAsync() + { + HourSlot = new List(); + for (int i = StartHour; i <= EndHour; i++) + { + HourSlot.Add(i); + } + await InvokeAsync(StateHasChanged); + } + protected async Task OpenCalendarMonth() { await backToCalendar.InvokeAsync(true); } - protected async Task SelectDate( DateTime selDate) + protected async Task SelectDate(DateTime selDate) { await EC_HeadDateSel.InvokeAsync(selDate); } + /// + /// GetIso8601WeekOfYear + /// + /// + /// + protected int weekNum(DateTime DtReq) + { + int wNum = WeekData.GetIso8601WeekOfYear(DtReq); + return wNum; + } #endregion Protected Methods + + #region Private Properties + + private string dataWidth + { + get => $"{(double)contWidth / vBox.Width:P2}".Replace(",", "."); + } + + private string lblWidth + { + get => $"{(double)(vBox.Width - (contWidth * numDays)) / vBox.Width:P2}".Replace(",", "."); + } + + #endregion Private Properties } } \ No newline at end of file diff --git a/EgwCoreLib.Razor/Data/CalendarEvent.cs b/EgwCoreLib.Razor/Data/CalendarEvent.cs index f6fec86..34f24de 100644 --- a/EgwCoreLib.Razor/Data/CalendarEvent.cs +++ b/EgwCoreLib.Razor/Data/CalendarEvent.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -11,6 +12,11 @@ namespace EgwCoreLib.Razor.Data public int id { get; set; } = 0; public DateTime Inizio { get; set; } = DateTime.Today.AddHours(8); public DateTime Fine { get; set; } = DateTime.Today.AddHours(10); + [NotMapped] + public double Durata + { + get => Fine.Subtract(Inizio).TotalMinutes; + } public string CssClass { get; set; } = ""; public string Title { get; set; } = ""; public string Description { get; set; } = "";
- +