From fdbaa9ef4d50d5df66d1961a9b4783b28d211cf3 Mon Sep 17 00:00:00 2001 From: Sebastian Hedtrich Date: Fri, 19 Jun 2026 23:59:09 +0200 Subject: [PATCH] Drawer korrigiert, Gruppenanlegen optimiert. --- LehrerApp.Desktop/App.axaml.cs | 2 +- .../ViewModels/Groups/GroupViewModels.cs | 43 +++++-- .../ViewModels/MainWindowViewModel.cs | 3 +- .../Views/Groups/AddGroupDialog.axaml | 23 +++- .../Views/Groups/GroupDetailView.axaml | 2 +- .../Views/Groups/GroupListView.axaml | 109 +++++++++++++----- LehrerApp.Desktop/Views/MainWindow.axaml | 50 ++++---- 7 files changed, 163 insertions(+), 69 deletions(-) diff --git a/LehrerApp.Desktop/App.axaml.cs b/LehrerApp.Desktop/App.axaml.cs index 5ea7ee9..6772be1 100644 --- a/LehrerApp.Desktop/App.axaml.cs +++ b/LehrerApp.Desktop/App.axaml.cs @@ -33,7 +33,7 @@ public class App : Application { // GroupList → GroupDetail var gl = Services.GetRequiredService(); - gl.OnNavigateToDetail = id => main.NavigateToGroupDetail(id); + gl.OnNavigateToDetail = (id, tab) => main.NavigateToGroupDetail(id, tab); gl.OnAddGroup = () => ShowAddGroupDialog(gl); // Dashboard → GroupDetail (Chips) diff --git a/LehrerApp.Desktop/ViewModels/Groups/GroupViewModels.cs b/LehrerApp.Desktop/ViewModels/Groups/GroupViewModels.cs index 6ed2cbe..7cbb0ea 100644 --- a/LehrerApp.Desktop/ViewModels/Groups/GroupViewModels.cs +++ b/LehrerApp.Desktop/ViewModels/Groups/GroupViewModels.cs @@ -14,7 +14,7 @@ public partial class GroupListViewModel : ObservableObject private readonly IGroupRepository _groups; private readonly SchoolYearService _sy; - public Action? OnNavigateToDetail { get; set; } + public Action? OnNavigateToDetail { get; set; } public Action? OnAddGroup { get; set; } [ObservableProperty] private string _selectedSchoolYear = ""; @@ -33,10 +33,8 @@ public partial class GroupListViewModel : ObservableObject partial void OnSelectedSchoolYearChanged(string value) => LoadGroups(); partial void OnSearchTextChanged(string value) => LoadGroups(); - partial void OnSelectedGroupChanged(GroupListItem? value) - { - if (value is not null) OnNavigateToDetail?.Invoke(value.Id); - } + partial void OnSelectedGroupChanged(GroupListItem? value) => + NavigateToSectionCommand.NotifyCanExecuteChanged(); public void LoadGroups() { @@ -51,6 +49,15 @@ public partial class GroupListViewModel : ObservableObject [RelayCommand] private void AddGroup() => OnAddGroup?.Invoke(); [RelayCommand] private void Refresh() => LoadGroups(); + + [RelayCommand(CanExecute = nameof(HasSelectedGroup))] + private void NavigateToSection(string? tabIndex) + { + if (SelectedGroup is null || !int.TryParse(tabIndex, out var tab)) return; + OnNavigateToDetail?.Invoke(SelectedGroup.Id, tab); + } + + private bool HasSelectedGroup() => SelectedGroup is not null; } public class GroupListItem @@ -61,6 +68,7 @@ public class GroupListItem public string DisplayName { get; } public string TypeLabel { get; } public string GradingLabel { get; } + public string Subtitle { get; } public GroupListItem(LearningGroup g) { @@ -69,7 +77,8 @@ public class GroupListItem Subject = g.Subject ?? ""; TypeLabel = g.Type == GroupType.Class ? "Klasse" : "Kurs"; GradingLabel = g.GradingSystem == GradingSystem.Grades1To6 ? "1–6" : "0–15"; - DisplayName = string.IsNullOrEmpty(Subject) ? Name : $"{Name} · {Subject}"; + DisplayName = string.IsNullOrEmpty(g.Subject) ? g.Name : $"{g.Name} · {g.Subject}"; + Subtitle = $"{TypeLabel} · Stufe {g.GradeLevel} · Noten {GradingLabel} · {g.SchoolYear}"; } } @@ -86,6 +95,7 @@ public partial class GroupDetailViewModel : ObservableObject [ObservableProperty] private string _groupTitle = ""; [ObservableProperty] private string _groupSubtitle = ""; [ObservableProperty] private int _studentCount; + [ObservableProperty] private int _activeTabIndex = 0; public ObservableCollection Students { get; } = []; public ObservableCollection Exams { get; } = []; @@ -153,6 +163,20 @@ public partial class AddGroupDialogViewModel : ObservableObject private readonly IGroupRepository _groups; private readonly SchoolYearService _sy; + public List TypeOptions { get; } = ["Klasse", "Kurs"]; + [ObservableProperty] private string _selectedTypeName = "Kurs"; + + public bool IsKurs => SelectedTypeName == "Kurs"; + public string NameLabel => IsKurs ? "Kursname *" : "Klassenname *"; + public string NameHint => IsKurs ? "z.B. Q1, LK, GK" : "z.B. 10E, 5a, 11b"; + + partial void OnSelectedTypeNameChanged(string value) + { + OnPropertyChanged(nameof(IsKurs)); + OnPropertyChanged(nameof(NameLabel)); + OnPropertyChanged(nameof(NameHint)); + } + [ObservableProperty] private string _name = ""; [ObservableProperty] private string _subject = ""; [ObservableProperty] private int _gradeLevel = 10; @@ -168,7 +192,6 @@ public partial class AddGroupDialogViewModel : ObservableObject _groups = groups; _sy = sy; SchoolYears = sy.RecentSchoolYears(3); SelectedSchoolYear = sy.CurrentSchoolYear(); - // Notensystem automatisch nach Klassenstufe PropertyChanged += (_, e) => { if (e.PropertyName == nameof(GradeLevel)) @@ -180,13 +203,13 @@ public partial class AddGroupDialogViewModel : ObservableObject [RelayCommand] private void Save() { - if (string.IsNullOrWhiteSpace(Name)) { ValidationMessage = "Name erforderlich."; return; } + if (string.IsNullOrWhiteSpace(Name)) { ValidationMessage = "Bezeichnung erforderlich."; return; } if (GradeLevel is < 1 or > 13) { ValidationMessage = "Klassenstufe 1–13."; return; } Result = new LearningGroup { Name = Name.Trim(), - Subject = string.IsNullOrWhiteSpace(Subject) ? null : Subject.Trim(), - Type = GroupType.Course, + Subject = IsKurs && !string.IsNullOrWhiteSpace(Subject) ? Subject.Trim() : null, + Type = IsKurs ? GroupType.Course : GroupType.Class, GradeLevel = GradeLevel, GradingSystem = GradingSystem, SchoolYear = SelectedSchoolYear, diff --git a/LehrerApp.Desktop/ViewModels/MainWindowViewModel.cs b/LehrerApp.Desktop/ViewModels/MainWindowViewModel.cs index fb1c19d..55cd491 100644 --- a/LehrerApp.Desktop/ViewModels/MainWindowViewModel.cs +++ b/LehrerApp.Desktop/ViewModels/MainWindowViewModel.cs @@ -40,11 +40,12 @@ public partial class MainWindowViewModel : ObservableObject }; } - public void NavigateToGroupDetail(Guid groupId) + public void NavigateToGroupDetail(Guid groupId, int initialTab = 0) { ActiveNavItem = NavItem.Groups; var vm = _services.GetRequiredService(); vm.LoadGroup(groupId); + vm.ActiveTabIndex = initialTab; CurrentPage = vm; } diff --git a/LehrerApp.Desktop/Views/Groups/AddGroupDialog.axaml b/LehrerApp.Desktop/Views/Groups/AddGroupDialog.axaml index b742df6..0e3958a 100644 --- a/LehrerApp.Desktop/Views/Groups/AddGroupDialog.axaml +++ b/LehrerApp.Desktop/Views/Groups/AddGroupDialog.axaml @@ -10,14 +10,27 @@ + + - - + + + + - - + + + + + + + + + @@ -30,9 +43,11 @@ HorizontalAlignment="Stretch"/> + +