enable realtime final ranking update

sync2
Raz 10 months ago
parent 2ebfb79713
commit ca6b56f2f9
  1. 2
      PadelClub/Data/GroupStage.swift
  2. 3
      PadelClub/Data/Match.swift
  3. 5
      PadelClub/Data/Round.swift
  4. 4
      PadelClub/Data/Tournament.swift
  5. 2
      PadelClub/Views/Tournament/TournamentBuildView.swift
  6. 17
      PadelClub/Views/Tournament/TournamentView.swift

@ -239,6 +239,8 @@ final class GroupStage: ModelObject, Storable {
Logger.error(error) Logger.error(error)
} }
} }
tournament.updateTournamentState()
} }
} }

@ -232,7 +232,6 @@ defer {
servingTeamId = nil servingTeamId = nil
groupStageObject?.updateGroupStageState() groupStageObject?.updateGroupStageState()
roundObject?.updateTournamentState() roundObject?.updateTournamentState()
currentTournament()?.updateTournamentState()
teams().forEach({ $0.resetRestingTime() }) teams().forEach({ $0.resetRestingTime() })
} }
@ -554,7 +553,6 @@ defer {
losingTeamId = teamScoreWalkout.teamRegistration losingTeamId = teamScoreWalkout.teamRegistration
groupStageObject?.updateGroupStageState() groupStageObject?.updateGroupStageState()
roundObject?.updateTournamentState() roundObject?.updateTournamentState()
currentTournament()?.updateTournamentState()
updateFollowingMatchTeamScore() updateFollowingMatchTeamScore()
} }
@ -593,7 +591,6 @@ defer {
} catch { } catch {
Logger.error(error) Logger.error(error)
} }
tournament.updateTournamentState()
} }
updateFollowingMatchTeamScore() updateFollowingMatchTeamScore()
} }

@ -584,7 +584,8 @@ defer {
} }
func updateTournamentState() { func updateTournamentState() {
if let tournamentObject = tournamentObject(), index == 0, isUpperBracket(), hasEnded() { let tournamentObject = tournamentObject()
if let tournamentObject, index == 0, isUpperBracket(), hasEnded() {
tournamentObject.endDate = Date() tournamentObject.endDate = Date()
do { do {
try DataStore.shared.tournaments.addOrUpdate(instance: tournamentObject) try DataStore.shared.tournaments.addOrUpdate(instance: tournamentObject)
@ -592,6 +593,8 @@ defer {
Logger.error(error) Logger.error(error)
} }
} }
tournamentObject?.updateTournamentState()
} }
func roundStatus() -> String { func roundStatus() -> String {

@ -1403,6 +1403,7 @@ defer {
groupStages.forEach { groupStage in groupStages.forEach { groupStage in
let groupStageTeams = groupStage.teams(true) let groupStageTeams = groupStage.teams(true)
for (index, team) in groupStageTeams.enumerated() { for (index, team) in groupStageTeams.enumerated() {
if groupStage.hasEnded() {
if team.qualified == false && alreadyPlaceTeams.contains(team.id) == false { if team.qualified == false && alreadyPlaceTeams.contains(team.id) == false {
let groupStageWidth = max(((index == qualifiedPerGroupStage) ? groupStageCount - groupStageAdditionalQualified : groupStageCount) * (index - qualifiedPerGroupStage), 0) let groupStageWidth = max(((index == qualifiedPerGroupStage) ? groupStageCount - groupStageAdditionalQualified : groupStageCount) * (index - qualifiedPerGroupStage), 0)
@ -1416,6 +1417,7 @@ defer {
} }
} }
} }
}
return teams return teams
} }
@ -2347,12 +2349,10 @@ defer {
func updateTournamentState() { func updateTournamentState() {
Task { Task {
if hasEnded() {
let fr = await finalRanking() let fr = await finalRanking()
_ = await setRankings(finalRanks: fr) _ = await setRankings(finalRanks: fr)
} }
} }
}
func allLoserRoundMatches() -> [Match] { func allLoserRoundMatches() -> [Match] {
rounds().flatMap { $0.loserRoundsAndChildren().flatMap({ $0._matches() }) } rounds().flatMap { $0.loserRoundsAndChildren().flatMap({ $0._matches() }) }

@ -113,7 +113,7 @@ struct TournamentBuildView: View {
Section { Section {
if tournament.hasEnded() { if true {
NavigationLink(value: Screen.rankings) { NavigationLink(value: Screen.rankings) {
LabeledContent { LabeledContent {
if tournament.publishRankings == false { if tournament.publishRankings == false {

@ -237,6 +237,23 @@ struct TournamentView: View {
LabelStructure() LabelStructure()
} }
NavigationLink(value: Screen.rankings) {
LabeledContent {
if tournament.publishRankings == false {
Image(systemName: "exclamationmark.circle.fill")
.foregroundStyle(.logoYellow)
} else {
Image(systemName: "checkmark")
.foregroundStyle(.green)
}
} label: {
Text("Classement final des équipes")
if tournament.publishRankings == false {
Text("Vérifiez le classement avant de publier").foregroundStyle(.logoRed)
}
}
}
NavigationLink(value: Screen.broadcast) { NavigationLink(value: Screen.broadcast) {
Label("Publication", systemImage: "airplayvideo") Label("Publication", systemImage: "airplayvideo")
} }

Loading…
Cancel
Save