paca_championship
Raz 1 year ago
parent 17f371e450
commit 7c3725ce5b
  1. 6
      PadelClub/Data/Match.swift
  2. 8
      PadelClub/Data/TeamRegistration.swift
  3. 2
      PadelClub/Views/Calling/Components/MenuWarningView.swift
  4. 8
      PadelClub/Views/Cashier/CashierView.swift
  5. 2
      PadelClub/Views/GroupStage/Components/GroupStageTeamView.swift
  6. 7
      PadelClub/Views/GroupStage/GroupStageView.swift
  7. 2
      PadelClub/Views/GroupStage/Shared/GroupStageTeamReplacementView.swift
  8. 14
      PadelClub/Views/Match/Components/PlayerBlockView.swift
  9. 21
      PadelClub/Views/Round/LoserRoundSettingsView.swift
  10. 110
      PadelClub/Views/Round/RoundSettingsView.swift
  11. 4
      PadelClub/Views/Team/Components/TeamHeaderView.swift
  12. 8
      PadelClub/Views/Team/TeamRowView.swift
  13. 7
      PadelClub/Views/Tournament/FileImportView.swift
  14. 4
      PadelClub/Views/Tournament/Screen/TournamentRankView.swift

@ -347,16 +347,22 @@ defer {
guard let forwardMatch = _forwardMatch(inRound: roundObject) else { return } guard let forwardMatch = _forwardMatch(inRound: roundObject) else { return }
guard let next = _otherMatch() else { return } guard let next = _otherMatch() else { return }
if next.disabled && byeState == false && next.byeState == false { if next.disabled && byeState == false && next.byeState == false {
if forwardMatch.disabled != state || forwardMatch.byeState {
forwardMatch.byeState = false forwardMatch.byeState = false
forwardMatch._toggleMatchDisableState(state, forward: true) forwardMatch._toggleMatchDisableState(state, forward: true)
}
} else if byeState && next.byeState { } else if byeState && next.byeState {
print("don't disable forward match") print("don't disable forward match")
if forwardMatch.byeState || forwardMatch.disabled {
forwardMatch.byeState = false forwardMatch.byeState = false
forwardMatch._toggleMatchDisableState(false, forward: true) forwardMatch._toggleMatchDisableState(false, forward: true)
}
} else { } else {
if forwardMatch.byeState == false || forwardMatch.disabled != state {
forwardMatch.byeState = true forwardMatch.byeState = true
forwardMatch._toggleMatchDisableState(state, forward: true) forwardMatch._toggleMatchDisableState(state, forward: true)
} }
}
// if next.disabled == false { // if next.disabled == false {
// forwardMatch.byeState = state // forwardMatch.byeState = state

@ -536,6 +536,14 @@ final class TeamRegistration: ModelObject, Storable {
matches().sorted(by: \.computedEndDateForSorting).last?.endDate matches().sorted(by: \.computedEndDateForSorting).last?.endDate
} }
func teamNameLabel() -> String {
if let name, name.isEmpty == false {
return name
} else {
return "Toute l'équipe"
}
}
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case _id = "id" case _id = "id"
case _tournament = "tournament" case _tournament = "tournament"

@ -124,7 +124,7 @@ struct MenuWarningView: View {
@ViewBuilder @ViewBuilder
func _teamActionView(_ team: TeamRegistration) -> some View { func _teamActionView(_ team: TeamRegistration) -> some View {
Menu(team.name ?? "Toute l'équipe") { Menu(team.teamNameLabel()) {
let players = team.players() let players = team.players()
_actionView(players: players) _actionView(players: players)
} }

@ -377,8 +377,8 @@ struct CashierView: View {
} }
} header: { } header: {
HStack { HStack {
if let name = team.name { if let teamName = team.name, teamName.isEmpty == false {
Text(name) Text(teamName)
} }
if displayTournamentTitle, let tournamentTitle = team.tournamentObject()?.tournamentTitle() { if displayTournamentTitle, let tournamentTitle = team.tournamentObject()?.tournamentTitle() {
Spacer() Spacer()
@ -418,8 +418,8 @@ struct CashierView: View {
EditablePlayerView(player: player, editingOptions: editingOptions) EditablePlayerView(player: player, editingOptions: editingOptions)
} }
} header: { } header: {
if let name = team.name { if let teamName = team.name, teamName.isEmpty == false {
Text(name) Text(teamName)
} }
if displayTournamentTitle, let tournamentTitle = team.tournamentObject()?.tournamentTitle() { if displayTournamentTitle, let tournamentTitle = team.tournamentObject()?.tournamentTitle() {

@ -48,7 +48,7 @@ struct GroupStageTeamView: View {
var body: some View { var body: some View {
List { List {
Section { Section {
if let name = team.name { if let name = team.name, name.isEmpty == false {
Text(name).foregroundStyle(.secondary) Text(name).foregroundStyle(.secondary)
} }
ForEach(team.players()) { player in ForEach(team.players()) { player in

@ -142,9 +142,9 @@ struct GroupStageView: View {
.font(.footnote) .font(.footnote)
HStack { HStack {
VStack(alignment: .leading) { VStack(alignment: .leading) {
if let teamName = team.name { if let teamName = team.name, teamName.isEmpty == false {
Text(teamName).font(.title3) Text(teamName).foregroundStyle(.secondary).font(.footnote)
} else { }
ForEach(team.players()) { player in ForEach(team.players()) { player in
Text(player.playerLabel()).lineLimit(1) Text(player.playerLabel()).lineLimit(1)
.overlay { .overlay {
@ -154,7 +154,6 @@ struct GroupStageView: View {
} }
} }
} }
}
Spacer() Spacer()
if let score = groupStage.scoreLabel(forGroupStagePosition: groupStagePosition, score: scores?.first(where: { $0.team.groupStagePositionAtStep(groupStage.step) == groupStagePosition })) { if let score = groupStage.scoreLabel(forGroupStagePosition: groupStagePosition, score: scores?.first(where: { $0.team.groupStagePositionAtStep(groupStage.step) == groupStagePosition })) {
VStack(alignment: .trailing) { VStack(alignment: .trailing) {

@ -54,7 +54,7 @@ struct GroupStageTeamReplacementView: View {
Section { Section {
Picker(selection: $selectedPlayer) { Picker(selection: $selectedPlayer) {
HStack { HStack {
Text(team.name ?? "Toute l'équipe") Text(team.teamNameLabel())
Spacer() Spacer()
Text(team.weight.formatted()).bold() Text(team.weight.formatted()).bold()
} }

@ -58,23 +58,21 @@ struct PlayerBlockView: View {
Text("Repêchée").italic().font(.caption) Text("Repêchée").italic().font(.caption)
} }
if let name = team?.name { if let teamName = team?.name {
Text(name).font(.title3) Text(teamName).foregroundStyle(.secondary).font(.footnote)
} else { }
ForEach(names, id: \.self) { name in ForEach(names, id: \.self) { name in
Text(name).lineLimit(1) Text(name).lineLimit(1)
} }
}
} else { } else {
ZStack(alignment: .leading) { ZStack(alignment: .leading) {
VStack { VStack {
if let name = team?.name { if let teamName = team?.name {
Text(name).font(.title3) Text(teamName).foregroundStyle(.secondary).font(.footnote)
} else { }
Text("longLabelPlayerOne").lineLimit(1) Text("longLabelPlayerOne").lineLimit(1)
Text("longLabelPlayerTwo").lineLimit(1) Text("longLabelPlayerTwo").lineLimit(1)
} }
}
.opacity(0) .opacity(0)
Text(_defaultLabel()).foregroundStyle(.secondary).lineLimit(1) Text(_defaultLabel()).foregroundStyle(.secondary).lineLimit(1)
} }

@ -80,15 +80,7 @@ struct LoserRoundSettingsView: View {
Section { Section {
RowButtonView("Créer les matchs de classements", role: .destructive) { RowButtonView("Créer les matchs de classements", role: .destructive) {
upperBracketRound.round.buildLoserBracket() await _addLoserBracketMatches()
upperBracketRound.round.disabledMatches().forEach { match in
match._toggleLoserMatchDisableState(true)
}
do {
try self.tournament.tournamentStore.matches.addOrUpdate(contentOfs: upperBracketRound.round.allLoserRoundMatches())
} catch {
Logger.error(error)
}
} }
} }
.disabled(upperBracketRound.round.loserRounds().isEmpty == false) .disabled(upperBracketRound.round.loserRounds().isEmpty == false)
@ -147,6 +139,17 @@ struct LoserRoundSettingsView: View {
Text(" Modifier quand même ?").foregroundStyle(.red) Text(" Modifier quand même ?").foregroundStyle(.red)
} }
private func _addLoserBracketMatches() async {
upperBracketRound.round.buildLoserBracket()
upperBracketRound.round.disabledMatches().forEach { match in
match._toggleLoserMatchDisableState(true)
}
do {
try self.tournament.tournamentStore.matches.addOrUpdate(contentOfs: upperBracketRound.round.allLoserRoundMatches())
} catch {
Logger.error(error)
}
}
} }
//#Preview { //#Preview {

@ -93,6 +93,64 @@ struct RoundSettingsView: View {
Section { Section {
let roundIndex = tournament.rounds().count let roundIndex = tournament.rounds().count
RowButtonView("Ajouter " + RoundRule.roundName(fromRoundIndex: roundIndex), role: .destructive) { 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 round = Round(tournament: tournament.id, index: roundIndex, matchFormat: tournament.matchFormat)
let matchCount = RoundRule.numberOfMatches(forRoundIndex: roundIndex) let matchCount = RoundRule.numberOfMatches(forRoundIndex: roundIndex)
let matchStartIndex = RoundRule.matchIndex(fromRoundIndex: roundIndex) let matchStartIndex = RoundRule.matchIndex(fromRoundIndex: roundIndex)
@ -136,11 +194,8 @@ struct RoundSettingsView: View {
$0._toggleLoserMatchDisableState(true) $0._toggleLoserMatchDisableState(true)
} }
} }
}
Section { private func _removeRound(_ lastRound: Round) async {
if let lastRound = tournament.rounds().first { // first is final, last round
RowButtonView("Supprimer " + lastRound.roundTitle(), role: .destructive) {
do { do {
let teams = lastRound.seeds() let teams = lastRound.seeds()
teams.forEach { team in teams.forEach { team in
@ -152,53 +207,6 @@ struct RoundSettingsView: View {
Logger.error(error) Logger.error(error)
} }
} }
}
}
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 { //#Preview {

@ -29,10 +29,10 @@ struct TeamHeaderView: View {
Text(team.weight.formatted()) Text(team.weight.formatted())
} }
} }
if let name = team.name { if let name = team.name, name.isEmpty == false {
VStack(alignment: .leading, spacing: 0) { VStack(alignment: .leading, spacing: 0) {
Text("Nom de l'équipe").font(.caption) Text("Nom de l'équipe").font(.caption)
Text(name) Text(name).lineLimit(1).truncationMode(.tail)
} }
} }
} }

@ -35,10 +35,14 @@ struct TeamRowView: View {
} }
} }
if let name = team.name { if let name = team.name, name.isEmpty == false {
Text(name).font(.title3) Text(name).foregroundStyle(.secondary).font(.footnote)
if team.players().isEmpty { if team.players().isEmpty {
Text("Aucun joueur") Text("Aucun joueur")
} else {
ForEach(team.players()) { player in
Text(player.playerLabel()).lineLimit(1).truncationMode(.tail)
}
} }
} else { } else {
if team.players().isEmpty == false { if team.players().isEmpty == false {

@ -86,6 +86,11 @@ struct FileImportView: View {
@State private var validatedTournamentIds: Set<String> = Set() @State private var validatedTournamentIds: Set<String> = Set()
@State private var chunkByParameter: Bool = true @State private var chunkByParameter: Bool = true
enum ChunkMode {
case byParameter
case byCoupleOfLines
}
init(defaultFileProvider: FileImportManager.FileProvider = .frenchFederation) { init(defaultFileProvider: FileImportManager.FileProvider = .frenchFederation) {
_fileProvider = .init(wrappedValue: defaultFileProvider) _fileProvider = .init(wrappedValue: defaultFileProvider)
} }
@ -558,7 +563,7 @@ struct FileImportView: View {
Section { Section {
HStack { HStack {
VStack(alignment: .leading) { VStack(alignment: .leading) {
if let teamName = team.name { if let teamName = team.name, teamName.isEmpty == false {
Text(teamName).foregroundStyle(.secondary) Text(teamName).foregroundStyle(.secondary)
} }
ForEach(team.players.sorted(by: \.computedRank)) { ForEach(team.players.sorted(by: \.computedRank)) {

@ -233,8 +233,8 @@ struct TournamentRankView: View {
Divider() Divider()
VStack(alignment: .leading) { VStack(alignment: .leading) {
if let name = team.name { if let teamName = team.name, teamName.isEmpty == false {
Text(name).foregroundStyle(.secondary) Text(teamName).foregroundStyle(.secondary)
} }
ForEach(team.players()) { player in ForEach(team.players()) { player in

Loading…
Cancel
Save