Automate overdue homework and show outstanding work in teaching mode
CI / build-and-test (push) Canceled after 0s
CI / build-and-test (push) Canceled after 0s
This commit is contained in:
1 parent
f3e23ad207
commit
4b73d2bea2
10 files changed
+314
-2
No files matched your search
@@ -0,0 +1,77 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using LehrerApp.Core.Interfaces;
|
||||
using LehrerApp.Core.Models;
|
||||
using LehrerApp.Core.Services;
|
||||
|
||||
namespace LehrerApp.Desktop.ViewModels.Groups;
|
||||
|
||||
public sealed record OutstandingHomeworkRow(string StudentName, DateOnly Date, HomeworkStatus Status)
|
||||
{
|
||||
public string DateLabel => Date.ToString("dd.MM.yyyy");
|
||||
public string StatusLabel => HomeworkDisplay.Label(Status);
|
||||
}
|
||||
|
||||
/// <summary>Jüngste noch fehlende Hausaufgaben der aktuellen Lerngruppe. Liest bei jedem Öffnen
|
||||
/// und auf Wunsch erneut, damit die Anwesenheit der laufenden Stunde berücksichtigt wird.</summary>
|
||||
public partial class TeachingModeOutstandingHomeworkViewModel(
|
||||
Guid groupId, DateOnly lessonDate,
|
||||
IStudentRepository students, IGroupMembershipRepository memberships,
|
||||
IParticipationSessionRepository sessions, IParticipationRepository participation) : ObservableObject
|
||||
{
|
||||
private const int LookbackDays = 120;
|
||||
private const int MaxRows = 20;
|
||||
private Guid? _currentSessionId;
|
||||
|
||||
public ObservableCollection<OutstandingHomeworkRow> Rows { get; } = [];
|
||||
public string Header => $"Offene Nachreichungen ({Rows.Count})";
|
||||
public bool HasRows => Rows.Count > 0;
|
||||
|
||||
[ObservableProperty] private bool _isExpanded;
|
||||
[ObservableProperty] private bool _includeAbsentStudents;
|
||||
|
||||
partial void OnIsExpandedChanged(bool value)
|
||||
{
|
||||
if (value) Refresh();
|
||||
}
|
||||
|
||||
partial void OnIncludeAbsentStudentsChanged(bool value) => Refresh();
|
||||
|
||||
public void SetCurrentSessionId(Guid? sessionId) => _currentSessionId = sessionId;
|
||||
|
||||
[RelayCommand]
|
||||
public void Refresh()
|
||||
{
|
||||
Rows.Clear();
|
||||
var groupMemberships = memberships.GetByGroup(groupId);
|
||||
var roster = students.GetByGroup(groupId)
|
||||
.Where(s => groupMemberships.FirstOrDefault(m => m.StudentId == s.Id) is not { } membership ||
|
||||
GroupMembershipService.IsActiveOn(membership, lessonDate))
|
||||
.ToDictionary(s => s.Id);
|
||||
|
||||
var absentIds = _currentSessionId is { } sessionId
|
||||
? participation.GetBySession(sessionId)
|
||||
.Where(e => e.Attendance is not null and not AttendanceStatus.Present
|
||||
and not AttendanceStatus.Late and not AttendanceStatus.SignificantlyLate)
|
||||
.Select(e => e.StudentId).ToHashSet()
|
||||
: [];
|
||||
|
||||
var rows = sessions.GetByGroup(groupId)
|
||||
.Where(s => s.Date < lessonDate && s.Date >= lessonDate.AddDays(-LookbackDays))
|
||||
.SelectMany(session => participation.GetBySession(session.Id)
|
||||
.Select(entry => (session.Date, Entry: entry)))
|
||||
.Where(x => roster.ContainsKey(x.Entry.StudentId) &&
|
||||
(IncludeAbsentStudents || !absentIds.Contains(x.Entry.StudentId)))
|
||||
.Select(x => (x.Date, x.Entry.StudentId, Status: HomeworkDisplay.Effective(x.Entry)))
|
||||
.Where(x => x.Status is { } status && HomeworkDisplay.CountsAsMissing(status))
|
||||
.OrderByDescending(x => x.Date)
|
||||
.ThenBy(x => roster[x.StudentId].FullName)
|
||||
.Take(MaxRows);
|
||||
|
||||
foreach (var row in rows)
|
||||
Rows.Add(new OutstandingHomeworkRow(roster[row.StudentId].FullName, row.Date, row.Status!.Value));
|
||||
OnPropertyChanged(nameof(Header));
|
||||
OnPropertyChanged(nameof(HasRows));
|
||||
}
|
||||
}
|
||||
@@ -33,10 +33,12 @@ public class TeachingModeViewModel
|
||||
/// der richtigen Sitzung starten.</summary>
|
||||
public ParticipationTabViewModel Participation { get; }
|
||||
public TeachingModeHomeworkViewModel Homework { get; }
|
||||
public TeachingModeOutstandingHomeworkViewModel? OutstandingHomework { get; }
|
||||
|
||||
public TeachingModeViewModel(Lesson lesson, LearningGroup group,
|
||||
IAlternativeLessonPathRepository alternativePaths, ILessonRepository lessons,
|
||||
SeatingPlanTabViewModel seatingPlan, ParticipationTabViewModel participation)
|
||||
SeatingPlanTabViewModel seatingPlan, ParticipationTabViewModel participation,
|
||||
TeachingModeOutstandingHomeworkViewModel? outstandingHomework = null)
|
||||
{
|
||||
GroupName = group.Name;
|
||||
Timeline = new TeachingTimelineViewModel(lesson, lessons, !group.IsActive);
|
||||
@@ -52,6 +54,16 @@ public class TeachingModeViewModel
|
||||
if (SeatingPlan.SelectedSession is { } linkedSession)
|
||||
Participation.SelectedSession =
|
||||
Participation.Sessions.FirstOrDefault(s => s.Id == linkedSession.Id);
|
||||
OutstandingHomework = outstandingHomework;
|
||||
OutstandingHomework?.SetCurrentSessionId(SeatingPlan.SelectedSession?.Id);
|
||||
OutstandingHomework?.Refresh();
|
||||
SeatingPlan.OnAssessmentChanged = () => OutstandingHomework?.Refresh();
|
||||
SeatingPlan.PropertyChanged += (_, args) =>
|
||||
{
|
||||
if (args.PropertyName != nameof(SeatingPlan.SelectedSession)) return;
|
||||
OutstandingHomework?.SetCurrentSessionId(SeatingPlan.SelectedSession?.Id);
|
||||
OutstandingHomework?.Refresh();
|
||||
};
|
||||
|
||||
// 4.5.4: dieselbe "letzte Stunde vor dieser"-Suche wie das Stundenplan-Badge
|
||||
// "Hausaufgabe kontrollieren" (TimetableViewModel.HasUnhandledHomework) - 120 Tage
|
||||
|
||||
Reference in new issue
Block a user