feat: Kompetenzzuordnungen von Freitext-Code auf stabile CompetencyItem.Id umgestellt (TODO 16.5)
Unit/Lesson/ExamTask/ParticipationSession referenzierten Kompetenzen bisher per Freitext-Code, case-insensitiv gegen den Katalog gematcht - fragil bei Umbenennungen und seit der Bildungsplan-Versionierung nicht mehr eindeutig (zwei Versionen können denselben Code vergeben). Neuer Werttyp CompetencyReference (ItemId + Code/Description-Momentaufnahme) löst das: solange die Id noch im Katalog auflösbar ist, zählt die live Fassung (Rename wirkt sofort), sonst bleibt die gespeicherte historische Fassung sichtbar statt spurlos zu verschwinden. Migration (Schema-Version 6) löst bestehende Codes gegen den Katalog auf; die zuvor dreifach duplizierte Kompetenz-Tag-UI ist jetzt in CompetencyTagGroupBuilder konsolidiert. add_lesson_competency/remove_lesson_competency nehmen jetzt itemId statt code und validieren gegen den Katalog (vorher ungeprüft). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f97edff2fe
commit
dc2f58c4dc
28 files changed
+691
-202
No files matched your search
@@ -205,7 +205,7 @@ public class AiPlanningService(HttpClient http, ILessonRepository lessons,
|
||||
Title = unit.Title,
|
||||
StartDate = unit.StartDate,
|
||||
EndDate = unit.EndDate,
|
||||
Competencies = unit.Competencies,
|
||||
Competencies = unit.Competencies.Select(c => c.Code).ToList(),
|
||||
Notes = unit.Notes,
|
||||
SubjectName = subject?.Name ?? "",
|
||||
GradeLevel = gradeLevel,
|
||||
|
||||
@@ -34,9 +34,14 @@ public record LessonPhaseDto(
|
||||
|
||||
public record LessonAttachmentDto(string StorageId, string FileName, long SizeBytes);
|
||||
|
||||
/// <summary>Eine über MCP zugeordnete Kompetenz - Id + zum Zuordnungszeitpunkt gespeicherte
|
||||
/// Momentaufnahme aus Code/Description (siehe CompetencyReference), damit ein KI-Client sie ohne
|
||||
/// Zusatzabfrage lesen kann, auch wenn das Katalog-Item inzwischen gelöscht wurde.</summary>
|
||||
public record CompetencyReferenceDto(Guid ItemId, string Code, string Description);
|
||||
|
||||
public record LessonDto(
|
||||
Guid Id, Guid UnitId, Guid GroupId, DateOnly Date, int? LessonNumber, string Topic,
|
||||
string? Homework, string? PlanningIdeas, LessonStatus Status, List<string> Competencies,
|
||||
string? Homework, string? PlanningIdeas, LessonStatus Status, List<CompetencyReferenceDto> Competencies,
|
||||
List<LessonPhaseDto> Phases, List<LessonAttachmentDto> Attachments);
|
||||
|
||||
/// <summary>Ergebnis von "download_lesson_attachment": Inhalt Base64-kodiert, weil MCP-Tool-Antworten
|
||||
@@ -47,7 +52,7 @@ public record AttachmentContentDto(string FileName, long SizeBytes, string Base6
|
||||
|
||||
public record UnitDto(
|
||||
Guid Id, Guid GroupId, string Title, DateOnly? StartDate, DateOnly? EndDate,
|
||||
UnitStatus Status, List<string> Competencies);
|
||||
UnitStatus Status, List<CompetencyReferenceDto> Competencies);
|
||||
|
||||
public record LessonPlanResultDto(List<UnitDto> Units, List<LessonDto> Lessons);
|
||||
|
||||
|
||||
@@ -25,7 +25,8 @@ namespace LehrerApp.Desktop.Services.Mcp.Tools;
|
||||
/// (siehe McpServerHostedService) und mit besonders deutlicher Bestätigungsnachricht.</summary>
|
||||
public class LessonPlanTools(
|
||||
IUnitRepository units, ILessonRepository lessons, IGroupRepository groups,
|
||||
IAttachmentStorage attachments, IMcpConfirmationService confirmation)
|
||||
IAttachmentStorage attachments, ICompetencyDomainRepository competencyDomains,
|
||||
IMcpConfirmationService confirmation)
|
||||
{
|
||||
/// <summary>Deckelt die Antwortgröße von "download_lesson_attachment" (Base64 bläht ca. um
|
||||
/// Faktor 1,33 auf). Kleiner als <see cref="IAttachmentStorage.MaxSizeBytes"/> (App-weites
|
||||
@@ -42,7 +43,7 @@ public class LessonPlanTools(
|
||||
[Description("Enddatum (einschließlich) für die Einzelstunden, Format YYYY-MM-DD.")] DateOnly to)
|
||||
{
|
||||
var unitDtos = units.GetByGroup(groupId)
|
||||
.Select(u => new UnitDto(u.Id, u.GroupId, u.Title, u.StartDate, u.EndDate, u.Status, u.Competencies))
|
||||
.Select(u => new UnitDto(u.Id, u.GroupId, u.Title, u.StartDate, u.EndDate, u.Status, ToDto(u.Competencies)))
|
||||
.ToList();
|
||||
var lessonDtos = lessons.GetByGroupAndRange(groupId, from, to)
|
||||
.Select(ToDto)
|
||||
@@ -311,40 +312,40 @@ public class LessonPlanTools(
|
||||
// Race-Condition-Überlegung wie bei den Verlaufsplan-Phasen (add/update/remove_lesson_phase) -
|
||||
// ein Tool-Aufruf ändert nur einen Code, kein "letzter Schreiber gewinnt" über die ganze Liste.
|
||||
|
||||
[Description("Ordnet einer Einzelstunde einen Kompetenzcode aus dem Katalog zu (siehe get_competency_catalog). Muss der Nutzer erst bestätigen.")]
|
||||
[Description("Ordnet einer Einzelstunde eine Kompetenz aus dem Katalog zu (siehe get_competency_catalog). Muss der Nutzer erst bestätigen.")]
|
||||
public async Task<WriteResultDto> AddLessonCompetency(
|
||||
[Description("ID der Einzelstunde.")] Guid lessonId,
|
||||
[Description("Kompetenzcode, z.B. \"M.5.1\".")] string code,
|
||||
[Description("ID der Einzelkompetenz, aus get_competency_catalog.")] Guid itemId,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
var lesson = lessons.GetById(lessonId);
|
||||
if (lesson is null) return new WriteResultDto(false, null, "Unbekannte Stunden-ID.");
|
||||
code = code.Trim();
|
||||
if (code.Length == 0) return new WriteResultDto(false, null, "Leerer Kompetenzcode.");
|
||||
if (lesson.Competencies.Contains(code, StringComparer.OrdinalIgnoreCase))
|
||||
return new WriteResultDto(true, lesson.Id, "Kompetenzcode ist bereits zugeordnet.");
|
||||
var item = FindCompetencyItem(itemId);
|
||||
if (item is null) return new WriteResultDto(false, null, "Unbekannte Kompetenz-ID.");
|
||||
if (lesson.Competencies.Any(c => c.ItemId == itemId))
|
||||
return new WriteResultDto(true, lesson.Id, "Kompetenz ist bereits zugeordnet.");
|
||||
|
||||
var message = $"Kompetenz „{code}“ zu „{lesson.Topic}“ am {lesson.Date:dd.MM.yyyy} hinzufügen?";
|
||||
var message = $"Kompetenz „{item.Code}“ zu „{lesson.Topic}“ am {lesson.Date:dd.MM.yyyy} hinzufügen?";
|
||||
if (!await confirmation.ConfirmAsync("Kompetenz zuordnen?", message, ct))
|
||||
return new WriteResultDto(false, null, "Vom Nutzer abgelehnt oder nicht bestätigt.");
|
||||
|
||||
lesson.Competencies.Add(code);
|
||||
lesson.Competencies.Add(new CompetencyReference { ItemId = item.Id, Code = item.Code, Description = item.Description });
|
||||
lessons.Save(lesson);
|
||||
return new WriteResultDto(true, lesson.Id, "Kompetenz zugeordnet.");
|
||||
}
|
||||
|
||||
[Description("Entfernt einen Kompetenzcode von einer Einzelstunde. Muss der Nutzer erst bestätigen.")]
|
||||
[Description("Entfernt eine Kompetenz von einer Einzelstunde. Muss der Nutzer erst bestätigen.")]
|
||||
public async Task<WriteResultDto> RemoveLessonCompetency(
|
||||
[Description("ID der Einzelstunde.")] Guid lessonId,
|
||||
[Description("Kompetenzcode, wie in get_lesson_plans hinterlegt.")] string code,
|
||||
[Description("ID der Einzelkompetenz, wie in get_lesson_plans hinterlegt.")] Guid itemId,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
var lesson = lessons.GetById(lessonId);
|
||||
if (lesson is null) return new WriteResultDto(false, null, "Unbekannte Stunden-ID.");
|
||||
var existing = lesson.Competencies.FirstOrDefault(c => string.Equals(c, code, StringComparison.OrdinalIgnoreCase));
|
||||
if (existing is null) return new WriteResultDto(false, null, "Dieser Kompetenzcode ist dieser Stunde nicht zugeordnet.");
|
||||
var existing = lesson.Competencies.FirstOrDefault(c => c.ItemId == itemId);
|
||||
if (existing is null) return new WriteResultDto(false, null, "Diese Kompetenz ist dieser Stunde nicht zugeordnet.");
|
||||
|
||||
var message = $"Kompetenz „{existing}“ von „{lesson.Topic}“ am {lesson.Date:dd.MM.yyyy} entfernen?";
|
||||
var message = $"Kompetenz „{existing.Code}“ von „{lesson.Topic}“ am {lesson.Date:dd.MM.yyyy} entfernen?";
|
||||
if (!await confirmation.ConfirmAsync("Kompetenz entfernen?", message, ct))
|
||||
return new WriteResultDto(false, null, "Vom Nutzer abgelehnt oder nicht bestätigt.");
|
||||
|
||||
@@ -353,6 +354,9 @@ public class LessonPlanTools(
|
||||
return new WriteResultDto(true, lesson.Id, "Kompetenz entfernt.");
|
||||
}
|
||||
|
||||
private CompetencyItem? FindCompetencyItem(Guid itemId) =>
|
||||
competencyDomains.GetAll().SelectMany(d => d.Items).FirstOrDefault(i => i.Id == itemId);
|
||||
|
||||
// ── Einzelstunden (Lesson) — Verschieben & Löschen ───────────────────────────────────────
|
||||
|
||||
[Description("Verschiebt eine Einzelstunde auf ein neues Datum (und optional eine neue Stundennummer). Mit shiftFollowingLessons=true verschieben sich alle noch nicht durchgeführten, späteren Stunden derselben Einheit um denselben Tages-Versatz mit — so lässt sich eine Lücke für eine neue Stunde öffnen: diese Stunde auf den Termin der übernächsten verschieben (mit shiftFollowingLessons), dann create_lesson auf das dadurch freigewordene ursprüngliche Datum. Muss der Nutzer erst bestätigen.")]
|
||||
@@ -414,7 +418,10 @@ public class LessonPlanTools(
|
||||
}
|
||||
|
||||
private static LessonDto ToDto(Lesson l) => new(
|
||||
l.Id, l.UnitId, l.GroupId, l.Date, l.LessonNumber, l.Topic, l.Homework, l.PlanningIdeas, l.Status, l.Competencies,
|
||||
l.Id, l.UnitId, l.GroupId, l.Date, l.LessonNumber, l.Topic, l.Homework, l.PlanningIdeas, l.Status, ToDto(l.Competencies),
|
||||
l.Phases.Select(p => new LessonPhaseDto(p.Id, p.Name, p.DurationMinutes, p.Activity, p.Material, p.Shorthand, p.MaterialPrompt)).ToList(),
|
||||
l.Attachments.Select(a => new LessonAttachmentDto(a.StorageId, a.FileName, a.SizeBytes)).ToList());
|
||||
|
||||
private static List<CompetencyReferenceDto> ToDto(List<CompetencyReference> competencies) =>
|
||||
competencies.Select(c => new CompetencyReferenceDto(c.ItemId, c.Code, c.Description)).ToList();
|
||||
}
|
||||
@@ -62,9 +62,16 @@ public sealed class PlanningExchangeService(IUnitRepository units, ILessonReposi
|
||||
Title = document.Unit.Title.Trim(),
|
||||
StartDate = document.Unit.StartDate,
|
||||
EndDate = document.Unit.EndDate,
|
||||
// Das Austauschformat überträgt bewusst nie interne DB-IDs ("jeder Import legt neue
|
||||
// Objekte an", siehe Klassenkommentar) - jeder importierte Code wird deshalb als NICHT
|
||||
// aufgelöste Referenz gespeichert (kein Matching gegen den Katalog der Zielinstallation,
|
||||
// das wäre wieder dasselbe fragile Code-Matching, das TODO 16.5 vermeiden soll, nur
|
||||
// installationsübergreifend). Die Tag-UI zeigt sie ehrlich als "Nicht mehr im Katalog";
|
||||
// der Nutzer kann sie bei Bedarf manuell dem echten Katalogeintrag neu zuordnen.
|
||||
Competencies = document.Unit.Competencies
|
||||
.Where(c => !string.IsNullOrWhiteSpace(c)).Select(c => c.Trim())
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase).ToList(),
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.Select(c => new CompetencyReference { ItemId = Guid.Empty, Code = c }).ToList(),
|
||||
Status = document.Unit.Status,
|
||||
Notes = Clean(document.Unit.Notes),
|
||||
};
|
||||
@@ -94,7 +101,7 @@ public sealed class PlanningExchangeService(IUnitRepository units, ILessonReposi
|
||||
Title = unit.Title,
|
||||
StartDate = unit.StartDate,
|
||||
EndDate = unit.EndDate,
|
||||
Competencies = [.. unit.Competencies],
|
||||
Competencies = [.. unit.Competencies.Select(c => c.Code)],
|
||||
Status = unit.Status,
|
||||
Notes = unit.Notes,
|
||||
Lessons = [.. unitLessons.Select(ToPayload)],
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using LehrerApp.Core.Models;
|
||||
|
||||
namespace LehrerApp.Desktop.ViewModels.Groups;
|
||||
|
||||
// ── Kompetenz-Tags ──────────────────────────────────────────────────────────────
|
||||
//
|
||||
// Gemeinsame Toggle-UI für die drei Stellen, an denen Kompetenzen aus dem Katalog einem anderen
|
||||
// Objekt zugeordnet werden (Unterrichtseinheit, Klausuraufgabe, Mitarbeit-Sitzung) - vor der
|
||||
// Umstellung auf CompetencyItem.Id (TODO 16.5) war die Bau-Logik dreifach fast identisch
|
||||
// dupliziert, jetzt an einer Stelle.
|
||||
|
||||
public class CompetencyTagGroup(string name, string code)
|
||||
{
|
||||
public string Name { get; } = name;
|
||||
public string Code { get; } = code;
|
||||
public string DisplayName { get; } = string.IsNullOrEmpty(code) ? name : $"{name} ({code})";
|
||||
public List<CompetencyTag> Items { get; } = [];
|
||||
}
|
||||
|
||||
public partial class CompetencyTag : ObservableObject
|
||||
{
|
||||
public Guid ItemId { get; }
|
||||
public string Code { get; }
|
||||
public string Description { get; }
|
||||
public string Display { get; }
|
||||
|
||||
[ObservableProperty] private bool _isSelected;
|
||||
|
||||
/// <summary>Reicht die Tag-Instanz selbst durch, statt nur Id/Zustand - der Aufrufer liest
|
||||
/// Code/Description direkt vom Tag, ohne eine eigene Lookup-Tabelle führen zu müssen.</summary>
|
||||
public Action<CompetencyTag>? OnChanged { get; set; }
|
||||
|
||||
public CompetencyTag(Guid itemId, string code, string description, bool isSelected)
|
||||
{
|
||||
ItemId = itemId;
|
||||
Code = code;
|
||||
Description = description;
|
||||
Display = string.IsNullOrEmpty(code) ? description : $"[{code}] {description}";
|
||||
_isSelected = isSelected;
|
||||
}
|
||||
|
||||
partial void OnIsSelectedChanged(bool value) => OnChanged?.Invoke(this);
|
||||
}
|
||||
|
||||
public static class CompetencyTagGroupBuilder
|
||||
{
|
||||
/// <summary>Baut Tag-Gruppen aus dem aktuellen Katalog plus eine synthetische Gruppe "Nicht mehr
|
||||
/// im Katalog" für bereits zugeordnete Referenzen, deren ItemId im übergebenen Katalog nicht
|
||||
/// auflösbar ist (gelöscht, andere Bildungsplan-Version, oder nie aufgelöster Import) - zeigt
|
||||
/// deren gespeicherte Momentaufnahme, damit eine Zuordnung nie stillschweigend verschwindet
|
||||
/// (Kernanliegen von TODO 16.5). Tags der Katalog-Gruppen sind auf/abwählbar; Tags der
|
||||
/// "Nicht mehr im Katalog"-Gruppe sind immer bereits ausgewählt (es gibt keinen Katalogeintrag,
|
||||
/// dem man sie stattdessen zuordnen könnte) und lassen sich nur abwählen/entfernen.</summary>
|
||||
public static List<CompetencyTagGroup> Build(
|
||||
IReadOnlyList<CompetencyDomain> catalog, List<CompetencyReference> selected,
|
||||
Action<CompetencyTag> onChanged)
|
||||
{
|
||||
var groups = new List<CompetencyTagGroup>();
|
||||
var matchedIds = new HashSet<Guid>();
|
||||
|
||||
foreach (var domain in catalog.OrderBy(d => d.SortOrder))
|
||||
{
|
||||
var group = new CompetencyTagGroup(domain.Name, domain.Code);
|
||||
foreach (var item in domain.Items.OrderBy(i => i.SortOrder))
|
||||
{
|
||||
var isSelected = selected.Any(s => s.ItemId == item.Id);
|
||||
if (isSelected) matchedIds.Add(item.Id);
|
||||
group.Items.Add(new CompetencyTag(item.Id, item.Code, item.Description, isSelected)
|
||||
{
|
||||
OnChanged = onChanged,
|
||||
});
|
||||
}
|
||||
if (group.Items.Count > 0) groups.Add(group);
|
||||
}
|
||||
|
||||
var orphaned = selected.Where(s => !matchedIds.Contains(s.ItemId)).ToList();
|
||||
if (orphaned.Count > 0)
|
||||
{
|
||||
var group = new CompetencyTagGroup("Nicht mehr im Katalog", "");
|
||||
foreach (var reference in orphaned)
|
||||
group.Items.Add(new CompetencyTag(reference.ItemId, reference.Code, reference.Description, isSelected: true)
|
||||
{
|
||||
OnChanged = onChanged,
|
||||
});
|
||||
groups.Add(group);
|
||||
}
|
||||
|
||||
return groups;
|
||||
}
|
||||
}
|
||||
@@ -98,7 +98,7 @@ public partial class ExamDialogViewModel : ObservableObject
|
||||
// gerade eine andere Niveau-Variante (E/G/Förder) derselben Klausur anzulegen.
|
||||
SelectedNiveauName = isDuplicate ? "–" : NiveauDisplay.ToName(source.Niveau);
|
||||
foreach (var t in source.Tasks.OrderBy(t => t.Nr))
|
||||
AddTaskInternal(t.Title, t.MaxPoints, t.Weight, [.. t.CompetencyCodes]);
|
||||
AddTaskInternal(t.Title, t.MaxPoints, t.Weight, [.. t.Competencies]);
|
||||
UseWeighting = Tasks.Any(t => Math.Abs(t.Weight - 1.0) > 0.0001);
|
||||
foreach (var e in source.GradingKey.OrderByDescending(e => e.MinPercent))
|
||||
AddGradingKeyRowInternal(e.Grade, e.MinPercent);
|
||||
@@ -148,10 +148,10 @@ public partial class ExamDialogViewModel : ObservableObject
|
||||
RecomputeTotals();
|
||||
}
|
||||
|
||||
private void AddTaskInternal(string? title, double maxPoints, double weight, List<string> competencyCodes)
|
||||
private void AddTaskInternal(string? title, double maxPoints, double weight, List<CompetencyReference> competencies)
|
||||
{
|
||||
var item = new ExamTaskEditItem(title, maxPoints, weight, competencyCodes,
|
||||
BuildCompetencyTagGroups(competencyCodes))
|
||||
var item = new ExamTaskEditItem(title, maxPoints, weight, competencies,
|
||||
BuildCompetencyTagGroups(competencies))
|
||||
{
|
||||
OnChanged = RecomputeTotals,
|
||||
OnRemove = RemoveTask,
|
||||
@@ -162,19 +162,13 @@ public partial class ExamDialogViewModel : ObservableObject
|
||||
RenumberTasks();
|
||||
}
|
||||
|
||||
private List<CompetencyTagGroup> BuildCompetencyTagGroups(List<string> selectedCodes)
|
||||
private List<CompetencyTagGroup> BuildCompetencyTagGroups(List<CompetencyReference> selected)
|
||||
{
|
||||
var groups = new List<CompetencyTagGroup>();
|
||||
if (!_subjectId.HasValue) return groups;
|
||||
var selected = selectedCodes.ToHashSet();
|
||||
foreach (var domain in _competencyDomains.GetBySubjectAndGrade(_subjectId.Value, _gradeLevel, _competencyCatalogVersionId))
|
||||
{
|
||||
var group = new CompetencyTagGroup(domain.Name, domain.Code);
|
||||
foreach (var item in domain.Items.OrderBy(i => i.SortOrder))
|
||||
group.Items.Add(new CompetencyTag(item.Code, item.Description, selected.Contains(item.Code)));
|
||||
if (group.Items.Count > 0) groups.Add(group);
|
||||
}
|
||||
return groups;
|
||||
if (!_subjectId.HasValue) return [];
|
||||
var catalog = _competencyDomains.GetBySubjectAndGrade(_subjectId.Value, _gradeLevel, _competencyCatalogVersionId);
|
||||
// onChanged wird hier bewusst nicht gesetzt (bleibt null) - ExamTaskEditItem verdrahtet
|
||||
// tag.OnChanged selbst auf seinen eigenen OnCompetencyToggled-Handler, siehe Konstruktor.
|
||||
return CompetencyTagGroupBuilder.Build(catalog, selected, _ => { });
|
||||
}
|
||||
|
||||
private void RemoveTask(ExamTaskEditItem item)
|
||||
@@ -368,12 +362,12 @@ public partial class ExamTaskEditItem : ObservableObject
|
||||
[ObservableProperty] private bool _isCompetencyPanelOpen;
|
||||
[ObservableProperty] private bool _showWeight;
|
||||
|
||||
public List<string> CompetencyCodes { get; }
|
||||
public List<CompetencyReference> Competencies { get; }
|
||||
public ObservableCollection<CompetencyTagGroup> CompetencyTagGroups { get; } = [];
|
||||
|
||||
public string CompetencySummary => CompetencyCodes.Count == 0
|
||||
public string CompetencySummary => Competencies.Count == 0
|
||||
? "Keine Kompetenzen"
|
||||
: $"{CompetencyCodes.Count} Kompetenz(en)";
|
||||
: $"{Competencies.Count} Kompetenz(en)";
|
||||
|
||||
public Action? OnChanged { get; set; }
|
||||
public Action<ExamTaskEditItem>? OnRemove { get; set; }
|
||||
@@ -381,12 +375,12 @@ public partial class ExamTaskEditItem : ObservableObject
|
||||
public Action<ExamTaskEditItem>? OnMoveDown { get; set; }
|
||||
|
||||
public ExamTaskEditItem(string? title, double maxPoints, double weight,
|
||||
List<string> competencyCodes, List<CompetencyTagGroup> tagGroups)
|
||||
List<CompetencyReference> competencies, List<CompetencyTagGroup> tagGroups)
|
||||
{
|
||||
_title = title ?? "";
|
||||
_maxPoints = maxPoints;
|
||||
_weight = weight;
|
||||
CompetencyCodes = competencyCodes;
|
||||
Competencies = competencies;
|
||||
foreach (var g in tagGroups)
|
||||
{
|
||||
foreach (var tag in g.Items) tag.OnChanged = OnCompetencyToggled;
|
||||
@@ -394,10 +388,17 @@ public partial class ExamTaskEditItem : ObservableObject
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCompetencyToggled(string code, bool selected)
|
||||
private void OnCompetencyToggled(CompetencyTag tag)
|
||||
{
|
||||
if (selected) { if (!CompetencyCodes.Contains(code)) CompetencyCodes.Add(code); }
|
||||
else CompetencyCodes.Remove(code);
|
||||
if (tag.IsSelected)
|
||||
{
|
||||
if (!Competencies.Any(r => r.ItemId == tag.ItemId))
|
||||
Competencies.Add(new CompetencyReference { ItemId = tag.ItemId, Code = tag.Code, Description = tag.Description });
|
||||
}
|
||||
else
|
||||
{
|
||||
Competencies.RemoveAll(r => r.ItemId == tag.ItemId);
|
||||
}
|
||||
OnPropertyChanged(nameof(CompetencySummary));
|
||||
OnChanged?.Invoke();
|
||||
}
|
||||
@@ -415,6 +416,6 @@ public partial class ExamTaskEditItem : ObservableObject
|
||||
Title = string.IsNullOrWhiteSpace(Title) ? null : Title.Trim(),
|
||||
MaxPoints = MaxPoints,
|
||||
Weight = Weight,
|
||||
CompetencyCodes = CompetencyCodes,
|
||||
Competencies = Competencies,
|
||||
};
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public partial class ParticipationTabViewModel : ObservableObject
|
||||
[ObservableProperty] private bool _isReadOnly;
|
||||
|
||||
public string SelectedSessionDisplay => SelectedSession?.Display ?? "";
|
||||
public List<string> ActiveCompetencyCodes { get; private set; } = [];
|
||||
public List<CompetencyReference> ActiveCompetencies { get; private set; } = [];
|
||||
|
||||
public ObservableCollection<ParticipationSessionItem> Sessions { get; } = [];
|
||||
public ObservableCollection<ParticipationStudentRow> StudentRows { get; } = [];
|
||||
@@ -132,14 +132,14 @@ public partial class ParticipationTabViewModel : ObservableObject
|
||||
{
|
||||
StudentRows.Clear();
|
||||
CompetencyTagGroups.Clear();
|
||||
ActiveCompetencyCodes = [];
|
||||
ActiveCompetencies = [];
|
||||
QuickInputCommand.NotifyCanExecuteChanged();
|
||||
StatusQuickInputCommand.NotifyCanExecuteChanged();
|
||||
RebuildColumnsSignal++;
|
||||
return;
|
||||
}
|
||||
LoadCompetencyTags(value.Id); // sets ActiveCompetencyCodes first
|
||||
LoadGrid(value.Id); // uses ActiveCompetencyCodes, fires RebuildColumnsSignal++
|
||||
LoadCompetencyTags(value.Id); // sets ActiveCompetencies first
|
||||
LoadGrid(value.Id); // uses ActiveCompetencies, fires RebuildColumnsSignal++
|
||||
}
|
||||
|
||||
private void LoadGrid(Guid sessionId)
|
||||
@@ -159,7 +159,7 @@ public partial class ParticipationTabViewModel : ObservableObject
|
||||
|
||||
var entry = entries.FirstOrDefault(e => e.StudentId == s.Id)
|
||||
?? new ParticipationEntry { SessionId = sessionId, StudentId = s.Id };
|
||||
var row = new ParticipationStudentRow(s.Id, s.FullName, entry, Aspects.ToList(), ActiveCompetencyCodes);
|
||||
var row = new ParticipationStudentRow(s.Id, s.FullName, entry, Aspects.ToList(), ActiveCompetencies);
|
||||
row.OnRatingChanged = (sid, key, val) => SaveRating(sessionId, sid, key, val);
|
||||
row.OnCompetencyRatingChanged = (sid, code, val) => SaveCompetencyRating(sessionId, sid, code, val);
|
||||
row.HomeworkChangedCallback = (sid, val) => SaveHomework(sessionId, sid, val);
|
||||
@@ -237,35 +237,31 @@ public partial class ParticipationTabViewModel : ObservableObject
|
||||
{
|
||||
CompetencyTagGroups.Clear();
|
||||
var session = _sessions.GetById(sessionId);
|
||||
ActiveCompetencyCodes = session?.CompetencyCodes?.ToList() ?? [];
|
||||
ActiveCompetencies = session?.Competencies?.ToList() ?? [];
|
||||
|
||||
if (!_subjectId.HasValue) return;
|
||||
var active = ActiveCompetencyCodes.ToHashSet();
|
||||
|
||||
foreach (var domain in _competencyDomains.GetBySubjectAndGrade(_subjectId.Value, _gradeLevel, _competencyCatalogVersionId))
|
||||
{
|
||||
var group = new CompetencyTagGroup(domain.Name, domain.Code);
|
||||
foreach (var item in domain.Items.OrderBy(i => i.SortOrder))
|
||||
{
|
||||
var tag = new CompetencyTag(item.Code, item.Description, active.Contains(item.Code));
|
||||
tag.OnChanged = (code, sel) => OnTagToggled(code, sel);
|
||||
group.Items.Add(tag);
|
||||
}
|
||||
if (group.Items.Count > 0)
|
||||
CompetencyTagGroups.Add(group);
|
||||
}
|
||||
var catalog = _competencyDomains.GetBySubjectAndGrade(_subjectId.Value, _gradeLevel, _competencyCatalogVersionId);
|
||||
foreach (var group in CompetencyTagGroupBuilder.Build(catalog, ActiveCompetencies, OnTagToggled))
|
||||
CompetencyTagGroups.Add(group);
|
||||
}
|
||||
|
||||
private void OnTagToggled(string code, bool selected)
|
||||
private void OnTagToggled(CompetencyTag tag)
|
||||
{
|
||||
if (SelectedSession is null) return;
|
||||
var session = _sessions.GetById(SelectedSession.Id);
|
||||
if (session is null) return;
|
||||
if (selected) { if (!session.CompetencyCodes.Contains(code)) session.CompetencyCodes.Add(code); }
|
||||
else { session.CompetencyCodes.Remove(code); }
|
||||
if (tag.IsSelected)
|
||||
{
|
||||
if (!session.Competencies.Any(r => r.ItemId == tag.ItemId))
|
||||
session.Competencies.Add(new CompetencyReference { ItemId = tag.ItemId, Code = tag.Code, Description = tag.Description });
|
||||
}
|
||||
else
|
||||
{
|
||||
session.Competencies.RemoveAll(r => r.ItemId == tag.ItemId);
|
||||
}
|
||||
_sessions.Save(session);
|
||||
|
||||
ActiveCompetencyCodes = session.CompetencyCodes.ToList();
|
||||
ActiveCompetencies = session.Competencies.ToList();
|
||||
if (StudentCompetencyRatingsVisible)
|
||||
LoadGrid(SelectedSession.Id); // reloads rows with updated cells, fires RebuildColumnsSignal++
|
||||
}
|
||||
@@ -369,22 +365,25 @@ public partial class ParticipationTabViewModel : ObservableObject
|
||||
_entries.Save(entry);
|
||||
}
|
||||
|
||||
private void SaveCompetencyRating(Guid sessionId, Guid studentId, string code, int? value)
|
||||
// "key" ist der Kompetenz-ItemId als String (siehe ParticipationStudentRow/RatingCell) - reiner
|
||||
// In-Memory-Transport zwischen Zelle und Save-Callback, nie persistiert.
|
||||
private void SaveCompetencyRating(Guid sessionId, Guid studentId, string key, int? value)
|
||||
{
|
||||
var itemId = Guid.Parse(key);
|
||||
var entry = _entries.GetBySessionAndStudent(sessionId, studentId)
|
||||
?? new ParticipationEntry
|
||||
{
|
||||
SessionId = sessionId,
|
||||
StudentId = studentId,
|
||||
};
|
||||
var existing = entry.CompetencyRatings.FirstOrDefault(r => r.Code == code);
|
||||
var existing = entry.CompetencyRatings.FirstOrDefault(r => r.ItemId == itemId);
|
||||
if (value is null)
|
||||
{
|
||||
if (existing is not null) entry.CompetencyRatings.Remove(existing);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (existing is null) entry.CompetencyRatings.Add(new CompetencyRating { Code = code, Value = value.Value });
|
||||
if (existing is null) entry.CompetencyRatings.Add(new CompetencyRating { ItemId = itemId, Value = value.Value });
|
||||
else existing.Value = value.Value;
|
||||
}
|
||||
_entries.Save(entry);
|
||||
@@ -425,7 +424,7 @@ public partial class ParticipationStudentRow : ObservableObject
|
||||
public Action<Guid, DayHighlightKind?>? DayHighlightChangedCallback { get; set; }
|
||||
|
||||
public ParticipationStudentRow(Guid id, string name, ParticipationEntry entry,
|
||||
List<AspectColumnDef> aspects, List<string> competencyCodes)
|
||||
List<AspectColumnDef> aspects, List<CompetencyReference> competencies)
|
||||
{
|
||||
StudentId = id;
|
||||
Name = name;
|
||||
@@ -442,10 +441,12 @@ public partial class ParticipationStudentRow : ObservableObject
|
||||
Cells.Add(cell);
|
||||
}
|
||||
|
||||
foreach (var code in competencyCodes)
|
||||
// AspectKey trägt hier den Kompetenz-ItemId als String - reiner In-Memory-Transport
|
||||
// zwischen Zelle und Save-Callback (siehe SaveCompetencyRating), nie persistiert.
|
||||
foreach (var competency in competencies)
|
||||
{
|
||||
var existing = entry.CompetencyRatings.FirstOrDefault(r => r.Code == code);
|
||||
var cell = new RatingCell(id, code, existing?.Value);
|
||||
var existing = entry.CompetencyRatings.FirstOrDefault(r => r.ItemId == competency.ItemId);
|
||||
var cell = new RatingCell(id, competency.ItemId.ToString("D"), existing?.Value);
|
||||
cell.OnChanged = (sid, key, val) => OnCompetencyRatingChanged?.Invoke(sid, key, val);
|
||||
CompetencyCells.Add(cell);
|
||||
}
|
||||
@@ -726,37 +727,6 @@ public partial class RatingCell : ObservableObject
|
||||
private void UpdateLabel() => DisplayLabel = ParticipationRatingScale.DisplayLabel(Type, Value);
|
||||
}
|
||||
|
||||
// ── Kompetenz-Tags ────────────────────────────────────────────────────────────
|
||||
|
||||
public class CompetencyTagGroup(string name, string code)
|
||||
{
|
||||
public string Name { get; } = name;
|
||||
public string Code { get; } = code;
|
||||
public string DisplayName { get; } = string.IsNullOrEmpty(code) ? name : $"{name} ({code})";
|
||||
public List<CompetencyTag> Items { get; } = [];
|
||||
}
|
||||
|
||||
public partial class CompetencyTag : ObservableObject
|
||||
{
|
||||
public string Code { get; }
|
||||
public string Description { get; }
|
||||
public string Display { get; }
|
||||
|
||||
[ObservableProperty] private bool _isSelected;
|
||||
|
||||
public Action<string, bool>? OnChanged { get; set; }
|
||||
|
||||
public CompetencyTag(string code, string description, bool isSelected)
|
||||
{
|
||||
Code = code;
|
||||
Description = description;
|
||||
Display = string.IsNullOrEmpty(code) ? description : $"[{code}] {description}";
|
||||
_isSelected = isSelected;
|
||||
}
|
||||
|
||||
partial void OnIsSelectedChanged(bool value) => OnChanged?.Invoke(Code, value);
|
||||
}
|
||||
|
||||
// ── Hilfsklassen ──────────────────────────────────────────────────────────────
|
||||
|
||||
public class AspectColumnDef
|
||||
|
||||
@@ -586,7 +586,7 @@ public partial class UnitDialogViewModel : ObservableObject
|
||||
private readonly int _gradeLevel;
|
||||
private readonly Guid _competencyCatalogVersionId;
|
||||
private readonly Unit? _editingUnit;
|
||||
private readonly List<string> _competencyCodes;
|
||||
private readonly List<CompetencyReference> _competencyRefs;
|
||||
|
||||
[ObservableProperty] private string _title = "";
|
||||
[ObservableProperty] private string _startDateText = "";
|
||||
@@ -601,8 +601,8 @@ public partial class UnitDialogViewModel : ObservableObject
|
||||
|
||||
public string[] StatusOptions => UnitStatusDisplay.Options;
|
||||
public ObservableCollection<CompetencyTagGroup> CompetencyTagGroups { get; } = [];
|
||||
public string CompetencySummary => _competencyCodes.Count == 0
|
||||
? "Keine Kompetenzen" : $"{_competencyCodes.Count} Kompetenz(en)";
|
||||
public string CompetencySummary => _competencyRefs.Count == 0
|
||||
? "Keine Kompetenzen" : $"{_competencyRefs.Count} Kompetenz(en)";
|
||||
|
||||
/// Gruppe + Fach kommen von der Lerngruppe, nicht editierbar (jede Gruppe unterrichtet ein
|
||||
/// Fach) — beide zusammen zeigen, da dieselbe Klasse in mehreren Fächern (mehrere
|
||||
@@ -638,7 +638,7 @@ public partial class UnitDialogViewModel : ObservableObject
|
||||
GroupSubjectDisplay = string.IsNullOrWhiteSpace(subjectName)
|
||||
? $"{groupName} · kein Fach hinterlegt (siehe Lerngruppe)" : $"{groupName} · {subjectName}";
|
||||
|
||||
_competencyCodes = editingUnit is not null ? [.. editingUnit.Competencies] : [];
|
||||
_competencyRefs = editingUnit is not null ? [.. editingUnit.Competencies] : [];
|
||||
BuildCompetencyTagGroups();
|
||||
|
||||
if (editingUnit is not null)
|
||||
@@ -655,24 +655,22 @@ public partial class UnitDialogViewModel : ObservableObject
|
||||
{
|
||||
CompetencyTagGroups.Clear();
|
||||
if (!_subjectId.HasValue) return;
|
||||
var selected = _competencyCodes.ToHashSet();
|
||||
foreach (var domain in _competencyDomains.GetBySubjectAndGrade(_subjectId.Value, _gradeLevel, _competencyCatalogVersionId))
|
||||
{
|
||||
var group = new CompetencyTagGroup(domain.Name, domain.Code);
|
||||
foreach (var item in domain.Items.OrderBy(i => i.SortOrder))
|
||||
{
|
||||
var tag = new CompetencyTag(item.Code, item.Description, selected.Contains(item.Code));
|
||||
tag.OnChanged = OnCompetencyToggled;
|
||||
group.Items.Add(tag);
|
||||
}
|
||||
if (group.Items.Count > 0) CompetencyTagGroups.Add(group);
|
||||
}
|
||||
var catalog = _competencyDomains.GetBySubjectAndGrade(_subjectId.Value, _gradeLevel, _competencyCatalogVersionId);
|
||||
foreach (var group in CompetencyTagGroupBuilder.Build(catalog, _competencyRefs, OnCompetencyToggled))
|
||||
CompetencyTagGroups.Add(group);
|
||||
}
|
||||
|
||||
private void OnCompetencyToggled(string code, bool selected)
|
||||
private void OnCompetencyToggled(CompetencyTag tag)
|
||||
{
|
||||
if (selected) { if (!_competencyCodes.Contains(code)) _competencyCodes.Add(code); }
|
||||
else _competencyCodes.Remove(code);
|
||||
if (tag.IsSelected)
|
||||
{
|
||||
if (!_competencyRefs.Any(r => r.ItemId == tag.ItemId))
|
||||
_competencyRefs.Add(new CompetencyReference { ItemId = tag.ItemId, Code = tag.Code, Description = tag.Description });
|
||||
}
|
||||
else
|
||||
{
|
||||
_competencyRefs.RemoveAll(r => r.ItemId == tag.ItemId);
|
||||
}
|
||||
OnPropertyChanged(nameof(CompetencySummary));
|
||||
}
|
||||
|
||||
@@ -713,7 +711,7 @@ public partial class UnitDialogViewModel : ObservableObject
|
||||
Result.EndDate = endDate;
|
||||
Result.Status = UnitStatusDisplay.FromName(StatusName);
|
||||
Result.Notes = string.IsNullOrWhiteSpace(Notes) ? null : Notes.Trim();
|
||||
Result.Competencies = _competencyCodes;
|
||||
Result.Competencies = _competencyRefs;
|
||||
if (Result.Status == UnitStatus.Active)
|
||||
{
|
||||
// Pro Lerngruppe gibt es genau einen aktuellen Arbeitskontext. Frühere laufende
|
||||
|
||||
@@ -81,14 +81,14 @@ public partial class ParticipationTabView : UserControl
|
||||
});
|
||||
|
||||
// Kompetenz-Spalten (opt-in)
|
||||
if (_vm.StudentCompetencyRatingsVisible && _vm.ActiveCompetencyCodes.Count > 0)
|
||||
if (_vm.StudentCompetencyRatingsVisible && _vm.ActiveCompetencies.Count > 0)
|
||||
{
|
||||
foreach (var (code, i) in _vm.ActiveCompetencyCodes.Select((c, i) => (c, i)))
|
||||
foreach (var (competency, i) in _vm.ActiveCompetencies.Select((c, i) => (c, i)))
|
||||
{
|
||||
var idx = i;
|
||||
grid.Columns.Add(new DataGridTemplateColumn
|
||||
{
|
||||
Header = code,
|
||||
Header = string.IsNullOrEmpty(competency.Code) ? competency.Description : competency.Code,
|
||||
Width = new DataGridLength(80, DataGridLengthUnitType.Pixel),
|
||||
CellTemplate = BuildCellTemplate(idx, forCompetency: true, _vm.IsReadOnly),
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user