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)
}
}
tournament.updateTournamentState()
}
}

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

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

@ -1403,14 +1403,16 @@ defer {
groupStages.forEach { groupStage in
let groupStageTeams = groupStage.teams(true)
for (index, team) in groupStageTeams.enumerated() {
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] {
teams[_index] = existingTeams + [team.id]
} else {
teams[_index] = [team.id]
if groupStage.hasEnded() {
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] {
teams[_index] = existingTeams + [team.id]
} else {
teams[_index] = [team.id]
}
}
}
}
@ -2347,10 +2349,8 @@ defer {
func updateTournamentState() {
Task {
if hasEnded() {
let fr = await finalRanking()
_ = await setRankings(finalRanks: fr)
}
let fr = await finalRanking()
_ = await setRankings(finalRanks: fr)
}
}

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

@ -237,6 +237,23 @@ struct TournamentView: View {
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) {
Label("Publication", systemImage: "airplayvideo")
}

Loading…
Cancel
Save