Kapitel 3.1: Mitarbeit-Aspekte pro Gruppe verwalten (3.1.1/3.1.2/3.1.4)
Neuer Button "Aspekte verwalten" im Mitarbeit-Tab öffnet ParticipationAspectsDialog: Anlegen, Bezeichnung/Typ/Gewichtung/Aktiv-Status bearbeiten (speichert sofort, gleiches Muster wie die bestehende Gewichtungs-Bearbeitung in 3.2.1), Hoch/Runter-Reihenfolge, Löschen mit Rückfrage. Verwaltet bewusst nur die gruppenspezifischen Aspekte, nicht den bislang nirgends befüllten globalen Standardkatalog. Schlüssel ist nur beim Neuanlegen editierbar - er verknüpft AspectRating mit dem Aspekt per Key, ein nachträgliches Umbenennen würde historische Bewertungen unauffindbar machen. IParticipationAspectRepository.Save validiert jetzt Pflichtfelder und Schlüssel-Eindeutigkeit gegen globale Standards UND eigene Gruppen-Aspekte zusammen, da beide im Bewertungsraster kombiniert verwendet werden. Neue GetAllByGroup-Methode (inkl. inaktiver) für die Verwaltungsansicht. 3.1.3 (Scale3/Binary/Points im Bewertungsraster selbst) bewusst nicht angefasst - eigener, größerer Eingriff in die Bewertungs-UI. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -160,6 +160,9 @@ public interface IParticipationAspectRepository
|
||||
{
|
||||
List<ParticipationAspect> GetDefaults();
|
||||
List<ParticipationAspect> GetByGroup(Guid groupId);
|
||||
// Wie GetByGroup, aber inkl. deaktivierter Aspekte — für die Verwaltungsansicht (3.1),
|
||||
// damit ein deaktivierter Aspekt dort sichtbar bleibt und wieder aktiviert werden kann.
|
||||
List<ParticipationAspect> GetAllByGroup(Guid groupId);
|
||||
void Save(ParticipationAspect aspect);
|
||||
void Delete(Guid id);
|
||||
}
|
||||
|
||||
@@ -376,6 +376,58 @@ public sealed class RepositoryTests
|
||||
Assert.Null(repo.GetById(subject.Id));
|
||||
}
|
||||
|
||||
// ── ParticipationAspectRepository (3.1) ───────────────────────────────────
|
||||
|
||||
[Fact]
|
||||
public void ParticipationAspectRepository_Save_LehntLeerenSchluesselUndBezeichnungAb()
|
||||
{
|
||||
using var db = NewInMemoryContext();
|
||||
var repo = new ParticipationAspectRepository(db);
|
||||
var groupId = Guid.NewGuid();
|
||||
|
||||
Assert.Throws<ArgumentException>(() => repo.Save(new ParticipationAspect { GroupId = groupId, Key = " ", Label = "Experiment" }));
|
||||
Assert.Throws<ArgumentException>(() => repo.Save(new ParticipationAspect { GroupId = groupId, Key = "experiment", Label = " " }));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParticipationAspectRepository_Save_LehntDuplikatSchluesselInnerhalbDerGruppeAb()
|
||||
{
|
||||
using var db = NewInMemoryContext();
|
||||
var repo = new ParticipationAspectRepository(db);
|
||||
var groupId = Guid.NewGuid();
|
||||
repo.Save(new ParticipationAspect { GroupId = groupId, Key = "experiment", Label = "Experiment" });
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
repo.Save(new ParticipationAspect { GroupId = groupId, Key = "Experiment", Label = "Anderes Label" }));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParticipationAspectRepository_Save_LehntDuplikatGegenGlobalenStandardAb()
|
||||
{
|
||||
using var db = NewInMemoryContext();
|
||||
var repo = new ParticipationAspectRepository(db);
|
||||
var groupId = Guid.NewGuid();
|
||||
repo.Save(new ParticipationAspect { GroupId = null, Key = "quality", Label = "Qualität" });
|
||||
|
||||
// Gleicher Schlüssel wie ein globaler Standardaspekt wäre in der Bewertungsübersicht
|
||||
// dieser Gruppe eine mehrdeutige Spalte (siehe ParticipationTabViewModel.LoadAspects).
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
repo.Save(new ParticipationAspect { GroupId = groupId, Key = "quality", Label = "Andere Qualität" }));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ParticipationAspectRepository_GetByGroup_FiltertInaktiveAus_GetAllByGroupNicht()
|
||||
{
|
||||
using var db = NewInMemoryContext();
|
||||
var repo = new ParticipationAspectRepository(db);
|
||||
var groupId = Guid.NewGuid();
|
||||
repo.Save(new ParticipationAspect { GroupId = groupId, Key = "a", Label = "Aktiv", IsActive = true });
|
||||
repo.Save(new ParticipationAspect { GroupId = groupId, Key = "b", Label = "Inaktiv", IsActive = false });
|
||||
|
||||
Assert.Single(repo.GetByGroup(groupId));
|
||||
Assert.Equal(2, repo.GetAllByGroup(groupId).Count);
|
||||
}
|
||||
|
||||
// ── GradingSchemeRepository ───────────────────────────────────────────────
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -439,9 +439,24 @@ public class ParticipationAspectRepository(LiteDbContext db) : IParticipationAsp
|
||||
db.ParticipationAspects.Find(a => a.GroupId == null && a.IsActive).OrderBy(a => a.SortOrder).ToList();
|
||||
public List<ParticipationAspect> GetByGroup(Guid groupId) =>
|
||||
db.ParticipationAspects.Find(a => a.GroupId == groupId && a.IsActive).OrderBy(a => a.SortOrder).ToList();
|
||||
public List<ParticipationAspect> GetAllByGroup(Guid groupId) =>
|
||||
db.ParticipationAspects.Find(a => a.GroupId == groupId).OrderBy(a => a.SortOrder).ToList();
|
||||
public void Save(ParticipationAspect a)
|
||||
{
|
||||
if (a.GroupId is Guid groupId) ArchivedGroupWriteGuard.EnsureActive(db, groupId);
|
||||
a.Key = a.Key.Trim();
|
||||
a.Label = a.Label.Trim();
|
||||
if (a.Key.Length == 0) throw new ArgumentException("Der Schlüssel darf nicht leer sein.");
|
||||
if (a.Label.Length == 0) throw new ArgumentException("Die Bezeichnung darf nicht leer sein.");
|
||||
// Ein Schlüssel muss innerhalb dessen, was für eine Gruppe tatsächlich gilt, eindeutig
|
||||
// sein — das sind die globalen Standardaspekte UND die gruppenspezifischen zusammen
|
||||
// (siehe ParticipationTabViewModel.LoadAspects, das beide konkateniert). Sonst entstünde
|
||||
// in der Bewertungsübersicht eine mehrdeutige Spalte mit identischem Schlüssel.
|
||||
var relevant = db.ParticipationAspects.Find(x => x.GroupId == null || x.GroupId == a.GroupId);
|
||||
var duplicate = relevant.FirstOrDefault(x =>
|
||||
x.Id != a.Id && string.Equals(x.Key, a.Key, StringComparison.OrdinalIgnoreCase));
|
||||
if (duplicate is not null)
|
||||
throw new InvalidOperationException("Ein Aspekt mit diesem Schlüssel existiert für diese Gruppe bereits.");
|
||||
a.UpdatedAt = DateTime.UtcNow;
|
||||
db.ParticipationAspects.Upsert(a);
|
||||
}
|
||||
|
||||
@@ -87,10 +87,25 @@ public class FakeEntries : IParticipationRepository
|
||||
|
||||
public class FakeAspects : IParticipationAspectRepository
|
||||
{
|
||||
public List<ParticipationAspect> GetDefaults() => [];
|
||||
public List<ParticipationAspect> GetByGroup(Guid groupId) => [];
|
||||
public void Save(ParticipationAspect aspect) { }
|
||||
public void Delete(Guid id) { }
|
||||
private readonly List<ParticipationAspect> _all = [];
|
||||
public List<ParticipationAspect> GetDefaults() =>
|
||||
_all.Where(a => a.GroupId == null && a.IsActive).OrderBy(a => a.SortOrder).ToList();
|
||||
public List<ParticipationAspect> GetByGroup(Guid groupId) =>
|
||||
_all.Where(a => a.GroupId == groupId && a.IsActive).OrderBy(a => a.SortOrder).ToList();
|
||||
public List<ParticipationAspect> GetAllByGroup(Guid groupId) =>
|
||||
_all.Where(a => a.GroupId == groupId).OrderBy(a => a.SortOrder).ToList();
|
||||
public void Save(ParticipationAspect a)
|
||||
{
|
||||
a.Key = a.Key.Trim(); a.Label = a.Label.Trim();
|
||||
if (a.Key.Length == 0) throw new ArgumentException("Der Schlüssel darf nicht leer sein.");
|
||||
if (a.Label.Length == 0) throw new ArgumentException("Die Bezeichnung darf nicht leer sein.");
|
||||
var duplicate = _all.Where(x => x.GroupId == null || x.GroupId == a.GroupId)
|
||||
.FirstOrDefault(x => x.Id != a.Id && string.Equals(x.Key, a.Key, StringComparison.OrdinalIgnoreCase));
|
||||
if (duplicate is not null) throw new InvalidOperationException("Ein Aspekt mit diesem Schlüssel existiert für diese Gruppe bereits.");
|
||||
_all.RemoveAll(x => x.Id == a.Id);
|
||||
_all.Add(a);
|
||||
}
|
||||
public void Delete(Guid id) => _all.RemoveAll(a => a.Id == id);
|
||||
}
|
||||
|
||||
public class FakeGrades : IGradeRepository
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
using LehrerApp.Core.Models;
|
||||
using LehrerApp.Desktop.ViewModels.Groups;
|
||||
using Xunit;
|
||||
|
||||
namespace LehrerApp.Desktop.Tests;
|
||||
|
||||
/// Tests für die Aspekt-Verwaltung (3.1.1/3.1.2/3.1.4): Anlegen, Umsortieren, Deaktivieren,
|
||||
/// Löschen. FakeAspects verhält sich hier wie der echte Repository (Validierung, Duplikatprüfung),
|
||||
/// damit auch Fehlerfälle über die ViewModel-Schicht hinweg realistisch getestet werden.
|
||||
public sealed class ParticipationAspectsDialogViewModelTests
|
||||
{
|
||||
[Fact]
|
||||
public void AddAspect_LegtNeuenAspektMitFortlaufenderSortOrderAn()
|
||||
{
|
||||
var groupId = Guid.NewGuid();
|
||||
var vm = new ParticipationAspectsDialogViewModel(new FakeAspects(), groupId)
|
||||
{
|
||||
NewKey = "experiment", NewLabel = "Experiment",
|
||||
};
|
||||
|
||||
vm.AddAspectCommand.Execute(null);
|
||||
|
||||
var item = Assert.Single(vm.Aspects);
|
||||
Assert.Equal("experiment", item.Key);
|
||||
Assert.Equal("Experiment", item.Label);
|
||||
Assert.Equal("", vm.NewKey); // Formular wird nach Erfolg geleert
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddAspect_OhneSchluessel_ZeigtFehlerUndLegtNichtsAn()
|
||||
{
|
||||
var vm = new ParticipationAspectsDialogViewModel(new FakeAspects(), Guid.NewGuid())
|
||||
{
|
||||
NewKey = "", NewLabel = "Experiment",
|
||||
};
|
||||
|
||||
vm.AddAspectCommand.Execute(null);
|
||||
|
||||
Assert.Empty(vm.Aspects);
|
||||
Assert.NotEqual("", vm.NewAspectError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddAspect_DuplikatSchluessel_ZeigtRepositoryFehlerAnUndLegtNichtsAnderesAn()
|
||||
{
|
||||
var groupId = Guid.NewGuid();
|
||||
var repo = new FakeAspects();
|
||||
var vm = new ParticipationAspectsDialogViewModel(repo, groupId) { NewKey = "a", NewLabel = "Erste" };
|
||||
vm.AddAspectCommand.Execute(null);
|
||||
|
||||
vm.NewKey = "a"; vm.NewLabel = "Zweite";
|
||||
vm.AddAspectCommand.Execute(null);
|
||||
|
||||
Assert.Single(vm.Aspects);
|
||||
Assert.NotEqual("", vm.NewAspectError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MoveAspect_VertauschtReihenfolgeUndPersistiertSortOrder()
|
||||
{
|
||||
var groupId = Guid.NewGuid();
|
||||
var repo = new FakeAspects();
|
||||
var vm = new ParticipationAspectsDialogViewModel(repo, groupId) { NewKey = "a", NewLabel = "Erste" };
|
||||
vm.AddAspectCommand.Execute(null);
|
||||
vm.NewKey = "b"; vm.NewLabel = "Zweite";
|
||||
vm.AddAspectCommand.Execute(null);
|
||||
|
||||
vm.Aspects[1].MoveUpCommand.Execute(null);
|
||||
|
||||
Assert.Equal("b", vm.Aspects[0].Key);
|
||||
Assert.Equal("a", vm.Aspects[1].Key);
|
||||
var stored = repo.GetAllByGroup(groupId).OrderBy(a => a.SortOrder).ToList();
|
||||
Assert.Equal(["b", "a"], stored.Select(a => a.Key));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsActive_AendernSpeichertSofortUndBleibtInGetAllByGroupSichtbar()
|
||||
{
|
||||
var groupId = Guid.NewGuid();
|
||||
var repo = new FakeAspects();
|
||||
var vm = new ParticipationAspectsDialogViewModel(repo, groupId) { NewKey = "a", NewLabel = "Erste" };
|
||||
vm.AddAspectCommand.Execute(null);
|
||||
|
||||
vm.Aspects[0].IsActive = false;
|
||||
|
||||
Assert.Empty(repo.GetByGroup(groupId));
|
||||
Assert.Single(repo.GetAllByGroup(groupId));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Label_UngueltigeAenderung_RolltZurueckUndZeigtFehler()
|
||||
{
|
||||
var groupId = Guid.NewGuid();
|
||||
var repo = new FakeAspects();
|
||||
var vm = new ParticipationAspectsDialogViewModel(repo, groupId) { NewKey = "a", NewLabel = "Erste" };
|
||||
vm.AddAspectCommand.Execute(null);
|
||||
|
||||
vm.Aspects[0].Label = " "; // leer nach Trim -> Repository lehnt ab
|
||||
|
||||
Assert.Equal("Erste", vm.Aspects[0].Label);
|
||||
Assert.NotEqual("", vm.Aspects[0].ErrorMessage);
|
||||
Assert.Equal("Erste", repo.GetAllByGroup(groupId).Single().Label);
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,7 @@ public partial class ParticipationTabViewModel : ObservableObject
|
||||
public Func<ParticipationTabViewModel, Task>? OnStatusQuickInput { get; set; }
|
||||
public Func<ParticipationTabViewModel, Task>? OnComputeGrade { get; set; }
|
||||
public Func<ParticipationTabViewModel, Task>? OnOpenWizard { get; set; }
|
||||
public Func<ParticipationTabViewModel, Task>? OnManageAspects { get; set; }
|
||||
|
||||
public ParticipationTabViewModel(
|
||||
IParticipationSessionRepository sessions,
|
||||
@@ -296,6 +297,15 @@ public partial class ParticipationTabViewModel : ObservableObject
|
||||
await OnOpenWizard(this);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task ManageAspects()
|
||||
{
|
||||
if (IsReadOnly || OnManageAspects is null) return;
|
||||
await OnManageAspects(this);
|
||||
LoadAspects();
|
||||
if (SelectedSession is not null) LoadGrid(SelectedSession.Id);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void DeleteSession()
|
||||
{
|
||||
@@ -883,3 +893,202 @@ public partial class AttendanceHomeworkQuickInputViewModel : ObservableObject
|
||||
if (AdvanceAfterInput) MoveSelection(1);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Aspekte verwalten (3.1) ──────────────────────────────────────────────────
|
||||
|
||||
/// Deutsche Anzeige für <see cref="AspectValueType"/>, gleiches Muster wie NiveauDisplay/
|
||||
/// GradeCategoryDisplay — ComboBox bindet an das Enum sonst über ToString() (englische Namen).
|
||||
public static class AspectValueTypeDisplay
|
||||
{
|
||||
public static string[] Options { get; } = ["Skala 1–5", "Skala 1–3", "Ja/Nein", "Punkte"];
|
||||
|
||||
public static string ToName(AspectValueType t) => t switch
|
||||
{
|
||||
AspectValueType.Scale5 => "Skala 1–5",
|
||||
AspectValueType.Scale3 => "Skala 1–3",
|
||||
AspectValueType.Binary => "Ja/Nein",
|
||||
AspectValueType.Points => "Punkte",
|
||||
_ => "Skala 1–5",
|
||||
};
|
||||
|
||||
public static AspectValueType FromName(string? name) => name switch
|
||||
{
|
||||
"Skala 1–3" => AspectValueType.Scale3,
|
||||
"Ja/Nein" => AspectValueType.Binary,
|
||||
"Punkte" => AspectValueType.Points,
|
||||
_ => AspectValueType.Scale5,
|
||||
};
|
||||
}
|
||||
|
||||
/// Eine Zeile in der Aspekt-Verwaltung (3.1.1/3.1.2/3.1.4). Label/Gewichtung/Aktiv-Status
|
||||
/// speichern bei jeder Änderung sofort (gleiches Muster wie AspectWeightItem in 3.2.1) —
|
||||
/// "Schlüssel" ist bewusst nur beim Neuanlegen editierbar, nicht nachträglich in der Zeile: er
|
||||
/// ist die Verknüpfung zu historischen AspectRating-Einträgen (per Key, nicht per Id), ein
|
||||
/// nachträgliches Umbenennen würde alte Bewertungen dieses Aspekts unauffindbar machen.
|
||||
public partial class AspectEditItem : ObservableObject
|
||||
{
|
||||
private readonly ParticipationAspect _aspect;
|
||||
private readonly IParticipationAspectRepository _repo;
|
||||
|
||||
public Guid Id => _aspect.Id;
|
||||
public string Key => _aspect.Key;
|
||||
|
||||
[ObservableProperty] private string _label;
|
||||
[ObservableProperty] private string _valueTypeName;
|
||||
[ObservableProperty] private double _weight;
|
||||
[ObservableProperty] private bool _isActive;
|
||||
[ObservableProperty] private string _errorMessage = "";
|
||||
|
||||
public string[] ValueTypeOptions => AspectValueTypeDisplay.Options;
|
||||
public Action<AspectEditItem>? OnDelete { get; set; }
|
||||
public IRelayCommand DeleteCommand { get; }
|
||||
public IRelayCommand MoveUpCommand { get; }
|
||||
public IRelayCommand MoveDownCommand { get; }
|
||||
|
||||
public AspectEditItem(ParticipationAspect aspect, IParticipationAspectRepository repo,
|
||||
Action<AspectEditItem>? onMoveUp = null, Action<AspectEditItem>? onMoveDown = null)
|
||||
{
|
||||
_aspect = aspect; _repo = repo;
|
||||
_label = aspect.Label;
|
||||
_valueTypeName = AspectValueTypeDisplay.ToName(aspect.ValueType);
|
||||
_weight = aspect.Weight;
|
||||
_isActive = aspect.IsActive;
|
||||
|
||||
DeleteCommand = new RelayCommand(() => OnDelete?.Invoke(this));
|
||||
MoveUpCommand = new RelayCommand(() => onMoveUp?.Invoke(this), () => _canMoveUp);
|
||||
MoveDownCommand = new RelayCommand(() => onMoveDown?.Invoke(this), () => _canMoveDown);
|
||||
}
|
||||
|
||||
private bool _canMoveUp;
|
||||
private bool _canMoveDown;
|
||||
|
||||
internal void SetMoveState(bool canMoveUp, bool canMoveDown)
|
||||
{
|
||||
_canMoveUp = canMoveUp; _canMoveDown = canMoveDown;
|
||||
MoveUpCommand.NotifyCanExecuteChanged();
|
||||
MoveDownCommand.NotifyCanExecuteChanged();
|
||||
}
|
||||
|
||||
internal void SetSortOrder(int sortOrder)
|
||||
{
|
||||
if (_aspect.SortOrder == sortOrder) return;
|
||||
_aspect.SortOrder = sortOrder;
|
||||
_repo.Save(_aspect);
|
||||
}
|
||||
|
||||
private void TrySave(Action apply)
|
||||
{
|
||||
ErrorMessage = "";
|
||||
var before = (_aspect.Label, _aspect.ValueType, _aspect.Weight, _aspect.IsActive);
|
||||
apply();
|
||||
try { _repo.Save(_aspect); }
|
||||
catch (Exception ex) when (ex is ArgumentException or InvalidOperationException)
|
||||
{
|
||||
// Zurückrollen, damit Feld und gespeicherter Stand nicht auseinanderlaufen. Bewusst
|
||||
// die Backing-Felder direkt gesetzt statt der generierten Properties — über die
|
||||
// Properties würde erneut On{X}Changed feuern und damit wieder TrySave aufrufen.
|
||||
#pragma warning disable MVVMTK0034
|
||||
(_aspect.Label, _aspect.ValueType, _aspect.Weight, _aspect.IsActive) = before;
|
||||
_label = _aspect.Label; _valueTypeName = AspectValueTypeDisplay.ToName(_aspect.ValueType);
|
||||
_weight = _aspect.Weight; _isActive = _aspect.IsActive;
|
||||
#pragma warning restore MVVMTK0034
|
||||
OnPropertyChanged(nameof(Label)); OnPropertyChanged(nameof(ValueTypeName));
|
||||
OnPropertyChanged(nameof(Weight)); OnPropertyChanged(nameof(IsActive));
|
||||
ErrorMessage = ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnLabelChanged(string value) => TrySave(() => _aspect.Label = value);
|
||||
partial void OnValueTypeNameChanged(string value) => TrySave(() => _aspect.ValueType = AspectValueTypeDisplay.FromName(value));
|
||||
partial void OnWeightChanged(double value) => TrySave(() => _aspect.Weight = value);
|
||||
partial void OnIsActiveChanged(bool value) => TrySave(() => _aspect.IsActive = value);
|
||||
}
|
||||
|
||||
/// Verwaltungsdialog für ParticipationAspect (3.1.1/3.1.2/3.1.4), pro Gruppe. Verwaltet bewusst
|
||||
/// nur die gruppenspezifischen Aspekte (GroupId = diese Gruppe), nicht den globalen
|
||||
/// Standardkatalog (GroupId = null) — der wird bislang nirgends befüllt (siehe
|
||||
/// DefaultParticipationAspects, reiner In-Memory-Fallback ohne UI) und eine Änderung dort würde
|
||||
/// sofort alle Gruppen betreffen; das wäre ein eigener, separat zu entscheidender Schritt.
|
||||
public partial class ParticipationAspectsDialogViewModel : ObservableObject
|
||||
{
|
||||
private readonly IParticipationAspectRepository _repo;
|
||||
private readonly Guid _groupId;
|
||||
|
||||
[ObservableProperty] private string _newKey = "";
|
||||
[ObservableProperty] private string _newLabel = "";
|
||||
[ObservableProperty] private string _newValueTypeName = AspectValueTypeDisplay.Options[0];
|
||||
[ObservableProperty] private string _newAspectError = "";
|
||||
|
||||
public string[] ValueTypeOptions => AspectValueTypeDisplay.Options;
|
||||
public ObservableCollection<AspectEditItem> Aspects { get; } = [];
|
||||
public Func<AspectEditItem, Task<bool>>? OnConfirmDelete { get; set; }
|
||||
|
||||
public ParticipationAspectsDialogViewModel(IParticipationAspectRepository repo, Guid groupId)
|
||||
{
|
||||
_repo = repo; _groupId = groupId;
|
||||
Load();
|
||||
}
|
||||
|
||||
private void Load()
|
||||
{
|
||||
Aspects.Clear();
|
||||
foreach (var a in _repo.GetAllByGroup(_groupId))
|
||||
Aspects.Add(CreateItem(a));
|
||||
RefreshMoveState();
|
||||
}
|
||||
|
||||
private AspectEditItem CreateItem(ParticipationAspect a) =>
|
||||
new(a, _repo, item => MoveAspect(item, -1), item => MoveAspect(item, 1)) { OnDelete = DeleteAspectAsync };
|
||||
|
||||
private void MoveAspect(AspectEditItem item, int offset)
|
||||
{
|
||||
var oldIndex = Aspects.IndexOf(item);
|
||||
var newIndex = oldIndex + offset;
|
||||
if (oldIndex < 0 || newIndex < 0 || newIndex >= Aspects.Count) return;
|
||||
Aspects.Move(oldIndex, newIndex);
|
||||
for (var i = 0; i < Aspects.Count; i++) Aspects[i].SetSortOrder(i);
|
||||
RefreshMoveState();
|
||||
}
|
||||
|
||||
private void RefreshMoveState()
|
||||
{
|
||||
for (var i = 0; i < Aspects.Count; i++)
|
||||
Aspects[i].SetMoveState(i > 0, i < Aspects.Count - 1);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void AddAspect()
|
||||
{
|
||||
NewAspectError = "";
|
||||
if (string.IsNullOrWhiteSpace(NewKey)) { NewAspectError = "Schlüssel erforderlich."; return; }
|
||||
if (string.IsNullOrWhiteSpace(NewLabel)) { NewAspectError = "Bezeichnung erforderlich."; return; }
|
||||
|
||||
var aspect = new ParticipationAspect
|
||||
{
|
||||
GroupId = _groupId,
|
||||
Key = NewKey.Trim(),
|
||||
Label = NewLabel.Trim(),
|
||||
ValueType = AspectValueTypeDisplay.FromName(NewValueTypeName),
|
||||
SortOrder = Aspects.Count,
|
||||
};
|
||||
try { _repo.Save(aspect); }
|
||||
catch (Exception ex) when (ex is ArgumentException or InvalidOperationException)
|
||||
{
|
||||
NewAspectError = ex.Message;
|
||||
return;
|
||||
}
|
||||
|
||||
Aspects.Add(CreateItem(aspect));
|
||||
RefreshMoveState();
|
||||
NewKey = ""; NewLabel = ""; NewValueTypeName = AspectValueTypeDisplay.Options[0];
|
||||
}
|
||||
|
||||
private async void DeleteAspectAsync(AspectEditItem item)
|
||||
{
|
||||
if (OnConfirmDelete is not null && !await OnConfirmDelete(item)) return;
|
||||
_repo.Delete(item.Id);
|
||||
Aspects.Remove(item);
|
||||
for (var i = 0; i < Aspects.Count; i++) Aspects[i].SetSortOrder(i);
|
||||
RefreshMoveState();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="clr-namespace:LehrerApp.Desktop.ViewModels.Groups"
|
||||
x:Class="LehrerApp.Desktop.Views.Groups.ParticipationAspectsDialog"
|
||||
x:DataType="vm:ParticipationAspectsDialogViewModel"
|
||||
Title="Mitarbeit-Aspekte verwalten"
|
||||
Width="620" Height="620" MinWidth="520" MinHeight="380"
|
||||
CanResize="True" WindowStartupLocation="CenterOwner">
|
||||
|
||||
<Grid RowDefinitions="*,Auto" Margin="24">
|
||||
<ScrollViewer Grid.Row="0">
|
||||
<StackPanel Spacing="14" Margin="0,0,12,0">
|
||||
<TextBlock Text="Mitarbeit-Aspekte" Classes="dialogtitle"/>
|
||||
<TextBlock Text="Gilt nur für diese Gruppe, zusätzlich zu den globalen Standardaspekten (Qualität, Quantität, Arbeitsphase)."
|
||||
FontSize="12" Opacity="0.6" TextWrapping="Wrap"/>
|
||||
|
||||
<ItemsControl ItemsSource="{Binding Aspects}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate x:DataType="vm:AspectEditItem">
|
||||
<Border BorderBrush="{DynamicResource SystemControlForegroundBaseLowBrush}"
|
||||
BorderThickness="0,0,0,1" Padding="0,8">
|
||||
<StackPanel Spacing="4">
|
||||
<Grid ColumnDefinitions="70,*,120,80,60,26,26,26">
|
||||
<TextBlock Grid.Column="0" Text="{Binding Key}" FontSize="12" Opacity="0.6"
|
||||
VerticalAlignment="Center" Margin="0,0,8,0" TextTrimming="CharacterEllipsis"
|
||||
ToolTip.Tip="Schlüssel, nach dem Neuanlegen nicht mehr änderbar (Verknüpfung zu bereits erfassten Bewertungen)."/>
|
||||
<TextBox Grid.Column="1" Text="{Binding Label}" Margin="0,0,6,0"/>
|
||||
<ComboBox Grid.Column="2" ItemsSource="{Binding ValueTypeOptions}"
|
||||
SelectedItem="{Binding ValueTypeName}" Margin="0,0,6,0"/>
|
||||
<NumericUpDown Grid.Column="3" Value="{Binding Weight}" Minimum="0" Maximum="10"
|
||||
FormatString="0.0" Increment="0.1" ShowButtonSpinner="False" Margin="0,0,6,0"/>
|
||||
<CheckBox Grid.Column="4" Content="Aktiv" IsChecked="{Binding IsActive}"
|
||||
VerticalAlignment="Center" Margin="0,0,4,0"
|
||||
ToolTip.Tip="Deaktivieren statt löschen, damit bereits erfasste Bewertungen dieses Aspekts gültig bleiben."/>
|
||||
<Button Grid.Column="5" Content="↑" Command="{Binding MoveUpCommand}" Padding="4,2"
|
||||
ToolTip.Tip="Nach oben"/>
|
||||
<Button Grid.Column="6" Content="↓" Command="{Binding MoveDownCommand}" Padding="4,2"
|
||||
Margin="2,0,0,0" ToolTip.Tip="Nach unten"/>
|
||||
<Button Grid.Column="7" Content="✕" Command="{Binding DeleteCommand}" Padding="4,2"
|
||||
Margin="2,0,0,0" ToolTip.Tip="Endgültig löschen"/>
|
||||
</Grid>
|
||||
<TextBlock Text="{Binding ErrorMessage}" Foreground="Red" FontSize="11"
|
||||
IsVisible="{Binding ErrorMessage, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<TextBlock Text="Noch keine gruppenspezifischen Aspekte." Classes="emptyhint"
|
||||
IsVisible="{Binding !Aspects.Count}"/>
|
||||
|
||||
<Separator Margin="0,4"/>
|
||||
|
||||
<TextBlock Text="Neuer Aspekt" FontSize="14" FontWeight="SemiBold"/>
|
||||
<Grid ColumnDefinitions="*,12,*,12,160">
|
||||
<StackPanel Grid.Column="0" Spacing="4">
|
||||
<TextBlock Text="Schlüssel *" FontSize="12" Opacity="0.7"/>
|
||||
<TextBox Text="{Binding NewKey}" PlaceholderText="z.B. experiment"/>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="2" Spacing="4">
|
||||
<TextBlock Text="Bezeichnung *" FontSize="12" Opacity="0.7"/>
|
||||
<TextBox Text="{Binding NewLabel}" PlaceholderText="z.B. Experiment"/>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="4" Spacing="4">
|
||||
<TextBlock Text="Typ" FontSize="12" Opacity="0.7"/>
|
||||
<ComboBox ItemsSource="{Binding ValueTypeOptions}" SelectedItem="{Binding NewValueTypeName}"
|
||||
HorizontalAlignment="Stretch"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<TextBlock Text="{Binding NewAspectError}" Foreground="Red" FontSize="12"
|
||||
IsVisible="{Binding NewAspectError, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"/>
|
||||
<Button Content="+ Aspekt hinzufügen" Command="{Binding AddAspectCommand}" HorizontalAlignment="Left"/>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
|
||||
<Button Grid.Row="1" Content="Fertig" HorizontalAlignment="Right" Margin="0,20,0,0" Click="OnClose"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,35 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using LehrerApp.Desktop.ViewModels.Groups;
|
||||
using LehrerApp.Desktop.Views.Shared;
|
||||
|
||||
namespace LehrerApp.Desktop.Views.Groups;
|
||||
|
||||
public partial class ParticipationAspectsDialog : Window
|
||||
{
|
||||
public ParticipationAspectsDialog() => InitializeComponent();
|
||||
|
||||
protected override void OnDataContextChanged(EventArgs e)
|
||||
{
|
||||
base.OnDataContextChanged(e);
|
||||
if (DataContext is ParticipationAspectsDialogViewModel vm)
|
||||
vm.OnConfirmDelete = ConfirmDelete;
|
||||
}
|
||||
|
||||
private async Task<bool> ConfirmDelete(AspectEditItem item)
|
||||
{
|
||||
var info = new ConfirmDialogInfo
|
||||
{
|
||||
Title = "Aspekt endgültig löschen?",
|
||||
Message = $"„{item.Label}“ wird endgültig gelöscht. Falls er bereits in Bewertungen " +
|
||||
"verwendet wurde, bleiben diese Werte in der Historie erhalten, sind dort " +
|
||||
"aber keinem Aspekt mehr zuordenbar. Zum Erhalt der Zuordnung stattdessen " +
|
||||
"deaktivieren statt löschen.",
|
||||
ConfirmText = "Endgültig löschen",
|
||||
};
|
||||
var dialog = new ConfirmDialog { DataContext = info };
|
||||
return await dialog.ShowDialog<bool>(this);
|
||||
}
|
||||
|
||||
private void OnClose(object? s, RoutedEventArgs e) => Close();
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
<Border Grid.Column="0"
|
||||
BorderBrush="{DynamicResource SystemControlForegroundBaseLowBrush}"
|
||||
BorderThickness="0,0,1,0">
|
||||
<Grid RowDefinitions="Auto,Auto,Auto,Auto,*">
|
||||
<Grid RowDefinitions="Auto,Auto,Auto,Auto,Auto,*">
|
||||
|
||||
<Button Grid.Row="0" Content="+ Sitzung" Command="{Binding AddSessionCommand}"
|
||||
HorizontalAlignment="Stretch" Margin="10,10,10,6" IsEnabled="{Binding !IsReadOnly}"/>
|
||||
@@ -27,7 +27,10 @@
|
||||
<Button Grid.Row="3" Content="Mitarbeits-Assistent" Command="{Binding OpenWizardCommand}"
|
||||
HorizontalAlignment="Stretch" Margin="10,0,10,6" IsEnabled="{Binding !IsReadOnly}"/>
|
||||
|
||||
<ListBox Grid.Row="4"
|
||||
<Button Grid.Row="4" Content="Aspekte verwalten" Command="{Binding ManageAspectsCommand}"
|
||||
HorizontalAlignment="Stretch" Margin="10,0,10,6" IsEnabled="{Binding !IsReadOnly}"/>
|
||||
|
||||
<ListBox Grid.Row="5"
|
||||
ItemsSource="{Binding Sessions}"
|
||||
SelectedItem="{Binding SelectedSession}"
|
||||
BorderThickness="0">
|
||||
|
||||
@@ -26,6 +26,7 @@ public partial class ParticipationTabView : UserControl
|
||||
vm.OnStatusQuickInput = ShowStatusQuickInputDialog;
|
||||
vm.OnComputeGrade = ShowComputeGradeDialog;
|
||||
vm.OnOpenWizard = ShowWizardDialog;
|
||||
vm.OnManageAspects = ShowManageAspectsDialog;
|
||||
vm.Aspects.CollectionChanged += (_, _) => BuildColumns();
|
||||
vm.PropertyChanged += (_, pe) =>
|
||||
{
|
||||
@@ -305,4 +306,15 @@ public partial class ParticipationTabView : UserControl
|
||||
if (owner is not null)
|
||||
await dialog.ShowDialog(owner);
|
||||
}
|
||||
|
||||
private async Task ShowManageAspectsDialog(ParticipationTabViewModel tabVm)
|
||||
{
|
||||
var dialogVm = new ParticipationAspectsDialogViewModel(
|
||||
App.Services.GetRequiredService<IParticipationAspectRepository>(), tabVm.GroupId);
|
||||
|
||||
var dialog = new ParticipationAspectsDialog { DataContext = dialogVm };
|
||||
var owner = TopLevel.GetTopLevel(this) as Window;
|
||||
if (owner is not null)
|
||||
await dialog.ShowDialog(owner);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,13 +156,43 @@ Grundfunktion ist umgesetzt (Sitzungen, Raster, Schnelleingabe-Dialog).
|
||||
Siehe [ParticipationViewModels.cs](LehrerApp.Desktop/ViewModels/Groups/ParticipationViewModels.cs).
|
||||
|
||||
### 3.1 Aspekte konfigurieren
|
||||
- [ ] **3.1.1** UI zum Anlegen/Bearbeiten/Löschen von `ParticipationAspect` **pro Gruppe**
|
||||
- [x] **3.1.1** UI zum Anlegen/Bearbeiten/Löschen von `ParticipationAspect` **pro Gruppe**
|
||||
(Fach Chemie: z.B. "Experiment", "Protokoll") — `GroupId = null` bleibt global.
|
||||
- [ ] **3.1.2** Reihenfolge der Aspekte per Drag & Drop oder Hoch/Runter-Buttons festlegen
|
||||
(bestimmt auch die Q/W/E/R/T-Belegung im Schnelleingabe-Dialog).
|
||||
**Umsetzung:** neuer Button "Aspekte verwalten" im Mitarbeit-Tab öffnet
|
||||
`ParticipationAspectsDialog`. Verwaltet bewusst nur die gruppenspezifischen Aspekte
|
||||
(`GroupId` = diese Gruppe), nicht den globalen Standardkatalog (`GroupId = null`) — der wird
|
||||
bislang nirgends befüllt (`DefaultParticipationAspects` ist reiner In-Memory-Fallback ohne
|
||||
UI) und eine Änderung dort würde sofort alle Gruppen betreffen; das wäre ein eigener,
|
||||
separat zu entscheidender Schritt. Label/Typ/Gewichtung/Aktiv-Status speichern sofort bei
|
||||
Änderung (gleiches Muster wie die bestehende Gewichtungs-Bearbeitung in 3.2.1), mit
|
||||
Rollback + Fehlermeldung an der Zeile, falls das Repository ablehnt (leerer Wert, doppelter
|
||||
Schlüssel). "Schlüssel" ist bewusst nur beim Neuanlegen editierbar: er verknüpft
|
||||
`AspectRating` mit dem Aspekt (per Key, nicht per Id) — ein nachträgliches Umbenennen würde
|
||||
historische Bewertungen unauffindbar machen. `IParticipationAspectRepository.Save` prüft
|
||||
jetzt zusätzlich Pflichtfelder und Schlüssel-Eindeutigkeit (gegen die globalen Standards UND
|
||||
die eigenen Gruppen-Aspekte zusammen, da beide in der Bewertungsübersicht kombiniert
|
||||
verwendet werden — siehe `ParticipationTabViewModel.LoadAspects`).
|
||||
- [x] **3.1.2** Reihenfolge der Aspekte per Hoch/Runter-Buttons festlegen (bestimmt auch die
|
||||
Q/W/E/R/T-Belegung im Schnelleingabe-Dialog) — gleiches Muster wie die Kompetenzbereiche in
|
||||
8.1.1, `SortOrder` wird bei jeder Verschiebung sofort und lückenlos gespeichert.
|
||||
**Drag & Drop nicht umgesetzt:** Hoch/Runter deckt die vollständige Bedienung bereits ab,
|
||||
analog zur Drag-Entscheidung bei 4.3.3.
|
||||
- [ ] **3.1.3** Aspekt-Typen `Scale3`, `Binary`, `Points` in Raster und Dialog vollständig unterstützen
|
||||
(bisher primär `Scale5`).
|
||||
- [ ] **3.1.4** Aspekt deaktivieren statt löschen, damit alte Einträge gültig bleiben.
|
||||
(bisher primär `Scale5`). **Weiterhin offen:** 3.1.1 macht den Typ zwar anlegbar/speicherbar
|
||||
(`AspectValueTypeDisplay`, ComboBox in der Verwaltung), das Bewertungsraster und der
|
||||
Schnelleingabe-Dialog rendern und interpretieren Eingaben aber weiterhin nach dem
|
||||
Scale5-Schema — ein als `Binary`/`Points`/`Scale3` angelegter Aspekt wird dort noch nicht
|
||||
passend dargestellt. Bewusst getrennt von 3.1.1, da das die Bewertungs-UI selbst betrifft.
|
||||
- [x] **3.1.4** Aspekt deaktivieren statt löschen, damit alte Einträge gültig bleiben.
|
||||
**Umsetzung:** Checkbox "Aktiv" je Zeile in der neuen Verwaltung (3.1.1); die bestehenden
|
||||
Abfragen (`GetByGroup`/`GetDefaults`, für Bewertungsraster und -aggregation) filterten
|
||||
inaktive Aspekte bereits vorher heraus, das war schon vor dieser Aufgabe so gebaut. Neu ist
|
||||
nur `GetAllByGroup` (inkl. inaktiver), damit die Verwaltungsansicht deaktivierte Aspekte
|
||||
weiterhin anzeigt und wieder aktivierbar macht. "Löschen" bleibt zusätzlich verfügbar (mit
|
||||
Rückfrage über den bestehenden `ConfirmDialog`, Warnhinweis auf mögliche bereits erfasste
|
||||
Bewertungen), aber "Deaktivieren" ist der empfohlene Weg — ein echter Verwendungs-Check vor
|
||||
dem Löschen (durchsucht alle `ParticipationEntry.Ratings` nach dem Key) ist nicht umgesetzt,
|
||||
da `AspectRating` nicht nach Aspekt-Key indiziert ist.
|
||||
|
||||
### 3.2 Aggregation zur Mitarbeitsnote
|
||||
- [x] **3.2.1** Gewichtung je Aspekt konfigurierbar (z.B. Qualität 50 %, Quantität 30 %, Experiment 20 %).
|
||||
|
||||
Reference in New Issue
Block a user