Schüler hinzufügen, Kompetenzen
This commit is contained in:
@@ -3,6 +3,7 @@ using CommunityToolkit.Mvvm.Input;
|
||||
using LehrerApp.Core.Interfaces;
|
||||
using LehrerApp.Core.Models;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LehrerApp.Desktop.ViewModels.Groups;
|
||||
|
||||
@@ -14,18 +15,29 @@ public partial class ParticipationTabViewModel : ObservableObject
|
||||
private readonly IParticipationRepository _entries;
|
||||
private readonly IParticipationAspectRepository _aspects;
|
||||
private readonly IStudentRepository _students;
|
||||
private readonly IEnrollmentRepository _enrollments;
|
||||
private readonly IGroupRepository _groups;
|
||||
private readonly ICompetencyDomainRepository _competencyDomains;
|
||||
|
||||
private Guid _groupId;
|
||||
private string _schoolYear = "";
|
||||
private Guid? _subjectId;
|
||||
private int _gradeLevel;
|
||||
|
||||
[ObservableProperty] private ParticipationSessionItem? _selectedSession;
|
||||
[ObservableProperty] private string _noDataText = "Keine Bewertungssitzung ausgewählt.";
|
||||
[ObservableProperty] private bool _competencyTagsVisible;
|
||||
[ObservableProperty] private bool _hasCompetencyCatalog;
|
||||
[ObservableProperty] private bool _studentCompetencyRatingsVisible;
|
||||
[ObservableProperty] private int _rebuildColumnsSignal;
|
||||
|
||||
public string SelectedSessionDisplay => SelectedSession?.Display ?? "";
|
||||
public List<string> ActiveCompetencyCodes { get; private set; } = [];
|
||||
|
||||
public ObservableCollection<ParticipationSessionItem> Sessions { get; } = [];
|
||||
public ObservableCollection<ParticipationStudentRow> StudentRows { get; } = [];
|
||||
public ObservableCollection<AspectColumnDef> Aspects { get; } = [];
|
||||
public ObservableCollection<ParticipationSessionItem> Sessions { get; } = [];
|
||||
public ObservableCollection<ParticipationStudentRow> StudentRows { get; } = [];
|
||||
public ObservableCollection<AspectColumnDef> Aspects { get; } = [];
|
||||
public ObservableCollection<CompetencyTagGroup> CompetencyTagGroups { get; } = [];
|
||||
|
||||
public Func<Task<ParticipationSession?>>? OnAddSession { get; set; }
|
||||
public Func<ParticipationTabViewModel, Task>? OnQuickInput { get; set; }
|
||||
@@ -34,16 +46,29 @@ public partial class ParticipationTabViewModel : ObservableObject
|
||||
IParticipationSessionRepository sessions,
|
||||
IParticipationRepository entries,
|
||||
IParticipationAspectRepository aspects,
|
||||
IStudentRepository students)
|
||||
IStudentRepository students,
|
||||
IEnrollmentRepository enrollments,
|
||||
IGroupRepository groups,
|
||||
ICompetencyDomainRepository competencyDomains)
|
||||
{
|
||||
_sessions = sessions; _entries = entries;
|
||||
_aspects = aspects; _students = students;
|
||||
_sessions = sessions; _entries = entries;
|
||||
_aspects = aspects; _students = students;
|
||||
_enrollments = enrollments; _groups = groups;
|
||||
_competencyDomains = competencyDomains;
|
||||
}
|
||||
|
||||
public void Initialize(Guid groupId, string schoolYear)
|
||||
{
|
||||
_groupId = groupId;
|
||||
_schoolYear = schoolYear;
|
||||
|
||||
var group = _groups.GetById(groupId);
|
||||
_subjectId = group?.SubjectId;
|
||||
_gradeLevel = group?.GradeLevel ?? 0;
|
||||
|
||||
HasCompetencyCatalog = _subjectId.HasValue
|
||||
&& _competencyDomains.GetBySubjectAndGrade(_subjectId.Value, _gradeLevel).Count > 0;
|
||||
|
||||
LoadAspects();
|
||||
LoadSessions();
|
||||
}
|
||||
@@ -78,27 +103,54 @@ public partial class ParticipationTabViewModel : ObservableObject
|
||||
partial void OnSelectedSessionChanged(ParticipationSessionItem? value)
|
||||
{
|
||||
OnPropertyChanged(nameof(SelectedSessionDisplay));
|
||||
if (value is null) { StudentRows.Clear(); QuickInputCommand.NotifyCanExecuteChanged(); return; }
|
||||
LoadGrid(value.Id);
|
||||
if (value is null)
|
||||
{
|
||||
StudentRows.Clear();
|
||||
CompetencyTagGroups.Clear();
|
||||
ActiveCompetencyCodes = [];
|
||||
QuickInputCommand.NotifyCanExecuteChanged();
|
||||
RebuildColumnsSignal++;
|
||||
return;
|
||||
}
|
||||
LoadCompetencyTags(value.Id); // sets ActiveCompetencyCodes first
|
||||
LoadGrid(value.Id); // uses ActiveCompetencyCodes, fires RebuildColumnsSignal++
|
||||
}
|
||||
|
||||
private void LoadGrid(Guid sessionId)
|
||||
{
|
||||
StudentRows.Clear();
|
||||
var students = _students.GetByGroup(_groupId, _schoolYear);
|
||||
var entries = _entries.GetBySession(sessionId);
|
||||
var session = _sessions.GetById(sessionId);
|
||||
var sessionDate = session?.Date ?? DateOnly.FromDateTime(DateTime.Today);
|
||||
var students = _students.GetByGroup(_groupId, _schoolYear);
|
||||
var enrollments = _enrollments.GetByGroupAndYear(_groupId, _schoolYear);
|
||||
var entries = _entries.GetBySession(sessionId);
|
||||
|
||||
foreach (var s in students)
|
||||
{
|
||||
var enrollment = enrollments.FirstOrDefault(e => e.StudentId == s.Id);
|
||||
if (enrollment is not null && !IsEnrolledAtDate(enrollment, sessionDate))
|
||||
continue;
|
||||
|
||||
var entry = entries.FirstOrDefault(e => e.StudentId == s.Id)
|
||||
?? new ParticipationEntry { SessionId = sessionId, GroupId = _groupId, StudentId = s.Id };
|
||||
var row = new ParticipationStudentRow(s.Id, s.FullName, entry, Aspects.ToList());
|
||||
row.OnRatingChanged = (studentId, key, val) => SaveRating(sessionId, studentId, key, val);
|
||||
var row = new ParticipationStudentRow(s.Id, s.FullName, entry, Aspects.ToList(), ActiveCompetencyCodes);
|
||||
row.OnRatingChanged = (sid, key, val) => SaveRating(sessionId, sid, key, val);
|
||||
row.OnCompetencyRatingChanged = (sid, code, val) => SaveCompetencyRating(sessionId, sid, code, val);
|
||||
StudentRows.Add(row);
|
||||
}
|
||||
QuickInputCommand.NotifyCanExecuteChanged();
|
||||
RebuildColumnsSignal++;
|
||||
}
|
||||
|
||||
private static bool IsEnrolledAtDate(Enrollment e, DateOnly date) => e.Period switch
|
||||
{
|
||||
EnrollmentPeriod.H1Only => date.Month >= 8 || date.Month <= 1,
|
||||
EnrollmentPeriod.H2Only => date.Month >= 2 && date.Month <= 7,
|
||||
EnrollmentPeriod.Custom => (e.JoinedAt is null || date >= e.JoinedAt.Value)
|
||||
&& (e.LeftAt is null || date <= e.LeftAt.Value),
|
||||
_ => true,
|
||||
};
|
||||
|
||||
private void SaveRating(Guid sessionId, Guid studentId, string key, int? value)
|
||||
{
|
||||
var session = _sessions.GetById(sessionId);
|
||||
@@ -124,6 +176,53 @@ public partial class ParticipationTabViewModel : ObservableObject
|
||||
_entries.Save(entry);
|
||||
}
|
||||
|
||||
public void RefreshCurrentGrid()
|
||||
{
|
||||
if (SelectedSession is not null) LoadGrid(SelectedSession.Id);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void ToggleCompetencyTags() => CompetencyTagsVisible = !CompetencyTagsVisible;
|
||||
|
||||
partial void OnStudentCompetencyRatingsVisibleChanged(bool value) => RebuildColumnsSignal++;
|
||||
|
||||
private void LoadCompetencyTags(Guid sessionId)
|
||||
{
|
||||
CompetencyTagGroups.Clear();
|
||||
var session = _sessions.GetById(sessionId);
|
||||
ActiveCompetencyCodes = session?.CompetencyCodes?.ToList() ?? [];
|
||||
|
||||
if (!_subjectId.HasValue) return;
|
||||
var active = ActiveCompetencyCodes.ToHashSet();
|
||||
|
||||
foreach (var domain in _competencyDomains.GetBySubjectAndGrade(_subjectId.Value, _gradeLevel))
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTagToggled(string code, bool selected)
|
||||
{
|
||||
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); }
|
||||
_sessions.Save(session);
|
||||
|
||||
ActiveCompetencyCodes = session.CompetencyCodes.ToList();
|
||||
if (StudentCompetencyRatingsVisible)
|
||||
LoadGrid(SelectedSession.Id); // reloads rows with updated cells, fires RebuildColumnsSignal++
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task AddSession()
|
||||
{
|
||||
@@ -132,7 +231,10 @@ public partial class ParticipationTabViewModel : ObservableObject
|
||||
if (session is null) return;
|
||||
session.GroupId = _groupId;
|
||||
_sessions.Save(session);
|
||||
LoadSessions();
|
||||
|
||||
Sessions.Clear();
|
||||
foreach (var s in _sessions.GetByGroup(_groupId))
|
||||
Sessions.Add(new ParticipationSessionItem(s));
|
||||
SelectedSession = Sessions.FirstOrDefault(s => s.Id == session.Id);
|
||||
}
|
||||
|
||||
@@ -161,6 +263,30 @@ public partial class ParticipationTabViewModel : ObservableObject
|
||||
entry.Note = note;
|
||||
_entries.Save(entry);
|
||||
}
|
||||
|
||||
private void SaveCompetencyRating(Guid sessionId, Guid studentId, string code, int? value)
|
||||
{
|
||||
var session = _sessions.GetById(sessionId);
|
||||
var entry = _entries.GetBySessionAndStudent(sessionId, studentId)
|
||||
?? new ParticipationEntry
|
||||
{
|
||||
SessionId = sessionId,
|
||||
GroupId = _groupId,
|
||||
StudentId = studentId,
|
||||
Date = session?.Date ?? DateOnly.FromDateTime(DateTime.Today),
|
||||
};
|
||||
var existing = entry.CompetencyRatings.FirstOrDefault(r => r.Code == code);
|
||||
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 });
|
||||
else existing.Value = value.Value;
|
||||
}
|
||||
_entries.Save(entry);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Zeilendaten für das Bewertungsraster ─────────────────────────────────────
|
||||
@@ -170,17 +296,21 @@ public partial class ParticipationStudentRow : ObservableObject
|
||||
public Guid StudentId { get; }
|
||||
public string Name { get; }
|
||||
|
||||
private readonly ParticipationEntry _entry;
|
||||
private readonly ParticipationEntry _entry;
|
||||
private readonly IReadOnlyList<AspectColumnDef> _aspectDefs;
|
||||
|
||||
public ObservableCollection<RatingCell> Cells { get; } = [];
|
||||
public Action<Guid, string, int?>? OnRatingChanged { get; set; }
|
||||
public ObservableCollection<RatingCell> Cells { get; } = [];
|
||||
public ObservableCollection<RatingCell> CompetencyCells { get; } = [];
|
||||
|
||||
public ParticipationStudentRow(Guid id, string name, ParticipationEntry entry, List<AspectColumnDef> aspects)
|
||||
public Action<Guid, string, int?>? OnRatingChanged { get; set; }
|
||||
public Action<Guid, string, int?>? OnCompetencyRatingChanged { get; set; }
|
||||
|
||||
public ParticipationStudentRow(Guid id, string name, ParticipationEntry entry,
|
||||
List<AspectColumnDef> aspects, List<string> competencyCodes)
|
||||
{
|
||||
StudentId = id;
|
||||
Name = name;
|
||||
_entry = entry;
|
||||
StudentId = id;
|
||||
Name = name;
|
||||
_entry = entry;
|
||||
_aspectDefs = aspects;
|
||||
|
||||
foreach (var a in aspects)
|
||||
@@ -190,6 +320,14 @@ public partial class ParticipationStudentRow : ObservableObject
|
||||
cell.OnChanged = (sid, key, val) => OnRatingChanged?.Invoke(sid, key, val);
|
||||
Cells.Add(cell);
|
||||
}
|
||||
|
||||
foreach (var code in competencyCodes)
|
||||
{
|
||||
var existing = entry.CompetencyRatings.FirstOrDefault(r => r.Code == code);
|
||||
var cell = new RatingCell(id, code, existing?.Value);
|
||||
cell.OnChanged = (sid, key, val) => OnCompetencyRatingChanged?.Invoke(sid, key, val);
|
||||
CompetencyCells.Add(cell);
|
||||
}
|
||||
}
|
||||
|
||||
public int? GetRating(string key) =>
|
||||
@@ -258,6 +396,37 @@ public partial class RatingCell : ObservableObject
|
||||
};
|
||||
}
|
||||
|
||||
// ── 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
|
||||
|
||||
Reference in New Issue
Block a user