From 1e2a09a469f5ad8fa88707cc7dfd30760bd52be6 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 9 Jan 2023 15:54:17 +0100 Subject: [PATCH] Prima demo componente table mese --- GPW.CORE.Comp/CalendarMonth.razor | 38 +++++-- GPW.CORE.Comp/CalendarMonth.razor.cs | 144 +++++++++++++++++++++++---- GPW.CORE.Comp/LoadingData.razor | 6 ++ GPW.CORE.Comp/LoadingDataSmall.razor | 6 ++ GPW.CORE.Test/Pages/TestCal.razor | 13 +++ GPW.CORE.Test/Shared/NavMenu.razor | 5 + 6 files changed, 185 insertions(+), 27 deletions(-) create mode 100644 GPW.CORE.Comp/LoadingData.razor create mode 100644 GPW.CORE.Comp/LoadingDataSmall.razor create mode 100644 GPW.CORE.Test/Pages/TestCal.razor diff --git a/GPW.CORE.Comp/CalendarMonth.razor b/GPW.CORE.Comp/CalendarMonth.razor index f9d8287..e0fb1df 100644 --- a/GPW.CORE.Comp/CalendarMonth.razor +++ b/GPW.CORE.Comp/CalendarMonth.razor @@ -1,12 +1,30 @@ - - - - - - - - - -
+@if (WeekRow == null || WeekRow.Count == 0) +{ + +} +else +{ + + + + @for (int i = 0; i < 7; i++) + { + + } + + + + @foreach (var settim in WeekRow) + { + + @foreach (var giorno in settim) + { + + } + + } + +
@($"{DateList[i]:ddd}".Substring(0, 1).ToUpper())
@($"{giorno:dd}")
+} diff --git a/GPW.CORE.Comp/CalendarMonth.razor.cs b/GPW.CORE.Comp/CalendarMonth.razor.cs index c6ab347..26778ed 100644 --- a/GPW.CORE.Comp/CalendarMonth.razor.cs +++ b/GPW.CORE.Comp/CalendarMonth.razor.cs @@ -1,40 +1,150 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Components; -using Microsoft.AspNetCore.Components.Web; namespace GPW.CORE.Comp { public partial class CalendarMonth { + #region Public Properties + /// - /// Css sfondo principale - /// default: bg-dark + /// Css giorno mese corrente + /// default: text-danger /// [Parameter] - public string MainCss { get; set; } = "bg-dark"; + public string CurrMonthCss { get; set; } = "text-light"; + + /// + /// Day di riferimento (tipicamente = oggi) per disegnare calendario alla data corrente + /// [Parameter] - public DateOnly DtStart { get; set; } = DateOnly.FromDateTime(DateTime.Today); + public DateTime DtRif { get; set; } = DateTime.Today; + + /// + /// Css titolo + /// default: text-danger + /// [Parameter] - public DateOnly DtEnd { get; set; } = DateOnly.FromDateTime(DateTime.Today.AddMonths(1)); - private async Task CalcDate() + public string HeadCss { get; set; } = "text-danger"; + + /// + /// Css sfondo principale + /// default: table table-dark table-borderless table-striped + /// + [Parameter] + public string MainCss { get; set; } = "table table-dark table-borderless table-striped"; + + /// + /// Css giorno tipico + /// default: text-danger + /// + [Parameter] + public string OtherMonthCss { get; set; } = "text-secondary"; + + #endregion Public Properties + + #region Protected Methods + + protected override async Task OnParametersSetAsync() { - await Task.Delay(1); - DateTime oggi = DateTime.Today; - DtStart = new DateOnly(oggi.Year, oggi.Month, 1); - DtEnd = DtStart.AddMonths(1).AddDays(-1); - // calcolo elenco date (da disegnare) + await FixDate(); } + #endregion Protected Methods + + #region Private Properties + /// /// Elenco date da mostrare /// private List DateList { get; set; } = new List(); + + private DateTime MonthEnd { get; set; } = DateTime.Today.AddMonths(1); + + private DateTime MonthStart { get; set; } = DateTime.Today; + /// /// Righe da disegnare nel calendario /// - private List> RigheCalendario { get; set; } = new List>(); + private List> WeekRow { get; set; } = new List>(); + + #endregion Private Properties + + #region Private Methods + + private string dayCss(DateTime currDay) + { + string answ = CurrMonthCss; + // se è fuori estremi mese --> grigio... + if (currDay < MonthStart || currDay > MonthEnd) + { + answ = OtherMonthCss; + } + return answ; + } + + /// + /// Sistemazione date x disegnare controlli + /// + /// + private async Task FixDate() + { + await Task.Delay(1); + // disegno sempre 6 righe = 42 gg + int numDD = 42; + MonthStart = new DateTime(DtRif.Year, DtRif.Month, 1); + MonthEnd = MonthStart.AddMonths(1).AddDays(-1); + DateTime calStart = MonthStart; + // calcolo date calendario in base al giorno dell'inizio mese... + switch (MonthStart.DayOfWeek) + { + case DayOfWeek.Sunday: + calStart = MonthStart.AddDays(-6); + break; + + case DayOfWeek.Monday: + calStart = MonthStart.AddDays(-7); + break; + + case DayOfWeek.Tuesday: + calStart = MonthStart.AddDays(-1); + break; + + case DayOfWeek.Wednesday: + calStart = MonthStart.AddDays(-2); + break; + + case DayOfWeek.Thursday: + calStart = MonthStart.AddDays(-3); + break; + + case DayOfWeek.Friday: + calStart = MonthStart.AddDays(-4); + break; + + case DayOfWeek.Saturday: + calStart = MonthStart.AddDays(-5); + break; + + default: + break; + } + // calcolo fine mese sapendo che sono cmq 7 x 6 week... + int numEnd = numDD - MonthEnd.Subtract(calStart).Days; + DateTime calEnd = MonthEnd.AddDays(numEnd); + // calcolo elenco date (da disegnare) + DateList = new List(); + for (int i = 0; i < numDD; i++) + { + DateList.Add(calStart.AddDays(i)); + } + // ora sistemo le righe da disegnare... + WeekRow = new List>(); + for (int i = 0; i < 6; i++) + { + WeekRow.Add(DateList.GetRange(i * 7, 7)); + } + } + + #endregion Private Methods } } \ No newline at end of file diff --git a/GPW.CORE.Comp/LoadingData.razor b/GPW.CORE.Comp/LoadingData.razor new file mode 100644 index 0000000..354d765 --- /dev/null +++ b/GPW.CORE.Comp/LoadingData.razor @@ -0,0 +1,6 @@ +
+
+

loading data

+ +
+
\ No newline at end of file diff --git a/GPW.CORE.Comp/LoadingDataSmall.razor b/GPW.CORE.Comp/LoadingDataSmall.razor new file mode 100644 index 0000000..8362fbb --- /dev/null +++ b/GPW.CORE.Comp/LoadingDataSmall.razor @@ -0,0 +1,6 @@ +
+
+ loading data + +
+
\ No newline at end of file diff --git a/GPW.CORE.Test/Pages/TestCal.razor b/GPW.CORE.Test/Pages/TestCal.razor new file mode 100644 index 0000000..c82b44e --- /dev/null +++ b/GPW.CORE.Test/Pages/TestCal.razor @@ -0,0 +1,13 @@ +@page "/TestCal" + + +

TestCal

+ + + + + + +@code { + +} diff --git a/GPW.CORE.Test/Shared/NavMenu.razor b/GPW.CORE.Test/Shared/NavMenu.razor index 6ac7f07..8d07f42 100644 --- a/GPW.CORE.Test/Shared/NavMenu.razor +++ b/GPW.CORE.Test/Shared/NavMenu.razor @@ -14,6 +14,11 @@ Home +