|
|
|
|
@ -58,6 +58,10 @@ struct TournamentRankView: View { |
|
|
|
|
RowButtonView("Publier le classement", role: .destructive) { |
|
|
|
|
_publishRankings() |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
RowButtonView("Re-publier le classement", role: .destructive) { |
|
|
|
|
_publishRankings() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -78,10 +82,82 @@ struct TournamentRankView: View { |
|
|
|
|
if rankingPublished { |
|
|
|
|
Section { |
|
|
|
|
ForEach(tournament.teamsRanked()) { team in |
|
|
|
|
let key = team.finalRanking! |
|
|
|
|
let key = team.finalRanking ?? 0 |
|
|
|
|
Button { |
|
|
|
|
selectedTeam = team |
|
|
|
|
} label: { |
|
|
|
|
TeamRankCellView(team: team, key: key) |
|
|
|
|
.frame(maxWidth: .infinity) |
|
|
|
|
} |
|
|
|
|
.contentShape(Rectangle()) |
|
|
|
|
.buttonStyle(.plain) |
|
|
|
|
} |
|
|
|
|
} footer: { |
|
|
|
|
Text("Vous pouvez appuyer sur une ligne pour éditer manuellement le classement calculé par Padel Club.") |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
let keys = rankings.keys.sorted() |
|
|
|
|
ForEach(keys, id: \.self) { key in |
|
|
|
|
if let rankedTeams = rankings[key] { |
|
|
|
|
ForEach(rankedTeams) { team in |
|
|
|
|
TeamRankCellView(team: team, key: key) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.alert("Position", isPresented: isEditingTeam) { |
|
|
|
|
if let selectedTeam { |
|
|
|
|
@Bindable var team = selectedTeam |
|
|
|
|
TextField("Position", value: $team.finalRanking, format: .number) |
|
|
|
|
.keyboardType(.numberPad) |
|
|
|
|
.multilineTextAlignment(.trailing) |
|
|
|
|
.frame(maxWidth: .infinity) |
|
|
|
|
|
|
|
|
|
Button("Valider") { |
|
|
|
|
selectedTeam.pointsEarned = tournament.isAnimation() ? nil : tournament.tournamentLevel.points(for: selectedTeam.finalRanking! - 1, count: tournament.teamCount) |
|
|
|
|
dataStore.teamRegistrations.addOrUpdate(instance: selectedTeam) |
|
|
|
|
self.selectedTeam = nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Button("Annuler", role: .cancel) { |
|
|
|
|
self.selectedTeam = nil |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.overlay(content: { |
|
|
|
|
if calculating { |
|
|
|
|
ProgressView() |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.onAppear { |
|
|
|
|
let rankingPublished = tournament.selectedSortedTeams().allSatisfy({ $0.finalRanking != nil }) |
|
|
|
|
if rankingPublished == false { |
|
|
|
|
calculating = true |
|
|
|
|
Task { |
|
|
|
|
await _calculateRankings() |
|
|
|
|
calculating = false |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.navigationTitle("Classement") |
|
|
|
|
.navigationBarTitleDisplayMode(.inline) |
|
|
|
|
.toolbarBackground(.visible, for: .navigationBar) |
|
|
|
|
.toolbar { |
|
|
|
|
ToolbarItem(placement: .topBarTrailing) { |
|
|
|
|
if let url = tournament.shareURL(.rankings) { |
|
|
|
|
_actionForURL(url) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct TeamRankCellView: View { |
|
|
|
|
@Environment(Tournament.self) var tournament: Tournament |
|
|
|
|
let team: TeamRegistration |
|
|
|
|
let key: Int |
|
|
|
|
|
|
|
|
|
var body: some View { |
|
|
|
|
HStack { |
|
|
|
|
VStack(alignment: .trailing) { |
|
|
|
|
VStack(alignment: .trailing, spacing: -8.0) { |
|
|
|
|
@ -140,7 +216,7 @@ struct TournamentRankView: View { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if tournament.isAnimation() == false { |
|
|
|
|
if tournament.isAnimation() == false && key > 0 { |
|
|
|
|
Spacer() |
|
|
|
|
VStack(alignment: .trailing) { |
|
|
|
|
HStack(alignment: .lastTextBaseline, spacing: 0.0) { |
|
|
|
|
@ -150,68 +226,6 @@ struct TournamentRankView: View { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.frame(maxWidth: .infinity) |
|
|
|
|
} |
|
|
|
|
.contentShape(Rectangle()) |
|
|
|
|
.buttonStyle(.plain) |
|
|
|
|
} |
|
|
|
|
} footer: { |
|
|
|
|
Text("Vous pouvez appuyer sur une ligne pour éditer manuellement le classement calculé par Padel Club.") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// let keys = rankings.keys.sorted() |
|
|
|
|
// ForEach(keys, id: \.self) { key in |
|
|
|
|
// if let rankedTeams = rankings[key] { |
|
|
|
|
// ForEach(rankedTeams) { team in |
|
|
|
|
// |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
} |
|
|
|
|
.alert("Position", isPresented: isEditingTeam) { |
|
|
|
|
if let selectedTeam { |
|
|
|
|
@Bindable var team = selectedTeam |
|
|
|
|
TextField("Position", value: $team.finalRanking, format: .number) |
|
|
|
|
.keyboardType(.numberPad) |
|
|
|
|
.multilineTextAlignment(.trailing) |
|
|
|
|
.frame(maxWidth: .infinity) |
|
|
|
|
|
|
|
|
|
Button("Valider") { |
|
|
|
|
selectedTeam.pointsEarned = tournament.isAnimation() ? nil : tournament.tournamentLevel.points(for: selectedTeam.finalRanking! - 1, count: tournament.teamCount) |
|
|
|
|
dataStore.teamRegistrations.addOrUpdate(instance: selectedTeam) |
|
|
|
|
self.selectedTeam = nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Button("Annuler", role: .cancel) { |
|
|
|
|
self.selectedTeam = nil |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.overlay(content: { |
|
|
|
|
if calculating { |
|
|
|
|
ProgressView() |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.onAppear { |
|
|
|
|
let rankingPublished = tournament.selectedSortedTeams().allSatisfy({ $0.finalRanking != nil }) |
|
|
|
|
if rankingPublished == false { |
|
|
|
|
calculating = true |
|
|
|
|
Task { |
|
|
|
|
await _calculateRankings() |
|
|
|
|
_publishRankings() |
|
|
|
|
calculating = false |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.navigationTitle("Classement") |
|
|
|
|
.navigationBarTitleDisplayMode(.inline) |
|
|
|
|
.toolbarBackground(.visible, for: .navigationBar) |
|
|
|
|
.toolbar { |
|
|
|
|
ToolbarItem(placement: .topBarTrailing) { |
|
|
|
|
if let url = tournament.shareURL(.rankings) { |
|
|
|
|
_actionForURL(url) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|