parent
a442cd934d
commit
9a2d293b41
@ -0,0 +1,122 @@ |
||||
// |
||||
// LoserBracketFromGroupStageView.swift |
||||
// PadelClub |
||||
// |
||||
// Created by razmig on 07/09/2024. |
||||
// |
||||
|
||||
import SwiftUI |
||||
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 |
||||
|
||||
var tournamentStore: TournamentStore { |
||||
return self.tournament.tournamentStore |
||||
} |
||||
|
||||
var body: some View { |
||||
List { |
||||
let displayableMatches = loserBracket.playedMatches().sorted(by: \.index) |
||||
|
||||
if isEditingTournamentSeed.wrappedValue == true { |
||||
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) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
ForEach(displayableMatches) { match in |
||||
Section { |
||||
MatchRowView(match: match, matchViewStyle: .sectionedStandardStyle) |
||||
} header: { |
||||
let tournamentTeamCount = tournament.teamCount |
||||
let seedIntervalPointRange = tournament.tournamentLevel.pointsRange(first: match.index, last: match.index + 1, teamsCount: tournamentTeamCount) |
||||
HStack { |
||||
Text(match.matchTitle(.wide)) |
||||
Spacer() |
||||
Text(seedIntervalPointRange) |
||||
.font(.caption) |
||||
} |
||||
} footer: { |
||||
if isEditingTournamentSeed.wrappedValue == true { |
||||
HStack { |
||||
if match.index > tournament.groupStageLoserBracketsInitialPlace() { |
||||
FooterButtonView("même place qu'au-dessus") { |
||||
match.index -= 2 |
||||
do { |
||||
try tournamentStore.matches.addOrUpdate(instance: match) |
||||
} catch { |
||||
Logger.error(error) |
||||
} |
||||
} |
||||
Spacer() |
||||
} |
||||
FooterButtonView("effacer", role: .destructive) { |
||||
do { |
||||
try match.deleteDependencies() |
||||
try tournamentStore.matches.delete(instance: match) |
||||
} catch { |
||||
Logger.error(error) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
Section { |
||||
if displayableMatches.isEmpty == false && isEditingTournamentSeed.wrappedValue == true { |
||||
Section { |
||||
RowButtonView("Effacer tous les matchs", role: .destructive) { |
||||
_deleteAllMatches() |
||||
} |
||||
} footer: { |
||||
Text("Efface tous les matchs de classement de poules ci-dessus.") |
||||
} |
||||
} |
||||
} |
||||
} |
||||
.headerProminence(.increased) |
||||
.navigationTitle("Classement de poules") |
||||
.toolbar { |
||||
ToolbarItem(placement: .topBarTrailing) { |
||||
Button(isEditingTournamentSeed.wrappedValue == true ? "Valider" : "Modifier") { |
||||
if isEditingTournamentSeed.wrappedValue == true { |
||||
isEditingTournamentSeed.wrappedValue = false |
||||
} else { |
||||
isEditingTournamentSeed.wrappedValue = true |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
private func _deleteAllMatches() { |
||||
let displayableMatches = loserBracket.playedMatches().sorted(by: \.index) |
||||
|
||||
do { |
||||
for match in displayableMatches { |
||||
try match.deleteDependencies() |
||||
} |
||||
try tournamentStore.matches.delete(contentOfs: displayableMatches) |
||||
} catch { |
||||
Logger.error(error) |
||||
} |
||||
|
||||
} |
||||
} |
||||
@ -1,85 +0,0 @@ |
||||
// |
||||
// LoserGroupStageSettingsView.swift |
||||
// PadelClub |
||||
// |
||||
// Created by Razmig Sarkissian on 29/06/2024. |
||||
// |
||||
|
||||
import SwiftUI |
||||
|
||||
extension Round { |
||||
var isGroupStageLoserBracket: Bool { |
||||
return false |
||||
} |
||||
} |
||||
|
||||
extension Tournament { |
||||
func groupStageLoserBrackets() -> [Round] { |
||||
[] |
||||
} |
||||
|
||||
func removeGroupStageLoserBrackets() { |
||||
|
||||
} |
||||
} |
||||
|
||||
struct LoserGroupStageSettingsView: View { |
||||
var tournament: Tournament |
||||
@State private var loserGroupStageBracketType: Int? = nil |
||||
@State private var losers : Set<TeamRegistration> = Set() |
||||
@Environment(\.editMode) private var editMode |
||||
|
||||
var body: some View { |
||||
List(selection: $losers) { |
||||
if tournament.groupStageLoserBrackets().isEmpty == false { |
||||
//for each all rounds without parent and loserGroupStage, ability to delete them |
||||
Section { |
||||
RowButtonView("Effacer", role: .destructive) { |
||||
tournament.removeGroupStageLoserBrackets() |
||||
} |
||||
} |
||||
} |
||||
|
||||
if self.editMode?.wrappedValue == .active { |
||||
Section { |
||||
//rajouter + toolbar valider / cancel |
||||
ForEach(tournament.groupStageTeams().filter({ $0.qualified == false })) { team in |
||||
TeamRowView(team: team).tag(team) |
||||
} |
||||
} header: { |
||||
Text("Sélection des perdants de poules") |
||||
} |
||||
} else { |
||||
Section { |
||||
RowButtonView("Ajouter un match de perdant") { |
||||
self.editMode?.wrappedValue = .active |
||||
} |
||||
} footer: { |
||||
Text("Permet d'ajouter un match de perdant de poules.") |
||||
} |
||||
} |
||||
} |
||||
.toolbar { |
||||
if self.editMode?.wrappedValue == .active { |
||||
ToolbarItem(placement: .topBarLeading) { |
||||
Button("Annuler") { |
||||
self.editMode?.wrappedValue = .inactive |
||||
} |
||||
} |
||||
|
||||
ToolbarItem(placement: .topBarTrailing) { |
||||
Button("Valider") { |
||||
self.editMode?.wrappedValue = .inactive |
||||
//tournament.createGroupStageLoserBracket() |
||||
} |
||||
} |
||||
} |
||||
} |
||||
.navigationTitle("Match de perdant de poules") |
||||
.navigationBarBackButtonHidden(self.editMode?.wrappedValue == .active) |
||||
.navigationBarTitleDisplayMode(.inline) |
||||
.toolbar(.visible, for: .navigationBar) |
||||
.headerProminence(.increased) |
||||
.toolbarBackground(.visible, for: .navigationBar) |
||||
} |
||||
} |
||||
Loading…
Reference in new issue