Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f0462bd2a1
commit
6c0a2dbd2e
6 files changed
+214
-6
No files matched your search
@@ -7,22 +7,67 @@ using LehrerApp.Core.Services;
|
||||
|
||||
namespace LehrerApp.Desktop.ViewModels.Groups;
|
||||
|
||||
public sealed record OutstandingHomeworkRow(string StudentName, DateOnly Date, HomeworkStatus Status)
|
||||
/// <summary>Eine offene Nachreichung. Die Aktionen setzen nur die Endzustände, die beim Nachreichen
|
||||
/// sinnvoll sind: nachgereicht, endgültig nicht nachgereicht oder (bei ganz fehlender Hausaufgabe)
|
||||
/// teilweise angefertigt mit endgültig fehlendem Rest.</summary>
|
||||
public sealed class OutstandingHomeworkRow
|
||||
{
|
||||
public OutstandingHomeworkRow(Guid sessionId, Guid studentId, string studentName, DateOnly date,
|
||||
HomeworkStatus status, bool canEdit, Action<OutstandingHomeworkRow, HomeworkStatus> apply)
|
||||
{
|
||||
SessionId = sessionId;
|
||||
StudentId = studentId;
|
||||
StudentName = studentName;
|
||||
Date = date;
|
||||
Status = status;
|
||||
CanEdit = canEdit;
|
||||
MarkSubmittedCommand = new RelayCommand(() => apply(this, SubmittedStatus));
|
||||
MarkFinalCommand = new RelayCommand(() => apply(this, FinalStatus));
|
||||
MarkPartialCommand = new RelayCommand(() => apply(this, HomeworkStatus.PartialMissingOverdue));
|
||||
}
|
||||
|
||||
public Guid SessionId { get; }
|
||||
public Guid StudentId { get; }
|
||||
public string StudentName { get; }
|
||||
public DateOnly Date { get; }
|
||||
public HomeworkStatus Status { get; }
|
||||
public string DateLabel => Date.ToString("dd.MM.yyyy");
|
||||
public string StatusLabel => HomeworkDisplay.Label(Status);
|
||||
|
||||
private bool IsPartial => Status is HomeworkStatus.PartiallyCompleted or HomeworkStatus.PartialMissingOverdue;
|
||||
private bool IsFinal => Status is HomeworkStatus.MissingOverdue or HomeworkStatus.PartialMissingOverdue;
|
||||
|
||||
public HomeworkStatus SubmittedStatus =>
|
||||
IsPartial ? HomeworkStatus.PartialSubmittedLate : HomeworkStatus.SubmittedLate;
|
||||
public HomeworkStatus FinalStatus =>
|
||||
IsPartial ? HomeworkStatus.PartialMissingOverdue : HomeworkStatus.MissingOverdue;
|
||||
|
||||
public string SubmittedLabel => IsPartial ? "◕ Rest nachgereicht" : "↺ Nachgereicht";
|
||||
public string FinalLabel => IsPartial ? "✕ Rest endgültig nicht" : "✕ Endgültig nicht";
|
||||
|
||||
public bool CanEdit { get; }
|
||||
public bool CanMarkFinal => CanEdit && !IsFinal;
|
||||
public bool CanMarkPartial => CanEdit && !IsPartial;
|
||||
|
||||
public IRelayCommand MarkSubmittedCommand { get; }
|
||||
public IRelayCommand MarkFinalCommand { get; }
|
||||
public IRelayCommand MarkPartialCommand { get; }
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// und auf Wunsch erneut, damit die Anwesenheit der laufenden Stunde berücksichtigt wird.
|
||||
/// Nachreichungen lassen sich direkt in der Liste abschließen, ohne die alte Sitzung zu öffnen;
|
||||
/// die jeweils letzte Änderung kann rückgängig gemacht werden.</summary>
|
||||
public partial class TeachingModeOutstandingHomeworkViewModel(
|
||||
Guid groupId, DateOnly lessonDate,
|
||||
IStudentRepository students, IGroupMembershipRepository memberships,
|
||||
IParticipationSessionRepository sessions, IParticipationRepository participation) : ObservableObject
|
||||
IParticipationSessionRepository sessions, IParticipationRepository participation,
|
||||
bool isReadOnly = false) : ObservableObject
|
||||
{
|
||||
private const int LookbackDays = 120;
|
||||
private const int MaxRows = 20;
|
||||
private Guid? _currentSessionId;
|
||||
private (Guid EntryId, Guid SessionId, Guid StudentId, HomeworkStatus? Homework, bool Missing)? _undo;
|
||||
|
||||
public ObservableCollection<OutstandingHomeworkRow> Rows { get; } = [];
|
||||
public string Header => $"Offene Nachreichungen ({Rows.Count})";
|
||||
@@ -30,6 +75,10 @@ public partial class TeachingModeOutstandingHomeworkViewModel(
|
||||
|
||||
[ObservableProperty] private bool _isExpanded;
|
||||
[ObservableProperty] private bool _includeAbsentStudents;
|
||||
[ObservableProperty] private string? _lastChangeLabel;
|
||||
|
||||
/// <summary>Wird nach jeder Statusänderung aufgerufen, damit andere Ansichten neu laden können.</summary>
|
||||
public Action? OnHomeworkChanged { get; set; }
|
||||
|
||||
partial void OnIsExpandedChanged(bool value)
|
||||
{
|
||||
@@ -63,15 +112,55 @@ public partial class TeachingModeOutstandingHomeworkViewModel(
|
||||
.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)))
|
||||
.Select(x => (x.Date, x.Entry.SessionId, 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));
|
||||
Rows.Add(new OutstandingHomeworkRow(row.SessionId, row.StudentId, roster[row.StudentId].FullName,
|
||||
row.Date, row.Status!.Value, !isReadOnly, Apply));
|
||||
OnPropertyChanged(nameof(Header));
|
||||
OnPropertyChanged(nameof(HasRows));
|
||||
}
|
||||
|
||||
public bool CanUndo => _undo is not null;
|
||||
|
||||
public void Apply(OutstandingHomeworkRow row, HomeworkStatus status)
|
||||
{
|
||||
if (isReadOnly) return;
|
||||
var entry = participation.GetBySessionAndStudent(row.SessionId, row.StudentId);
|
||||
if (entry is null) return;
|
||||
_undo = (entry.Id, entry.SessionId, entry.StudentId, entry.Homework, entry.HomeworkMissing);
|
||||
entry.Homework = status;
|
||||
entry.HomeworkMissing = HomeworkDisplay.CountsAsMissing(status);
|
||||
entry.UpdatedAt = DateTime.UtcNow;
|
||||
participation.Save(entry);
|
||||
LastChangeLabel = $"{row.StudentName} ({row.DateLabel}): {HomeworkDisplay.Label(status)}";
|
||||
OnPropertyChanged(nameof(CanUndo));
|
||||
UndoCommand.NotifyCanExecuteChanged();
|
||||
Refresh();
|
||||
OnHomeworkChanged?.Invoke();
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanUndo))]
|
||||
private void Undo()
|
||||
{
|
||||
if (_undo is not { } undo) return;
|
||||
_undo = null;
|
||||
var entry = participation.GetBySessionAndStudent(undo.SessionId, undo.StudentId);
|
||||
if (entry is not null && entry.Id == undo.EntryId)
|
||||
{
|
||||
entry.Homework = undo.Homework;
|
||||
entry.HomeworkMissing = undo.Missing;
|
||||
entry.UpdatedAt = DateTime.UtcNow;
|
||||
participation.Save(entry);
|
||||
}
|
||||
LastChangeLabel = null;
|
||||
OnPropertyChanged(nameof(CanUndo));
|
||||
UndoCommand.NotifyCanExecuteChanged();
|
||||
Refresh();
|
||||
OnHomeworkChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,8 @@ public class TeachingModeViewModel
|
||||
OutstandingHomework?.SetCurrentSessionId(SeatingPlan.SelectedSession?.Id);
|
||||
OutstandingHomework?.Refresh();
|
||||
SeatingPlan.OnAssessmentChanged = () => OutstandingHomework?.Refresh();
|
||||
if (OutstandingHomework is not null)
|
||||
OutstandingHomework.OnHomeworkChanged = Participation.RefreshCurrentGrid;
|
||||
SeatingPlan.PropertyChanged += (_, args) =>
|
||||
{
|
||||
if (args.PropertyName != nameof(SeatingPlan.SelectedSession)) return;
|
||||
|
||||
Reference in new issue
Block a user