Initial
This commit is contained in:
87
LehrerApp.Desktop/ViewModels/MainWindowViewModel.cs
Normal file
87
LehrerApp.Desktop/ViewModels/MainWindowViewModel.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using LehrerApp.Core.Services;
|
||||
using LehrerApp.Desktop.ViewModels.Groups;
|
||||
using LehrerApp.Desktop.ViewModels.Students;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace LehrerApp.Desktop.ViewModels;
|
||||
|
||||
public partial class MainWindowViewModel : ObservableObject
|
||||
{
|
||||
private readonly IServiceProvider _services;
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableObject? _currentPage;
|
||||
|
||||
[ObservableProperty]
|
||||
private NavItem _activeNavItem = NavItem.Dashboard;
|
||||
|
||||
// ── Fehlende Property die im MainWindow.axaml referenziert wird ───────────
|
||||
[ObservableProperty]
|
||||
private string _currentSchoolYear = "";
|
||||
|
||||
public MainWindowViewModel(
|
||||
IServiceProvider services,
|
||||
DashboardViewModel dashboard,
|
||||
SchoolYearService schoolYearService)
|
||||
{
|
||||
_services = services;
|
||||
CurrentPage = dashboard;
|
||||
CurrentSchoolYear = schoolYearService.CurrentSchoolYear();
|
||||
}
|
||||
|
||||
// ── Navigation ────────────────────────────────────────────────────────────
|
||||
|
||||
[RelayCommand]
|
||||
private void NavigateTo(NavItem item)
|
||||
{
|
||||
ActiveNavItem = item;
|
||||
CurrentPage = item switch
|
||||
{
|
||||
NavItem.Dashboard => _services.GetRequiredService<DashboardViewModel>(),
|
||||
NavItem.Groups => _services.GetRequiredService<GroupListViewModel>(),
|
||||
NavItem.Students => _services.GetRequiredService<StudentListViewModel>(),
|
||||
NavItem.Exams => CreatePlaceholder("Klausuren"),
|
||||
NavItem.Planner => CreatePlaceholder("Unterrichtsplanung"),
|
||||
NavItem.Workload => CreatePlaceholder("Arbeitszeit"),
|
||||
NavItem.Settings => CreatePlaceholder("Einstellungen"),
|
||||
_ => CurrentPage,
|
||||
};
|
||||
}
|
||||
|
||||
public void NavigateToGroup(Guid groupId)
|
||||
{
|
||||
ActiveNavItem = NavItem.Groups;
|
||||
var vm = _services.GetRequiredService<GroupDetailViewModel>();
|
||||
vm.LoadGroup(groupId);
|
||||
CurrentPage = vm;
|
||||
}
|
||||
|
||||
public void NavigateToStudent(Guid studentId)
|
||||
{
|
||||
ActiveNavItem = NavItem.Students;
|
||||
var vm = _services.GetRequiredService<StudentDetailViewModel>();
|
||||
vm.LoadStudent(studentId);
|
||||
CurrentPage = vm;
|
||||
}
|
||||
|
||||
private static PlaceholderViewModel CreatePlaceholder(string title) =>
|
||||
new() { Title = title };
|
||||
}
|
||||
|
||||
public enum NavItem
|
||||
{
|
||||
Dashboard,
|
||||
Groups,
|
||||
Students,
|
||||
Exams,
|
||||
Planner,
|
||||
Workload,
|
||||
Settings,
|
||||
}
|
||||
|
||||
public partial class PlaceholderViewModel : ObservableObject
|
||||
{
|
||||
[ObservableProperty] private string _title = "";
|
||||
}
|
||||
Reference in New Issue
Block a user