Klausur-Deckblätter als Sammel-PDF aus Vorlagen vom Typ exam-cover
Neuer Dialog "Deckblätter…" bei Klausuren, Punktetabelle als Drawing mit festen Spaltenbreiten, FLOWDRAWBOX-Attribut fit=content, Stapel-Rendering mit Seitenzahl je Datensatz, Kursbezeichnung und konfigurierbares Kürzel. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f56caced32
commit
dd92128464
33 files changed
+1158
-28
No files matched your search
@@ -0,0 +1,77 @@
|
||||
using System.Globalization;
|
||||
using LehrerApp.Core.Models;
|
||||
using LehrerApp.Core.Services;
|
||||
using LehrerApp.Desktop.ViewModels.Groups;
|
||||
using LehrerApp.Templating;
|
||||
|
||||
namespace LehrerApp.Desktop.Services;
|
||||
|
||||
/// <summary>Platzhalterwerte für Klausur-Deckblätter (Vorlagen mit
|
||||
/// <c>report-type=exam-cover</c>): die Standardwerte der Elternbriefe (Student.*, Group.Name, …)
|
||||
/// plus Exam.*, Result.* und die Punktetabelle. Alle Punktwerte gelten für die Fassung, die der
|
||||
/// Schüler geschrieben hat.</summary>
|
||||
public static class ExamCoverPlaceholderBuilder
|
||||
{
|
||||
/// <summary>Stehen statt Punkten bzw. Note auf dem Blatt, solange nichts eingetragen wird —
|
||||
/// als Linie zum Ausfüllen von Hand.</summary>
|
||||
public const string BlankPoints = "_________", BlankGrade = "_____";
|
||||
|
||||
private static readonly CultureInfo German = CultureInfo.GetCultureInfo("de-DE");
|
||||
|
||||
/// <param name="result">Ergebnis des Schülers oder null. Punkte und Note werden nur
|
||||
/// eingetragen, wenn <paramref name="fillResults"/> gesetzt und das Ergebnis korrigiert ist.</param>
|
||||
/// <param name="studentNiveau">Niveau des Schülers in dieser Lerngruppe, falls die Arbeit
|
||||
/// selbst keinem Niveau zugeordnet ist.</param>
|
||||
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 = "")
|
||||
{
|
||||
var tasks = exam.Tasks.OrderBy(t => t.Nr).ToList();
|
||||
var variant = result?.Variant ?? ExamVariant.A;
|
||||
var maximum = ExamScoringService.Maximum(tasks, variant);
|
||||
var filled = fillResults && ExamCoverSheetService.IsCorrected(result);
|
||||
|
||||
var values = LetterPlaceholderBuilder.BuildStandardValues(student, contact: null, group, today, "", "");
|
||||
values["Group.GradeLevel"] = new TextValue(group.GradeLevel > 0 ? group.GradeLevel.ToString() : "");
|
||||
values["Subject.Name"] = new TextValue(subjectName);
|
||||
values["Exam.Title"] = new TextValue(exam.Title);
|
||||
values["Exam.Date"] = new DateValue(exam.Date);
|
||||
values["Exam.Number"] = new TextValue(exam.ExamNumber?.ToString() ?? "");
|
||||
values["Exam.Kind"] = new TextValue(exam.Kind.Label());
|
||||
values["Exam.Niveau"] = new TextValue(exam.Niveau.HasValue ? NiveauDisplay.ToName(exam.Niveau) : "");
|
||||
values["Exam.Course"] = new TextValue(CourseLabel(group, exam.Niveau ?? studentNiveau));
|
||||
values["Teacher.Abbreviation"] = new TextValue(teacherAbbreviation.Trim());
|
||||
values["Exam.Variant"] = new TextValue(tasks.Any(t => t.Variant is not null) ? variant.ToString() : "");
|
||||
values["Exam.MaxPoints"] = new TextValue(Format(maximum));
|
||||
values["Exam.ApprovalDate"] = new TextValue(Format(exam.ApprovalGrantedAt));
|
||||
values["Exam.AnnouncedDate"] = new TextValue(Format(exam.AnnouncedAt));
|
||||
values["Exam.ReturnDate"] = new TextValue(Format(exam.ReturnedAt));
|
||||
values["Result.Points"] = new TextValue(filled ? Format(result!.TotalPoints) : BlankPoints);
|
||||
values["Result.Percent"] = new TextValue(filled && maximum > 0
|
||||
? (result!.TotalPoints / maximum).ToString("0 %", German) : "");
|
||||
values["Result.Grade"] = new TextValue(filled
|
||||
? result!.Grade ?? grading.CalculateGrade(result.TotalPoints, maximum, exam.GradingKey) : BlankGrade);
|
||||
|
||||
// Ohne Box in der Vorlage gibt es nichts zu zeichnen (die Tabelle ist optional).
|
||||
values[ExamPointsTableDrawingBuilder.PlaceholderName] =
|
||||
LetterPlaceholderBuilder.FindDeclaredDrawingBox(template, ExamPointsTableDrawingBuilder.PlaceholderName) is { } box
|
||||
? ExamPointsTableDrawingBuilder.Build(
|
||||
ExamCoverSheetService.Columns(tasks, variant, filled ? result!.Points : null),
|
||||
box.Width, box.MillimeterScale)
|
||||
: new DrawingValue([], 0);
|
||||
return values;
|
||||
}
|
||||
|
||||
/// <summary>"E-Kurs" / "G-Kurs" für die äußere Differenzierung; leer im Klassenverband und
|
||||
/// ohne E-/G-Zuordnung.</summary>
|
||||
public static string CourseLabel(LearningGroup group, Niveau? niveau) =>
|
||||
group.Type == GroupType.Class ? "" : niveau switch
|
||||
{
|
||||
Niveau.E => "E-Kurs",
|
||||
Niveau.G => "G-Kurs",
|
||||
_ => "",
|
||||
};
|
||||
|
||||
private static string Format(double value) => value.ToString("0.##", German);
|
||||
private static string Format(DateOnly? date) => date?.ToString("dd.MM.yyyy", CultureInfo.InvariantCulture) ?? "";
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Avalonia.Controls;
|
||||
using LehrerApp.Core.Interfaces;
|
||||
using LehrerApp.Core.Models;
|
||||
using LehrerApp.Core.Services;
|
||||
using LehrerApp.Desktop.ViewModels.Groups;
|
||||
using LehrerApp.Desktop.Views.Groups;
|
||||
using LehrerApp.Templating;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace LehrerApp.Desktop.Services;
|
||||
|
||||
/// <summary>Öffnet den Deckblatt-Dialog zu einer Klausur — ein Einstieg für die Klausuren-
|
||||
/// Hauptseite und den Klausuren-Tab der Lerngruppe.</summary>
|
||||
public static class ExamCoverSheetDialogs
|
||||
{
|
||||
public static async Task ShowAsync(Control source, Exam exam)
|
||||
{
|
||||
var group = App.Services.GetRequiredService<IGroupRepository>().GetById(exam.GroupId);
|
||||
if (group is null || TopLevel.GetTopLevel(source) is not Window owner) return;
|
||||
var subject = group.SubjectId is { } subjectId
|
||||
? App.Services.GetRequiredService<ISubjectRepository>().GetById(subjectId)?.Name ?? ""
|
||||
: "";
|
||||
var vm = new ExamCoverSheetDialogViewModel(exam, group, subject,
|
||||
App.Services.GetRequiredService<IStudentRepository>(),
|
||||
App.Services.GetRequiredService<IGroupMembershipRepository>(),
|
||||
App.Services.GetRequiredService<IExamResultRepository>(),
|
||||
App.Services.GetRequiredService<GradingService>(),
|
||||
[App.Services.GetRequiredService<TemplateStore>(), App.Services.GetRequiredService<WorksheetTemplateStore>().Store],
|
||||
App.Services.GetRequiredService<ITemplateBatchRenderer>(),
|
||||
App.Services.GetRequiredService<TeacherSettingsService>().LoadAbbreviation());
|
||||
await new ExamCoverSheetDialog { DataContext = vm }.ShowDialog(owner);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
using System.Globalization;
|
||||
using LehrerApp.Core.Services;
|
||||
using LehrerApp.Templating;
|
||||
|
||||
namespace LehrerApp.Desktop.Services;
|
||||
|
||||
/// <summary>Zeichnet die Punktetabelle des Klausur-Deckblatts (Aufgabe / Max. Punktzahl /
|
||||
/// Punktzahl). Die Spalten haben eine feste Breite: passen nicht alle Aufgaben nebeneinander in die
|
||||
/// Box der Vorlage, folgt darunter ein weiterer Tabellenblock, statt alles zu verkleinern. Gedacht
|
||||
/// für eine <c>FLOWDRAWBOX … fit=content</c>, damit nachfolgende Elemente mitwandern.</summary>
|
||||
public static class ExamPointsTableDrawingBuilder
|
||||
{
|
||||
public const string PlaceholderName = "Exam.PointsTable";
|
||||
|
||||
private static readonly CultureInfo German = CultureInfo.GetCultureInfo("de-DE");
|
||||
|
||||
// Referenzentwurf in Millimetern, abgemessen an der Schulvorlage.
|
||||
private const float LabelWidth = 38f, ColumnWidth = 20.5f;
|
||||
private const float HeaderHeight = 5.5f, MaximumHeight = 8.5f, PointsHeight = 11.5f;
|
||||
private const float BlockGap = 4f, Padding = 1.5f, Stroke = 0.2f, HeavyStroke = 0.45f;
|
||||
private const float FontSize = 10f;
|
||||
|
||||
/// <param name="contentWidth">Breite der deklarierten Box in der Maßeinheit der Vorlage.</param>
|
||||
/// <param name="millimeterScale">1 mm in der Maßeinheit der Vorlage (siehe
|
||||
/// <see cref="LetterPlaceholderBuilder.FindDeclaredDrawingBox(LoadedTemplate, string)"/>).</param>
|
||||
public static DrawingValue Build(IReadOnlyList<ExamCoverTaskColumn> columns, float contentWidth = 170,
|
||||
float millimeterScale = 1)
|
||||
{
|
||||
if (columns.Count == 0) return new DrawingValue([], 0);
|
||||
var k = millimeterScale;
|
||||
var perBlock = ColumnsPerBlock(contentWidth, millimeterScale);
|
||||
// Halbe Strichstärke Abstand zum Rand, sonst schneidet die Box die äußeren Linien an.
|
||||
var origin = HeavyStroke / 2 * k;
|
||||
var blockHeight = (HeaderHeight + MaximumHeight + PointsHeight) * k;
|
||||
var commands = new List<DrawingCommand>();
|
||||
var y = origin;
|
||||
for (var start = 0; start < columns.Count; start += perBlock)
|
||||
{
|
||||
if (start > 0) y += BlockGap * k;
|
||||
var block = columns.Skip(start).Take(perBlock).ToList();
|
||||
var maximumY = y + HeaderHeight * k;
|
||||
var pointsY = maximumY + MaximumHeight * k;
|
||||
|
||||
Cell(commands, origin, y, LabelWidth * k, HeaderHeight * k, "Aufgabe", DrawingTextAlignment.AlignRight, false, k);
|
||||
Cell(commands, origin, maximumY, LabelWidth * k, MaximumHeight * k, "Max. Punktzahl", DrawingTextAlignment.AlignRight, false, k);
|
||||
Cell(commands, origin, pointsY, LabelWidth * k, PointsHeight * k, "Punktzahl", DrawingTextAlignment.AlignRight, true, k);
|
||||
for (var index = 0; index < block.Count; index++)
|
||||
{
|
||||
var column = block[index];
|
||||
var x = origin + (LabelWidth + index * ColumnWidth) * k;
|
||||
Cell(commands, x, y, ColumnWidth * k, HeaderHeight * k,
|
||||
column.IsBonus ? "" : $"Nr. {column.Number}", DrawingTextAlignment.AlignCenter, false, k);
|
||||
Cell(commands, x, maximumY, ColumnWidth * k, MaximumHeight * k,
|
||||
(column.IsBonus ? "+" : "") + Format(column.MaxPoints), DrawingTextAlignment.AlignCenter, false, k);
|
||||
Cell(commands, x, pointsY, ColumnWidth * k, PointsHeight * k,
|
||||
column.AchievedPoints is { } achieved ? Format(achieved) : "", DrawingTextAlignment.AlignCenter, false, k);
|
||||
}
|
||||
commands.Add(new DrawLine(origin, pointsY, origin + (LabelWidth + block.Count * ColumnWidth) * k, pointsY,
|
||||
StrokeWidth: HeavyStroke * k));
|
||||
y += blockHeight;
|
||||
}
|
||||
return new DrawingValue(commands, y + origin);
|
||||
}
|
||||
|
||||
/// <summary>Wie viele Aufgaben bei fester Spaltenbreite nebeneinander in die Box passen.</summary>
|
||||
public static int ColumnsPerBlock(float contentWidth, float millimeterScale = 1) =>
|
||||
Math.Max(1, (int)Math.Floor((contentWidth / millimeterScale - HeavyStroke - LabelWidth + 0.01f) / ColumnWidth));
|
||||
|
||||
private static void Cell(List<DrawingCommand> commands, float x, float y, float width, float height,
|
||||
string text, DrawingTextAlignment alignment, bool bold, float k)
|
||||
{
|
||||
commands.Add(new DrawRectangle(x, y, width, height, StrokeWidth: Stroke * k));
|
||||
if (text.Length == 0) return;
|
||||
// DrawStringEx setzt die Grundlinie auf Y + Schriftgröße; so sitzt die Zeile optisch mittig.
|
||||
var fontHeight = FontSize * UnitConverter.Points(1, "pt") / UnitConverter.Points(1, "mm") * k;
|
||||
var textY = y + height / 2 - fontHeight * 0.64f;
|
||||
commands.Add(new DrawStringEx(x + Padding * k, textY, y + height - textY, width - 2 * Padding * k, text,
|
||||
alignment, FontSize, Bold: bold));
|
||||
}
|
||||
|
||||
private static string Format(double value) => value.ToString("0.##", German);
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public class LetterTemplateTools(
|
||||
public List<LetterTemplateDto> ListLetterTemplates()
|
||||
{
|
||||
var result = new List<LetterTemplateDto>();
|
||||
foreach (var installed in templates.GetTemplates())
|
||||
foreach (var installed in templates.GetTemplates().Where(x => !x.IsExamCover))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace LehrerApp.Desktop.Services;
|
||||
|
||||
internal sealed class TeacherSettingsConfig
|
||||
{
|
||||
public string Abbreviation { get; set; } = "";
|
||||
}
|
||||
|
||||
/// <summary>Angaben zur Lehrkraft, die auf Formularen erscheinen (bisher nur das Kürzel fürs
|
||||
/// Klausur-Deckblatt) — aus der Konfiguration statt fest in der Vorlage, damit eine weitergegebene
|
||||
/// Vorlage nicht das Kürzel ihres Erstellers trägt.</summary>
|
||||
public sealed class TeacherSettingsService
|
||||
{
|
||||
private readonly string _configPath;
|
||||
|
||||
public TeacherSettingsService(string appDataPath) =>
|
||||
_configPath = Path.Combine(appDataPath, "teachersettings.json");
|
||||
|
||||
public string LoadAbbreviation()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(_configPath))
|
||||
return JsonSerializer.Deserialize<TeacherSettingsConfig>(File.ReadAllText(_configPath))
|
||||
?.Abbreviation ?? "";
|
||||
}
|
||||
catch { /* beschädigte Konfiguration -> leer */ }
|
||||
return "";
|
||||
}
|
||||
|
||||
public void SaveAbbreviation(string abbreviation)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.WriteAllText(_configPath,
|
||||
JsonSerializer.Serialize(new TeacherSettingsConfig { Abbreviation = abbreviation.Trim() }));
|
||||
}
|
||||
catch { /* Einstellung ist Komfort — Fehler beim Schreiben nicht an die UI durchreichen */ }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user