Schülerberichte und erweiterte Deckblatt-Bausteine ergänzen
CI / build-and-test (push) Canceled after 0s
CI / build-and-test (push) Canceled after 0s
This commit is contained in:
1 parent
336869e75f
commit
e2f019667a
31 files changed
+961
-14
No files matched your search
@@ -238,6 +238,7 @@ public static class AppBootstrapper
|
||||
services.AddSingleton<GroupMembershipTools>();
|
||||
services.AddSingleton<LetterTemplateTools>();
|
||||
services.AddSingleton<StudentAttendanceCalendarService>();
|
||||
services.AddSingleton<StudentReportService>();
|
||||
services.AddSingleton<CompetencyTools>();
|
||||
services.AddSingleton<GroupTools>();
|
||||
services.AddSingleton<ParticipationTools>();
|
||||
|
||||
@@ -27,7 +27,8 @@ public static class ExamCoverPlaceholderBuilder
|
||||
public static Dictionary<string, PlaceholderValue> Build(Exam exam, LearningGroup group, string subjectName,
|
||||
Student student, ExamResult? result, bool fillResults, GradingService grading, LoadedTemplate template,
|
||||
DateOnly today, Niveau? studentNiveau = null, string teacherAbbreviation = "",
|
||||
string? title = null)
|
||||
string? title = null, Exam? original = null, ExamResult? originalResult = null,
|
||||
InterimGrade? interim = null)
|
||||
{
|
||||
var tasks = exam.Tasks.OrderBy(t => t.Nr).ToList();
|
||||
var variant = result?.Variant ?? ExamVariant.A;
|
||||
@@ -62,6 +63,10 @@ public static class ExamCoverPlaceholderBuilder
|
||||
ExamCoverSheetService.Columns(tasks, variant, filled ? result!.Points : null),
|
||||
box.Width, box.MillimeterScale)
|
||||
: new DrawingValue([], 0);
|
||||
values[ReportTextDrawing.RepeatInfo] = DrawingBoxLocator.Find(template, ReportTextDrawing.RepeatInfo) is null
|
||||
? new DrawingValue([], 0) : GradeReportDrawingBuilder.Repeat(exam, original, originalResult, template);
|
||||
values[ReportTextDrawing.InterimGrades] = interim is null
|
||||
? new DrawingValue([], 0) : GradeReportDrawingBuilder.Interim(interim, template);
|
||||
return values;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,9 @@ public static class ExamCoverSheetDialogs
|
||||
App.Services.GetRequiredService<GradingService>(),
|
||||
[App.Services.GetRequiredService<TemplateStore>(), App.Services.GetRequiredService<WorksheetTemplateStore>().Store],
|
||||
App.Services.GetRequiredService<ITemplateBatchRenderer>(),
|
||||
App.Services.GetRequiredService<TeacherSettingsService>().LoadAbbreviation());
|
||||
App.Services.GetRequiredService<TeacherSettingsService>().LoadAbbreviation(),
|
||||
App.Services.GetRequiredService<IExamRepository>(),
|
||||
App.Services.GetRequiredService<IInterimGradeRepository>());
|
||||
await new ExamCoverSheetDialog { DataContext = vm }.ShowDialog(owner);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using LehrerApp.Core.Models;
|
||||
using LehrerApp.Core.Services;
|
||||
using LehrerApp.Templating;
|
||||
|
||||
namespace LehrerApp.Desktop.Services;
|
||||
|
||||
public static class GradeReportDrawingBuilder
|
||||
{
|
||||
public static DrawingValue Interim(InterimGrade grade, LoadedTemplate template) =>
|
||||
Text(template, ReportTextDrawing.InterimGrades, "Vorläufiger Notenzwischenstand",
|
||||
[
|
||||
$"Stichtag: {grade.Date:dd.MM.yyyy} · {grade.Occasion}",
|
||||
$"Mündlich: {Value(grade.OralValue)}",
|
||||
$"Schriftlich: {Value(grade.WrittenValue)}",
|
||||
$"Vorläufige Zeugnisnote: {Value(grade.OverallValue)}",
|
||||
"Dieser Zwischenstand ist keine festgeschriebene Zeugnisnote.",
|
||||
]);
|
||||
|
||||
public static DrawingValue Repeat(Exam exam, Exam? original, ExamResult? originalResult,
|
||||
LoadedTemplate template)
|
||||
{
|
||||
if (exam.RepeatOfExamId is null) return new DrawingValue([], 0);
|
||||
if (original is null || original.Id != exam.RepeatOfExamId || original.GroupId != exam.GroupId)
|
||||
throw new InvalidDataException("Die verknüpfte erste Arbeit ist nicht verfügbar.");
|
||||
var rule = exam.IsMakeUp ? "Die Nachschreibarbeit ersetzt die versäumte erste Arbeit. Liegen beide Noten vor, zählt die erste Arbeit."
|
||||
: exam.RepeatGradeRule switch
|
||||
{
|
||||
RepeatGradeRule.Repeat => "Für die Bewertung zählt die Note der Wiederholungsarbeit.",
|
||||
RepeatGradeRule.Original => "Für die Bewertung zählt die Note der ersten Arbeit.",
|
||||
_ => "Für die Bewertung zählt die bessere Note aus beiden Arbeiten.",
|
||||
};
|
||||
var grade = originalResult?.Grade;
|
||||
if (string.IsNullOrWhiteSpace(grade) && ExamCoverSheetService.IsCorrected(originalResult))
|
||||
grade = new GradingService().CalculateGrade(originalResult!.TotalPoints,
|
||||
ExamScoringService.Maximum(original.Tasks, originalResult.Variant), original.GradingKey);
|
||||
var firstGrade = originalResult is { Absent: true } ? "abwesend" : Value(grade);
|
||||
return Text(template, ReportTextDrawing.RepeatInfo,
|
||||
exam.IsMakeUp ? "Nachschreibarbeit" : "Wiederholungsarbeit",
|
||||
[$"Erste Arbeit: {original.Title} vom {original.Date:dd.MM.yyyy}",
|
||||
$"Note der ersten Arbeit: {firstGrade}", rule]);
|
||||
}
|
||||
|
||||
public static DrawingValue Text(LoadedTemplate template, string name, string title, IEnumerable<string> paragraphs)
|
||||
{
|
||||
if (DrawingBoxLocator.Find(template, name) is not { } box) return new DrawingValue([], 0);
|
||||
return ReportTextDrawing.Build(title, paragraphs, box.Width, box.MillimeterScale, box.Height, box.IsFixed);
|
||||
}
|
||||
|
||||
private static string Value(string? value) => string.IsNullOrWhiteSpace(value) ? "nicht erfasst" : value;
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public class LetterTemplateTools(
|
||||
public List<LetterTemplateDto> ListLetterTemplates()
|
||||
{
|
||||
var result = new List<LetterTemplateDto>();
|
||||
foreach (var installed in templates.GetTemplates().Where(x => !x.IsExamCover))
|
||||
foreach (var installed in templates.GetTemplates().Where(x => !x.IsExamCover && !x.IsStudentReport))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
using LehrerApp.Core.Interfaces;
|
||||
using LehrerApp.Core.Models;
|
||||
using LehrerApp.Core.Services;
|
||||
using LehrerApp.Desktop.ViewModels.Groups;
|
||||
using LehrerApp.Desktop.ViewModels.Students;
|
||||
using LehrerApp.Templating;
|
||||
|
||||
namespace LehrerApp.Desktop.Services;
|
||||
|
||||
public sealed record StudentReportOptions(DateOnly From, DateOnly To, InterimGrade? Interim,
|
||||
bool IncludeInterim = true, bool IncludeParticipation = true, bool IncludeCompetencies = true,
|
||||
bool IncludeHomework = true, bool IncludeDocumentation = true, bool IncludeConfidential = false,
|
||||
string Comment = "");
|
||||
|
||||
/// <summary>Stellt die vorhandenen Bewertungen eines Schülers für eine Lerngruppe zusammen.
|
||||
/// Die Berechnungen stammen aus denselben Diensten wie die interaktiven Auswertungen.</summary>
|
||||
public sealed class StudentReportService(
|
||||
IParticipationSessionRepository sessions, IParticipationRepository entries,
|
||||
IParticipationAspectRepository aspects, IExamRepository exams, IExamResultRepository results,
|
||||
IGradeRepository grades, IGroupMembershipRepository memberships,
|
||||
ICompetencyDomainRepository domains, IDocumentationRepository documentation,
|
||||
GradingService grading, CompetencyAnalysisService competencies)
|
||||
{
|
||||
public Dictionary<string, PlaceholderValue> Build(Student student, LearningGroup group,
|
||||
LoadedTemplate template, StudentReportOptions options)
|
||||
{
|
||||
if (options.From > options.To) throw new InvalidDataException("Das Ende des Berichtszeitraums liegt vor dem Beginn.");
|
||||
var values = LetterPlaceholderBuilder.BuildStandardValues(student, null, group, DateOnly.FromDateTime(DateTime.Today), "", "");
|
||||
values["Report.Period"] = new TextValue($"{options.From:dd.MM.yyyy} - {options.To:dd.MM.yyyy}");
|
||||
values["Report.Comment"] = new MultilineValue(options.Comment);
|
||||
foreach (var name in StudentReportTemplate.Drawings) values[name] = new DrawingValue([], 0);
|
||||
if (options.IncludeInterim && Uses(ReportTextDrawing.InterimGrades))
|
||||
{
|
||||
var interim = options.Interim;
|
||||
if (interim is null || interim.StudentId != student.Id || interim.GroupId != group.Id
|
||||
|| interim.Date < options.From || interim.Date > options.To)
|
||||
throw new InvalidDataException("Bitte einen gespeicherten Zwischenstand dieses Schülers im Berichtszeitraum auswählen oder den Baustein abwählen.");
|
||||
values[ReportTextDrawing.InterimGrades] = GradeReportDrawingBuilder.Interim(interim, template);
|
||||
}
|
||||
|
||||
var membership = memberships.GetByStudentAndGroup(student.Id, group.Id);
|
||||
bool Within(DateOnly date) => date >= options.From && date <= options.To
|
||||
&& (membership is null || GroupMembershipService.IsActiveOn(membership, date));
|
||||
var groupSessions = sessions.GetByGroup(group.Id).Where(s => Within(s.Date)).OrderBy(s => s.Date).ToList();
|
||||
var bySession = groupSessions.ToDictionary(s => s.Id);
|
||||
var studentEntries = entries.GetByStudent(student.Id).Where(e => bySession.ContainsKey(e.SessionId)).ToList();
|
||||
var applicableAspects = aspects.GetDefaults().Concat(aspects.GetByGroup(group.Id))
|
||||
.GroupBy(a => a.Key).Select(g => g.Last()).ToList();
|
||||
|
||||
if (options.IncludeParticipation && Uses(StudentReportTemplate.Participation))
|
||||
{
|
||||
var timeline = new ParticipationTimelineBuilder(sessions, entries, aspects, exams, results, grades,
|
||||
membership is null ? new Dictionary<Guid, GroupMembership>() : new() { [student.Id] = membership },
|
||||
grading, group.Id, group.GradingSystem);
|
||||
var points = timeline.BuildPoints(student.Id).Where(p => !p.IsExam && Within(p.Date)).ToList();
|
||||
List<ReportChartSeries> series = [new("Gewichtete Mitarbeit", "#6C5CE7",
|
||||
points.Where(p => p.WeightedValue.HasValue).Select(p => new ReportChartPoint(p.Date, p.WeightedValue!.Value)).ToList())];
|
||||
string[] colors = ["#2E86DE", "#E67E22", "#16A085", "#C0392B"];
|
||||
foreach (var (aspect, index) in applicableAspects.Select((a, i) => (a, i)))
|
||||
series.Add(new(aspect.Label, colors[index % colors.Length],
|
||||
points.Where(p => p.AspectValues.ContainsKey(aspect.Key)).Select(p => new ReportChartPoint(p.Date,
|
||||
ParticipationRatingScale.Normalize(aspect.ValueType, p.AspectValues[aspect.Key], aspect.MaxPoints))).ToList()));
|
||||
var box = DrawingBoxLocator.Find(template, StudentReportTemplate.Participation)!.Value;
|
||||
var drawing = ParticipationReportDrawing.Build(series, options.From, options.To, box.Width, box.MillimeterScale);
|
||||
if (drawing.ContentHeight > box.Height)
|
||||
throw new InvalidDataException("Der Mitarbeitsgraph benötigt eine höhere Zeichenbox in der Vorlage.");
|
||||
values[StudentReportTemplate.Participation] = drawing;
|
||||
}
|
||||
if (options.IncludeCompetencies && Uses(StudentReportTemplate.Competencies))
|
||||
{
|
||||
var groupExams = exams.GetByGroup(group.Id).Where(e => Within(e.Date)).ToList();
|
||||
var examIds = groupExams.Select(e => e.Id).ToHashSet();
|
||||
var scores = competencies.Analyze(domains.GetAll(), [], groupExams,
|
||||
results.GetByStudent(student.Id).Where(r => examIds.Contains(r.ExamId)).ToList(),
|
||||
groupSessions, studentEntries, applicableAspects);
|
||||
var lines = scores.Where(s => s.StudentScores.ContainsKey(student.Id)).Select(s =>
|
||||
{
|
||||
var score = s.StudentScores[student.Id];
|
||||
return $"{s.Code} {s.Description}: {score.Percent.ToString("0", System.Globalization.CultureInfo.GetCultureInfo("de-DE"))} % ({score.EvidenceCount} Bewertungen)";
|
||||
}).ToList();
|
||||
Add(StudentReportTemplate.Competencies, "Kompetenzen", lines, "Keine Kompetenzbewertungen im gewählten Zeitraum.");
|
||||
}
|
||||
if (options.IncludeHomework && Uses(StudentReportTemplate.Homework))
|
||||
Add(StudentReportTemplate.Homework, "Hausaufgaben", studentEntries.Where(e => HomeworkDisplay.Effective(e) is not null)
|
||||
.OrderBy(e => bySession[e.SessionId].Date).Select(e =>
|
||||
$"{bySession[e.SessionId].Date:dd.MM.yyyy}: {HomeworkDisplay.Label(HomeworkDisplay.Effective(e))}").ToList(),
|
||||
"Keine Hausaufgabenkontrollen im gewählten Zeitraum.");
|
||||
if (options.IncludeDocumentation && Uses(StudentReportTemplate.Documentation))
|
||||
{
|
||||
var lines = documentation.GetByStudent(student.Id)
|
||||
.Where(d => !d.IsDeleted && !d.IsDraft && (options.IncludeConfidential || !d.IsConfidential)
|
||||
&& d.GroupId == group.Id && Within(d.Date) && d.Concerns(student.Id))
|
||||
.OrderBy(d => d.Date).Select(d =>
|
||||
$"{d.Date:dd.MM.yyyy} · {DocumentationTypeDisplay.Label(d.Type)}: {d.Title}"
|
||||
+ (d.IsConfidential ? " [Vertraulich]" : "") + "\n" + d.Content).ToList();
|
||||
lines.AddRange(studentEntries.Where(e => !string.IsNullOrWhiteSpace(e.Note)).OrderBy(e => bySession[e.SessionId].Date)
|
||||
.Select(e => $"{bySession[e.SessionId].Date:dd.MM.yyyy} · Unterrichtsnotiz: {e.Note}"));
|
||||
Add(StudentReportTemplate.Documentation, "Klassenbucheinträge und Unterrichtsnotizen", lines,
|
||||
"Keine freigegebenen Einträge mit Bezug zu dieser Lerngruppe im gewählten Zeitraum.");
|
||||
}
|
||||
return values;
|
||||
|
||||
bool Uses(string name) => DrawingBoxLocator.Find(template, name) is not null;
|
||||
void Add(string name, string title, List<string> lines, string empty) =>
|
||||
values[name] = GradeReportDrawingBuilder.Text(template, name, title, lines.Count > 0 ? lines : [empty]);
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,17 @@ public partial class ExamCoverSheetDialogViewModel : ObservableObject
|
||||
private readonly GradingService _grading;
|
||||
private readonly TemplateStore _loader;
|
||||
private readonly ITemplateBatchRenderer _renderer;
|
||||
private readonly Exam? _original;
|
||||
private readonly Dictionary<Guid, ExamResult> _originalResults;
|
||||
[ObservableProperty] private ReportInterimRunChoice? _selectedInterimRun;
|
||||
[ObservableProperty] private bool _usesInterimGrades;
|
||||
public ObservableCollection<ReportInterimRunChoice> InterimRuns { get; } = [];
|
||||
|
||||
partial void OnSelectedTemplateChanged(LetterTemplateChoice? value)
|
||||
{
|
||||
UsesInterimGrades = value is not null &&
|
||||
DrawingBoxLocator.Find(_loader.Load(value.Model), ReportTextDrawing.InterimGrades) is not null;
|
||||
}
|
||||
|
||||
[ObservableProperty] private LetterTemplateChoice? _selectedTemplate;
|
||||
[ObservableProperty] private bool _fillResults;
|
||||
@@ -50,12 +61,19 @@ public partial class ExamCoverSheetDialogViewModel : ObservableObject
|
||||
public ExamCoverSheetDialogViewModel(Exam exam, LearningGroup group, string subjectName,
|
||||
IStudentRepository students, IGroupMembershipRepository memberships, IExamResultRepository results,
|
||||
GradingService grading, IReadOnlyList<TemplateStore> templateStores, ITemplateBatchRenderer renderer,
|
||||
string teacherAbbreviation = "")
|
||||
string teacherAbbreviation = "", IExamRepository? exams = null, IInterimGradeRepository? interims = null)
|
||||
{
|
||||
_teacherAbbreviation = teacherAbbreviation;
|
||||
_coverTitle = exam.Title;
|
||||
_exam = exam; _group = group; _subjectName = subjectName; _grading = grading; _renderer = renderer;
|
||||
_loader = templateStores[0];
|
||||
_original = exam.RepeatOfExamId is { } originalId ? exams?.GetById(originalId) : null;
|
||||
_originalResults = exam.RepeatOfExamId is { } firstId
|
||||
? results.GetByExam(firstId).ToDictionary(r => r.StudentId) : [];
|
||||
foreach (var run in (interims?.GetByGroup(group.Id) ?? [])
|
||||
.GroupBy(g => (g.Date, g.Occasion)).OrderByDescending(g => g.Key.Date).ThenBy(g => g.Key.Occasion))
|
||||
InterimRuns.Add(new(run.Key.Date, run.Key.Occasion, run.ToList()));
|
||||
// Bewusste Auswahl statt stillschweigend den neuesten Zwischenstand zu drucken.
|
||||
foreach (var template in templateStores.SelectMany(x => x.GetTemplates()).Where(x => x.IsExamCover)
|
||||
.DistinctBy(x => x.Id).OrderBy(x => x.Name, StringComparer.CurrentCultureIgnoreCase))
|
||||
Templates.Add(new(template));
|
||||
@@ -87,10 +105,20 @@ public partial class ExamCoverSheetDialogViewModel : ObservableObject
|
||||
try
|
||||
{
|
||||
var loaded = _loader.Load(SelectedTemplate.Model);
|
||||
if (UsesInterimGrades && SelectedInterimRun is null)
|
||||
{ StatusMessage = "Bitte einen gespeicherten Notenzwischenstand auswählen."; return false; }
|
||||
if (UsesInterimGrades)
|
||||
{
|
||||
var missing = included.Where(s => !SelectedInterimRun!.Grades.Any(g => g.StudentId == s.Model.Id)).ToList();
|
||||
if (missing.Count > 0)
|
||||
{ StatusMessage = "Im gewählten Zwischenstand fehlen: " + string.Join(", ", missing.Select(s => s.FullName)) + ". Bitte Schüler abwählen oder einen anderen Durchgang wählen."; return false; }
|
||||
}
|
||||
var today = DateOnly.FromDateTime(DateTime.Now);
|
||||
var data = included.Select(s => (ITemplateDataProvider)new LetterDataProvider(
|
||||
ExamCoverPlaceholderBuilder.Build(_exam, _group, _subjectName, s.Model, s.Result, FillResults,
|
||||
_grading, loaded, today, s.Niveau, TeacherAbbreviation, CoverTitle))).ToList();
|
||||
_grading, loaded, today, s.Niveau, TeacherAbbreviation, CoverTitle,
|
||||
_original, _originalResults.GetValueOrDefault(s.Model.Id),
|
||||
UsesInterimGrades ? SelectedInterimRun!.Grades.Single(g => g.StudentId == s.Model.Id) : null))).ToList();
|
||||
ReportProgress(0, included.Count);
|
||||
IsGenerating = true;
|
||||
var progress = new Progress<int>(done => ReportProgress(done, included.Count));
|
||||
@@ -110,7 +138,7 @@ public partial class ExamCoverSheetDialogViewModel : ObservableObject
|
||||
StatusMessage = message;
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or InvalidDataException or UnauthorizedAccessException or TemplateValidationException)
|
||||
catch (Exception ex) when (ex is IOException or InvalidDataException or UnauthorizedAccessException or TemplateValidationException or QuestPDF.Drawing.Exceptions.DocumentLayoutException)
|
||||
{ StatusMessage = $"Deckblätter konnten nicht erzeugt werden: {ex.Message}"; return false; }
|
||||
finally { IsGenerating = false; }
|
||||
}
|
||||
@@ -146,3 +174,8 @@ public partial class ExamCoverStudentChoice : ObservableObject
|
||||
_isIncluded = result is not { Absent: true };
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record ReportInterimRunChoice(DateOnly Date, string Occasion, IReadOnlyList<InterimGrade> Grades)
|
||||
{
|
||||
public string Label => $"{Date:dd.MM.yyyy} · {Occasion}";
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public partial class PersonalizeWorksheetDialogViewModel : ObservableObject
|
||||
IStudentRepository students, WorksheetTemplateStore templates, ITemplateRenderer renderer)
|
||||
{
|
||||
_group = group; _templates = templates; _renderer = renderer;
|
||||
foreach (var template in templates.Store.GetTemplates().Where(x => !x.IsExamCover)) Templates.Add(new(template));
|
||||
foreach (var template in templates.Store.GetTemplates().Where(x => !x.IsExamCover && !x.IsStudentReport)) Templates.Add(new(template));
|
||||
SelectedTemplate = Templates.FirstOrDefault();
|
||||
foreach (var id in studentIds)
|
||||
if (students.GetById(id) is { } student) Students.Add(new(student));
|
||||
|
||||
@@ -60,7 +60,7 @@ public partial class CreateLetterDialogViewModel : ObservableObject
|
||||
_attendanceCalendarFactory = attendanceCalendarFactory;
|
||||
_absenceDayListFactory = absenceDayListFactory;
|
||||
_attendanceDataRefresher = attendanceDataRefresher;
|
||||
foreach (var template in templates.GetTemplates().Where(x => !x.IsExamCover)) Templates.Add(new(template));
|
||||
foreach (var template in templates.GetTemplates().Where(x => !x.IsExamCover && !x.IsStudentReport)) Templates.Add(new(template));
|
||||
foreach (var contact in student.Contacts.Where(c => !c.InvalidSince.HasValue).OrderBy(c => c.Name)) Contacts.Add(new(contact));
|
||||
foreach (var membership in memberships.GetByStudent(student.Id))
|
||||
if (groups.GetById(membership.GroupId) is { } group) Groups.Add(new(group));
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using LehrerApp.Core.Interfaces;
|
||||
using LehrerApp.Core.Models;
|
||||
using LehrerApp.Core.Services;
|
||||
using LehrerApp.Desktop.Services;
|
||||
using LehrerApp.Templating;
|
||||
|
||||
namespace LehrerApp.Desktop.ViewModels.Students;
|
||||
|
||||
public partial class StudentReportDialogViewModel : ObservableObject
|
||||
{
|
||||
private readonly Student _student;
|
||||
private readonly StudentReportService _reports;
|
||||
private readonly ITemplateRenderer _renderer;
|
||||
private readonly IInterimGradeRepository _interims;
|
||||
private readonly SchoolYearService _schoolYears;
|
||||
private readonly TemplateStore _loader;
|
||||
public string StudentName => _student.FullName;
|
||||
public string SuggestedFileName => string.Concat($"Schülerbericht_{_student.LastName}_{_student.FirstName}.pdf"
|
||||
.Select(c => Path.GetInvalidFileNameChars().Contains(c) ? '_' : c));
|
||||
public ObservableCollection<LetterGroupChoice> Groups { get; } = [];
|
||||
public ObservableCollection<StudentReportTemplateChoice> Templates { get; } = [];
|
||||
public ObservableCollection<StudentReportInterimChoice> Interims { get; } = [];
|
||||
[ObservableProperty] private LetterGroupChoice? _selectedGroup;
|
||||
[ObservableProperty] private StudentReportTemplateChoice? _selectedTemplate;
|
||||
[ObservableProperty] private StudentReportInterimChoice? _selectedInterim;
|
||||
[ObservableProperty] private string _from = "";
|
||||
[ObservableProperty] private string _to = DateTime.Today.ToString("dd.MM.yyyy");
|
||||
[ObservableProperty] private bool _includeInterim = true;
|
||||
[ObservableProperty] private bool _includeParticipation = true;
|
||||
[ObservableProperty] private bool _includeCompetencies = true;
|
||||
[ObservableProperty] private bool _includeHomework = true;
|
||||
[ObservableProperty] private bool _includeDocumentation = true;
|
||||
[ObservableProperty] private bool _includeConfidential;
|
||||
[ObservableProperty] private string _comment = "";
|
||||
[ObservableProperty] private string _statusMessage = "";
|
||||
[ObservableProperty, NotifyPropertyChangedFor(nameof(CanGenerate))] private bool _isGenerating;
|
||||
public bool CanGenerate => !IsGenerating && SelectedGroup is not null && SelectedTemplate is not null;
|
||||
|
||||
public StudentReportDialogViewModel(Student student, IGroupMembershipRepository memberships,
|
||||
IGroupRepository groups, IInterimGradeRepository interims, StudentReportService reports,
|
||||
ITemplateRenderer renderer, SchoolYearService schoolYears, IReadOnlyList<TemplateStore> stores)
|
||||
{
|
||||
_student = student; _interims = interims; _reports = reports; _renderer = renderer;
|
||||
_schoolYears = schoolYears; _loader = stores[0];
|
||||
Templates.Add(new(null));
|
||||
foreach (var template in stores.SelectMany(s => s.GetTemplates()).Where(t => t.IsStudentReport)
|
||||
.DistinctBy(t => t.PackagePath).OrderBy(t => t.Name)) Templates.Add(new(template));
|
||||
foreach (var membership in memberships.GetByStudent(student.Id))
|
||||
if (groups.GetById(membership.GroupId) is { } group && !Groups.Any(g => g.Model.Id == group.Id))
|
||||
Groups.Add(new(group));
|
||||
SelectedTemplate = Templates[0];
|
||||
SelectedGroup = Groups.OrderByDescending(g => g.Model.SchoolYear).FirstOrDefault();
|
||||
}
|
||||
|
||||
partial void OnSelectedGroupChanged(LetterGroupChoice? value)
|
||||
{
|
||||
Interims.Clear(); SelectedInterim = null;
|
||||
if (value is not null)
|
||||
{
|
||||
From = _schoolYears.SchoolYearStart(value.Model.SchoolYear).ToString("dd.MM.yyyy");
|
||||
To = _schoolYears.SchoolYearEnd(value.Model.SchoolYear).ToString("dd.MM.yyyy");
|
||||
var today = DateOnly.FromDateTime(DateTime.Today);
|
||||
if (_schoolYears.SchoolYearEnd(value.Model.SchoolYear) > today) To = today.ToString("dd.MM.yyyy");
|
||||
foreach (var grade in _interims.GetByStudentAndGroup(_student.Id, value.Model.Id)
|
||||
.OrderByDescending(g => g.Date).ThenBy(g => g.Occasion)) Interims.Add(new(grade));
|
||||
}
|
||||
OnPropertyChanged(nameof(CanGenerate));
|
||||
}
|
||||
partial void OnSelectedTemplateChanged(StudentReportTemplateChoice? value) => OnPropertyChanged(nameof(CanGenerate));
|
||||
|
||||
public async Task<bool> GenerateAsync(string outputPath)
|
||||
{
|
||||
if (!CanGenerate) return false;
|
||||
StatusMessage = "";
|
||||
if (!DateOnly.TryParseExact(From, "dd.MM.yyyy", CultureInfo.GetCultureInfo("de-DE"), DateTimeStyles.None, out var from)
|
||||
|| !DateOnly.TryParseExact(To, "dd.MM.yyyy", CultureInfo.GetCultureInfo("de-DE"), DateTimeStyles.None, out var to))
|
||||
{ StatusMessage = "Bitte Beginn und Ende als TT.MM.JJJJ eingeben."; return false; }
|
||||
try
|
||||
{
|
||||
var template = SelectedTemplate!.Model is { } installed ? _loader.Load(installed) : StudentReportTemplate.Create();
|
||||
// Datenbankzugriffe auf dem UI-Thread; nur das Setzen und Schreiben läuft im Hintergrund.
|
||||
var values = _reports.Build(_student, SelectedGroup!.Model, template,
|
||||
new(from, to, SelectedInterim?.Model, IncludeInterim, IncludeParticipation, IncludeCompetencies,
|
||||
IncludeHomework, IncludeDocumentation, IncludeConfidential, Comment));
|
||||
IsGenerating = true;
|
||||
await Task.Run(() => File.WriteAllBytes(outputPath, _renderer.RenderToPdf(template, new LetterDataProvider(values))));
|
||||
StatusMessage = "Schülerbericht erzeugt.";
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or InvalidDataException or UnauthorizedAccessException or TemplateValidationException or QuestPDF.Drawing.Exceptions.DocumentLayoutException)
|
||||
{ StatusMessage = $"Der Schülerbericht konnte nicht erzeugt werden: {ex.Message}"; return false; }
|
||||
finally { IsGenerating = false; }
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record StudentReportTemplateChoice(InstalledTemplate? Model)
|
||||
{
|
||||
public string Name => Model?.Name ?? "Schülerbericht Standard";
|
||||
}
|
||||
public sealed record StudentReportInterimChoice(InterimGrade Model)
|
||||
{
|
||||
public string Label => $"{Model.Date:dd.MM.yyyy} · {Model.Occasion}";
|
||||
}
|
||||
@@ -276,6 +276,7 @@ public partial class StudentDetailViewModel : ObservableObject
|
||||
public Func<Documentation, string, Task<Documentation?>>? OnConductParentCall { get; set; }
|
||||
public Func<Student, Task<StudentManagementResult>>? OnManageStudent { get; set; }
|
||||
public Func<Task>? OnCreateLetter { get; set; }
|
||||
public Func<Task>? OnCreateStudentReport { get; set; }
|
||||
public Action? OnReturnToStudentList { get; set; }
|
||||
|
||||
partial void OnIsStudentActiveChanged(bool value) => OnPropertyChanged(nameof(StudentStatus));
|
||||
@@ -455,6 +456,12 @@ public partial class StudentDetailViewModel : ObservableObject
|
||||
|
||||
[RelayCommand] private void StartEdit() => IsEditing = true;
|
||||
|
||||
[RelayCommand]
|
||||
private async Task CreateStudentReport()
|
||||
{
|
||||
if (Student is not null && OnCreateStudentReport is not null) await OnCreateStudentReport();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task CreateLetter()
|
||||
{
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
x:Class="LehrerApp.Desktop.Views.Groups.ExamCoverSheetDialog"
|
||||
x:DataType="vm:ExamCoverSheetDialogViewModel"
|
||||
Title="Deckblätter drucken"
|
||||
Width="460" Height="680"
|
||||
CanResize="False" WindowStartupLocation="CenterOwner">
|
||||
Width="460" Height="740" MinWidth="440" MinHeight="500"
|
||||
CanResize="True" WindowStartupLocation="CenterOwner">
|
||||
|
||||
<Grid RowDefinitions="Auto,Auto,*,Auto,Auto" Margin="24">
|
||||
|
||||
@@ -29,6 +29,14 @@
|
||||
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding TeacherAbbreviation}" PlaceholderText="z. B. MON HED"
|
||||
ToolTip.Tip="Vorbelegt mit dem eigenen Kürzel aus den Einstellungen. Änderungen gelten nur für diesen Druck."/>
|
||||
</Grid>
|
||||
<StackPanel Spacing="4" IsVisible="{Binding UsesInterimGrades}">
|
||||
<TextBlock Text="Gespeicherter Notenzwischenstand" FontWeight="SemiBold"/>
|
||||
<ComboBox ItemsSource="{Binding InterimRuns}" SelectedItem="{Binding SelectedInterimRun}"
|
||||
DisplayMemberBinding="{Binding Label}" HorizontalAlignment="Stretch"
|
||||
PlaceholderText="Datum und Anlass auswählen"/>
|
||||
<TextBlock Text="Für alle ausgewählten Schüler muss in diesem Durchgang ein Zwischenstand vorliegen."
|
||||
TextWrapping="Wrap" FontSize="12" Opacity="0.65"/>
|
||||
</StackPanel>
|
||||
<CheckBox Content="Punkte und Note eintragen" IsChecked="{Binding FillResults}"
|
||||
ToolTip.Tip="Aus: Blanko-Deckblatt mit Namen und leerer Punktetabelle zum Ausfüllen von Hand."/>
|
||||
</StackPanel>
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal" Spacing="8" VerticalAlignment="Top">
|
||||
<TextBlock Text="{Binding StudentStatus}" VerticalAlignment="Center" Opacity="0.65"/>
|
||||
<Button Content="Schülerbericht" Command="{Binding CreateStudentReportCommand}"
|
||||
IsVisible="{Binding !IsEditing}"/>
|
||||
<Button Content="PDF-Brief" Command="{Binding CreateLetterCommand}"
|
||||
IsVisible="{Binding !IsEditing}"/>
|
||||
<Button Content="Bearbeiten" Command="{Binding StartEditCommand}"
|
||||
|
||||
@@ -27,6 +27,7 @@ public partial class StudentDetailView : UserControl
|
||||
vm.OnConductParentCall = ShowParentCallSessionDialog;
|
||||
vm.OnManageStudent = ShowManageStudentDialog;
|
||||
vm.OnCreateLetter = ShowCreateLetterDialog;
|
||||
vm.OnCreateStudentReport = ShowStudentReportDialog;
|
||||
}
|
||||
|
||||
private async Task<Contact?> ShowContactDialog(Contact? contact)
|
||||
@@ -58,6 +59,22 @@ public partial class StudentDetailView : UserControl
|
||||
await LetterDialogs.ShowCreateLetterDialogAsync(owner, student);
|
||||
}
|
||||
|
||||
private async Task ShowStudentReportDialog()
|
||||
{
|
||||
if (TopLevel.GetTopLevel(this) is not Window owner ||
|
||||
DataContext is not StudentDetailViewModel { Student: { } student }) return;
|
||||
var vm = new StudentReportDialogViewModel(student,
|
||||
App.Services.GetRequiredService<IGroupMembershipRepository>(),
|
||||
App.Services.GetRequiredService<IGroupRepository>(),
|
||||
App.Services.GetRequiredService<IInterimGradeRepository>(),
|
||||
App.Services.GetRequiredService<StudentReportService>(),
|
||||
App.Services.GetRequiredService<LehrerApp.Templating.ITemplateRenderer>(),
|
||||
App.Services.GetRequiredService<LehrerApp.Core.Services.SchoolYearService>(),
|
||||
[App.Services.GetRequiredService<LehrerApp.Templating.TemplateStore>(),
|
||||
App.Services.GetRequiredService<LehrerApp.Templating.WorksheetTemplateStore>().Store]);
|
||||
await new StudentReportDialog { DataContext = vm }.ShowDialog(owner);
|
||||
}
|
||||
|
||||
private void ShowAddressViewer(ContactItem contact)
|
||||
{
|
||||
if (!contact.HasAddress) return;
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="clr-namespace:LehrerApp.Desktop.ViewModels.Students"
|
||||
x:Class="LehrerApp.Desktop.Views.Students.StudentReportDialog"
|
||||
x:DataType="vm:StudentReportDialogViewModel"
|
||||
Title="Schülerbericht" Width="560" Height="760" MinWidth="460" MinHeight="500"
|
||||
WindowStartupLocation="CenterOwner">
|
||||
<Grid RowDefinitions="Auto,*,Auto" Margin="24">
|
||||
<StackPanel Spacing="4" Margin="0,0,0,16">
|
||||
<TextBlock Text="Schülerbericht" Classes="dialogtitle"/>
|
||||
<TextBlock Text="{Binding StudentName}"/>
|
||||
</StackPanel>
|
||||
<ScrollViewer Grid.Row="1">
|
||||
<StackPanel Spacing="12" IsEnabled="{Binding !IsGenerating}">
|
||||
<TextBlock Text="Lerngruppe und Schuljahr" FontWeight="SemiBold"/>
|
||||
<ComboBox ItemsSource="{Binding Groups}" SelectedItem="{Binding SelectedGroup}"
|
||||
DisplayMemberBinding="{Binding Display}" HorizontalAlignment="Stretch"/>
|
||||
<TextBlock Text="Vorlage" FontWeight="SemiBold"/>
|
||||
<ComboBox ItemsSource="{Binding Templates}" SelectedItem="{Binding SelectedTemplate}"
|
||||
DisplayMemberBinding="{Binding Name}" HorizontalAlignment="Stretch"/>
|
||||
<Grid ColumnDefinitions="*,12,*">
|
||||
<StackPanel Spacing="4">
|
||||
<TextBlock Text="Von (TT.MM.JJJJ)"/>
|
||||
<TextBox Text="{Binding From}"/>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="2" Spacing="4">
|
||||
<TextBlock Text="Bis (TT.MM.JJJJ)"/>
|
||||
<TextBox Text="{Binding To}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<CheckBox Content="Notenzwischenstand" IsChecked="{Binding IncludeInterim}"/>
|
||||
<ComboBox ItemsSource="{Binding Interims}" SelectedItem="{Binding SelectedInterim}"
|
||||
DisplayMemberBinding="{Binding Label}" HorizontalAlignment="Stretch"
|
||||
PlaceholderText="Gespeicherten Zwischenstand auswählen" IsVisible="{Binding IncludeInterim}"/>
|
||||
<CheckBox Content="Mitarbeitsgraph mit gewichteter Mitarbeit und Einzelaspekten" IsChecked="{Binding IncludeParticipation}"/>
|
||||
<CheckBox Content="Kompetenzbewertungen" IsChecked="{Binding IncludeCompetencies}"/>
|
||||
<CheckBox Content="Hausaufgabenkontrollen" IsChecked="{Binding IncludeHomework}"/>
|
||||
<CheckBox Content="Klassenbucheinträge und Unterrichtsnotizen" IsChecked="{Binding IncludeDocumentation}"/>
|
||||
<CheckBox Content="Vertrauliche Dokumentation einschließen" IsChecked="{Binding IncludeConfidential}"
|
||||
IsVisible="{Binding IncludeDocumentation}"/>
|
||||
<TextBlock Text="Dokumentation wird auf die gewählte Lerngruppe begrenzt. Entwürfe werden ausgelassen."
|
||||
TextWrapping="Wrap" FontSize="12" Opacity="0.65"/>
|
||||
<TextBlock Text="Ergänzender Text" FontWeight="SemiBold"/>
|
||||
<TextBox Text="{Binding Comment}" AcceptsReturn="True" TextWrapping="Wrap" MinHeight="90"/>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
<StackPanel Grid.Row="2" Spacing="10" Margin="0,12,0,0">
|
||||
<ProgressBar IsVisible="{Binding IsGenerating}" IsIndeterminate="True" Height="6"/>
|
||||
<TextBlock Text="{Binding StatusMessage}" TextWrapping="Wrap"/>
|
||||
<Grid ColumnDefinitions="*,12,*">
|
||||
<Button Content="Schließen" Click="OnClose" IsEnabled="{Binding !IsGenerating}" HorizontalAlignment="Stretch"/>
|
||||
<Button Grid.Column="2" Content="PDF erzeugen…" Click="OnGenerate" IsEnabled="{Binding CanGenerate}" HorizontalAlignment="Stretch"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,28 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Platform.Storage;
|
||||
using LehrerApp.Desktop.ViewModels.Students;
|
||||
|
||||
namespace LehrerApp.Desktop.Views.Students;
|
||||
|
||||
public partial class StudentReportDialog : Window
|
||||
{
|
||||
public StudentReportDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
Closing += (_, e) => e.Cancel = DataContext is StudentReportDialogViewModel { IsGenerating: true };
|
||||
}
|
||||
private void OnClose(object? sender, RoutedEventArgs e) => Close();
|
||||
private async void OnGenerate(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext is not StudentReportDialogViewModel vm) return;
|
||||
var file = await StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
|
||||
{
|
||||
Title = "Schülerbericht speichern", SuggestedFileName = vm.SuggestedFileName,
|
||||
DefaultExtension = "pdf", FileTypeChoices = [new FilePickerFileType("PDF") { Patterns = ["*.pdf"] }],
|
||||
});
|
||||
if (file is null) return;
|
||||
if (await vm.GenerateAsync(file.Path.LocalPath))
|
||||
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(file.Path.LocalPath) { UseShellExecute = true });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user