Files
LehrerApp/LehrerApp.Desktop/ViewModels/UntisHub/UntisHubViewModel.cs
T
adminandClaude Sonnet 5 ba52109eaa
CI / build-and-test (push) Canceled after 0s
feat: Untis-Hub für WebUntis-Sync-Gesundheitsstatus
Zeigt die Fälligkeit der vier bestehenden, manuell ausgelösten WebUntis-Abgleiche
(Fehlzeiten je Lerngruppe, offene Stunden, Klassenbuch-, Hausaufgabenabgleich) in
einem neuen Hub-Fenster, ohne selbst WebUntis anzufragen - nur gespeicherte
Zeitstempel werden ausgewertet. Konsolidiert die bisher verstreuten Einstiegspunkte
(Sidebar-Button, Dashboard-Buttons) in ein neues WebUntis-Menü plus einen
kompakten Gesundheits-Indikator auf dem Dashboard.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-10 23:41:12 +02:00

79 lines
3.1 KiB
C#

using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using LehrerApp.Core.Interfaces;
using LehrerApp.Core.Models;
using LehrerApp.Desktop.Services;
namespace LehrerApp.Desktop.ViewModels.UntisHub;
/// <summary>Eine Zeile im Untis-Hub-Fenster - reine Anzeige-Projektion von
/// <see cref="UntisHubJobRow"/>, neu aufgebaut bei jedem <see cref="UntisHubViewModel.Load"/>.</summary>
public sealed class UntisHubRowViewModel
{
public UntisHubJobKind Kind { get; }
public Guid? GroupId { get; }
public string GroupName { get; }
public string JobLabel { get; }
public string DueLabel { get; }
public string? LastResultSummary { get; }
public bool IsWarning { get; }
public bool IsDanger { get; }
public UntisHubRowViewModel(UntisHubJobRow row)
{
Kind = row.Kind; GroupId = row.GroupId; GroupName = row.GroupName;
JobLabel = Label(row.Kind); DueLabel = row.DueLabel; LastResultSummary = row.LastResultSummary;
IsWarning = row.DueState == UntisHubDueState.Due;
IsDanger = row.DueState == UntisHubDueState.Overdue;
}
private static string Label(UntisHubJobKind kind) => kind switch
{
UntisHubJobKind.FehlzeitenKurz => "Fehlzeiten (kurzfristig)",
UntisHubJobKind.FehlzeitenLang => "Fehlzeiten (seit Schuljahresbeginn)",
UntisHubJobKind.OffenePeriods => "Offene Stunden",
UntisHubJobKind.Klassenbuchabgleich => "Klassenbuchabgleich",
UntisHubJobKind.Hausaufgabenabgleich => "Hausaufgabenabgleich",
_ => kind.ToString(),
};
}
/// <summary>ViewModel des Untis-Hub-Fensters (siehe TODO.md) - zeigt nur den gespeicherten
/// Fälligkeitsstand an (<see cref="UntisHubService.GetRows"/>, rein lesend aus LiteDB). Das
/// tatsächliche Ausführen eines Jobs (inkl. WebUntis-Anfrage) übernimmt die Code-Behind-Klasse über
/// <see cref="UntisHubActions"/>, weil dafür ein Fenster-Owner für <c>ShowDialog</c> gebraucht wird.</summary>
public partial class UntisHubViewModel : ObservableObject
{
private readonly UntisHubService _hub;
private readonly IGroupRepository _groups;
public ObservableCollection<UntisHubRowViewModel> Rows { get; } = [];
[ObservableProperty] private bool _isAvailable;
[ObservableProperty] private string _status = "";
public UntisHubViewModel(UntisHubService hub, IGroupRepository groups, WebUntisIntegrationService untis)
{
_hub = hub; _groups = groups;
IsAvailable = untis.IsAvailable;
Load();
}
public void Load()
{
Rows.Clear();
if (!IsAvailable)
{
Status = "WebUntis ist nicht konfiguriert (siehe Einstellungen).";
return;
}
foreach (var row in _hub.GetRows()) Rows.Add(new UntisHubRowViewModel(row));
var overdue = Rows.Count(r => r.IsDanger);
var due = Rows.Count(r => r.IsWarning);
Status = overdue > 0 || due > 0
? $"{overdue + due} von {Rows.Count} Prüfungen fällig ({overdue} überfällig)."
: $"Alle {Rows.Count} Prüfungen aktuell.";
}
public LearningGroup? FindGroup(Guid id) => _groups.GetById(id);
}