Files
LehrerApp/LehrerApp.Desktop/Views/Students/StudentDetailView.axaml.cs
T
adminandClaude Sonnet 5 7365947edc feat: PDF-Druck für Sitzplan, Notenliste, Klausur-Notenspiegel, Kompetenzbericht, Dokumentation
QuestPDF als PDF-Bibliothek eingeführt (11.3), bewusst nur in LehrerApp.Desktop referenziert -
zieht SkiaSharp-Native-Binaries mit, die im Server-Docker-Image nichts verloren haben. Neuer
PdfExportService mit gemeinsamem Kopf-/Fußzeilen-Layout (Titel, Stand-Datum, Seitenzahlen) und
schlanken Druck-DTOs statt ViewModels, damit die Erzeugung ohne Avalonia-Bezug testbar bleibt.
Speicherdialog läuft über den bestehenden ExportService (neues PDF-Format).

Fünf Druckvorlagen (11.4) als "Als PDF"-Button direkt in der jeweiligen Ansicht:
- Sitzplan: Raster mit Tafel-Banner, Tischabständen als echte Lücken, ausgeblendeten Plätzen als
  leere Rasterposition.
- Notenliste: druckt exakt die aktuell angezeigte Matrix (Zeitraum/Darstellung/Sortierung).
- Klausur-Notenspiegel: Kennzahlen, Notenverteilung und Aufgabenanalyse mit Balkendiagrammen,
  auffällig schwache Aufgaben rot markiert.
- Kompetenzbericht: Analyse-Tabelle für den ausgewählten Schüler (erledigt zugleich 8.3.3).
- Schülerdokumentation: alle Einträge chronologisch, vertrauliche/Entwurfs-Einträge markiert.

Layout an gerenderten Muster-PDFs visuell geprüft, nicht nur per Unit-Test.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-20 14:27:05 +02:00

157 lines
6.5 KiB
C#

using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
using LehrerApp.Core.Interfaces;
using LehrerApp.Core.Models;
using LehrerApp.Desktop.Services;
using LehrerApp.Desktop.ViewModels.Students;
using LehrerApp.Desktop.Views.Shared;
using Microsoft.Extensions.DependencyInjection;
namespace LehrerApp.Desktop.Views.Students;
public partial class StudentDetailView : UserControl
{
public StudentDetailView() => InitializeComponent();
protected override void OnDataContextChanged(EventArgs e)
{
base.OnDataContextChanged(e);
if (DataContext is not StudentDetailViewModel vm) return;
vm.OnEditContact = ShowContactDialog;
vm.OnViewAddress = ShowAddressViewer;
vm.OnEditDocumentation = ShowDocumentationDialog;
vm.OnConfirmDeleteDocumentation = ShowDeleteDocumentationDialog;
vm.OnSaveExportFile = SaveExportFile;
vm.OnConductParentCall = ShowParentCallSessionDialog;
vm.OnManageStudent = ShowManageStudentDialog;
vm.OnCreateLetter = ShowCreateLetterDialog;
}
private async Task<Contact?> ShowContactDialog(Contact? contact)
{
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner is null) return null;
var vm = new ContactEditDialogViewModel(contact);
var dialog = new ContactEditDialog { DataContext = vm };
var saved = await dialog.ShowDialog<bool>(owner);
return saved ? vm.Result : null;
}
private async Task<StudentManagementResult> ShowManageStudentDialog(Student student)
{
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner is null) return StudentManagementResult.Cancelled;
var vm = new ManageStudentDialogViewModel(
App.Services.GetRequiredService<IStudentRepository>(), student);
var dialog = new ManageStudentDialog { DataContext = vm };
return await dialog.ShowDialog<StudentManagementResult>(owner);
}
private async Task ShowCreateLetterDialog()
{
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner is null || DataContext is not StudentDetailViewModel { Student: { } student }) return;
var vm = new CreateLetterDialogViewModel(student,
App.Services.GetRequiredService<LehrerApp.Core.Services.LetterTemplateService>(),
App.Services.GetRequiredService<IGroupMembershipRepository>(),
App.Services.GetRequiredService<IGroupRepository>());
var dialog = new CreateLetterDialog { DataContext = vm };
var path = await dialog.ShowDialog<string?>(owner);
if (!string.IsNullOrEmpty(path) && File.Exists(path))
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(path) { UseShellExecute = true });
}
private void ShowAddressViewer(ContactItem contact)
{
if (!contact.HasAddress) return;
var owner = TopLevel.GetTopLevel(this) as Window;
var viewer = new AddressViewerWindow { DataContext = contact };
if (owner is not null)
viewer.Show(owner);
else
viewer.Show();
}
private void OnContactDoubleTapped(object? sender, TappedEventArgs e)
{
if (DataContext is StudentDetailViewModel vm &&
vm.ViewSelectedAddressCommand.CanExecute(null))
vm.ViewSelectedAddressCommand.Execute(null);
}
private async Task<Documentation?> ShowDocumentationDialog(Guid studentId, Documentation? editing)
{
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner is null) return null;
var vm = new DocumentationDialogViewModel(studentId, editing,
App.Services.GetRequiredService<IAttachmentStorage>());
var dialog = new DocumentationDialog { DataContext = vm };
var saved = await dialog.ShowDialog<bool>(owner);
if (!saved) vm.DiscardUnsavedAttachments();
return saved ? vm.Result : null;
}
private async Task<Documentation?> ShowParentCallSessionDialog(Documentation documentation, string studentTitle)
{
var owner = TopLevel.GetTopLevel(this) as Window;
if (owner is null) return null;
var vm = new ParentCallSessionViewModel(documentation, studentTitle);
var dialog = new ParentCallSessionDialog { DataContext = vm };
var saved = await dialog.ShowDialog<bool>(owner);
return saved ? vm.Result : null;
}
private async Task<bool> ShowDeleteDocumentationDialog(DocumentationItem item)
{
var info = new ConfirmDialogInfo
{
Title = "Eintrag löschen?",
Message = $"\"{item.Model.Title}\" wird als gelöscht markiert und nicht mehr angezeigt.",
ConfirmText = "Löschen",
};
var dialog = new ConfirmDialog { DataContext = info };
var owner = TopLevel.GetTopLevel(this) as Window;
return owner is not null && await dialog.ShowDialog<bool>(owner);
}
private async void OnExportDocumentationPdfClick(object? sender, RoutedEventArgs e)
{
var topLevel = TopLevel.GetTopLevel(this);
if (topLevel is null || DataContext is not StudentDetailViewModel { Student: not null } vm
|| vm.Documentation.Count == 0) return;
var data = new StudentDocumentationPrintData(vm.Student.FullName,
vm.Documentation.Select(d => new DocumentationPrintEntry(
d.DateDisplay, d.TypeLabel, d.Model.Title, d.Model.Content,
d.Model.Tags, d.IsConfidential, d.IsDraft)).ToList());
var pdf = App.Services.GetRequiredService<PdfExportService>().BuildStudentDocumentationPdf(data);
await App.Services.GetRequiredService<ExportService>().SaveAsync(topLevel.StorageProvider,
ExportFile.Pdf("Dokumentation als PDF speichern",
$"Dokumentation_{vm.Student.LastName}_{vm.Student.FirstName}", pdf));
}
private async Task SaveExportFile(string json)
{
var topLevel = TopLevel.GetTopLevel(this);
if (topLevel is null || DataContext is not StudentDetailViewModel vm || vm.Student is null) return;
var file = await topLevel.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
{
Title = "Datenauskunft exportieren",
SuggestedFileName = $"Datenauskunft_{vm.Student.LastName}_{vm.Student.FirstName}.json",
FileTypeChoices = [new FilePickerFileType("JSON-Dateien") { Patterns = ["*.json"] }],
});
if (file is null) return;
await File.WriteAllTextAsync(file.Path.LocalPath, json);
}
}