Prima demo componente table mese

This commit is contained in:
Samuele Locatelli
2023-01-09 15:54:17 +01:00
parent 2ef42fefd5
commit 1e2a09a469
6 changed files with 185 additions and 27 deletions
+28 -10
View File
@@ -1,12 +1,30 @@
<table class="table table-sm table-striped table-responsive-md @MainCss">
<thead>
</thead>
<tbody>
<tr>
</tr>
</tbody>
</table>
@if (WeekRow == null || WeekRow.Count == 0)
{
<LoadingData></LoadingData>
}
else
{
<table class="@MainCss text-center">
<thead>
<tr>
@for (int i = 0; i < 7; i++)
{
<th class="@HeadCss">@($"{DateList[i]:ddd}".Substring(0, 1).ToUpper())</th>
}
</tr>
</thead>
<tbody>
@foreach (var settim in WeekRow)
{
<tr>
@foreach (var giorno in settim)
{
<td class="@dayCss(giorno)">@($"{giorno:dd}")</td>
}
</tr>
}
</tbody>
</table>
}
+127 -17
View File
@@ -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
/// <summary>
/// Css sfondo principale
/// default: bg-dark
/// Css giorno mese corrente
/// default: text-danger
/// </summary>
[Parameter]
public string MainCss { get; set; } = "bg-dark";
public string CurrMonthCss { get; set; } = "text-light";
/// <summary>
/// Day di riferimento (tipicamente = oggi) per disegnare calendario alla data corrente
/// </summary>
[Parameter]
public DateOnly DtStart { get; set; } = DateOnly.FromDateTime(DateTime.Today);
public DateTime DtRif { get; set; } = DateTime.Today;
/// <summary>
/// Css titolo
/// default: text-danger
/// </summary>
[Parameter]
public DateOnly DtEnd { get; set; } = DateOnly.FromDateTime(DateTime.Today.AddMonths(1));
private async Task CalcDate()
public string HeadCss { get; set; } = "text-danger";
/// <summary>
/// Css sfondo principale
/// default: table table-dark table-borderless table-striped
/// </summary>
[Parameter]
public string MainCss { get; set; } = "table table-dark table-borderless table-striped";
/// <summary>
/// Css giorno tipico
/// default: text-danger
/// </summary>
[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
/// <summary>
/// Elenco date da mostrare
/// </summary>
private List<DateTime> DateList { get; set; } = new List<DateTime>();
private DateTime MonthEnd { get; set; } = DateTime.Today.AddMonths(1);
private DateTime MonthStart { get; set; } = DateTime.Today;
/// <summary>
/// Righe da disegnare nel calendario
/// </summary>
private List<List<DateTime>> RigheCalendario { get; set; } = new List<List<DateTime>>();
private List<List<DateTime>> WeekRow { get; set; } = new List<List<DateTime>>();
#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;
}
/// <summary>
/// Sistemazione date x disegnare controlli
/// </summary>
/// <returns></returns>
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<DateTime>();
for (int i = 0; i < numDD; i++)
{
DateList.Add(calStart.AddDays(i));
}
// ora sistemo le righe da disegnare...
WeekRow = new List<List<DateTime>>();
for (int i = 0; i < 6; i++)
{
WeekRow.Add(DateList.GetRange(i * 7, 7));
}
}
#endregion Private Methods
}
}
+6
View File
@@ -0,0 +1,6 @@
<div class="row p-3 m-2">
<div class="col-12 text-center mt-5 py-5 alert alert-primary">
<h3>loading data</h3>
<i class="fas fa-spinner fa-spin fa-5x"></i>
</div>
</div>
+6
View File
@@ -0,0 +1,6 @@
<div class="row p-2 m-2">
<div class="col-12 text-center mt-2 py-2 alert alert-primary">
<b>loading data</b>
<i class="fas fa-spinner fa-spin fa-2x"></i>
</div>
</div>
+13
View File
@@ -0,0 +1,13 @@
@page "/TestCal"
<h3>TestCal</h3>
<CalendarMonth DtRif="DateTime.Today" MainCss="table table-dark table-borderless"></CalendarMonth>
<CalendarMonth DtRif="DateTime.Today.AddMonths(2)"></CalendarMonth>
@code {
}
+5
View File
@@ -14,6 +14,11 @@
<span class="oi oi-home" aria-hidden="true"></span> Home
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="TestCal">
<span class="oi oi-list-rich" aria-hidden="true"></span> Test Calendario
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="oi oi-plus" aria-hidden="true"></span> Counter