|
|
|
|
@ -93,6 +93,64 @@ struct RoundSettingsView: View { |
|
|
|
|
Section { |
|
|
|
|
let roundIndex = tournament.rounds().count |
|
|
|
|
RowButtonView("Ajouter " + RoundRule.roundName(fromRoundIndex: roundIndex), role: .destructive) { |
|
|
|
|
await _addNewRound(roundIndex) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Section { |
|
|
|
|
if let lastRound = tournament.rounds().first { // first is final, last round |
|
|
|
|
RowButtonView("Supprimer " + lastRound.roundTitle(), role: .destructive) { |
|
|
|
|
await _removeRound(lastRound) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Section { |
|
|
|
|
RowButtonView("Synchroniser les noms des matchs") { |
|
|
|
|
let allRoundMatches = tournament.allLoserRoundMatches() |
|
|
|
|
allRoundMatches.forEach({ $0.setMatchName($0.roundTitle()) }) |
|
|
|
|
do { |
|
|
|
|
try self.tournament.tournamentStore.matches.addOrUpdate(contentOfs: allRoundMatches) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} header: { |
|
|
|
|
Text("Matchs de classement") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.toolbar { |
|
|
|
|
ToolbarItem(placement: .topBarTrailing) { |
|
|
|
|
ShareLink(item: tournament.rounds().compactMap { $0.pasteData() }.joined(separator: "\n\n")) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _removeAllSeeds() async { |
|
|
|
|
tournament.unsortedTeams().forEach({ team in |
|
|
|
|
team.bracketPosition = nil |
|
|
|
|
}) |
|
|
|
|
let ts = tournament.allRoundMatches().flatMap { match in |
|
|
|
|
match.teamScores |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
do { |
|
|
|
|
try tournamentStore.teamScores.delete(contentOfs: ts) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
do { |
|
|
|
|
try tournamentStore.teamRegistrations.addOrUpdate(contentOfs: tournament.unsortedTeams()) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
tournament.allRounds().forEach({ round in |
|
|
|
|
round.enableRound() |
|
|
|
|
}) |
|
|
|
|
self.isEditingTournamentSeed.wrappedValue = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _addNewRound(_ roundIndex: Int) async { |
|
|
|
|
let round = Round(tournament: tournament.id, index: roundIndex, matchFormat: tournament.matchFormat) |
|
|
|
|
let matchCount = RoundRule.numberOfMatches(forRoundIndex: roundIndex) |
|
|
|
|
let matchStartIndex = RoundRule.matchIndex(fromRoundIndex: roundIndex) |
|
|
|
|
@ -136,11 +194,8 @@ struct RoundSettingsView: View { |
|
|
|
|
$0._toggleLoserMatchDisableState(true) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Section { |
|
|
|
|
if let lastRound = tournament.rounds().first { // first is final, last round |
|
|
|
|
RowButtonView("Supprimer " + lastRound.roundTitle(), role: .destructive) { |
|
|
|
|
private func _removeRound(_ lastRound: Round) async { |
|
|
|
|
do { |
|
|
|
|
let teams = lastRound.seeds() |
|
|
|
|
teams.forEach { team in |
|
|
|
|
@ -153,53 +208,6 @@ struct RoundSettingsView: View { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Section { |
|
|
|
|
RowButtonView("Synchroniser les noms des matchs") { |
|
|
|
|
let allRoundMatches = tournament.allLoserRoundMatches() |
|
|
|
|
allRoundMatches.forEach({ $0.setMatchName($0.roundTitle()) }) |
|
|
|
|
do { |
|
|
|
|
try self.tournament.tournamentStore.matches.addOrUpdate(contentOfs: allRoundMatches) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} header: { |
|
|
|
|
Text("Matchs de classement") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.toolbar { |
|
|
|
|
ToolbarItem(placement: .topBarTrailing) { |
|
|
|
|
ShareLink(item: tournament.rounds().compactMap { $0.pasteData() }.joined(separator: "\n\n")) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _removeAllSeeds() async { |
|
|
|
|
tournament.unsortedTeams().forEach({ team in |
|
|
|
|
team.bracketPosition = nil |
|
|
|
|
}) |
|
|
|
|
let ts = tournament.allRoundMatches().flatMap { match in |
|
|
|
|
match.teamScores |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
do { |
|
|
|
|
try tournamentStore.teamScores.delete(contentOfs: ts) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
do { |
|
|
|
|
try tournamentStore.teamRegistrations.addOrUpdate(contentOfs: tournament.unsortedTeams()) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
tournament.allRounds().forEach({ round in |
|
|
|
|
round.enableRound() |
|
|
|
|
}) |
|
|
|
|
self.isEditingTournamentSeed.wrappedValue = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//#Preview { |
|
|
|
|
// RoundSettingsView() |
|
|
|
|
|