Gastansicht, Verbesserungen bei Planung

This commit is contained in:
concierge committed 2026-11-18 07:57:00 +01:00
1 parent b3afa3ef32
commit c08d43e7dd
38 files changed
+3845 -219

No files matched your search

+164
View File
@@ -107,8 +107,58 @@ public struct Church: Identifiable, Codable, Hashable, Sendable {
// MARK: - People
public enum WeekdayPeriod: String, Codable, CaseIterable, Identifiable, Sendable, Hashable {
case all
case morning
case afternoon
case evening
public var id: String { rawValue }
public var label: String {
switch self {
case .morning: "vormittags (0–12 Uhr)"
case .afternoon: "nachmittags (12–17 Uhr)"
case .evening: "abends (ab 17 Uhr)"
case .all: "ganztägig"
}
}
public var shortLabel: String {
switch self {
case .morning: "vormittags"
case .afternoon: "nachmittags"
case .evening: "abends"
case .all: "ganztägig"
}
}
/// Morning is 0–12, afternoon 12–17, evening after 17.
public func matches(timeMinutes: Int) -> Bool {
switch self {
case .morning: timeMinutes < 12 * 60
case .afternoon: timeMinutes >= 12 * 60 && timeMinutes < 17 * 60
case .evening: timeMinutes >= 17 * 60
case .all: true
}
}
}
public struct WeekdayPeriodPreference: Codable, Hashable, Sendable, Identifiable {
public var weekday: Int
public var period: WeekdayPeriod
public var id: Int { weekday }
public init(weekday: Int, period: WeekdayPeriod = .all) {
self.weekday = weekday
self.period = period
}
}
public struct Person: Identifiable, Codable, Hashable, Sendable {
public var id: String
public var shortCode: String
public var firstName: String
public var lastName: String
public var roles: Set<Role>
@@ -116,13 +166,16 @@ public struct Person: Identifiable, Codable, Hashable, Sendable {
public var phone: String
public var preferredChurchIDs: Set<String>
public var preferredWeekdays: Set<Int> // 1 = Sunday … 7 = Saturday; empty = no preference
public var preferredWeekdayPeriods: [WeekdayPeriodPreference]
public var preferredServiceTitles: [String]
public var maxPerMonth: Int
public var allowBeyondPreferences: Bool
public var active: Bool
public var notes: String
public init(
id: String = UUID().uuidString,
shortCode: String = "",
firstName: String,
lastName: String,
roles: Set<Role> = [.lector],
@@ -130,12 +183,15 @@ public struct Person: Identifiable, Codable, Hashable, Sendable {
phone: String = "",
preferredChurchIDs: Set<String> = [],
preferredWeekdays: Set<Int> = [],
preferredWeekdayPeriods: [WeekdayPeriodPreference] = [],
preferredServiceTitles: [String] = [],
maxPerMonth: Int = 6,
allowBeyondPreferences: Bool = false,
active: Bool = true,
notes: String = ""
) {
self.id = id
self.shortCode = shortCode
self.firstName = firstName
self.lastName = lastName
self.roles = roles
@@ -143,12 +199,42 @@ public struct Person: Identifiable, Codable, Hashable, Sendable {
self.phone = phone
self.preferredChurchIDs = preferredChurchIDs
self.preferredWeekdays = preferredWeekdays
self.preferredWeekdayPeriods = preferredWeekdayPeriods
self.preferredServiceTitles = preferredServiceTitles
self.maxPerMonth = maxPerMonth
self.allowBeyondPreferences = allowBeyondPreferences
self.active = active
self.notes = notes
}
private enum CodingKeys: String, CodingKey {
case id, shortCode, firstName, lastName, roles, email, phone
case preferredChurchIDs, preferredWeekdays, preferredWeekdayPeriods
case preferredServiceTitles, maxPerMonth, allowBeyondPreferences
case active, notes
}
/// Older exchange files and backups predate the Kürzel, weekday periods and
/// the beyond-preferences flag, so every new key falls back to a default.
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
shortCode = try container.decodeIfPresent(String.self, forKey: .shortCode) ?? ""
firstName = try container.decode(String.self, forKey: .firstName)
lastName = try container.decode(String.self, forKey: .lastName)
roles = try container.decodeIfPresent(Set<Role>.self, forKey: .roles) ?? [.lector]
email = try container.decodeIfPresent(String.self, forKey: .email) ?? ""
phone = try container.decodeIfPresent(String.self, forKey: .phone) ?? ""
preferredChurchIDs = try container.decodeIfPresent(Set<String>.self, forKey: .preferredChurchIDs) ?? []
preferredWeekdays = try container.decodeIfPresent(Set<Int>.self, forKey: .preferredWeekdays) ?? []
preferredWeekdayPeriods = try container.decodeIfPresent([WeekdayPeriodPreference].self, forKey: .preferredWeekdayPeriods) ?? []
preferredServiceTitles = try container.decodeIfPresent([String].self, forKey: .preferredServiceTitles) ?? []
maxPerMonth = try container.decodeIfPresent(Int.self, forKey: .maxPerMonth) ?? 6
allowBeyondPreferences = try container.decodeIfPresent(Bool.self, forKey: .allowBeyondPreferences) ?? false
active = try container.decodeIfPresent(Bool.self, forKey: .active) ?? true
notes = try container.decodeIfPresent(String.self, forKey: .notes) ?? ""
}
public var fullName: String {
"\(firstName) \(lastName)".trimmingCharacters(in: .whitespaces)
}
@@ -176,6 +262,34 @@ public struct Person: Identifiable, Codable, Hashable, Sendable {
}
public func canFill(_ role: Role) -> Bool { roles.contains(role) }
/// Guest-facing label: an explicitly maintained Kürzel wins, otherwise the
/// initials from first and last name.
public var displayShort: String {
let code = shortCode.trimmingCharacters(in: .whitespacesAndNewlines)
return code.isEmpty ? initials : code
}
public func weekdayPeriod(for weekday: Int) -> WeekdayPeriod {
preferredWeekdayPeriods.first { $0.weekday == weekday }?.period ?? .all
}
/// High feasts count like Sundays, so a Sunday preference also covers them.
/// An empty weekday list means no restriction.
public func matchesWeekdayPreference(weekday: Int, timeMinutes: Int, highFeast: Bool) -> Bool {
guard !preferredWeekdays.isEmpty else { return true }
var candidates = [weekday]
if highFeast && weekday != 1 { candidates.append(1) }
for day in candidates where preferredWeekdays.contains(day) {
if weekdayPeriod(for: day).matches(timeMinutes: timeMinutes) { return true }
}
return false
}
/// Free-text planning note shown next to assignments and candidates.
public var preferenceNote: String {
notes.trimmingCharacters(in: .whitespacesAndNewlines)
}
}
public struct Absence: Identifiable, Codable, Hashable, Sendable {
@@ -380,6 +494,7 @@ public struct Assignment: Identifiable, Codable, Hashable, Sendable {
public var personID: String
public var role: Role
public var locked: Bool
public var beyondPreferences: Bool
public var note: String
public var createdAt: Date
@@ -389,6 +504,7 @@ public struct Assignment: Identifiable, Codable, Hashable, Sendable {
personID: String,
role: Role,
locked: Bool = false,
beyondPreferences: Bool = false,
note: String = "",
createdAt: Date = Date()
) {
@@ -397,9 +513,28 @@ public struct Assignment: Identifiable, Codable, Hashable, Sendable {
self.personID = personID
self.role = role
self.locked = locked
self.beyondPreferences = beyondPreferences
self.note = note
self.createdAt = createdAt
}
private enum CodingKeys: String, CodingKey {
case id, serviceID, personID, role, locked, beyondPreferences, note, createdAt
}
/// Exchange files created before the beyond-preferences marker decode to
/// the ordinary case.
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
serviceID = try container.decode(String.self, forKey: .serviceID)
personID = try container.decode(String.self, forKey: .personID)
role = try container.decode(Role.self, forKey: .role)
locked = try container.decodeIfPresent(Bool.self, forKey: .locked) ?? false
beyondPreferences = try container.decodeIfPresent(Bool.self, forKey: .beyondPreferences) ?? false
note = try container.decodeIfPresent(String.self, forKey: .note) ?? ""
createdAt = try container.decodeIfPresent(Date.self, forKey: .createdAt) ?? Date()
}
}
// MARK: - Liturgy
@@ -710,6 +845,13 @@ public struct DayPlanRow: Identifiable, Hashable, Sendable {
public var openSlots: Int { services.reduce(0) { $0 + $1.openSlots } }
public var assignmentCount: Int { services.reduce(0) { $0 + $1.assignments.count } }
public var hasServices: Bool { !services.isEmpty }
/// Marks days with at least one assignment beyond the person's preferences.
public var hasBeyondPreferences: Bool {
services.contains { service in
service.assignments.contains(where: \.beyondPreferences)
}
}
}
public struct UnfilledSlot: Identifiable, Hashable, Sendable {
@@ -898,6 +1040,7 @@ public struct ExchangeSummary: Hashable, Sendable {
public struct PlannerOptions: Codable, Hashable, Sendable {
public var replaceExisting: Bool
public var respectPreferredWeekdays: Bool
public var allowBeyondPreferences: Bool
public var allowDoubleRolesOnSameDay: Bool
public var weightChurchPreference: Double
public var weightServicePreference: Double
@@ -908,6 +1051,7 @@ public struct PlannerOptions: Codable, Hashable, Sendable {
public init(
replaceExisting: Bool = false,
respectPreferredWeekdays: Bool = true,
allowBeyondPreferences: Bool = false,
allowDoubleRolesOnSameDay: Bool = false,
weightChurchPreference: Double = 8,
weightServicePreference: Double = 4,
@@ -917,6 +1061,7 @@ public struct PlannerOptions: Codable, Hashable, Sendable {
) {
self.replaceExisting = replaceExisting
self.respectPreferredWeekdays = respectPreferredWeekdays
self.allowBeyondPreferences = allowBeyondPreferences
self.allowDoubleRolesOnSameDay = allowDoubleRolesOnSameDay
self.weightChurchPreference = weightChurchPreference
self.weightServicePreference = weightServicePreference
@@ -924,6 +1069,25 @@ public struct PlannerOptions: Codable, Hashable, Sendable {
self.weightDualRolePreference = weightDualRolePreference
self.maxAssignmentsPerDay = maxAssignmentsPerDay
}
private enum CodingKeys: String, CodingKey {
case replaceExisting, respectPreferredWeekdays, allowBeyondPreferences
case allowDoubleRolesOnSameDay, weightChurchPreference, weightServicePreference
case weightFairness, weightDualRolePreference, maxAssignmentsPerDay
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
replaceExisting = try container.decodeIfPresent(Bool.self, forKey: .replaceExisting) ?? false
respectPreferredWeekdays = try container.decodeIfPresent(Bool.self, forKey: .respectPreferredWeekdays) ?? true
allowBeyondPreferences = try container.decodeIfPresent(Bool.self, forKey: .allowBeyondPreferences) ?? false
allowDoubleRolesOnSameDay = try container.decodeIfPresent(Bool.self, forKey: .allowDoubleRolesOnSameDay) ?? false
weightChurchPreference = try container.decodeIfPresent(Double.self, forKey: .weightChurchPreference) ?? 8
weightServicePreference = try container.decodeIfPresent(Double.self, forKey: .weightServicePreference) ?? 4
weightFairness = try container.decodeIfPresent(Double.self, forKey: .weightFairness) ?? 2.2
weightDualRolePreference = try container.decodeIfPresent(Double.self, forKey: .weightDualRolePreference) ?? 14
maxAssignmentsPerDay = try container.decodeIfPresent(Int.self, forKey: .maxAssignmentsPerDay) ?? 1
}
}
public struct PlanResult: Sendable {