From b5a8fd049f1e689e12faf64026827f95b3f8a3ab Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Tue, 1 Dec 2026 10:18:21 +0100 Subject: [PATCH] Tagesbloecke im Editor baubar (Mac und WinUI) Die Bloecke gab es im Modell, aber nicht in der Oberflaeche. Jetzt: Liste mit Band je Abschnitt, eigener Laenge auf Wunsch, Block hinzufuegen und entfernen - so laesst sich der Tag zusammenstecken und per Vorlage aufheben. --- mac/Sources/Cockpit/PlanEditor.swift | 39 ++++++++++++++++++++++++++ mac/Sources/CockpitKern/Zeitplan.swift | 31 +++++++++++++++++++- winui/Kern/Plan.cs | 28 ++++++++++++++++++ winui/Seiten/PlanEditor.cs | 21 ++++++++++++++ 4 files changed, 118 insertions(+), 1 deletion(-) diff --git a/mac/Sources/Cockpit/PlanEditor.swift b/mac/Sources/Cockpit/PlanEditor.swift index c14278de..263c29ff 100644 --- a/mac/Sources/Cockpit/PlanEditor.swift +++ b/mac/Sources/Cockpit/PlanEditor.swift @@ -156,6 +156,7 @@ private struct SitzungsEinstellung: View { } } Frage("Vorlage laden oder den Tag aufheben?") { vorlagenZeile } + Frage("Tagesblöcke?") { bloecke } Frage("Höchstens spielen?") { grenzen } Frage("Erst ab Uhrzeit?") { startzeit } Frage("Mittagspause?") { mittag } @@ -165,6 +166,44 @@ private struct SitzungsEinstellung: View { } } + /// Tagesbloecke: je Abschnitt ein Band, optional eigene Sitzung/Pause. Ausserhalb wird gewartet. + private var bloecke: some View { + @Bindable var c = cockpit + let uhr = { (wert: Int, neu: @escaping (Int) -> Void) in + Picker("", selection: Binding(get: { wert }, set: neu)) { + ForEach(0..<24, id: \.self) { Text(String(format: "%02d", $0)).tag($0) } + } + .labelsHidden().frame(width: 62) + } + let std = { (t: String) in Int(t.prefix(2)) ?? 0 } + return VStack(alignment: .leading, spacing: 6) { + ForEach(Array(c.wahl.zeitplan.bloecke.enumerated()), id: \.offset) { i, b in + HStack(spacing: 4) { + uhr(std(b.von)) { c.wahl.zeitplan.bloecke[i].von = String(format: "%02d:00", $0) } + Text("–") + uhr(std(b.bis)) { c.wahl.zeitplan.bloecke[i].bis = String(format: "%02d:00", $0) } + if c.wahl.zeitplan.bloecke[i].sitzung != nil { + MinutenSpanne(wert: Binding(get: { c.wahl.zeitplan.bloecke[i].sitzung ?? Spanne(30, 60) }, + set: { c.wahl.zeitplan.bloecke[i].sitzung = $0 }), unten: 5) + } + Button { c.wahl.zeitplan.bloecke[i].sitzung = + c.wahl.zeitplan.bloecke[i].sitzung == nil ? Spanne(30, 60) : nil } label: { + Text(c.wahl.zeitplan.bloecke[i].sitzung == nil ? "+Länge" : "−Länge").font(.caption2) + }.buttonStyle(.plain) + Button { c.wahl.zeitplan.bloecke.remove(at: i) } label: { + Image(systemName: "minus.circle") + }.buttonStyle(.plain).help("Block entfernen") + } + } + Button("Block hinzufügen") { + let letzte = c.wahl.zeitplan.bloecke.last?.bis ?? "09:00" + c.wahl.zeitplan.bloecke.append(.init(von: letzte, bis: "12:00")) + }.font(.caption) + Text("Ausserhalb der Blöcke wird nicht gespielt. Ohne Blöcke gilt das Tagesfenster.") + .font(.caption2).foregroundStyle(.tertiary) + } + } + /// Gesamtgrenzen ueber den ganzen Lauf: Minuten und Haende (beide optional). private var grenzen: some View { @Bindable var c = cockpit diff --git a/mac/Sources/CockpitKern/Zeitplan.swift b/mac/Sources/CockpitKern/Zeitplan.swift index 57861952..cb64806a 100644 --- a/mac/Sources/CockpitKern/Zeitplan.swift +++ b/mac/Sources/CockpitKern/Zeitplan.swift @@ -23,6 +23,32 @@ public struct Zeitplan: Equatable, Sendable, Decodable { public init(start: String, ende: String) { self.start = start; self.ende = ende } } + /// Ein Tagesabschnitt: Band plus eigene Sitzungs-/Pausenregeln (nil: es gilt der Plan). + public struct Block: Equatable, Sendable, Decodable, Identifiable { + public var von: String + public var bis: String + public var sitzung: Spanne? + public var pause: Spanne? + public var id: String { "\(von)-\(bis)" } + public init(von: String, bis: String, sitzung: Spanne? = nil, pause: Spanne? = nil) { + self.von = von; self.bis = bis; self.sitzung = sitzung; self.pause = pause + } + enum CodingKeys: String, CodingKey { case von, bis, sitzung, pause } + public init(from d: Decoder) throws { + let c = try d.container(keyedBy: CodingKeys.self) + von = c.liste(.von).first ?? "" + bis = c.liste(.bis).first ?? "" + sitzung = Spanne((try? c.decodeIfPresent([Double].self, forKey: .sitzung)) ?? nil) + pause = Spanne((try? c.decodeIfPresent([Double].self, forKey: .pause)) ?? nil) + } + var daten: [String: Any] { + var d: [String: Any] = ["von": von, "bis": bis] + if let sitzung { d["sitzung"] = sitzung.daten } + if let pause { d["pause"] = pause.daten } + return d + } + } + public struct Mittag: Equatable, Sendable { public var von: String // "HH:MM" public var bis: String @@ -40,6 +66,7 @@ public struct Zeitplan: Equatable, Sendable, Decodable { public var mittag: Mittag? // Band mit Pause am Mittag public var hoechstdauer: Double? // Minuten Spielzeit ueber den ganzen Lauf public var hoechstHaende: Int? // Haende ueber den ganzen Lauf + public var bloecke: [Block] = [] // Tagesabschnitte; leer: immer public var aktiv: Bool { self != .ohne } @@ -68,7 +95,7 @@ public struct Zeitplan: Equatable, Sendable, Decodable { enum CodingKeys: String, CodingKey { case sitzung, pause, sitzungen, fenster, start, mittag - case hoechstdauer, hoechstHaende = "hoechst_haende" + case hoechstdauer, hoechstHaende = "hoechst_haende", bloecke } public init(from d: Decoder) throws { @@ -81,6 +108,7 @@ public struct Zeitplan: Equatable, Sendable, Decodable { start: c.liste(.start).first.flatMap { $0.count == 5 ? $0 : nil }, mittag: ((try? c.decodeIfPresent(MittagRaw.self, forKey: .mittag)) ?? nil)?.bau(), hoechstdauer: c.zahl(.hoechstdauer), hoechstHaende: c.zahl(.hoechstHaende).map { Int($0) }) + bloecke = ((try? c.decodeIfPresent([Block].self, forKey: .bloecke)) ?? nil) ?? [] } var daten: [String: Any] { @@ -89,6 +117,7 @@ public struct Zeitplan: Equatable, Sendable, Decodable { if pause.bis > 0 { d["pause"] = pause.daten } if let sitzungen { d["sitzungen"] = sitzungen } if let fenster { d["fenster"] = [fenster.start, fenster.ende] } + if !bloecke.isEmpty { d["bloecke"] = bloecke.map { $0.daten } } if let hoechstdauer { d["hoechstdauer"] = hoechstdauer } if let hoechstHaende { d["hoechst_haende"] = hoechstHaende } if let start { d["start"] = start } diff --git a/winui/Kern/Plan.cs b/winui/Kern/Plan.cs index 326e4b63..066636e6 100644 --- a/winui/Kern/Plan.cs +++ b/winui/Kern/Plan.cs @@ -36,6 +36,7 @@ public sealed record Zeitplan public Mittag? Mittag { get; init; } // Pause im Mittagsband public double? Hoechstdauer { get; init; } // Minuten Spielzeit im Lauf public int? HoechstHaende { get; init; } // Haende im Lauf + public IReadOnlyList Bloecke { get; init; } = Array.Empty(); public static readonly Zeitplan Ohne = new(); @@ -56,6 +57,7 @@ public sealed record Zeitplan Mittag = Mittag.Aus(o["mittag"]), Hoechstdauer = o.Zahl("hoechstdauer") is double hd and > 0 ? hd : null, HoechstHaende = o.Zahl("hoechst_haende") is double hh and >= 1 ? (int)hh : null, + Bloecke = Block.Aus(o["bloecke"]), }; } @@ -70,6 +72,7 @@ public sealed record Zeitplan if (Mittag is Mittag m) d["mittag"] = m.Daten(); if (Hoechstdauer is double hd) d["hoechstdauer"] = hd; if (HoechstHaende is int hh) d["hoechst_haende"] = hh; + if (Bloecke.Count > 0) d["bloecke"] = new JsonArray(Bloecke.Select(b => (JsonNode)b.Daten()).ToArray()); return d; } @@ -86,6 +89,31 @@ public sealed record Zeitplan } } +/// Ein Tagesabschnitt: Band plus eigene Sitzungs-/Pausenregeln (betrieb/zeitplan.py). +public sealed record Block(string Von, string Bis, Spanne? Sitzung = null, Spanne? Pause = null) +{ + public static IReadOnlyList Aus(JsonNode? n) + { + if (n is not JsonArray a) return Array.Empty(); + var raus = new List(); + foreach (var x in a) + { + if (x is not JsonObject o) continue; + if (Json.TextVon(o["von"]) is not { Length: 5 } v || Json.TextVon(o["bis"]) is not { Length: 5 } b) continue; + raus.Add(new Block(v, b, Spanne.Aus(o["sitzung"]), Spanne.Aus(o["pause"]))); + } + return raus.OrderBy(x => x.Von).ToList(); + } + + public JsonObject Daten() + { + var d = new JsonObject { ["von"] = Von, ["bis"] = Bis }; + if (Sitzung is Spanne s) d["sitzung"] = s.Daten(); + if (Pause is Spanne p) d["pause"] = p.Daten(); + return d; + } +} + /// Mittagsband mit Pause: von–bis Uhrzeit, Laenge gewuerfelt (betrieb/zeitplan.py). public sealed record Mittag(string Von, string Bis, Spanne Dauer) { diff --git a/winui/Seiten/PlanEditor.cs b/winui/Seiten/PlanEditor.cs index b7b75fdc..8f14fdcb 100644 --- a/winui/Seiten/PlanEditor.cs +++ b/winui/Seiten/PlanEditor.cs @@ -102,6 +102,27 @@ public static class PlanEditor Teile.Knopf("Speichern", () => Daten("zeitplan_preset_speichern")), Teile.Knopf("Löschen", () => Daten("zeitplan_preset_loeschen"))))); + var bloeckeListe = Ui.Spalte(6); + for (var i = 0; i < zp.Bloecke.Count; i++) + { + var idx = i; + var b = zp.Bloecke[i]; + var zeile = Ui.Reihe(6, Uhr(int.Parse(b.Von[..2]), h => Setzen(x => x with + { Bloecke = x.Bloecke.Select((y, j) => j == idx ? y with { Von = $"{h:00}:00" } : y).ToList() }))); + zeile.Children.Add(Ui.Klein("–")); + zeile.Children.Add(Uhr(int.Parse(b.Bis[..2]), h => Setzen(x => x with + { Bloecke = x.Bloecke.Select((y, j) => j == idx ? y with { Bis = $"{h:00}:00" } : y).ToList() }))); + if (b.Sitzung is Spanne sz) + zeile.Children.Add(MinutenSpanne(sz, 5, sp => Setzen(x => x with + { Bloecke = x.Bloecke.Select((y, j) => j == idx ? y with { Sitzung = sp } : y).ToList() }))); + zeile.Children.Add(Teile.Knopf(b.Sitzung == null ? "+Länge" : "−Länge", () => Setzen(x => x with + { Bloecke = x.Bloecke.Select((y, j) => j == idx ? y with { Sitzung = y.Sitzung == null ? new Spanne(30, 60) : null } : y).ToList() }))); + zeile.Children.Add(Teile.Knopf("−", () => Setzen(x => x with { Bloecke = x.Bloecke.Where((_, j) => j != idx).ToList() }))); + bloeckeListe.Children.Add(zeile); + } + bloeckeListe.Children.Add(Teile.Knopf("Block hinzufügen", () => Setzen(x => + x with { Bloecke = x.Bloecke.Append(new Block(x.Bloecke.LastOrDefault()?.Bis ?? "09:00", "12:00")).ToList() }))); + s.Children.Add(Frage("Tagesblöcke?", bloeckeListe)); s.Children.Add(Frage("Höchstens spielen?", Ui.Reihe(8, Zahl(zp.Hoechstdauer ?? 0, 0, 1440, 30, n => Setzen(x => x with { Hoechstdauer = n > 0 ? n : null })), Ui.Klein("min"),