- Neue-Stunde-Dialog: Datum wird beim Anlegen anhand des Stundenplans
und der letzten Stunde der Einheit vorbelegt statt auf "heute"
(behebt eine falsch erkannte Doppelstunde, wenn "heute" nicht auf
den passenden Wochentag fiel).
- Zeiterfassung: Button "Unterrichtszeit heute übernehmen" schlägt
Start/Ende aus dem heutigen Stundenplan inkl. Puffer davor/danach vor.
- Dashboard: neue Kachel "Ungeplante Stunden" erinnert an Stunden ohne
Thema für heute/morgen, mit Opt-out je Gruppe ("Benötigt
Unterrichtsplanung"), Doppelstunden-Erkennung (keine doppelte Meldung
für die zweite Periode) und Berücksichtigung von Stundenausfall.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
63 lines
2.4 KiB
C#
63 lines
2.4 KiB
C#
using System.Text.Json;
|
|
|
|
namespace LehrerApp.Core.Services;
|
|
|
|
public sealed class DashboardCardSetting
|
|
{
|
|
public string Key { get; set; } = "";
|
|
public bool IsVisible { get; set; } = true;
|
|
public int Order { get; set; }
|
|
}
|
|
|
|
/// <summary>Speichert Sichtbarkeit und Reihenfolge der Dashboard-Kacheln lokal.</summary>
|
|
public sealed class DashboardSettingsService
|
|
{
|
|
public static readonly string[] DefaultCardOrder =
|
|
[
|
|
"today", "tasks", "calendar", "excuses", "upcoming",
|
|
"corrections", "unplanned", "alerts", "attendance", "support", "groups",
|
|
];
|
|
|
|
private readonly string _configPath;
|
|
|
|
public DashboardSettingsService(string appDataPath) =>
|
|
_configPath = Path.Combine(appDataPath, "dashboardsettings.json");
|
|
|
|
public List<DashboardCardSetting> Load()
|
|
{
|
|
try
|
|
{
|
|
if (File.Exists(_configPath))
|
|
{
|
|
var saved = JsonSerializer.Deserialize<List<DashboardCardSetting>>(
|
|
File.ReadAllText(_configPath)) ?? [];
|
|
var byKey = saved
|
|
.Where(s => DefaultCardOrder.Contains(s.Key))
|
|
.GroupBy(s => s.Key).ToDictionary(g => g.Key, g => g.First());
|
|
return DefaultCardOrder.Select((key, defaultOrder) => byKey.TryGetValue(key, out var item)
|
|
? new DashboardCardSetting { Key = key, IsVisible = item.IsVisible, Order = item.Order }
|
|
: new DashboardCardSetting { Key = key, IsVisible = true, Order = defaultOrder })
|
|
.OrderBy(s => s.Order).ThenBy(s => Array.IndexOf(DefaultCardOrder, s.Key))
|
|
.Select((s, index) => new DashboardCardSetting
|
|
{ Key = s.Key, IsVisible = s.IsVisible, Order = index })
|
|
.ToList();
|
|
}
|
|
}
|
|
catch { /* beschädigte Konfiguration -> Standardreihenfolge */ }
|
|
|
|
return DefaultCardOrder.Select((key, index) => new DashboardCardSetting
|
|
{ Key = key, IsVisible = true, Order = index }).ToList();
|
|
}
|
|
|
|
public void Save(IEnumerable<DashboardCardSetting> settings)
|
|
{
|
|
var normalized = settings.Select((s, index) => new DashboardCardSetting
|
|
{
|
|
Key = s.Key,
|
|
IsVisible = s.IsVisible,
|
|
Order = index,
|
|
}).ToList();
|
|
File.WriteAllText(_configPath, JsonSerializer.Serialize(normalized));
|
|
}
|
|
}
|