Defuse handled dashboard warnings and add a snooze action
CI / build-and-test (push) Canceled after 0s
CI / build-and-test (push) Canceled after 0s
Cross-class warnings (attendance, homework backlog, lateness) stayed red and at the top even after being acted on. A warning now turns gray and sorts to the bottom of its group once a recently-updated open Vorgang with a matching tag exists, or once explicitly snoozed for 1/2/4 weeks. Both are time-limited: once the grace period lapses without the underlying number actually improving, the warning goes active again on the next dashboard load - no background job needed since it's just recomputed on every RebuildAttention. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3270b48850
commit
54ad7f7419
15 files changed
+421
-18
No files matched your search
@@ -49,13 +49,22 @@ public sealed class AttentionItem
|
||||
/// bei Attendance/MissingHomework/Lateness gesetzt, weil ein AttentionItem dieser Arten per
|
||||
/// Konstruktion nur entsteht, wenn der jeweilige Schwellenwert bereits überschritten ist.</summary>
|
||||
public bool IsWarningTrailing { get; }
|
||||
/// <summary>Nur bei Attendance/MissingHomework/Lateness gesetzt: ein offener Vorgang mit
|
||||
/// passendem Tag wurde kürzlich bearbeitet, oder die Warnung wurde manuell zurückgestellt (siehe
|
||||
/// DashboardViewModel.SnoozeWarningAsync) — beides zeitlich befristet, damit eine ausbleibende
|
||||
/// Besserung nach Ablauf der Frist wieder auffällt statt dauerhaft entschärft zu bleiben. Steuert
|
||||
/// nur die Optik (grau statt rot) und die Sortierung (ans Ende der Gruppe); der Schwellenwert-
|
||||
/// Vergleich selbst bleibt unverändert, die Warnung verschwindet also ganz, sobald sich die
|
||||
/// zugrunde liegende Zahl tatsächlich bessert.</summary>
|
||||
public bool IsDefused { get; }
|
||||
public IReadOnlyList<AttentionAction> Actions { get; }
|
||||
public Action? Navigate { get; }
|
||||
|
||||
public AttentionItem(AttentionKind kind, string title, string subtitle = "", string trailingText = "",
|
||||
string dateDisplay = "", bool isOverdue = false, AlertSeverity? severity = null,
|
||||
int progressPercent = 0, string progressLabel = "", bool hasProgress = false,
|
||||
bool isWarningTrailing = false, IReadOnlyList<AttentionAction>? actions = null, Action? navigate = null)
|
||||
bool isWarningTrailing = false, bool isDefused = false,
|
||||
IReadOnlyList<AttentionAction>? actions = null, Action? navigate = null)
|
||||
{
|
||||
Kind = kind;
|
||||
Title = title;
|
||||
@@ -68,6 +77,7 @@ public sealed class AttentionItem
|
||||
ProgressLabel = progressLabel;
|
||||
HasProgress = hasProgress;
|
||||
IsWarningTrailing = isWarningTrailing;
|
||||
IsDefused = isDefused;
|
||||
Actions = actions ?? [];
|
||||
Navigate = navigate;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ public partial class DashboardViewModel : ObservableObject
|
||||
private readonly IParticipationRepository _participationEntries;
|
||||
private readonly IStudentRepository _students;
|
||||
private readonly IDocumentationRepository _documentation;
|
||||
private readonly IVorgangRepository _vorgaenge;
|
||||
private readonly IDashboardWarningSnoozeRepository _warningSnoozes;
|
||||
private readonly ITimetableSlotRepository _timetableSlots;
|
||||
private readonly PeriodScheduleService _periodSchedule;
|
||||
private readonly AttendanceBalanceService _attendanceBalance;
|
||||
@@ -62,6 +64,17 @@ public partial class DashboardViewModel : ObservableObject
|
||||
/// Nutzer-Entscheidung: ab 8 Verspätungen (Late/SignificantlyLate) im laufenden Schuljahr
|
||||
/// (alle Gruppen) wird gewarnt.
|
||||
private const int LatenessWarningThreshold = 8;
|
||||
/// Nutzer-Feedback: eine Warnung, zu der bereits ein offener Vorgang mit passendem Tag existiert
|
||||
/// ODER die manuell zurückgestellt wurde, erscheint "entschärft" (grau, ans Ende der Gruppe
|
||||
/// einsortiert) statt weiter rot hervorgehoben — aber nur befristet: bessert sich die zugrunde
|
||||
/// liegende Zahl innerhalb dieser Frist nicht, soll die Warnung wieder auffallen, statt durch
|
||||
/// einen dauerhaft offenen Vorgang für immer entschärft zu bleiben. Für den Vorgang-Fall zählt
|
||||
/// dessen UpdatedAt (jede Interaktion setzt die Frist zurück); für "Zurückstellen" wählt die
|
||||
/// Nutzerin die Frist selbst (siehe OnPickSnoozeDuration).
|
||||
private const int VorgangDefusalGraceDays = 14;
|
||||
private const string AbsentismusTag = "Absentismus";
|
||||
private const string HausaufgabenTag = "Hausaufgaben";
|
||||
private const string VerspaetungenTag = "Verspätungen";
|
||||
/// Nutzer-Feedback: "ich vergesse es, und fasse die App auch außerhalb der Schule manchmal
|
||||
/// nicht mehr an" — die Erinnerung an fehlende Unterrichtszeit-Erfassung schaut deshalb nicht
|
||||
/// nur auf heute zurück, sondern auf ein paar Tage, damit ein vergessener Tag nicht verloren
|
||||
@@ -151,6 +164,9 @@ public partial class DashboardViewModel : ObservableObject
|
||||
// string vorgeschlagener Titel) — eigenes Delegate statt OnNavigateToStudent zu erweitern, damit
|
||||
// dessen übrige Aufrufer (Förderplan, Auffälligkeiten, Termine) unverändert bleiben.
|
||||
public Action<Guid, string, string>? OnNavigateToStudentCase { get; set; }
|
||||
// Fragt beim Klick auf "Zurückstellen" die gewünschte Frist ab (Anzeigetext, z.B. "Fehlzeiten –
|
||||
// Anna Beispiel") und liefert die Anzahl Tage zurück, oder null bei Abbruch.
|
||||
public Func<string, Task<int?>>? OnPickSnoozeDuration { get; set; }
|
||||
// Sprungziel eigens für eine Stunde in TodaysLessons (9.2) — bewusst getrennt von
|
||||
// OnNavigateToGroup (Lerngruppen-Kacheln, Tab "Übersicht"), da der Sprung von einer konkreten
|
||||
// Stunde aus sinnvollerweise direkt in die Mitarbeitserfassung führt.
|
||||
@@ -194,7 +210,8 @@ public partial class DashboardViewModel : ObservableObject
|
||||
IReportGradeRepository reportGrades, IGroupMembershipRepository memberships,
|
||||
IWorkTaskRepository tasks, IParticipationSessionRepository participationSessions,
|
||||
IParticipationRepository participationEntries, IStudentRepository students,
|
||||
IDocumentationRepository documentation, ITimetableSlotRepository timetableSlots,
|
||||
IDocumentationRepository documentation, IVorgangRepository vorgaenge,
|
||||
IDashboardWarningSnoozeRepository warningSnoozes, ITimetableSlotRepository timetableSlots,
|
||||
PeriodScheduleService periodSchedule, AttendanceBalanceService attendanceBalance, SchoolYearService sy,
|
||||
DashboardSettingsService dashboardSettings, ISchoolHolidayRepository schoolHolidays,
|
||||
PublicHolidayService publicHolidays, SchoolCalendarSettingsService calendarSettings,
|
||||
@@ -208,6 +225,7 @@ public partial class DashboardViewModel : ObservableObject
|
||||
_examResults = examResults; _grades = grades; _reportGrades = reportGrades; _memberships = memberships;
|
||||
_participationSessions = participationSessions; _participationEntries = participationEntries;
|
||||
_students = students; _documentation = documentation;
|
||||
_vorgaenge = vorgaenge; _warningSnoozes = warningSnoozes;
|
||||
_timetableSlots = timetableSlots; _periodSchedule = periodSchedule;
|
||||
_attendanceBalance = attendanceBalance; _sy = sy; _dashboardSettings = dashboardSettings;
|
||||
_schoolHolidays = schoolHolidays; _publicHolidays = publicHolidays; _calendarSettings = calendarSettings;
|
||||
@@ -401,6 +419,71 @@ public partial class DashboardViewModel : ObservableObject
|
||||
private Dictionary<Guid, DateOnly> BuildSessionDateLookup() =>
|
||||
_participationSessions.GetAll().ToDictionary(s => s.Id, s => s.Date);
|
||||
|
||||
// ── Entschärfen (Nutzer-Feedback) ─────────────────────────────────────────
|
||||
//
|
||||
// Eine der drei klassenübergreifenden Warnungen gilt als "entschärft" (grau, ans Ende ihrer
|
||||
// Gruppe sortiert), solange entweder ein offener Vorgang mit passendem Tag kürzlich bearbeitet
|
||||
// wurde, oder eine manuelle Rückstellung noch läuft — beides zeitlich befristet (siehe
|
||||
// VorgangDefusalGraceDays-Kommentar), damit ausbleibende Besserung nach Fristablauf wieder
|
||||
// auffällt statt dauerhaft entschärft zu bleiben. Beide Nachschlage-Mengen bulk-geladen wie
|
||||
// BuildSessionDateLookup, um kein N+1 über alle Schüler/Vorgänge zu erzeugen.
|
||||
|
||||
private HashSet<(Guid StudentId, string Tag)> BuildRecentVorgangTagSet()
|
||||
{
|
||||
var cutoffUtc = DateTime.UtcNow.AddDays(-VorgangDefusalGraceDays);
|
||||
var set = new HashSet<(Guid, string)>();
|
||||
foreach (var v in _vorgaenge.GetAll())
|
||||
{
|
||||
if (v.Status != VorgangStatus.Open) continue;
|
||||
// Siehe CLAUDE.md (LiteDB-Details): DateTime-Vergleiche nach dem Utc→Local-Roundtrip
|
||||
// sind nur nach beidseitigem ToUniversalTime() sicher.
|
||||
if (v.UpdatedAt.ToUniversalTime() < cutoffUtc) continue;
|
||||
foreach (var studentId in v.StudentIds)
|
||||
foreach (var tag in v.Tags)
|
||||
set.Add((studentId, tag.ToLowerInvariant()));
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
private HashSet<(Guid StudentId, string Tag)> BuildActiveSnoozeSet(DateOnly today) =>
|
||||
_warningSnoozes.GetAll().Where(s => s.SnoozedUntil >= today)
|
||||
.Select(s => (s.StudentId, s.WarningTag.ToLowerInvariant())).ToHashSet();
|
||||
|
||||
private static bool IsDefused(Guid studentId, string tag,
|
||||
HashSet<(Guid StudentId, string Tag)> recentVorgaenge, HashSet<(Guid StudentId, string Tag)> activeSnoozes)
|
||||
{
|
||||
var key = (studentId, tag.ToLowerInvariant());
|
||||
return recentVorgaenge.Contains(key) || activeSnoozes.Contains(key);
|
||||
}
|
||||
|
||||
/// Von der "Zurückstellen"-Aktion einer Warnung aufgerufen (siehe ToAttentionItem-Überladungen
|
||||
/// unten) — fragt über OnPickSnoozeDuration die Frist ab und speichert sie, sofern nicht
|
||||
/// abgebrochen. Aktualisiert danach nur die drei klassenübergreifenden Warnungen neu, kein
|
||||
/// voller Dashboard-Reload nötig (gleiches Muster wie ResolveExcuse/AddMissingTeachingTime).
|
||||
private async Task SnoozeWarningAsync(Guid studentId, string tag, string label)
|
||||
{
|
||||
if (OnPickSnoozeDuration is null) return;
|
||||
var days = await OnPickSnoozeDuration(label);
|
||||
if (days is null) return;
|
||||
|
||||
var snooze = _warningSnoozes.Get(studentId, tag) ?? new DashboardWarningSnooze
|
||||
{ StudentId = studentId, WarningTag = tag };
|
||||
snooze.SnoozedUntil = DateOnly.FromDateTime(_now()).AddDays(days.Value);
|
||||
_warningSnoozes.Save(snooze);
|
||||
|
||||
var today = DateOnly.FromDateTime(_now());
|
||||
LoadAttendanceWarnings(today);
|
||||
LoadMissingHomeworkWarnings(today);
|
||||
LoadLatenessWarnings(today);
|
||||
RebuildAttention();
|
||||
UpdateDashboardSummary();
|
||||
}
|
||||
|
||||
private AttentionAction SnoozeAction(Guid studentId, string tag, string label) => new("Zurückstellen",
|
||||
new AsyncRelayCommand(() => SnoozeWarningAsync(studentId, tag, label)));
|
||||
|
||||
// ── Fehlzeiten-Warnung (5.2.3) ────────────────────────────────────────────
|
||||
|
||||
private void LoadAttendanceWarnings(DateOnly today)
|
||||
{
|
||||
_attendanceItems.Clear();
|
||||
@@ -408,6 +491,8 @@ public partial class DashboardViewModel : ObservableObject
|
||||
var from = _sy.SchoolYearStart(schoolYear);
|
||||
var to = _sy.SchoolYearEnd(schoolYear);
|
||||
var sessionDates = BuildSessionDateLookup();
|
||||
var recentVorgaenge = BuildRecentVorgangTagSet();
|
||||
var activeSnoozes = BuildActiveSnoozeSet(today);
|
||||
|
||||
var items = new List<AttendanceWarningItem>();
|
||||
foreach (var student in _students.GetAll())
|
||||
@@ -422,14 +507,18 @@ public partial class DashboardViewModel : ObservableObject
|
||||
if (balance.TotalChecked >= AttendanceMinSampleSize && balance.ExceedsThreshold)
|
||||
items.Add(new AttendanceWarningItem(student.Id, student.FullName, balance.AbsenceRatePercent));
|
||||
}
|
||||
foreach (var item in items.OrderByDescending(i => i.AbsenceRatePercent))
|
||||
_attendanceItems.Add(ToAttentionItem(item));
|
||||
var ordered = items
|
||||
.Select(i => (Item: i, Defused: IsDefused(i.StudentId, AbsentismusTag, recentVorgaenge, activeSnoozes)))
|
||||
.OrderBy(x => x.Defused).ThenByDescending(x => x.Item.AbsenceRatePercent);
|
||||
foreach (var (item, defused) in ordered)
|
||||
_attendanceItems.Add(ToAttentionItem(item, defused));
|
||||
}
|
||||
|
||||
private AttentionItem ToAttentionItem(AttendanceWarningItem w) => new(
|
||||
private AttentionItem ToAttentionItem(AttendanceWarningItem w, bool isDefused) => new(
|
||||
AttentionKind.Attendance, w.StudentName, trailingText: $"{w.AbsenceRatePercent:0.#} %",
|
||||
isWarningTrailing: true,
|
||||
navigate: () => OnNavigateToStudentCase?.Invoke(w.StudentId, "Absentismus", "Fehlzeiten"));
|
||||
isWarningTrailing: true, isDefused: isDefused,
|
||||
actions: [SnoozeAction(w.StudentId, AbsentismusTag, $"Fehlzeiten – {w.StudentName}")],
|
||||
navigate: () => OnNavigateToStudentCase?.Invoke(w.StudentId, AbsentismusTag, "Fehlzeiten"));
|
||||
|
||||
// ── Hausaufgaben-Warnung (Nutzer-Feedback: analog zur Fehlzeiten-Warnung, klassenübergreifend) ──
|
||||
|
||||
@@ -440,6 +529,8 @@ public partial class DashboardViewModel : ObservableObject
|
||||
var from = _sy.SchoolYearStart(schoolYear);
|
||||
var to = _sy.SchoolYearEnd(schoolYear);
|
||||
var sessionDates = BuildSessionDateLookup();
|
||||
var recentVorgaenge = BuildRecentVorgangTagSet();
|
||||
var activeSnoozes = BuildActiveSnoozeSet(today);
|
||||
|
||||
var items = new List<MissingHomeworkWarningItem>();
|
||||
foreach (var student in _students.GetAll())
|
||||
@@ -450,14 +541,18 @@ public partial class DashboardViewModel : ObservableObject
|
||||
if (count >= MissingHomeworkWarningThreshold)
|
||||
items.Add(new MissingHomeworkWarningItem(student.Id, student.FullName, count));
|
||||
}
|
||||
foreach (var item in items.OrderByDescending(i => i.MissingCount))
|
||||
_missingHomeworkItems.Add(ToAttentionItem(item));
|
||||
var ordered = items
|
||||
.Select(i => (Item: i, Defused: IsDefused(i.StudentId, HausaufgabenTag, recentVorgaenge, activeSnoozes)))
|
||||
.OrderBy(x => x.Defused).ThenByDescending(x => x.Item.MissingCount);
|
||||
foreach (var (item, defused) in ordered)
|
||||
_missingHomeworkItems.Add(ToAttentionItem(item, defused));
|
||||
}
|
||||
|
||||
private AttentionItem ToAttentionItem(MissingHomeworkWarningItem w) => new(
|
||||
private AttentionItem ToAttentionItem(MissingHomeworkWarningItem w, bool isDefused) => new(
|
||||
AttentionKind.MissingHomework, w.StudentName, trailingText: $"{w.MissingCount} offen",
|
||||
isWarningTrailing: true,
|
||||
navigate: () => OnNavigateToStudentCase?.Invoke(w.StudentId, "Hausaufgaben", "Hausaufgaben"));
|
||||
isWarningTrailing: true, isDefused: isDefused,
|
||||
actions: [SnoozeAction(w.StudentId, HausaufgabenTag, $"Hausaufgaben – {w.StudentName}")],
|
||||
navigate: () => OnNavigateToStudentCase?.Invoke(w.StudentId, HausaufgabenTag, "Hausaufgaben"));
|
||||
|
||||
// ── Verspätungs-Warnung (Nutzer-Feedback: analog zur Fehlzeiten-Warnung, klassenübergreifend) ──
|
||||
//
|
||||
@@ -472,6 +567,8 @@ public partial class DashboardViewModel : ObservableObject
|
||||
var from = _sy.SchoolYearStart(schoolYear);
|
||||
var to = _sy.SchoolYearEnd(schoolYear);
|
||||
var sessionDates = BuildSessionDateLookup();
|
||||
var recentVorgaenge = BuildRecentVorgangTagSet();
|
||||
var activeSnoozes = BuildActiveSnoozeSet(today);
|
||||
|
||||
var items = new List<LatenessWarningItem>();
|
||||
foreach (var student in _students.GetAll())
|
||||
@@ -482,14 +579,18 @@ public partial class DashboardViewModel : ObservableObject
|
||||
if (count >= LatenessWarningThreshold)
|
||||
items.Add(new LatenessWarningItem(student.Id, student.FullName, count));
|
||||
}
|
||||
foreach (var item in items.OrderByDescending(i => i.LateCount))
|
||||
_latenessItems.Add(ToAttentionItem(item));
|
||||
var ordered = items
|
||||
.Select(i => (Item: i, Defused: IsDefused(i.StudentId, VerspaetungenTag, recentVorgaenge, activeSnoozes)))
|
||||
.OrderBy(x => x.Defused).ThenByDescending(x => x.Item.LateCount);
|
||||
foreach (var (item, defused) in ordered)
|
||||
_latenessItems.Add(ToAttentionItem(item, defused));
|
||||
}
|
||||
|
||||
private AttentionItem ToAttentionItem(LatenessWarningItem w) => new(
|
||||
private AttentionItem ToAttentionItem(LatenessWarningItem w, bool isDefused) => new(
|
||||
AttentionKind.Lateness, w.StudentName, trailingText: $"{w.LateCount}× verspätet",
|
||||
isWarningTrailing: true,
|
||||
navigate: () => OnNavigateToStudentCase?.Invoke(w.StudentId, "Verspätungen", "Verspätungen"));
|
||||
isWarningTrailing: true, isDefused: isDefused,
|
||||
actions: [SnoozeAction(w.StudentId, VerspaetungenTag, $"Verspätungen – {w.StudentName}")],
|
||||
navigate: () => OnNavigateToStudentCase?.Invoke(w.StudentId, VerspaetungenTag, "Verspätungen"));
|
||||
|
||||
// ── Klausurwochen (Nutzer-Feedback) ───────────────────────────────────────
|
||||
//
|
||||
|
||||
Reference in new issue
Block a user