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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user