feat: Implement sidebar toggle functionality and enhance Monthly Timesheet summary view

This commit is contained in:
Marco 2026-04-20 17:23:54 +02:00
commit a7f8dfba01
13 changed files with 686 additions and 58 deletions

View file

@ -81,7 +81,7 @@ else
@if (IsActiveCell(cell.Date))
{
<div class="calendar-popup" @onclick:stopPropagation="true">
<div class="calendar-popup @GetPopupClass(cell)" @onclick:stopPropagation="true">
<div class="d-flex align-items-start justify-content-between gap-2 mb-2">
<div>
<div class="fw-semibold">@cell.Date.ToString("dddd d MMMM")</div>
@ -241,6 +241,7 @@ else
currentWeek[dayOfWeek] = new CalendarCell
{
Date = d,
ColumnIndex = dayOfWeek,
IsWeekend = d.DayOfWeek is DayOfWeek.Saturday or DayOfWeek.Sunday,
IsFestivity = festivities.Contains(d),
Entry = lookup.GetValueOrDefault(d)
@ -293,6 +294,16 @@ else
activeDate = null;
}
private static string GetPopupClass(CalendarCell cell)
{
if (cell.ColumnIndex == 0)
{
return "calendar-popup-left";
}
return cell.ColumnIndex >= 5 ? "calendar-popup-right" : string.Empty;
}
private bool IsActiveCell(DateOnly date) => activeDate == date;
private void CreateWorkUnit(DateOnly date)
@ -437,6 +448,7 @@ else
private sealed class CalendarCell
{
public DateOnly Date { get; set; }
public int ColumnIndex { get; set; }
public bool IsWeekend { get; set; }
public bool IsFestivity { get; set; }
public WorkDayDocument? Entry { get; set; }

View file

@ -3,7 +3,8 @@
@attribute [Authorize]
@rendermode InteractiveServer
@inject IWorkDayService WorkDayService
@using System.Globalization
@inject global::WorkTracker.Services.WorkDays.IWorkDayService WorkDayService
<PageTitle>Monthly Summary</PageTitle>
@ -20,11 +21,16 @@
<label class="form-check-label" for="include-preview">Include preview work units in totals</label>
</div>
<div class="btn-group mb-3" role="group" aria-label="Summary view selector">
<button type="button" class="btn @(viewMode == SummaryViewMode.Cards ? "btn-primary" : "btn-outline-primary")" @onclick="() => SetViewMode(SummaryViewMode.Cards)">Cards</button>
<button type="button" class="btn @(viewMode == SummaryViewMode.Timesheet ? "btn-primary" : "btn-outline-primary")" @onclick="() => SetViewMode(SummaryViewMode.Timesheet)">Timesheet</button>
</div>
@if (loading)
{
<p><em>Loading...</em></p>
}
else if (summary is not null)
else if (viewMode == SummaryViewMode.Cards && summary is not null)
{
<div class="row g-3">
<div class="col-6 col-md-4 col-xl-3">
@ -141,14 +147,75 @@ else if (summary is not null)
</div>
</div>
}
else if (viewMode == SummaryViewMode.Timesheet && timesheet is not null)
{
<div class="timesheet-summary-card card border-0 shadow-sm">
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-bordered table-sm align-middle mb-0 timesheet-summary-table">
<thead>
<tr>
<th class="timesheet-summary-sticky-column">Categoria</th>
@for (var i = 0; i < timesheet.Days.Count; i++)
{
var day = timesheet.Days[i];
<th class="text-center timesheet-summary-day-header @GetDayColumnClass(day) @GetDayPopupClass(i, timesheet.Days.Count)">
<div>@day.Date.Day</div>
<div class="small text-muted">@GetDayHeader(day.Date)</div>
<div class="timesheet-summary-day-popup">
<div class="fw-semibold mb-2">@day.Date.ToString("dddd d MMMM", ItalianCulture)</div>
@if (day.WorkUnitSummaries.Count == 0 && day.EventSummaries.Count == 0)
{
<div class="small text-muted">Nessun elemento registrato.</div>
}
else
{
@foreach (var workUnit in day.WorkUnitSummaries)
{
<div class="timesheet-summary-day-popup-item">@workUnit</div>
}
@foreach (var calendarEvent in day.EventSummaries)
{
<div class="timesheet-summary-day-popup-item timesheet-summary-day-popup-item-event">@calendarEvent</div>
}
}
</div>
</th>
}
<th class="text-center timesheet-summary-total-column">Totale</th>
</tr>
</thead>
<tbody>
@foreach (var row in timesheet.Rows)
{
<tr>
<th scope="row" class="timesheet-summary-sticky-column">@row.Label</th>
@for (var i = 0; i < row.DailyValues.Count; i++)
{
<td class="text-center @GetDayColumnClass(timesheet.Days[i])">@FormatTimesheetValue(row.DailyValues[i], row.ValueFormat)</td>
}
<td class="text-center fw-semibold timesheet-summary-total-column">@FormatTimesheetValue(row.Total, row.ValueFormat)</td>
</tr>
}
</tbody>
</table>
</div>
</div>
</div>
}
@code {
[Parameter] public string? YearMonth { get; set; }
private static readonly CultureInfo ItalianCulture = CultureInfo.GetCultureInfo("it-IT");
private DateOnly currentMonth;
private bool loading = true;
private bool includePreview;
private MonthlySummaryModel? summary;
private global::WorkTracker.Domain.MonthlySummaryModel? summary;
private global::WorkTracker.Domain.MonthlyTimesheetModel? timesheet;
private SummaryViewMode viewMode = SummaryViewMode.Timesheet;
protected override async Task OnInitializedAsync()
{
@ -174,6 +241,7 @@ else if (summary is not null)
{
loading = true;
summary = await WorkDayService.GetMonthlySummaryAsync(currentMonth.Year, currentMonth.Month, includePreview);
timesheet = await WorkDayService.GetMonthlyTimesheetAsync(currentMonth.Year, currentMonth.Month, includePreview);
loading = false;
}
@ -189,6 +257,53 @@ else if (summary is not null)
await LoadSummary();
}
private void SetViewMode(SummaryViewMode mode)
{
viewMode = mode;
}
private static string GetDayHeader(DateOnly date)
{
return ItalianCulture.TextInfo.ToTitleCase(date.ToString("ddd", ItalianCulture));
}
private static string GetDayColumnClass(global::WorkTracker.Domain.MonthlyTimesheetDayModel day)
{
if (day.IsWeekend || day.IsHoliday)
{
return "timesheet-summary-day-danger";
}
return day.IsClosure ? "timesheet-summary-day-closure" : string.Empty;
}
private static string GetDayPopupClass(int index, int totalDays)
{
if (index == 0)
{
return "timesheet-summary-day-popup-left";
}
return index >= totalDays - 2 ? "timesheet-summary-day-popup-right" : string.Empty;
}
private static string FormatTimesheetValue(decimal? value, global::WorkTracker.Domain.MonthlyTimesheetValueFormat valueFormat)
{
if (!value.HasValue || value.Value <= 0m)
{
return string.Empty;
}
return valueFormat == global::WorkTracker.Domain.MonthlyTimesheetValueFormat.Days
? value.Value.ToString("0.##", ItalianCulture)
: FormatDecimalHours(value.Value);
}
private static string FormatDecimalHours(decimal value)
{
return value.ToString("0.##", ItalianCulture);
}
private static string FormatHours(decimal value)
{
var totalMinutes = (int)Math.Round(value * 60m, MidpointRounding.AwayFromZero);
@ -196,4 +311,10 @@ else if (summary is not null)
var minutes = totalMinutes % 60;
return $"{hours:00}:{minutes:00}";
}
private enum SummaryViewMode
{
Cards,
Timesheet
}
}