fix round title issues

paca_championship
Raz 1 year ago
parent 131ee06fd4
commit ad5b2f06c4
  1. 11
      PadelClub/Data/Round.swift
  2. 4
      PadelClub/Data/Tournament.swift
  3. 25
      PadelClub/Views/Round/LoserRoundView.swift
  4. 12
      PadelClub/Views/Round/RoundView.swift

@ -503,17 +503,26 @@ defer {
if isUpperBracket() { if isUpperBracket() {
if index == 0 { return SeedInterval(first: 1, last: 2) } if index == 0 { return SeedInterval(first: 1, last: 2) }
let initialMatchIndexFromRoundIndex = RoundRule.matchIndex(fromRoundIndex: index) let initialMatchIndexFromRoundIndex = RoundRule.matchIndex(fromRoundIndex: index)
if initialMode {
let playedMatches = RoundRule.numberOfMatches(forRoundIndex: index)
let seedInterval = SeedInterval(first: playedMatches + 1, last: playedMatches * 2)
//print(seedInterval.localizedLabel())
return seedInterval
} else {
let seedsAfterThisRound : [TeamRegistration] = self.tournamentStore.teamRegistrations.filter { let seedsAfterThisRound : [TeamRegistration] = self.tournamentStore.teamRegistrations.filter {
$0.bracketPosition != nil $0.bracketPosition != nil
&& ($0.bracketPosition! / 2) < initialMatchIndexFromRoundIndex && ($0.bracketPosition! / 2) < initialMatchIndexFromRoundIndex
} }
let playedMatches = playedMatches().count let playedMatches = playedMatches().count
let minimumMatches = initialMode ? RoundRule.numberOfMatches(forRoundIndex: index) : playedMatches * 2 let minimumMatches = playedMatches * 2
//print("playedMatches \(playedMatches)", initialMode, parent, parentRound?.roundTitle(), seedsAfterThisRound.count) //print("playedMatches \(playedMatches)", initialMode, parent, parentRound?.roundTitle(), seedsAfterThisRound.count)
let seedInterval = SeedInterval(first: playedMatches + seedsAfterThisRound.count + 1, last: minimumMatches + seedsAfterThisRound.count) let seedInterval = SeedInterval(first: playedMatches + seedsAfterThisRound.count + 1, last: minimumMatches + seedsAfterThisRound.count)
//print(seedInterval.localizedLabel()) //print(seedInterval.localizedLabel())
return seedInterval return seedInterval
}
} }
if let previousRound = previousRound() { if let previousRound = previousRound() {

@ -800,13 +800,13 @@ defer {
func selectedSortedTeams() -> [TeamRegistration] { func selectedSortedTeams() -> [TeamRegistration] {
// #if _DEBUG_TIME //DEBUGING TIME #if _DEBUG_TIME //DEBUGING TIME
let start = Date() let start = Date()
defer { defer {
let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000) let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000)
print("func selectedSortedTeams", id, tournamentTitle(), duration.formatted(.units(allowed: [.seconds, .milliseconds]))) print("func selectedSortedTeams", id, tournamentTitle(), duration.formatted(.units(allowed: [.seconds, .milliseconds])))
} }
// #endif #endif
var _sortedTeams : [TeamRegistration] = [] var _sortedTeams : [TeamRegistration] = []
var _teams = unsortedTeams().filter({ $0.walkOut == false }) var _teams = unsortedTeams().filter({ $0.walkOut == false })

@ -70,13 +70,13 @@ struct LoserRoundView: View {
if let seedInterval = previousRound.seedInterval(initialMode: isEditingTournamentSeed.wrappedValue == true) { if let seedInterval = previousRound.seedInterval(initialMode: isEditingTournamentSeed.wrappedValue == true) {
Text(seedInterval.localizedLabel()) Text(seedInterval.localizedLabel())
} else { } else {
Text("no previous round") Text("seedInterval is missing (previous round)")
} }
} else if let parentRound = loserRound.parentRound { } else if let parentRound = loserRound.parentRound {
if let seedInterval = parentRound.seedInterval(initialMode: isEditingTournamentSeed.wrappedValue == true) { if let seedInterval = parentRound.seedInterval(initialMode: isEditingTournamentSeed.wrappedValue == true) {
Text(seedInterval.localizedLabel()) Text(seedInterval.localizedLabel())
} else { } else {
Text("no parent round") Text("seedInterval is missing (parent round)")
} }
} }
} }
@ -103,13 +103,7 @@ struct LoserRoundView: View {
isEditingTournamentSeed.wrappedValue.toggle() isEditingTournamentSeed.wrappedValue.toggle()
if isEditingTournamentSeed.wrappedValue == false { if isEditingTournamentSeed.wrappedValue == false {
let allRoundMatches = loserBracket.allMatches _refreshNames()
allRoundMatches.forEach({ $0.name = $0.roundTitle() })
do {
try self.tournament.tournamentStore.matches.addOrUpdate(contentOfs: allRoundMatches)
} catch {
Logger.error(error)
}
} }
} }
} }
@ -131,4 +125,17 @@ struct LoserRoundView: View {
} }
} }
} }
private func _refreshNames() {
DispatchQueue.global(qos: .background).async {
let allRoundMatches = loserBracket.allMatches
allRoundMatches.forEach({ $0.name = $0.roundTitle() })
do {
try self.tournament.tournamentStore.matches.addOrUpdate(contentOfs: allRoundMatches)
} catch {
Logger.error(error)
}
}
}
} }

@ -338,6 +338,15 @@ struct RoundView: View {
Logger.error(error) Logger.error(error)
} }
if tournament.availableSeeds().isEmpty && tournament.availableQualifiedTeams().isEmpty {
self.isEditingTournamentSeed.wrappedValue = false
}
_refreshNames()
}
private func _refreshNames() {
DispatchQueue.global(qos: .background).async {
//todo should be done server side //todo should be done server side
let rounds = tournament.rounds() let rounds = tournament.rounds()
rounds.forEach { round in rounds.forEach { round in
@ -359,9 +368,6 @@ struct RoundView: View {
} catch { } catch {
Logger.error(error) Logger.error(error)
} }
if tournament.availableSeeds().isEmpty && tournament.availableQualifiedTeams().isEmpty {
self.isEditingTournamentSeed.wrappedValue = false
} }
} }
} }

Loading…
Cancel
Save