fix loserbracket missing from pdf

newoffer2025
Razmig Sarkissian 4 months ago
parent 3781aac090
commit ae58efd2f7
  1. 4
      PadelClub.xcodeproj/project.pbxproj
  2. 2
      PadelClub/Utils/HtmlGenerator.swift
  3. 22
      PadelClub/Utils/HtmlService.swift
  4. 122
      PadelClub/Views/Tournament/Screen/PrintSettingsView.swift

@ -3137,7 +3137,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.2.43; MARKETING_VERSION = 1.2.44;
PRODUCT_BUNDLE_IDENTIFIER = app.padelclub; PRODUCT_BUNDLE_IDENTIFIER = app.padelclub;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
@ -3183,7 +3183,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.2.43; MARKETING_VERSION = 1.2.44;
PRODUCT_BUNDLE_IDENTIFIER = app.padelclub; PRODUCT_BUNDLE_IDENTIFIER = app.padelclub;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";

@ -189,7 +189,7 @@ class HtmlGenerator: ObservableObject {
} }
var options: HtmlOptions { var options: HtmlOptions {
HtmlOptions(headName: displayHeads, withRank: displayRank, withTeamIndex: displayTeamIndex, withScore: displayScore, withPlannedDate: displayPlannedDate) HtmlOptions(headName: displayHeads, withRank: displayRank, withTeamIndex: displayTeamIndex, withScore: displayScore, withPlannedDate: displayPlannedDate, includeLoserBracket: includeLoserBracket)
} }
var pdfURL: URL? { var pdfURL: URL? {

@ -14,6 +14,7 @@ struct HtmlOptions {
let withTeamIndex: Bool let withTeamIndex: Bool
let withScore: Bool let withScore: Bool
let withPlannedDate: Bool let withPlannedDate: Bool
let includeLoserBracket: Bool
// Default initializer with all options defaulting to true // Default initializer with all options defaulting to true
init( init(
@ -21,13 +22,15 @@ struct HtmlOptions {
withRank: Bool = true, withRank: Bool = true,
withTeamIndex: Bool = true, withTeamIndex: Bool = true,
withScore: Bool = true, withScore: Bool = true,
withPlannedDate: Bool = true withPlannedDate: Bool = true,
includeLoserBracket: Bool = false
) { ) {
self.headName = headName self.headName = headName
self.withRank = withRank self.withRank = withRank
self.withTeamIndex = withTeamIndex self.withTeamIndex = withTeamIndex
self.withScore = withScore self.withScore = withScore
self.withPlannedDate = withPlannedDate self.withPlannedDate = withPlannedDate
self.includeLoserBracket = includeLoserBracket
} }
} }
@ -308,6 +311,13 @@ enum HtmlService {
var brackets = "" var brackets = ""
for round in tournament.rounds() { for round in tournament.rounds() {
brackets = brackets.appending(HtmlService.bracket(round: round).html(options: options)) brackets = brackets.appending(HtmlService.bracket(round: round).html(options: options))
if options.includeLoserBracket {
if round.index == 1 {
let sub = HtmlService.loserBracket(upperRound: round, hideTitle: true).html(options: options)
template = template.appending(sub)
}
}
} }
var winnerName = "" var winnerName = ""
@ -326,6 +336,16 @@ enum HtmlService {
brackets = brackets.appending(winner) brackets = brackets.appending(winner)
template = template.replacingOccurrences(of: "{{brackets}}", with: brackets) template = template.replacingOccurrences(of: "{{brackets}}", with: brackets)
if options.includeLoserBracket {
for round in tournament.rounds() {
if round.index > 1 {
let sub = HtmlService.loserBracket(upperRound: round, hideTitle: true).html(options: options)
template = template.appending(sub)
}
}
}
return template return template
} }
} }

@ -50,11 +50,17 @@ struct PrintSettingsView: View {
Toggle(isOn: $generator.includeBracket, label: { Toggle(isOn: $generator.includeBracket, label: {
Text("Tableau") Text("Tableau")
}) })
.onChange(of: generator.includeBracket) { oldValue, newValue in
if newValue == false {
generator.includeLoserBracket = newValue
}
}
Toggle(isOn: $generator.includeLoserBracket, label: { Toggle(isOn: $generator.includeLoserBracket, label: {
Text("Tableau des matchs de classements") Text("Tableau des matchs de classements")
}) })
.disabled(generator.includeBracket == false)
if tournament.groupStages().isEmpty == false { if tournament.groupStages().isEmpty == false {
Toggle(isOn: $generator.includeGroupStage, label: { Toggle(isOn: $generator.includeGroupStage, label: {
Text("Poules") Text("Poules")
@ -62,71 +68,69 @@ struct PrintSettingsView: View {
} }
} }
if generator.includeBracket { Section {
Section { Picker(selection: $generator.zoomLevel) {
Picker(selection: $generator.zoomLevel) { Text("1 page").tag(nil as Optional<CGFloat>)
Text("1 page").tag(nil as Optional<CGFloat>) Text("50%").tag(2.0 as Optional<CGFloat>)
Text("50%").tag(2.0 as Optional<CGFloat>) Text("100%").tag(1.0 as Optional<CGFloat>)
Text("100%").tag(1.0 as Optional<CGFloat>) } label: {
} label: { Text("Zoom")
Text("Zoom") }
} .onChange(of: generator.zoomLevel) {
.onChange(of: generator.zoomLevel) { if generator.zoomLevel == nil {
if generator.zoomLevel == nil { generator.landscape = false
generator.landscape = false
}
}
if generator.zoomLevel != nil {
Toggle(isOn: $generator.landscape, label: {
Text("Format paysage")
})
}
HStack {
Text("Nombre de page A4 à imprimer")
Spacer()
Text(generator.estimatedPageCount.formatted())
} }
} header: {
Text("Tableau principal")
} }
if generating == false { if generator.zoomLevel != nil {
RowButtonView("Générer le PDF", systemImage: "printer") { Toggle(isOn: $generator.landscape, label: {
await MainActor.run() { Text("Format paysage")
self.generating = true })
} }
generator.preparePDF { result in
switch result { HStack {
case .success(true): Text("Nombre de page A4 à imprimer")
if generator.includeGroupStage && generator.groupStageIsReady == false && tournament.groupStages().isEmpty == false { Spacer()
self.prepareGroupStage = true Text(generator.estimatedPageCount.formatted())
self.generationGroupStageId = UUID() }
} else { } header: {
self.presentShareView = true Text("Tableau principal")
self.generating = false }
}
case .success(false): if generating == false {
print("didn't save pdf") RowButtonView("Générer le PDF", systemImage: "printer") {
break await MainActor.run() {
case .failure(let error): self.generating = true
print(error) }
break generator.preparePDF { result in
switch result {
case .success(true):
if generator.includeGroupStage && generator.groupStageIsReady == false && tournament.groupStages().isEmpty == false {
self.prepareGroupStage = true
self.generationGroupStageId = UUID()
} else {
self.presentShareView = true
self.generating = false
} }
case .success(false):
print("didn't save pdf")
break
case .failure(let error):
print(error)
break
} }
self.prepareGroupStage = false
self.generationId = UUID()
}
.disabled(generator.includeBracket == false && generator.includeGroupStage == false && generator.includeLoserBracket == false)
} else {
LabeledContent {
ProgressView()
} label: {
Text("Préparation du PDF")
} }
.id(generationId) self.prepareGroupStage = false
self.generationId = UUID()
}
.disabled(generator.includeBracket == false && generator.includeGroupStage == false)
} else {
LabeledContent {
ProgressView()
} label: {
Text("Préparation du PDF")
} }
.id(generationId)
} }
Section { Section {

Loading…
Cancel
Save