|
|
|
|
@ -10,32 +10,31 @@ import LeStorage |
|
|
|
|
|
|
|
|
|
struct LoserBracketFromGroupStageView: View { |
|
|
|
|
|
|
|
|
|
@Environment(\.isEditingTournamentSeed) var isEditingTournamentSeed |
|
|
|
|
@Environment(Tournament.self) var tournament: Tournament |
|
|
|
|
@EnvironmentObject var dataStore: DataStore |
|
|
|
|
@Environment(NavigationViewModel.self) private var navigation: NavigationViewModel |
|
|
|
|
|
|
|
|
|
@State var loserBracket: Round |
|
|
|
|
@State private var isEditingLoserBracketGroupStage: Bool |
|
|
|
|
|
|
|
|
|
init(loserBracket: Round) { |
|
|
|
|
self.loserBracket = loserBracket |
|
|
|
|
_isEditingLoserBracketGroupStage = .init(wrappedValue: loserBracket._matches().isEmpty) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var tournamentStore: TournamentStore { |
|
|
|
|
return self.tournament.tournamentStore |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var displayableMatches: [Match] { |
|
|
|
|
loserBracket.playedMatches().sorted(by: \.index) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var body: some View { |
|
|
|
|
List { |
|
|
|
|
let displayableMatches = loserBracket.playedMatches().sorted(by: \.index) |
|
|
|
|
|
|
|
|
|
if isEditingTournamentSeed.wrappedValue == true { |
|
|
|
|
if isEditingLoserBracketGroupStage == true && displayableMatches.isEmpty == false { |
|
|
|
|
Section { |
|
|
|
|
RowButtonView("Ajouter un match", role: .destructive) { |
|
|
|
|
let placeCount = tournament.groupStageLoserBracketsInitialPlace() + displayableMatches.count * 2 |
|
|
|
|
let match = Match(round: loserBracket.id, index: placeCount, matchFormat: loserBracket.matchFormat) |
|
|
|
|
match.name = "\(placeCount)\(placeCount.ordinalFormattedSuffix()) place" |
|
|
|
|
do { |
|
|
|
|
try tournamentStore.matches.addOrUpdate(instance: match) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
_addNewMatch() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -43,9 +42,10 @@ struct LoserBracketFromGroupStageView: View { |
|
|
|
|
ForEach(displayableMatches) { match in |
|
|
|
|
Section { |
|
|
|
|
MatchRowView(match: match, matchViewStyle: .sectionedStandardStyle) |
|
|
|
|
.environment(\.isEditingTournamentSeed, $isEditingLoserBracketGroupStage) |
|
|
|
|
} header: { |
|
|
|
|
let tournamentTeamCount = tournament.teamCount |
|
|
|
|
let seedIntervalPointRange = tournament.tournamentLevel.pointsRange(first: match.index, last: match.index + 1, teamsCount: tournamentTeamCount) |
|
|
|
|
let seedIntervalPointRange = tournament.tournamentLevel.pointsRange(first: match.index, last: match.index + displayableMatches.filter({ $0.index == match.index }).count, teamsCount: tournamentTeamCount) |
|
|
|
|
HStack { |
|
|
|
|
Text(match.matchTitle(.wide)) |
|
|
|
|
Spacer() |
|
|
|
|
@ -53,7 +53,7 @@ struct LoserBracketFromGroupStageView: View { |
|
|
|
|
.font(.caption) |
|
|
|
|
} |
|
|
|
|
} footer: { |
|
|
|
|
if isEditingTournamentSeed.wrappedValue == true { |
|
|
|
|
if isEditingLoserBracketGroupStage == true { |
|
|
|
|
HStack { |
|
|
|
|
if match.index > tournament.groupStageLoserBracketsInitialPlace() { |
|
|
|
|
FooterButtonView("même place qu'au-dessus") { |
|
|
|
|
@ -80,7 +80,7 @@ struct LoserBracketFromGroupStageView: View { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Section { |
|
|
|
|
if displayableMatches.isEmpty == false && isEditingTournamentSeed.wrappedValue == true { |
|
|
|
|
if displayableMatches.count > 1 && isEditingLoserBracketGroupStage == true { |
|
|
|
|
Section { |
|
|
|
|
RowButtonView("Effacer tous les matchs", role: .destructive) { |
|
|
|
|
_deleteAllMatches() |
|
|
|
|
@ -91,20 +91,48 @@ struct LoserBracketFromGroupStageView: View { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.overlay { |
|
|
|
|
if displayableMatches.isEmpty { |
|
|
|
|
ContentUnavailableView { |
|
|
|
|
Label("Aucun match de classement", systemImage: "figure.tennis") |
|
|
|
|
} description: { |
|
|
|
|
Text("Vous n'avez créé aucun match de classement entre les perdants de poules.") |
|
|
|
|
} actions: { |
|
|
|
|
RowButtonView("Ajouter un match") { |
|
|
|
|
isEditingLoserBracketGroupStage = true |
|
|
|
|
_addNewMatch() |
|
|
|
|
} |
|
|
|
|
.padding(.horizontal) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.headerProminence(.increased) |
|
|
|
|
.navigationTitle("Classement de poules") |
|
|
|
|
.toolbar { |
|
|
|
|
ToolbarItem(placement: .topBarTrailing) { |
|
|
|
|
Button(isEditingTournamentSeed.wrappedValue == true ? "Valider" : "Modifier") { |
|
|
|
|
if isEditingTournamentSeed.wrappedValue == true { |
|
|
|
|
isEditingTournamentSeed.wrappedValue = false |
|
|
|
|
if displayableMatches.isEmpty == false { |
|
|
|
|
Button(isEditingLoserBracketGroupStage == true ? "Valider" : "Modifier") { |
|
|
|
|
if isEditingLoserBracketGroupStage == true { |
|
|
|
|
isEditingLoserBracketGroupStage = false |
|
|
|
|
} else { |
|
|
|
|
isEditingTournamentSeed.wrappedValue = true |
|
|
|
|
isEditingLoserBracketGroupStage = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _addNewMatch() { |
|
|
|
|
let placeCount = tournament.groupStageLoserBracketsInitialPlace() + displayableMatches.count * 2 |
|
|
|
|
let match = Match(round: loserBracket.id, index: placeCount, matchFormat: loserBracket.matchFormat) |
|
|
|
|
match.name = "\(placeCount)\(placeCount.ordinalFormattedSuffix()) place" |
|
|
|
|
do { |
|
|
|
|
try tournamentStore.matches.addOrUpdate(instance: match) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _deleteAllMatches() { |
|
|
|
|
let displayableMatches = loserBracket.playedMatches().sorted(by: \.index) |
|
|
|
|
|