Initial
This commit is contained in:
136
LehrerApp.Desktop/ViewModels/DashboardViewModel.cs
Normal file
136
LehrerApp.Desktop/ViewModels/DashboardViewModel.cs
Normal file
@@ -0,0 +1,136 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using LehrerApp.Core.Interfaces;
|
||||
using LehrerApp.Core.Models;
|
||||
using LehrerApp.Core.Services;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace LehrerApp.Desktop.ViewModels;
|
||||
|
||||
public partial class DashboardViewModel : ObservableObject
|
||||
{
|
||||
private readonly IGroupRepository _groups;
|
||||
private readonly ILessonRepository _lessons;
|
||||
private readonly IWorkTaskRepository _tasks;
|
||||
private readonly SchoolYearService _schoolYearService;
|
||||
|
||||
[ObservableProperty] private string _greeting = "";
|
||||
[ObservableProperty] private string _currentDate = "";
|
||||
[ObservableProperty] private string _currentSchoolYear = "";
|
||||
|
||||
public ObservableCollection<LessonItem> TodaysLessons { get; } = [];
|
||||
public ObservableCollection<TaskItem> OpenTasks { get; } = [];
|
||||
public ObservableCollection<GroupChip> CurrentGroups { get; } = [];
|
||||
|
||||
public DashboardViewModel(
|
||||
IGroupRepository groups,
|
||||
ILessonRepository lessons,
|
||||
IWorkTaskRepository tasks,
|
||||
SchoolYearService schoolYearService)
|
||||
{
|
||||
_groups = groups;
|
||||
_lessons = lessons;
|
||||
_tasks = tasks;
|
||||
_schoolYearService = schoolYearService;
|
||||
|
||||
Load();
|
||||
}
|
||||
|
||||
private void Load()
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
var today = DateOnly.FromDateTime(now);
|
||||
|
||||
CurrentDate = now.ToString("dddd, d. MMMM yyyy",
|
||||
new System.Globalization.CultureInfo("de-DE"));
|
||||
CurrentSchoolYear = _schoolYearService.CurrentSchoolYear();
|
||||
Greeting = now.Hour < 12 ? "Guten Morgen" :
|
||||
now.Hour < 18 ? "Guten Tag" : "Guten Abend";
|
||||
|
||||
// Heutige Stunden
|
||||
TodaysLessons.Clear();
|
||||
var schoolYear = _schoolYearService.CurrentSchoolYear();
|
||||
var allGroups = _groups.GetBySchoolYear(schoolYear)
|
||||
.ToDictionary(g => g.Id);
|
||||
|
||||
var todayLessons = allGroups.Keys
|
||||
.SelectMany(gid => _lessons.GetByGroupAndDate(gid, today))
|
||||
.OrderBy(l => l.LessonNumber)
|
||||
.ToList();
|
||||
|
||||
foreach (var lesson in todayLessons)
|
||||
{
|
||||
if (!allGroups.TryGetValue(lesson.GroupId, out var group)) continue;
|
||||
TodaysLessons.Add(new LessonItem
|
||||
{
|
||||
GroupName = group.Name,
|
||||
Topic = lesson.Topic,
|
||||
Status = lesson.Status,
|
||||
});
|
||||
}
|
||||
|
||||
// Offene Aufgaben (mit Fälligkeit)
|
||||
OpenTasks.Clear();
|
||||
var openTasks = _tasks.GetByStatus(WorkTaskStatus.Open)
|
||||
.Concat(_tasks.GetByStatus(WorkTaskStatus.InProgress))
|
||||
.OrderBy(t => t.DueDate ?? DateOnly.MaxValue)
|
||||
.Take(5);
|
||||
|
||||
foreach (var task in openTasks)
|
||||
{
|
||||
var isOverdue = task.DueDate.HasValue && task.DueDate < today;
|
||||
var isDueSoon = task.DueDate.HasValue &&
|
||||
task.DueDate >= today &&
|
||||
task.DueDate <= today.AddDays(3);
|
||||
|
||||
OpenTasks.Add(new TaskItem
|
||||
{
|
||||
Title = task.Title,
|
||||
DueDate = task.DueDate?.ToString("dd.MM.") ?? "",
|
||||
IsOverdue = isOverdue,
|
||||
IsDueSoon = isDueSoon,
|
||||
Status = task.Status,
|
||||
});
|
||||
}
|
||||
|
||||
// Aktuelle Lerngruppen als Chips
|
||||
CurrentGroups.Clear();
|
||||
foreach (var group in _groups.GetBySchoolYear(schoolYear)
|
||||
.OrderBy(g => g.Name))
|
||||
{
|
||||
CurrentGroups.Add(new GroupChip
|
||||
{
|
||||
GroupId = group.Id,
|
||||
Name = group.Name,
|
||||
Subject = group.Subject ?? "",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Refresh() => Load();
|
||||
}
|
||||
|
||||
// Anzeigemodelle für Dashboard-Widgets
|
||||
public class LessonItem
|
||||
{
|
||||
public string GroupName { get; set; } = "";
|
||||
public string Topic { get; set; } = "";
|
||||
public LessonStatus Status { get; set; }
|
||||
}
|
||||
|
||||
public class TaskItem
|
||||
{
|
||||
public string Title { get; set; } = "";
|
||||
public string DueDate { get; set; } = "";
|
||||
public bool IsOverdue { get; set; }
|
||||
public bool IsDueSoon { get; set; }
|
||||
public WorkTaskStatus Status { get; set; }
|
||||
}
|
||||
|
||||
public class GroupChip
|
||||
{
|
||||
public Guid GroupId { get; set; }
|
||||
public string Name { get; set; } = "";
|
||||
public string Subject { get; set; } = "";
|
||||
}
|
||||
Reference in New Issue
Block a user