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. 24
      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,14 +1403,16 @@ 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 team.qualified == false && alreadyPlaceTeams.contains(team.id) == false { if groupStage.hasEnded() {
let groupStageWidth = max(((index == qualifiedPerGroupStage) ? groupStageCount - groupStageAdditionalQualified : groupStageCount) * (index - qualifiedPerGroupStage), 0) if team.qualified == false && alreadyPlaceTeams.contains(team.id) == false {
let groupStageWidth = max(((index == qualifiedPerGroupStage) ? groupStageCount - groupStageAdditionalQualified : groupStageCount) * (index - qualifiedPerGroupStage), 0)
let _index = baseRank + groupStageWidth + 1 - (index > qualifiedPerGroupStage ? groupStageAdditionalQualified : 0)
if let existingTeams = teams[_index] { let _index = baseRank + groupStageWidth + 1 - (index > qualifiedPerGroupStage ? groupStageAdditionalQualified : 0)
teams[_index] = existingTeams + [team.id] if let existingTeams = teams[_index] {
} else { teams[_index] = existingTeams + [team.id]
teams[_index] = [team.id] } else {
teams[_index] = [team.id]
}
} }
} }
} }
@ -2347,10 +2349,8 @@ 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)
}
} }
} }

@ -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