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

+58 -15
View File
@@ -47,6 +47,7 @@ public final class AppDatabase {
CREATE TABLE IF NOT EXISTS people (
id TEXT PRIMARY KEY,
short_code TEXT NOT NULL DEFAULT '',
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
roles TEXT NOT NULL,
@@ -54,8 +55,10 @@ public final class AppDatabase {
phone TEXT NOT NULL DEFAULT '',
preferred_church_ids TEXT NOT NULL DEFAULT '[]',
preferred_weekdays TEXT NOT NULL DEFAULT '[]',
preferred_weekday_periods TEXT NOT NULL DEFAULT '[]',
preferred_service_titles TEXT NOT NULL DEFAULT '[]',
max_per_month INTEGER NOT NULL DEFAULT 6,
allow_beyond_preferences INTEGER NOT NULL DEFAULT 0,
active INTEGER NOT NULL DEFAULT 1,
notes TEXT NOT NULL DEFAULT ''
);
@@ -118,6 +121,7 @@ public final class AppDatabase {
person_id TEXT NOT NULL REFERENCES people(id) ON DELETE CASCADE,
role TEXT NOT NULL,
locked INTEGER NOT NULL DEFAULT 0,
beyond_preferences INTEGER NOT NULL DEFAULT 0,
note TEXT NOT NULL DEFAULT '',
created_at TEXT NOT NULL,
UNIQUE(service_id, person_id, role)
@@ -178,7 +182,14 @@ public final class AppDatabase {
column: "location",
definition: "TEXT NOT NULL DEFAULT ''"
)
try database.run("INSERT OR REPLACE INTO settings(key, value) VALUES('schemaVersion', '3')")
// People gained a Kürzel, weekday time periods and permission to be
// planned beyond their preferences.
try addColumnIfMissing(table: "people", column: "short_code", definition: "TEXT NOT NULL DEFAULT ''")
try addColumnIfMissing(table: "people", column: "preferred_weekday_periods", definition: "TEXT NOT NULL DEFAULT '[]'")
try addColumnIfMissing(table: "people", column: "allow_beyond_preferences", definition: "INTEGER NOT NULL DEFAULT 0")
// Assignments record when a volunteer was planned beyond preferences.
try addColumnIfMissing(table: "assignments", column: "beyond_preferences", definition: "INTEGER NOT NULL DEFAULT 0")
try database.run("INSERT OR REPLACE INTO settings(key, value) VALUES('schemaVersion', '4')")
}
private func addColumnIfMissing(table: String, column: String, definition: String) throws {
@@ -246,22 +257,30 @@ public final class AppDatabase {
let roles = encode(person.roles.map(\.rawValue).sorted())
let churches = encode(person.preferredChurchIDs.sorted())
let weekdays = encode(person.preferredWeekdays.sorted())
let periods = encode(person.preferredWeekdayPeriods.sorted { $0.weekday < $1.weekday })
let titles = encode(person.preferredServiceTitles)
try database.run("""
INSERT INTO people(id, first_name, last_name, roles, email, phone, preferred_church_ids,
preferred_weekdays, preferred_service_titles, max_per_month, active, notes)
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
INSERT INTO people(id, short_code, first_name, last_name, roles, email, phone, preferred_church_ids,
preferred_weekdays, preferred_weekday_periods, preferred_service_titles,
max_per_month, allow_beyond_preferences, active, notes)
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(id) DO UPDATE SET
short_code=excluded.short_code,
first_name=excluded.first_name, last_name=excluded.last_name, roles=excluded.roles,
email=excluded.email, phone=excluded.phone,
preferred_church_ids=excluded.preferred_church_ids,
preferred_weekdays=excluded.preferred_weekdays,
preferred_weekday_periods=excluded.preferred_weekday_periods,
preferred_service_titles=excluded.preferred_service_titles,
max_per_month=excluded.max_per_month, active=excluded.active, notes=excluded.notes
max_per_month=excluded.max_per_month,
allow_beyond_preferences=excluded.allow_beyond_preferences,
active=excluded.active, notes=excluded.notes
""", [
.text(person.id), .text(person.firstName), .text(person.lastName), .text(roles),
.text(person.id), .text(person.shortCode.trimmingCharacters(in: .whitespacesAndNewlines)),
.text(person.firstName), .text(person.lastName), .text(roles),
.text(person.email), .text(person.phone), .text(churches), .text(weekdays),
.text(titles), .int(person.maxPerMonth), .bool(person.active), .text(person.notes)
.text(periods), .text(titles), .int(person.maxPerMonth),
.bool(person.allowBeyondPreferences), .bool(person.active), .text(person.notes)
])
}
@@ -277,6 +296,7 @@ public final class AppDatabase {
let roleStrings: [String] = decode(row.string("roles", default: "[]"))
return Person(
id: id,
shortCode: row.string("short_code", default: ""),
firstName: first,
lastName: last,
roles: Set(roleStrings.compactMap(Role.init(rawValue:))),
@@ -284,8 +304,10 @@ public final class AppDatabase {
phone: row.string("phone", default: ""),
preferredChurchIDs: Set(decode(row.string("preferred_church_ids", default: "[]")) as [String]),
preferredWeekdays: Set(decode(row.string("preferred_weekdays", default: "[]")) as [Int]),
preferredWeekdayPeriods: decode(row.string("preferred_weekday_periods", default: "[]")),
preferredServiceTitles: decode(row.string("preferred_service_titles", default: "[]")),
maxPerMonth: row.int("max_per_month", default: 6),
allowBeyondPreferences: row.bool("allow_beyond_preferences", default: false),
active: row.bool("active", default: true),
notes: row.string("notes", default: "")
)
@@ -545,29 +567,49 @@ public final class AppDatabase {
public func upsert(_ assignment: Assignment) throws {
try database.run("""
INSERT INTO assignments(id, service_id, person_id, role, locked, note, created_at)
VALUES(?, ?, ?, ?, ?, ?, ?)
INSERT INTO assignments(id, service_id, person_id, role, locked, beyond_preferences, note, created_at)
VALUES(?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(id) DO UPDATE SET service_id=excluded.service_id, person_id=excluded.person_id,
role=excluded.role, locked=excluded.locked, note=excluded.note
role=excluded.role, locked=excluded.locked,
beyond_preferences=excluded.beyond_preferences, note=excluded.note
""", [
.text(assignment.id), .text(assignment.serviceID), .text(assignment.personID),
.text(assignment.role.rawValue), .bool(assignment.locked), .text(assignment.note),
.text(assignment.role.rawValue), .bool(assignment.locked),
.bool(assignment.beyondPreferences), .text(assignment.note),
.text(ISO8601DateFormatter().string(from: assignment.createdAt))
])
}
/// Replaces the assignment for one role of a service. Passing nil clears the slot.
public func setAssignment(serviceID: String, role: Role, personID: String?, locked: Bool = false) throws {
public func setAssignment(
serviceID: String,
role: Role,
personID: String?,
locked: Bool = false,
beyondPreferences: Bool = false
) throws {
try database.transaction {
try database.run("DELETE FROM assignments WHERE service_id=? AND role=?", [.text(serviceID), .text(role.rawValue)])
guard let personID else { return }
let assignment = Assignment(serviceID: serviceID, personID: personID, role: role, locked: locked)
let assignment = Assignment(
serviceID: serviceID, personID: personID, role: role,
locked: locked, beyondPreferences: beyondPreferences
)
try upsert(assignment)
}
}
public func setAssignment(serviceID: String, personID: String?, role: Role, locked: Bool = false) throws {
try setAssignment(serviceID: serviceID, role: role, personID: personID, locked: locked)
public func setAssignment(
serviceID: String,
personID: String?,
role: Role,
locked: Bool = false,
beyondPreferences: Bool = false
) throws {
try setAssignment(
serviceID: serviceID, role: role, personID: personID,
locked: locked, beyondPreferences: beyondPreferences
)
}
public func deleteAssignment(id: String) throws {
@@ -605,6 +647,7 @@ public final class AppDatabase {
personID: personID,
role: role,
locked: row.bool("locked", default: false),
beyondPreferences: row.bool("beyond_preferences", default: false),
note: row.string("note", default: ""),
createdAt: ISO8601DateFormatter().date(from: row.string("created_at", default: "")) ?? Date()
)