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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -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<Block> Bloecke { get; init; } = Array.Empty<Block>();
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Ein Tagesabschnitt: Band plus eigene Sitzungs-/Pausenregeln (betrieb/zeitplan.py).</summary>
|
||||
public sealed record Block(string Von, string Bis, Spanne? Sitzung = null, Spanne? Pause = null)
|
||||
{
|
||||
public static IReadOnlyList<Block> Aus(JsonNode? n)
|
||||
{
|
||||
if (n is not JsonArray a) return Array.Empty<Block>();
|
||||
var raus = new List<Block>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Mittagsband mit Pause: von–bis Uhrzeit, Laenge gewuerfelt (betrieb/zeitplan.py).</summary>
|
||||
public sealed record Mittag(string Von, string Bis, Spanne Dauer)
|
||||
{
|
||||
|
||||
@@ -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"),
|
||||
|
||||
Reference in New Issue
Block a user