Bug fix, über Präferenz hinazs besetzen
This commit is contained in:
1 parent
a5d4251868
commit
4b88aca958
9 files changed
+153
-39
No files matched your search
@@ -94,7 +94,7 @@ enum PlanPDFRenderer {
|
||||
}
|
||||
|
||||
beginPage()
|
||||
drawHeader(range: range, generatedAt: generatedAt)
|
||||
drawHeader(range: range, generatedAt: generatedAt, showTitle: true)
|
||||
drawColumnHeader(churches: churches, churchWidth: churchWidth)
|
||||
|
||||
var cursorY = contentTop
|
||||
@@ -104,7 +104,7 @@ enum PlanPDFRenderer {
|
||||
if cursorY + height > contentBottom {
|
||||
endPage()
|
||||
beginPage()
|
||||
drawHeader(range: range, generatedAt: generatedAt)
|
||||
drawHeader(range: range, generatedAt: generatedAt, showTitle: false)
|
||||
drawColumnHeader(churches: churches, churchWidth: churchWidth)
|
||||
cursorY = contentTop
|
||||
}
|
||||
@@ -145,7 +145,7 @@ enum PlanPDFRenderer {
|
||||
|
||||
// MARK: - Page furniture
|
||||
|
||||
private static func drawHeader(range: DayRange, generatedAt: Date) {
|
||||
private static func drawHeader(range: DayRange, generatedAt: Date, showTitle: Bool) {
|
||||
let top = margin
|
||||
|
||||
drawText(
|
||||
@@ -154,12 +154,14 @@ enum PlanPDFRenderer {
|
||||
font: sans(7.5, weight: .bold),
|
||||
color: accent
|
||||
)
|
||||
if showTitle {
|
||||
drawText(
|
||||
"Gottesdienstplan",
|
||||
in: CGRect(x: margin, y: top + 13, width: 500, height: 22),
|
||||
font: serif(17.5, bold: true),
|
||||
color: ink
|
||||
)
|
||||
}
|
||||
drawText(
|
||||
range.longTitle,
|
||||
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 serviceDetail: ServiceDetailRequest?
|
||||
@Published var planResult: PlanResult?
|
||||
@Published var planResultUsedBeyond = false
|
||||
@Published var importPreview: ImportPreview?
|
||||
@Published var pdfPreview: PDFPreview?
|
||||
@Published var databasePath: String
|
||||
@@ -429,6 +430,7 @@ final class PlanModel: ObservableObject {
|
||||
}
|
||||
loadAll()
|
||||
planResult = result
|
||||
planResultUsedBeyond = allowBeyond
|
||||
return result
|
||||
} catch {
|
||||
alertTitle = "Planung fehlgeschlagen"
|
||||
@@ -587,8 +589,8 @@ final class PlanModel: ObservableObject {
|
||||
}
|
||||
let servicesThisDay = dayServices["\(person.id)|\(service.dateKey)", default: []]
|
||||
if !servicesThisDay.isEmpty, !servicesThisDay.isSubset(of: [service.id]) {
|
||||
// Only explicit absences remain hard blocks for manual assignments.
|
||||
warnings.append("bereits an diesem Tag")
|
||||
blocked = true
|
||||
}
|
||||
let total = totalCounts[person.id, default: 0]
|
||||
let withinFairnessReach = total - minimumTotal <= fairnessSlack
|
||||
|
||||
@@ -9,7 +9,7 @@ struct PlanResultSheet: View {
|
||||
VStack(spacing: 0) {
|
||||
if let result = model.planResult {
|
||||
let canOfferBeyond = !result.unfilled.isEmpty
|
||||
&& !result.assignments.contains(where: \.beyondPreferences)
|
||||
&& !model.planResultUsedBeyond
|
||||
&& model.people.contains { $0.active && $0.allowBeyondPreferences }
|
||||
SheetHeader(
|
||||
icon: result.unfilled.isEmpty ? "checkmark.seal" : "exclamationmark.triangle",
|
||||
|
||||
@@ -8,13 +8,37 @@ struct ServiceDetailSheet: View {
|
||||
let serviceID: String
|
||||
|
||||
@State private var selectedRole: Role = .lector
|
||||
@State private var pendingBeyondCandidate: CandidateSuggestion?
|
||||
@State private var confirmDelete = false
|
||||
@State private var confirmation: Confirmation?
|
||||
|
||||
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? {
|
||||
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 {
|
||||
VStack(spacing: 0) {
|
||||
if let item {
|
||||
@@ -48,7 +72,7 @@ struct ServiceDetailSheet: View {
|
||||
}
|
||||
|
||||
Button {
|
||||
confirmDelete = true
|
||||
confirmation = .deleteService
|
||||
} label: {
|
||||
Image(systemName: "trash")
|
||||
.font(.system(size: 11.5, weight: .medium))
|
||||
@@ -80,41 +104,39 @@ struct ServiceDetailSheet: View {
|
||||
}
|
||||
}
|
||||
.confirmationDialog(
|
||||
"Über Präferenzen einteilen?",
|
||||
confirmationTitle,
|
||||
isPresented: Binding(
|
||||
get: { pendingBeyondCandidate != nil },
|
||||
set: { if !$0 { pendingBeyondCandidate = nil } }
|
||||
get: { confirmation != nil },
|
||||
set: { if !$0 { confirmation = nil } }
|
||||
),
|
||||
titleVisibility: .visible
|
||||
) {
|
||||
Button("Trotzdem einteilen") {
|
||||
if let candidate = pendingBeyondCandidate {
|
||||
model.assign(serviceID: serviceID, role: selectedRole, personID: candidate.person.id)
|
||||
}
|
||||
pendingBeyondCandidate = nil
|
||||
}
|
||||
Button("Abbrechen", role: .cancel) {
|
||||
pendingBeyondCandidate = nil
|
||||
}
|
||||
} message: {
|
||||
if let candidate = pendingBeyondCandidate {
|
||||
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
|
||||
) {
|
||||
titleVisibility: .visible,
|
||||
presenting: confirmation
|
||||
) { pending in
|
||||
switch pending {
|
||||
case .deleteService:
|
||||
Button("Endgültig löschen", role: .destructive) {
|
||||
if let item {
|
||||
model.deleteService(item.service)
|
||||
}
|
||||
confirmation = nil
|
||||
dismiss()
|
||||
}
|
||||
Button("Abbrechen", role: .cancel) {}
|
||||
} message: {
|
||||
case .beyondPreferences(let candidate):
|
||||
Button("Trotzdem einteilen") {
|
||||
model.assign(serviceID: serviceID, role: selectedRole, personID: candidate.person.id)
|
||||
confirmation = nil
|
||||
}
|
||||
}
|
||||
Button("Abbrechen", role: .cancel) {
|
||||
confirmation = nil
|
||||
}
|
||||
} message: { pending in
|
||||
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.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,7 +478,7 @@ struct ServiceDetailSheet: View {
|
||||
|
||||
Button {
|
||||
if candidate.beyondPreferences {
|
||||
pendingBeyondCandidate = candidate
|
||||
confirmation = .beyondPreferences(candidate)
|
||||
} else {
|
||||
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)
|
||||
}
|
||||
|
||||
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() {
|
||||
let date = DayMath.date(fromKey: "2026-11-08")! // Sunday
|
||||
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()]
|
||||
if len(used) > 0 && !subsetOfSingle(used, service.ID) {
|
||||
// Only explicit absences are hard blocks for manual assignments.
|
||||
warnings = append(warnings, "bereits an diesem Tag")
|
||||
blocked = true
|
||||
}
|
||||
|
||||
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) {
|
||||
service := ServiceOccurrence{
|
||||
ID: "s1", ChurchID: "c1", Date: MustDate("2026-11-16"),
|
||||
|
||||
+5
-3
@@ -291,7 +291,7 @@ func FullPlan(w io.Writer, r domain.DayRange, rows []domain.DayPlanRow, churches
|
||||
columns = columns[:4]
|
||||
}
|
||||
|
||||
drawHeader := func() {
|
||||
drawHeader := func(showTitle bool) {
|
||||
setColor(pdf, colors.accent)
|
||||
pdf.SetFont("Helvetica", "B", 6.4)
|
||||
pdf.SetXY(margin, margin)
|
||||
@@ -299,8 +299,10 @@ func FullPlan(w io.Writer, r domain.DayRange, rows []domain.DayPlanRow, churches
|
||||
|
||||
setColor(pdf, colors.ink)
|
||||
pdf.SetFont("Times", "B", 15.5)
|
||||
if showTitle {
|
||||
pdf.SetXY(margin, margin+4.6)
|
||||
pdf.CellFormat(150, 7, tr("Gottesdienstplan"), "", 0, "L", false, 0, "")
|
||||
}
|
||||
|
||||
setColor(pdf, colors.secondary)
|
||||
pdf.SetFont("Helvetica", "", 8.2)
|
||||
@@ -370,7 +372,7 @@ func FullPlan(w io.Writer, r domain.DayRange, rows []domain.DayPlanRow, churches
|
||||
}
|
||||
|
||||
pdf.AddPage()
|
||||
drawHeader()
|
||||
drawHeader(true)
|
||||
drawColumnHeader()
|
||||
page := 1
|
||||
y := contentTop
|
||||
@@ -388,7 +390,7 @@ func FullPlan(w io.Writer, r domain.DayRange, rows []domain.DayPlanRow, churches
|
||||
drawFooter(page)
|
||||
page++
|
||||
pdf.AddPage()
|
||||
drawHeader()
|
||||
drawHeader(false)
|
||||
drawColumnHeader()
|
||||
y = contentTop
|
||||
}
|
||||
|
||||
@@ -222,6 +222,9 @@ func TestFullPlanPaginatesWithTotalPageCount(t *testing.T) {
|
||||
if strings.Contains(content, "Fortsetzung") {
|
||||
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)
|
||||
if match == nil {
|
||||
t.Fatalf("first page footer is missing the total page count:\n%s", content)
|
||||
|
||||
Reference in new issue
Block a user