PDFs erzeugen

This commit is contained in:
MarcWieland
2026-06-26 22:41:23 +02:00
parent 42a97a36b4
commit 4a69095f30
7 changed files with 635 additions and 0 deletions
@@ -0,0 +1,61 @@
@using System.Globalization
@using MudBlazor
<MudDialog>
<DialogContent>
<MudStack Spacing="3" Class="pa-2">
<MudSelect @bind-Value="_selectedYear" Label="Jahr" Variant="Variant.Outlined">
@foreach (var year in _years)
{
<MudSelectItem Value="@year">@year</MudSelectItem>
}
</MudSelect>
<MudSelect @bind-Value="_selectedMonth" Label="Monat" Variant="Variant.Outlined">
@foreach (var month in _months)
{
<MudSelectItem Value="@month.Value">@month.Name</MudSelectItem>
}
</MudSelect>
</MudStack>
</DialogContent>
<DialogActions>
<MudButton OnClick="Cancel">Abbrechen</MudButton>
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="Submit">Herunterladen</MudButton>
</DialogActions>
</MudDialog>
@code {
[CascadingParameter] IMudDialogInstance MudDialog { get; set; } = null!;
private int _selectedYear = DateTime.Today.Year;
private int _selectedMonth = DateTime.Today.Month;
private List<int> _years = Enumerable.Range(DateTime.Today.Year - 5, 6).OrderByDescending(y => y).ToList();
private class MonthOption
{
public int Value { get; set; }
public string Name { get; set; } = "";
}
private List<MonthOption> _months = [];
protected override void OnInitialized()
{
var deCulture = new CultureInfo("de-DE");
_months = Enumerable.Range(1, 12).Select(m => new MonthOption
{
Value = m,
Name = deCulture.DateTimeFormat.GetMonthName(m)
}).ToList();
}
public class MonthSelectorResult
{
public int Year { get; set; }
public int Month { get; set; }
}
void Submit() => MudDialog.Close(DialogResult.Ok(new MonthSelectorResult { Year = _selectedYear, Month = _selectedMonth }));
void Cancel() => MudDialog.Cancel();
}
@@ -9,6 +9,7 @@
@inject IUserNotificationService UserNotificationService
@inject HttpClient Http
@inject IDialogService DialogService
@inject NavigationManager NavigationManager
@implements IDisposable
<PageTitle>Benutzerverwaltung Timetracker</PageTitle>
@@ -131,6 +132,12 @@ else
Size="Size.Small"
OnClick="@(() => OpenResetPasswordDialog(context))" />
</MudTooltip>
<MudTooltip Text="Stundenzettel (PDF) herunterladen">
<MudIconButton Icon="@Icons.Material.Filled.PictureAsPdf"
Color="Color.Info"
Size="Size.Small"
OnClick="@(() => DownloadUserPdf(context))" />
</MudTooltip>
@if (context.Username != "marc")
{
<MudIconButton Icon="@Icons.Material.Filled.DeleteOutline"
@@ -297,4 +304,19 @@ else
}
}
}
private async Task DownloadUserPdf(User user)
{
var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall, FullWidth = true };
var dialog = await DialogService.ShowAsync<MonthSelectorDialog>($"Stundenzettel für {user.Username}", options);
var result = await dialog.Result;
if (result != null && !result.Canceled && result.Data is MonthSelectorDialog.MonthSelectorResult data)
{
int year = data.Year;
int month = data.Month;
NavigationManager.NavigateTo($"api/tracker/export/month/pdf?userId={user.Id}&year={year}&month={month}", forceLoad: true);
}
}
}
@@ -33,6 +33,10 @@ else
</MudText>
</MudStack>
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="0">
<MudTooltip Text="Stundenzettel (PDF) herunterladen">
<MudIconButton Icon="@Icons.Material.Filled.PictureAsPdf"
Style="color: var(--mud-palette-primary-text)" OnClick="ExportMonthPdf" />
</MudTooltip>
<MudTooltip Text="Monat als Excel exportieren">
<MudIconButton Icon="@Icons.Material.Filled.Download"
Style="color: var(--mud-palette-primary-text)" OnClick="ExportMonthExcel" />
@@ -333,6 +337,11 @@ else
NavigationManager.NavigateTo($"api/tracker/export/month?year={_year}&month={_month}", forceLoad: true);
}
private void ExportMonthPdf()
{
NavigationManager.NavigateTo($"api/tracker/export/month/pdf?userId={_userId}&year={_year}&month={_month}", forceLoad: true);
}
private static string FormatTs(TimeSpan ts, bool sign = false)
{
var neg = ts < TimeSpan.Zero;