Bug fix, über Präferenz hinazs besetzen
This commit is contained in:
1 parent
a5d4251868
commit
4b88aca958
9 files changed
+162
-48
No files matched your search
@@ -94,7 +94,7 @@ enum PlanPDFRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beginPage()
|
beginPage()
|
||||||
drawHeader(range: range, generatedAt: generatedAt)
|
drawHeader(range: range, generatedAt: generatedAt, showTitle: true)
|
||||||
drawColumnHeader(churches: churches, churchWidth: churchWidth)
|
drawColumnHeader(churches: churches, churchWidth: churchWidth)
|
||||||
|
|
||||||
var cursorY = contentTop
|
var cursorY = contentTop
|
||||||
@@ -104,7 +104,7 @@ enum PlanPDFRenderer {
|
|||||||
if cursorY + height > contentBottom {
|
if cursorY + height > contentBottom {
|
||||||
endPage()
|
endPage()
|
||||||
beginPage()
|
beginPage()
|
||||||
drawHeader(range: range, generatedAt: generatedAt)
|
drawHeader(range: range, generatedAt: generatedAt, showTitle: false)
|
||||||
drawColumnHeader(churches: churches, churchWidth: churchWidth)
|
drawColumnHeader(churches: churches, churchWidth: churchWidth)
|
||||||
cursorY = contentTop
|
cursorY = contentTop
|
||||||
}
|
}
|
||||||
@@ -145,7 +145,7 @@ enum PlanPDFRenderer {
|
|||||||
|
|
||||||
// MARK: - Page furniture
|
// MARK: - Page furniture
|
||||||
|
|
||||||
private static func drawHeader(range: DayRange, generatedAt: Date) {
|
private static func drawHeader(range: DayRange, generatedAt: Date, showTitle: Bool) {
|
||||||
let top = margin
|
let top = margin
|
||||||
|
|
||||||
drawText(
|
drawText(
|
||||||
@@ -154,12 +154,14 @@ enum PlanPDFRenderer {
|
|||||||
font: sans(7.5, weight: .bold),
|
font: sans(7.5, weight: .bold),
|
||||||
color: accent
|
color: accent
|
||||||
)
|
)
|
||||||
drawText(
|
if showTitle {
|
||||||
"Gottesdienstplan",
|
drawText(
|
||||||
in: CGRect(x: margin, y: top + 13, width: 500, height: 22),
|
"Gottesdienstplan",
|
||||||
font: serif(17.5, bold: true),
|
in: CGRect(x: margin, y: top + 13, width: 500, height: 22),
|
||||||
color: ink
|
font: serif(17.5, bold: true),
|
||||||
)
|
color: ink
|
||||||
|
)
|
||||||
|
}
|
||||||
drawText(
|
drawText(
|
||||||
range.longTitle,
|
range.longTitle,
|
||||||
in: CGRect(x: margin, y: top + 40, width: 460, height: 14),
|
in: CGRect(x: margin, y: top + 40, width: 460, height: 14),
|
||||||
|
|||||||
@@ -217,6 +217,7 @@ final class PlanModel: ObservableObject {
|
|||||||
@Published var specialServiceEditor: SpecialServiceRequest?
|
@Published var specialServiceEditor: SpecialServiceRequest?
|
||||||
@Published var serviceDetail: ServiceDetailRequest?
|
@Published var serviceDetail: ServiceDetailRequest?
|
||||||
@Published var planResult: PlanResult?
|
@Published var planResult: PlanResult?
|
||||||
|
@Published var planResultUsedBeyond = false
|
||||||
@Published var importPreview: ImportPreview?
|
@Published var importPreview: ImportPreview?
|
||||||
@Published var pdfPreview: PDFPreview?
|
@Published var pdfPreview: PDFPreview?
|
||||||
@Published var databasePath: String
|
@Published var databasePath: String
|
||||||
@@ -429,6 +430,7 @@ final class PlanModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
loadAll()
|
loadAll()
|
||||||
planResult = result
|
planResult = result
|
||||||
|
planResultUsedBeyond = allowBeyond
|
||||||
return result
|
return result
|
||||||
} catch {
|
} catch {
|
||||||
alertTitle = "Planung fehlgeschlagen"
|
alertTitle = "Planung fehlgeschlagen"
|
||||||
@@ -587,8 +589,8 @@ final class PlanModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
let servicesThisDay = dayServices["\(person.id)|\(service.dateKey)", default: []]
|
let servicesThisDay = dayServices["\(person.id)|\(service.dateKey)", default: []]
|
||||||
if !servicesThisDay.isEmpty, !servicesThisDay.isSubset(of: [service.id]) {
|
if !servicesThisDay.isEmpty, !servicesThisDay.isSubset(of: [service.id]) {
|
||||||
|
// Only explicit absences remain hard blocks for manual assignments.
|
||||||
warnings.append("bereits an diesem Tag")
|
warnings.append("bereits an diesem Tag")
|
||||||
blocked = true
|
|
||||||
}
|
}
|
||||||
let total = totalCounts[person.id, default: 0]
|
let total = totalCounts[person.id, default: 0]
|
||||||
let withinFairnessReach = total - minimumTotal <= fairnessSlack
|
let withinFairnessReach = total - minimumTotal <= fairnessSlack
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ struct PlanResultSheet: View {
|
|||||||
VStack(spacing: 0) {
|
VStack(spacing: 0) {
|
||||||
if let result = model.planResult {
|
if let result = model.planResult {
|
||||||
let canOfferBeyond = !result.unfilled.isEmpty
|
let canOfferBeyond = !result.unfilled.isEmpty
|
||||||
&& !result.assignments.contains(where: \.beyondPreferences)
|
&& !model.planResultUsedBeyond
|
||||||
&& model.people.contains { $0.active && $0.allowBeyondPreferences }
|
&& model.people.contains { $0.active && $0.allowBeyondPreferences }
|
||||||
SheetHeader(
|
SheetHeader(
|
||||||
icon: result.unfilled.isEmpty ? "checkmark.seal" : "exclamationmark.triangle",
|
icon: result.unfilled.isEmpty ? "checkmark.seal" : "exclamationmark.triangle",
|
||||||
|
|||||||
@@ -8,13 +8,37 @@ struct ServiceDetailSheet: View {
|
|||||||
let serviceID: String
|
let serviceID: String
|
||||||
|
|
||||||
@State private var selectedRole: Role = .lector
|
@State private var selectedRole: Role = .lector
|
||||||
@State private var pendingBeyondCandidate: CandidateSuggestion?
|
@State private var confirmation: Confirmation?
|
||||||
@State private var confirmDelete = false
|
|
||||||
|
private enum Confirmation: Identifiable {
|
||||||
|
case deleteService
|
||||||
|
case beyondPreferences(CandidateSuggestion)
|
||||||
|
|
||||||
|
var id: String {
|
||||||
|
switch self {
|
||||||
|
case .deleteService:
|
||||||
|
"delete-service"
|
||||||
|
case .beyondPreferences(let candidate):
|
||||||
|
"beyond-\(candidate.id)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private var item: ServiceWithAssignments? {
|
private var item: ServiceWithAssignments? {
|
||||||
model.serviceWithAssignments(id: serviceID)
|
model.serviceWithAssignments(id: serviceID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var confirmationTitle: String {
|
||||||
|
switch confirmation {
|
||||||
|
case .deleteService:
|
||||||
|
"Gottesdienst löschen?"
|
||||||
|
case .beyondPreferences:
|
||||||
|
"Über Präferenzen einteilen?"
|
||||||
|
case nil:
|
||||||
|
""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(spacing: 0) {
|
VStack(spacing: 0) {
|
||||||
if let item {
|
if let item {
|
||||||
@@ -48,7 +72,7 @@ struct ServiceDetailSheet: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Button {
|
Button {
|
||||||
confirmDelete = true
|
confirmation = .deleteService
|
||||||
} label: {
|
} label: {
|
||||||
Image(systemName: "trash")
|
Image(systemName: "trash")
|
||||||
.font(.system(size: 11.5, weight: .medium))
|
.font(.system(size: 11.5, weight: .medium))
|
||||||
@@ -80,42 +104,40 @@ struct ServiceDetailSheet: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.confirmationDialog(
|
.confirmationDialog(
|
||||||
"Über Präferenzen einteilen?",
|
confirmationTitle,
|
||||||
isPresented: Binding(
|
isPresented: Binding(
|
||||||
get: { pendingBeyondCandidate != nil },
|
get: { confirmation != nil },
|
||||||
set: { if !$0 { pendingBeyondCandidate = nil } }
|
set: { if !$0 { confirmation = nil } }
|
||||||
),
|
),
|
||||||
titleVisibility: .visible
|
titleVisibility: .visible,
|
||||||
) {
|
presenting: confirmation
|
||||||
Button("Trotzdem einteilen") {
|
) { pending in
|
||||||
if let candidate = pendingBeyondCandidate {
|
switch pending {
|
||||||
model.assign(serviceID: serviceID, role: selectedRole, personID: candidate.person.id)
|
case .deleteService:
|
||||||
|
Button("Endgültig löschen", role: .destructive) {
|
||||||
|
if let item {
|
||||||
|
model.deleteService(item.service)
|
||||||
|
}
|
||||||
|
confirmation = nil
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
case .beyondPreferences(let candidate):
|
||||||
|
Button("Trotzdem einteilen") {
|
||||||
|
model.assign(serviceID: serviceID, role: selectedRole, personID: candidate.person.id)
|
||||||
|
confirmation = nil
|
||||||
}
|
}
|
||||||
pendingBeyondCandidate = nil
|
|
||||||
}
|
}
|
||||||
Button("Abbrechen", role: .cancel) {
|
Button("Abbrechen", role: .cancel) {
|
||||||
pendingBeyondCandidate = nil
|
confirmation = nil
|
||||||
}
|
}
|
||||||
} message: {
|
} message: { pending in
|
||||||
if let candidate = pendingBeyondCandidate {
|
switch pending {
|
||||||
|
case .deleteService:
|
||||||
|
Text("Der Termin und alle zugehörigen Einsätze werden entfernt. Die Gottesdienstordnung bleibt unverändert.")
|
||||||
|
case .beyondPreferences(let candidate):
|
||||||
Text("\(candidate.person.fullName) ist bereit, auch über ihre Präferenzen oder ihr Monatslimit hinaus eingeplant zu werden.")
|
Text("\(candidate.person.fullName) ist bereit, auch über ihre Präferenzen oder ihr Monatslimit hinaus eingeplant zu werden.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.confirmationDialog(
|
|
||||||
"Gottesdienst löschen?",
|
|
||||||
isPresented: $confirmDelete,
|
|
||||||
titleVisibility: .visible
|
|
||||||
) {
|
|
||||||
Button("Endgültig löschen", role: .destructive) {
|
|
||||||
if let item {
|
|
||||||
model.deleteService(item.service)
|
|
||||||
}
|
|
||||||
dismiss()
|
|
||||||
}
|
|
||||||
Button("Abbrechen", role: .cancel) {}
|
|
||||||
} message: {
|
|
||||||
Text("Der Termin und alle zugehörigen Einsätze werden entfernt. Die Gottesdienstordnung bleibt unverändert.")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Header
|
// MARK: - Header
|
||||||
@@ -456,7 +478,7 @@ struct ServiceDetailSheet: View {
|
|||||||
|
|
||||||
Button {
|
Button {
|
||||||
if candidate.beyondPreferences {
|
if candidate.beyondPreferences {
|
||||||
pendingBeyondCandidate = candidate
|
confirmation = .beyondPreferences(candidate)
|
||||||
} else {
|
} else {
|
||||||
model.assign(serviceID: item.service.id, role: selectedRole, personID: candidate.person.id)
|
model.assign(serviceID: item.service.id, role: selectedRole, personID: candidate.person.id)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -229,6 +229,40 @@ final class CoreTests: XCTestCase {
|
|||||||
XCTAssertTrue(allowed.assignments.first?.beyondPreferences ?? false)
|
XCTAssertTrue(allowed.assignments.first?.beyondPreferences ?? false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testPlannerBeyondPreferencesHonorsMonthlyLimitPermission() {
|
||||||
|
let monday = DayMath.date(fromKey: "2026-11-16")!
|
||||||
|
let tuesday = DayMath.date(fromKey: "2026-11-17")!
|
||||||
|
var person = Person(
|
||||||
|
id: "p", firstName: "Paula", lastName: "Person", roles: [.lector],
|
||||||
|
maxPerMonth: 1
|
||||||
|
)
|
||||||
|
person.allowBeyondPreferences = true
|
||||||
|
let services = [
|
||||||
|
ServiceOccurrence(
|
||||||
|
churchID: "c1", date: monday, timeMinutes: 18 * 60,
|
||||||
|
title: "Abendmesse", lectorsNeeded: 1, helpersNeeded: 0
|
||||||
|
),
|
||||||
|
ServiceOccurrence(
|
||||||
|
churchID: "c1", date: tuesday, timeMinutes: 18 * 60,
|
||||||
|
title: "Abendmesse", lectorsNeeded: 1, helpersNeeded: 0
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
let firstPass = ServicePlanner(
|
||||||
|
people: [person], absences: [], services: services
|
||||||
|
).plan()
|
||||||
|
XCTAssertEqual(firstPass.assignments.count, 1)
|
||||||
|
XCTAssertEqual(firstPass.unfilled.count, 1)
|
||||||
|
|
||||||
|
let secondPass = ServicePlanner(
|
||||||
|
people: [person], absences: [], services: services,
|
||||||
|
options: PlannerOptions(allowBeyondPreferences: true)
|
||||||
|
).plan()
|
||||||
|
XCTAssertEqual(secondPass.assignments.count, 2)
|
||||||
|
XCTAssertEqual(secondPass.unfilled.count, 0)
|
||||||
|
XCTAssertTrue(secondPass.assignments.contains(where: \.beyondPreferences))
|
||||||
|
}
|
||||||
|
|
||||||
func testPlannerAssignsSamePersonToBothComplementaryRoles() {
|
func testPlannerAssignsSamePersonToBothComplementaryRoles() {
|
||||||
let date = DayMath.date(fromKey: "2026-11-08")! // Sunday
|
let date = DayMath.date(fromKey: "2026-11-08")! // Sunday
|
||||||
let dual = Person(id: "dual", firstName: "Dana", lastName: "Doppel", roles: [.lector, .helper], maxPerMonth: 10)
|
let dual = Person(id: "dual", firstName: "Dana", lastName: "Doppel", roles: [.lector, .helper], maxPerMonth: 10)
|
||||||
|
|||||||
@@ -515,8 +515,8 @@ func CandidateSuggestions(
|
|||||||
}
|
}
|
||||||
used := dayServices[person.ID+"|"+service.DateKey()]
|
used := dayServices[person.ID+"|"+service.DateKey()]
|
||||||
if len(used) > 0 && !subsetOfSingle(used, service.ID) {
|
if len(used) > 0 && !subsetOfSingle(used, service.ID) {
|
||||||
|
// Only explicit absences are hard blocks for manual assignments.
|
||||||
warnings = append(warnings, "bereits an diesem Tag")
|
warnings = append(warnings, "bereits an diesem Tag")
|
||||||
blocked = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
total := totalCounts[person.ID]
|
total := totalCounts[person.ID]
|
||||||
|
|||||||
@@ -159,6 +159,55 @@ func TestCandidateSuggestionsAllowPreferenceOverrides(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCandidateSuggestionsAllowMaxLimitOverride(t *testing.T) {
|
||||||
|
service := ServiceOccurrence{
|
||||||
|
ID: "s2", ChurchID: "c1", Date: MustDate("2026-11-17"),
|
||||||
|
TimeMinutes: 18 * 60, Title: "Abendmesse", LectorsNeeded: 1,
|
||||||
|
}
|
||||||
|
earlier := ServiceOccurrence{
|
||||||
|
ID: "s1", ChurchID: "c1", Date: MustDate("2026-11-16"),
|
||||||
|
TimeMinutes: 18 * 60, Title: "Abendmesse", LectorsNeeded: 1,
|
||||||
|
}
|
||||||
|
person := Person{
|
||||||
|
ID: "p1", FirstName: "Anna", LastName: "Berg", Roles: []Role{RoleLector},
|
||||||
|
Active: true, MaxPerMonth: 1,
|
||||||
|
}
|
||||||
|
existing := []Assignment{{
|
||||||
|
ID: "a1", ServiceID: earlier.ID, PersonID: person.ID, Role: RoleLector,
|
||||||
|
}}
|
||||||
|
suggestions := CandidateSuggestions(service, RoleLector,
|
||||||
|
[]Person{person}, nil, existing, []ServiceOccurrence{earlier, service}, nil, nil)
|
||||||
|
if len(suggestions) != 1 || suggestions[0].Blocked || !suggestions[0].BeyondPreferences {
|
||||||
|
t.Fatalf("manual suggestions should allow exceeding the monthly limit with a warning, got %#v", suggestions)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCandidateSuggestionsAllowSameDayConflict(t *testing.T) {
|
||||||
|
service := ServiceOccurrence{
|
||||||
|
ID: "s2", ChurchID: "c1", Date: MustDate("2026-11-16"),
|
||||||
|
TimeMinutes: 18 * 60, Title: "Abendmesse", LectorsNeeded: 1,
|
||||||
|
}
|
||||||
|
earlier := ServiceOccurrence{
|
||||||
|
ID: "s1", ChurchID: "c1", Date: MustDate("2026-11-16"),
|
||||||
|
TimeMinutes: 9 * 60, Title: "Frühmesse", LectorsNeeded: 1,
|
||||||
|
}
|
||||||
|
person := Person{
|
||||||
|
ID: "p1", FirstName: "Anna", LastName: "Berg", Roles: []Role{RoleLector},
|
||||||
|
Active: true, MaxPerMonth: 6,
|
||||||
|
}
|
||||||
|
existing := []Assignment{{
|
||||||
|
ID: "a1", ServiceID: earlier.ID, PersonID: person.ID, Role: RoleLector,
|
||||||
|
}}
|
||||||
|
suggestions := CandidateSuggestions(service, RoleLector,
|
||||||
|
[]Person{person}, nil, existing, []ServiceOccurrence{earlier, service}, nil, nil)
|
||||||
|
if len(suggestions) != 1 || suggestions[0].Blocked {
|
||||||
|
t.Fatalf("only absences should hard-block manual suggestions, got %#v", suggestions)
|
||||||
|
}
|
||||||
|
if !StringContains(suggestions[0].Warnings, "bereits an diesem Tag") {
|
||||||
|
t.Fatalf("same-day conflict should still be warned about, got %#v", suggestions[0].Warnings)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCandidateSuggestionsBlockAbsences(t *testing.T) {
|
func TestCandidateSuggestionsBlockAbsences(t *testing.T) {
|
||||||
service := ServiceOccurrence{
|
service := ServiceOccurrence{
|
||||||
ID: "s1", ChurchID: "c1", Date: MustDate("2026-11-16"),
|
ID: "s1", ChurchID: "c1", Date: MustDate("2026-11-16"),
|
||||||
|
|||||||
+7
-5
@@ -291,7 +291,7 @@ func FullPlan(w io.Writer, r domain.DayRange, rows []domain.DayPlanRow, churches
|
|||||||
columns = columns[:4]
|
columns = columns[:4]
|
||||||
}
|
}
|
||||||
|
|
||||||
drawHeader := func() {
|
drawHeader := func(showTitle bool) {
|
||||||
setColor(pdf, colors.accent)
|
setColor(pdf, colors.accent)
|
||||||
pdf.SetFont("Helvetica", "B", 6.4)
|
pdf.SetFont("Helvetica", "B", 6.4)
|
||||||
pdf.SetXY(margin, margin)
|
pdf.SetXY(margin, margin)
|
||||||
@@ -299,8 +299,10 @@ func FullPlan(w io.Writer, r domain.DayRange, rows []domain.DayPlanRow, churches
|
|||||||
|
|
||||||
setColor(pdf, colors.ink)
|
setColor(pdf, colors.ink)
|
||||||
pdf.SetFont("Times", "B", 15.5)
|
pdf.SetFont("Times", "B", 15.5)
|
||||||
pdf.SetXY(margin, margin+4.6)
|
if showTitle {
|
||||||
pdf.CellFormat(150, 7, tr("Gottesdienstplan"), "", 0, "L", false, 0, "")
|
pdf.SetXY(margin, margin+4.6)
|
||||||
|
pdf.CellFormat(150, 7, tr("Gottesdienstplan"), "", 0, "L", false, 0, "")
|
||||||
|
}
|
||||||
|
|
||||||
setColor(pdf, colors.secondary)
|
setColor(pdf, colors.secondary)
|
||||||
pdf.SetFont("Helvetica", "", 8.2)
|
pdf.SetFont("Helvetica", "", 8.2)
|
||||||
@@ -370,7 +372,7 @@ func FullPlan(w io.Writer, r domain.DayRange, rows []domain.DayPlanRow, churches
|
|||||||
}
|
}
|
||||||
|
|
||||||
pdf.AddPage()
|
pdf.AddPage()
|
||||||
drawHeader()
|
drawHeader(true)
|
||||||
drawColumnHeader()
|
drawColumnHeader()
|
||||||
page := 1
|
page := 1
|
||||||
y := contentTop
|
y := contentTop
|
||||||
@@ -388,7 +390,7 @@ func FullPlan(w io.Writer, r domain.DayRange, rows []domain.DayPlanRow, churches
|
|||||||
drawFooter(page)
|
drawFooter(page)
|
||||||
page++
|
page++
|
||||||
pdf.AddPage()
|
pdf.AddPage()
|
||||||
drawHeader()
|
drawHeader(false)
|
||||||
drawColumnHeader()
|
drawColumnHeader()
|
||||||
y = contentTop
|
y = contentTop
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -222,6 +222,9 @@ func TestFullPlanPaginatesWithTotalPageCount(t *testing.T) {
|
|||||||
if strings.Contains(content, "Fortsetzung") {
|
if strings.Contains(content, "Fortsetzung") {
|
||||||
t.Fatal("continuation title must not appear on later pages")
|
t.Fatal("continuation title must not appear on later pages")
|
||||||
}
|
}
|
||||||
|
if got := strings.Count(content, "Gottesdienstplan"); got != 1 {
|
||||||
|
t.Fatalf("large title appears %d times, want only on the first page", got)
|
||||||
|
}
|
||||||
match := regexp.MustCompile(`Seite 1 von (\d+)`).FindStringSubmatch(content)
|
match := regexp.MustCompile(`Seite 1 von (\d+)`).FindStringSubmatch(content)
|
||||||
if match == nil {
|
if match == nil {
|
||||||
t.Fatalf("first page footer is missing the total page count:\n%s", content)
|
t.Fatalf("first page footer is missing the total page count:\n%s", content)
|
||||||
|
|||||||
Reference in new issue
Block a user