diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index 85e0d4b..dee006b 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -1935,7 +1935,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 25; + CURRENT_PROJECT_VERSION = 28; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_TEAM = BQ3Y44M3Q6; @@ -1973,7 +1973,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 25; + CURRENT_PROJECT_VERSION = 28; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_TEAM = BQ3Y44M3Q6; diff --git a/PadelClub/Data/Club.swift b/PadelClub/Data/Club.swift index 3aeca00..14669ea 100644 --- a/PadelClub/Data/Club.swift +++ b/PadelClub/Data/Club.swift @@ -177,7 +177,15 @@ extension Club { guard let code else { return nil } return URL(string: "https://tenup.fft.fr/club/\(code)") } - + + func courtName(atIndex courtIndex: Int) -> String { + courtNameIfAvailable(atIndex: courtIndex) ?? Court.courtIndexedTitle(atIndex: courtIndex) + } + + func courtNameIfAvailable(atIndex courtIndex: Int) -> String? { + customizedCourts.first(where: { $0.index == courtIndex })?.name + } + func update(fromClub club: Club) { self.acronym = club.acronym self.name = club.name diff --git a/PadelClub/Data/GroupStage.swift b/PadelClub/Data/GroupStage.swift index 58d15ba..c1efdbe 100644 --- a/PadelClub/Data/GroupStage.swift +++ b/PadelClub/Data/GroupStage.swift @@ -179,7 +179,6 @@ class GroupStage: ModelObject, Storable { } func availableToStart(playedMatches: [Match], in runningMatches: [Match]) -> [Match] { - return [] return playedMatches.filter({ $0.canBeStarted(inMatches: runningMatches) && $0.isRunning() == false }) } diff --git a/PadelClub/Data/Match.swift b/PadelClub/Data/Match.swift index 492cfdd..33f3b28 100644 --- a/PadelClub/Data/Match.swift +++ b/PadelClub/Data/Match.swift @@ -36,8 +36,9 @@ class Match: ModelObject, Storable { //var order: Int var disabled: Bool = false private(set) var courtIndex: Int? + var confirmed: Bool = false - internal init(round: String? = nil, groupStage: String? = nil, startDate: Date? = nil, endDate: Date? = nil, index: Int, matchFormat: MatchFormat? = nil, servingTeamId: String? = nil, winningTeamId: String? = nil, losingTeamId: String? = nil, name: String? = nil, disabled: Bool = false, courtIndex: Int? = nil) { + internal init(round: String? = nil, groupStage: String? = nil, startDate: Date? = nil, endDate: Date? = nil, index: Int, matchFormat: MatchFormat? = nil, servingTeamId: String? = nil, winningTeamId: String? = nil, losingTeamId: String? = nil, name: String? = nil, disabled: Bool = false, courtIndex: Int? = nil, confirmed: Bool = false) { self.round = round self.groupStage = groupStage self.startDate = startDate @@ -51,6 +52,7 @@ class Match: ModelObject, Storable { self.disabled = disabled self.name = name self.courtIndex = courtIndex + self.confirmed = confirmed // self.broadcasted = broadcasted // self.order = order } @@ -162,6 +164,7 @@ class Match: ModelObject, Storable { func cleanScheduleAndSave(_ targetStartDate: Date? = nil) { startDate = targetStartDate + confirmed = targetStartDate == nil ? false : true endDate = nil followingMatch()?.cleanScheduleAndSave(nil) _loserMatch()?.cleanScheduleAndSave(nil) @@ -548,6 +551,8 @@ class Match: ModelObject, Storable { startDate = fromStartDate endDate = toEndDate } + + confirmed = true } func courtName() -> String? { @@ -734,7 +739,7 @@ class Match: ModelObject, Storable { } func isRunning() -> Bool { // at least a match has started - hasStarted() && hasEnded() == false + confirmed && hasStarted() && hasEnded() == false } func hasStarted() -> Bool { // meaning at least one match is over @@ -785,6 +790,7 @@ class Match: ModelObject, Storable { case _name = "name" // case _order = "order" case _disabled = "disabled" + case _confirmed = "confirmed" } func encode(to encoder: Encoder) throws { @@ -855,6 +861,8 @@ class Match: ModelObject, Storable { } else { try container.encodeNil(forKey: ._courtIndex) } + + try container.encode(confirmed, forKey: ._confirmed) } func insertOnServer() throws { diff --git a/PadelClub/Data/MatchScheduler.swift b/PadelClub/Data/MatchScheduler.swift index cda8c45..a85429a 100644 --- a/PadelClub/Data/MatchScheduler.swift +++ b/PadelClub/Data/MatchScheduler.swift @@ -90,6 +90,7 @@ class MatchScheduler : ModelObject, Storable { matches.forEach({ $0.removeCourt() $0.startDate = nil + $0.confirmed = false }) var lastDate : Date = tournament.startDate @@ -565,6 +566,7 @@ class MatchScheduler : ModelObject, Storable { if (roundId == nil && matchId == nil) || $0.startDate?.isEarlierThan(startDate) == false { $0.startDate = nil $0.removeCourt() + $0.confirmed = false } }) @@ -590,6 +592,7 @@ class MatchScheduler : ModelObject, Storable { flattenedMatches[index...].forEach { $0.startDate = nil $0.removeCourt() + $0.confirmed = false } } } else if let roundId { @@ -598,6 +601,7 @@ class MatchScheduler : ModelObject, Storable { flattenedMatches[index...].forEach { $0.startDate = nil $0.removeCourt() + $0.confirmed = false } } } diff --git a/PadelClub/Data/TeamRegistration.swift b/PadelClub/Data/TeamRegistration.swift index 6319671..98466c3 100644 --- a/PadelClub/Data/TeamRegistration.swift +++ b/PadelClub/Data/TeamRegistration.swift @@ -69,6 +69,16 @@ class TeamRegistration: ModelObject, Storable { try Store.main.deleteDependencies(items: self.unsortedPlayers()) } + func hasArrived() { + let unsortedPlayers = unsortedPlayers() + unsortedPlayers.forEach({ $0.hasArrived = true }) + do { + try DataStore.shared.playerRegistrations.addOrUpdate(contentOfs: unsortedPlayers) + } catch { + Logger.error(error) + } + } + func isSeedable() -> Bool { bracketPosition == nil && groupStage == nil } diff --git a/PadelClub/Data/TeamScore.swift b/PadelClub/Data/TeamScore.swift index dfadc9f..84411cc 100644 --- a/PadelClub/Data/TeamScore.swift +++ b/PadelClub/Data/TeamScore.swift @@ -17,15 +17,15 @@ class TeamScore: ModelObject, Storable { var id: String = Store.randomId() var match: String var teamRegistration: String? - var playerRegistrations: [String] = [] + //var playerRegistrations: [String] = [] var score: String? var walkOut: Int? var luckyLoser: Int? - init(match: String, teamRegistration: String? = nil, playerRegistrations: [String], score: String? = nil, walkOut: Int? = nil, luckyLoser: Int? = nil) { + init(match: String, teamRegistration: String? = nil, score: String? = nil, walkOut: Int? = nil, luckyLoser: Int? = nil) { self.match = match self.teamRegistration = teamRegistration - self.playerRegistrations = playerRegistrations +// self.playerRegistrations = playerRegistrations self.score = score self.walkOut = walkOut self.luckyLoser = luckyLoser @@ -65,7 +65,7 @@ class TeamScore: ModelObject, Storable { case _id = "id" case _match = "match" case _teamRegistration = "teamRegistration" - case _playerRegistrations = "playerRegistrations" + //case _playerRegistrations = "playerRegistrations" case _score = "score" case _walkOut = "walkOut" case _luckyLoser = "luckyLoser" @@ -83,7 +83,7 @@ class TeamScore: ModelObject, Storable { try container.encodeNil(forKey: ._teamRegistration) } - try container.encode(playerRegistrations, forKey: ._playerRegistrations) + //try container.encode(playerRegistrations, forKey: ._playerRegistrations) if let score = score { try container.encode(score, forKey: ._score) diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index bf49eca..9a25e8c 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -50,6 +50,7 @@ class Tournament : ModelObject, Storable { var publishBrackets: Bool = false var shouldVerifyGroupStage: Bool = false var shouldVerifyBracket: Bool = false + var hideTeamsWeight: Bool = false @ObservationIgnored var navigationPath: [Screen] = [] @@ -94,9 +95,10 @@ class Tournament : ModelObject, Storable { case _publishBrackets = "publishBrackets" case _shouldVerifyGroupStage = "shouldVerifyGroupStage" case _shouldVerifyBracket = "shouldVerifyBracket" + case _hideTeamsWeight = "hideTeamsWeight" } - internal init(event: String? = nil, name: String? = nil, startDate: Date = Date(), endDate: Date? = nil, creationDate: Date = Date(), isPrivate: Bool = false, groupStageFormat: MatchFormat? = nil, roundFormat: MatchFormat? = nil, loserRoundFormat: MatchFormat? = nil, groupStageSortMode: GroupStageOrderingMode, groupStageCount: Int = 4, rankSourceDate: Date? = nil, dayDuration: Int = 1, teamCount: Int = 24, teamSorting: TeamSortingType? = nil, federalCategory: TournamentCategory, federalLevelCategory: TournamentLevel, federalAgeCategory: FederalTournamentAge, closedRegistrationDate: Date? = nil, groupStageAdditionalQualified: Int = 0, courtCount: Int = 2, prioritizeClubMembers: Bool = false, qualifiedPerGroupStage: Int = 1, teamsPerGroupStage: Int = 4, entryFee: Double? = nil, additionalEstimationDuration: Int = 0, isDeleted: Bool = false, publishTeams: Bool = false, publishSummons: Bool = false, publishGroupStages: Bool = false, publishBrackets: Bool = false, shouldVerifyBracket: Bool = false, shouldVerifyGroupStage: Bool = false) { + internal init(event: String? = nil, name: String? = nil, startDate: Date = Date(), endDate: Date? = nil, creationDate: Date = Date(), isPrivate: Bool = false, groupStageFormat: MatchFormat? = nil, roundFormat: MatchFormat? = nil, loserRoundFormat: MatchFormat? = nil, groupStageSortMode: GroupStageOrderingMode, groupStageCount: Int = 4, rankSourceDate: Date? = nil, dayDuration: Int = 1, teamCount: Int = 24, teamSorting: TeamSortingType? = nil, federalCategory: TournamentCategory, federalLevelCategory: TournamentLevel, federalAgeCategory: FederalTournamentAge, closedRegistrationDate: Date? = nil, groupStageAdditionalQualified: Int = 0, courtCount: Int = 2, prioritizeClubMembers: Bool = false, qualifiedPerGroupStage: Int = 1, teamsPerGroupStage: Int = 4, entryFee: Double? = nil, additionalEstimationDuration: Int = 0, isDeleted: Bool = false, publishTeams: Bool = false, publishSummons: Bool = false, publishGroupStages: Bool = false, publishBrackets: Bool = false, shouldVerifyBracket: Bool = false, shouldVerifyGroupStage: Bool = false, hideTeamsWeight: Bool = false) { self.event = event self.name = name self.startDate = startDate @@ -130,6 +132,7 @@ class Tournament : ModelObject, Storable { self.publishGroupStages = publishGroupStages self.shouldVerifyBracket = shouldVerifyBracket self.shouldVerifyGroupStage = shouldVerifyGroupStage + self.hideTeamsWeight = hideTeamsWeight } required init(from decoder: Decoder) throws { @@ -170,6 +173,7 @@ class Tournament : ModelObject, Storable { publishBrackets = try container.decodeIfPresent(Bool.self, forKey: ._publishBrackets) ?? false shouldVerifyBracket = try container.decodeIfPresent(Bool.self, forKey: ._shouldVerifyBracket) ?? false shouldVerifyGroupStage = try container.decodeIfPresent(Bool.self, forKey: ._shouldVerifyGroupStage) ?? false + hideTeamsWeight = try container.decodeIfPresent(Bool.self, forKey: ._hideTeamsWeight) ?? false } fileprivate static let _numberFormatter: NumberFormatter = NumberFormatter() @@ -281,6 +285,7 @@ class Tournament : ModelObject, Storable { try container.encode(publishGroupStages, forKey: ._publishGroupStages) try container.encode(shouldVerifyBracket, forKey: ._shouldVerifyBracket) try container.encode(shouldVerifyGroupStage, forKey: ._shouldVerifyGroupStage) + try container.encode(hideTeamsWeight, forKey: ._hideTeamsWeight) } fileprivate func _encodePayment(container: inout KeyedEncodingContainer) throws { diff --git a/PadelClub/PadelClubApp.swift b/PadelClub/PadelClubApp.swift index 8dd82ed..1b760f9 100644 --- a/PadelClub/PadelClubApp.swift +++ b/PadelClub/PadelClubApp.swift @@ -15,6 +15,13 @@ struct PadelClubApp: App { @State private var navigationViewModel = NavigationViewModel() @StateObject var networkMonitor: NetworkMonitor = NetworkMonitor() + static var appVersion: String { + let dictionary = Bundle.main.infoDictionary! + let version = dictionary["CFBundleShortVersionString"] as! String + let build = dictionary["CFBundleVersion"] as! String + return "\(version) (\(build))" + } + var body: some Scene { WindowGroup { MainView() diff --git a/PadelClub/Utils/PadelRule.swift b/PadelClub/Utils/PadelRule.swift index e595111..4156058 100644 --- a/PadelClub/Utils/PadelRule.swift +++ b/PadelClub/Utils/PadelRule.swift @@ -1134,7 +1134,7 @@ enum MatchFormat: Int, Hashable, Codable, CaseIterable { case .twoSetsSuperTie: return 80 case .twoSetsDecisivePointSuperTie: - return 75 + return 70 case .twoSetsOfFourGames: return 60 case .twoSetsOfFourGamesDecisivePoint: @@ -1142,11 +1142,11 @@ enum MatchFormat: Int, Hashable, Codable, CaseIterable { case .nineGames: return 45 case .nineGamesDecisivePoint: - return 35 + return 40 case .megaTie: - return 20 + return 30 case .superTie: - return 15 + return 25 } } diff --git a/PadelClub/Views/Calling/Components/MenuWarningView.swift b/PadelClub/Views/Calling/Components/MenuWarningView.swift index 6668980..ef6ca1b 100644 --- a/PadelClub/Views/Calling/Components/MenuWarningView.swift +++ b/PadelClub/Views/Calling/Components/MenuWarningView.swift @@ -26,17 +26,24 @@ struct MenuWarningView: View { // TODO: Guard @ViewBuilder private func _actionView(players: [PlayerRegistration], privateMode: Bool = false) -> some View { - Menu { - ForEach(players) { player in - if let number = player.phoneNumber?.replacingOccurrences(of: " ", with: ""), let url = URL(string: "tel:\(number)") { - Link(destination: url) { - Text(player.playerLabel(.short)) - Label(number, systemImage: "phone") + if players.count == 1, let player = players.first, let number = player.phoneNumber?.replacingOccurrences(of: " ", with: ""), let url = URL(string: "tel:\(number)") { + Link(destination: url) { + Label("Appeler", systemImage: "phone") + Text(number) + } + } else { + Menu { + ForEach(players) { player in + if let number = player.phoneNumber?.replacingOccurrences(of: " ", with: ""), let url = URL(string: "tel:\(number)") { + Link(destination: url) { + Label(player.playerLabel(.short), systemImage: "phone") + Text(number) + } } } + } label: { + Text("Appeler un joueur") } - } label: { - Label("Appeler un joueur", systemImage: "phone") } Button("Message") { diff --git a/PadelClub/Views/Cashier/CashierDetailView.swift b/PadelClub/Views/Cashier/CashierDetailView.swift index 4e581ad..c262b32 100644 --- a/PadelClub/Views/Cashier/CashierDetailView.swift +++ b/PadelClub/Views/Cashier/CashierDetailView.swift @@ -43,14 +43,16 @@ struct CashierDetailView: View { DisclosureGroup { ForEach(PlayerRegistration.PlayerPaymentType.allCases) { type in let count = tournament.selectedPlayers().filter({ $0.paymentType == type }).count - LabeledContent { - if let entryFee = tournament.entryFee { - let sum = Double(count) * entryFee - Text(sum.formatted(.currency(code: "EUR"))) + if count > 0 { + LabeledContent { + if let entryFee = tournament.entryFee { + let sum = Double(count) * entryFee + Text(sum.formatted(.currency(code: "EUR"))) + } + } label: { + Text(type.localizedLabel()) + Text(count.formatted()) } - } label: { - Text(type.localizedLabel()) - Text(count.formatted()) } } } label: { diff --git a/PadelClub/Views/Cashier/CashierView.swift b/PadelClub/Views/Cashier/CashierView.swift index 5ca8df8..e3c107e 100644 --- a/PadelClub/Views/Cashier/CashierView.swift +++ b/PadelClub/Views/Cashier/CashierView.swift @@ -21,6 +21,9 @@ struct CashierView: View { init(tournament: Tournament, teams: [TeamRegistration]) { self.tournaments = [tournament] self.teams = teams + if tournament.hasEnded(), tournament.players().anySatisfy({ $0.hasPaid() == false }) { + _filterOption = .init(wrappedValue: .didNotPay) + } if teams.filter({ $0.callDate != nil }).isEmpty { _sortOption = .init(wrappedValue: .teamRank) } else { @@ -29,8 +32,8 @@ struct CashierView: View { } private func _sharedData() -> String { - let players = teams - .flatMap({ $0.players() }) + let players = teams.filter({ _shouldDisplayTeam($0) }) + .flatMap({ $0.players().filter({ _shouldDisplayPlayer($0) }) }) .map { [$0.pasteData()] .compacted() @@ -163,7 +166,7 @@ struct CashierView: View { } private func _shouldDisplayTeam(_ team: TeamRegistration) -> Bool { - team.players().allSatisfy({ + team.players().anySatisfy({ _shouldDisplayPlayer($0) }) } diff --git a/PadelClub/Views/Club/ClubDetailView.swift b/PadelClub/Views/Club/ClubDetailView.swift index 5b64730..538b021 100644 --- a/PadelClub/Views/Club/ClubDetailView.swift +++ b/PadelClub/Views/Club/ClubDetailView.swift @@ -142,6 +142,14 @@ struct ClubDetailView: View { ClubCourtSetupView(club: club, displayContext: displayContext, selectedCourt: $selectedCourt) + if let padelClubLink = club.shareURL() { + Section { + Link(destination: padelClubLink) { + Text("Accéder au club sur le site Padel Club") + } + } + } + if let federalLink = club.federalLink() { Section { LabeledContent("Code Club") { diff --git a/PadelClub/Views/GroupStage/GroupStageSettingsView.swift b/PadelClub/Views/GroupStage/GroupStageSettingsView.swift index e31a1cc..0d902f8 100644 --- a/PadelClub/Views/GroupStage/GroupStageSettingsView.swift +++ b/PadelClub/Views/GroupStage/GroupStageSettingsView.swift @@ -105,6 +105,7 @@ struct GroupStageSettingsView: View { tournament.deleteGroupStages() tournament.buildGroupStages() generationDone = true + tournament.shouldVerifyGroupStage = false _save() } } @@ -115,6 +116,7 @@ struct GroupStageSettingsView: View { tournament.groupStageOrderingMode = mode tournament.refreshGroupStages() generationDone = true + tournament.shouldVerifyGroupStage = false _save() } } diff --git a/PadelClub/Views/GroupStage/GroupStageView.swift b/PadelClub/Views/GroupStage/GroupStageView.swift index 0500678..1631bae 100644 --- a/PadelClub/Views/GroupStage/GroupStageView.swift +++ b/PadelClub/Views/GroupStage/GroupStageView.swift @@ -150,6 +150,11 @@ struct GroupStageView: View { } } } + .contextMenu { + Button("équipe présente") { + team.hasArrived() + } + } } .listRowView(isActive: team.qualified, color: .master) } else { diff --git a/PadelClub/Views/Match/Components/MatchDateView.swift b/PadelClub/Views/Match/Components/MatchDateView.swift index 67144e9..86a7829 100644 --- a/PadelClub/Views/Match/Components/MatchDateView.swift +++ b/PadelClub/Views/Match/Components/MatchDateView.swift @@ -29,10 +29,12 @@ struct MatchDateView: View { if match.startDate == nil && isReady { Button("Démarrer") { match.startDate = Date() + match.confirmed = true _save() } Button("Échauffement") { match.startDate = Calendar.current.date(byAdding: .minute, value: 5, to: Date()) + match.confirmed = true _save() } } else { @@ -40,6 +42,7 @@ struct MatchDateView: View { Button("Démarrer maintenant") { match.startDate = Date() match.endDate = nil + match.confirmed = true _save() } } else { @@ -69,7 +72,7 @@ struct MatchDateView: View { if showPrefix { Text("en cours").font(.footnote).foregroundStyle(.secondary) } - if match.isReady() { + if match.isReady() && match.confirmed { Text(startDate, style: .timer) .monospacedDigit() .foregroundStyle(Color.master) diff --git a/PadelClub/Views/Match/MatchDetailView.swift b/PadelClub/Views/Match/MatchDetailView.swift index 2b16ad3..bffc314 100644 --- a/PadelClub/Views/Match/MatchDetailView.swift +++ b/PadelClub/Views/Match/MatchDetailView.swift @@ -300,6 +300,7 @@ struct MatchDetailView: View { Button(role: .destructive) { match.startDate = nil match.endDate = nil + match.confirmed = false save() } label: { Text("Supprimer l'horaire") @@ -409,21 +410,22 @@ struct MatchDetailView: View { Picker(selection: $fieldSetup) { Text("Au hasard").tag(MatchFieldSetup.random) //Text("Premier disponible").tag(MatchFieldSetup.firstAvailable) - if let tournament = match.currentTournament() { + if let club = match.currentTournament()?.club() { + ForEach(0.. some View { Section { - let unsortedTeams = tournament.unsortedTeams() let walkoutTeams = tournament.walkoutTeams() let unsortedTeamsWithoutWO = tournament.unsortedTeamsWithoutWO() diff --git a/PadelClub/Views/Tournament/Screen/PrintSettingsView.swift b/PadelClub/Views/Tournament/Screen/PrintSettingsView.swift index 7aa4216..2f669e7 100644 --- a/PadelClub/Views/Tournament/Screen/PrintSettingsView.swift +++ b/PadelClub/Views/Tournament/Screen/PrintSettingsView.swift @@ -72,10 +72,7 @@ struct PrintSettingsView: View { } label: { Text("Aperçu du tableau") } - } - - ForEach(tournament.groupStages()) { groupStage in - Section { + ForEach(tournament.groupStages()) { groupStage in NavigationLink { WebView(htmlRawData: HtmlService.groupstage(groupStage: groupStage).html(headName: generator.displayHeads, withRank: generator.displayRank, withScore: false), loadStatusChanged: { loaded, error, webView in if let error { diff --git a/PadelClub/Views/Tournament/Screen/TournamentCashierView.swift b/PadelClub/Views/Tournament/Screen/TournamentCashierView.swift index ff51c2d..1c2fdbe 100644 --- a/PadelClub/Views/Tournament/Screen/TournamentCashierView.swift +++ b/PadelClub/Views/Tournament/Screen/TournamentCashierView.swift @@ -78,9 +78,10 @@ struct TournamentCashierView: View { let tournamentHasEnded = tournament.hasEnded() if tournamentHasEnded { allDestinations.append(.summary) - allDestinations.append(.all(tournament)) } - + + allDestinations.append(.all(tournament)) + let destinations : [CashierDestination] = tournament.groupStages().map { CashierDestination.groupStage($0) } allDestinations.append(contentsOf: destinations) tournament.rounds().forEach { round in @@ -90,7 +91,6 @@ struct TournamentCashierView: View { } if tournamentHasEnded == false { - allDestinations.append(.all(tournament)) allDestinations.append(.summary) } @@ -99,11 +99,19 @@ struct TournamentCashierView: View { init(tournament: Tournament) { self.tournament = tournament - let gs = tournament.getActiveGroupStage() - if let gs { - _selectedDestination = State(wrappedValue: .groupStage(gs)) - } else if let rs = tournament.getActiveRound(withSeeds: true) { - _selectedDestination = State(wrappedValue: .bracket(rs)) + if tournament.hasEnded() { + if tournament.players().anySatisfy({ $0.hasPaid() == false }) == false { + _selectedDestination = .init(wrappedValue: .summary) + } else { + _selectedDestination = .init(wrappedValue: .all(tournament)) + } + } else { + let gs = tournament.getActiveGroupStage() + if let gs { + _selectedDestination = State(wrappedValue: .groupStage(gs)) + } else if let rs = tournament.getActiveRound(withSeeds: true) { + _selectedDestination = State(wrappedValue: .bracket(rs)) + } } } diff --git a/PadelClub/Views/Tournament/Shared/TournamentCellView.swift b/PadelClub/Views/Tournament/Shared/TournamentCellView.swift index 5777594..de792c7 100644 --- a/PadelClub/Views/Tournament/Shared/TournamentCellView.swift +++ b/PadelClub/Views/Tournament/Shared/TournamentCellView.swift @@ -52,8 +52,14 @@ struct TournamentCellView: View { // .frame(width: 2) VStack(alignment: .leading, spacing: 0.0) { if let tournament = tournament as? Tournament { - Text(tournament.locationLabel(displayStyle)) - .font(.caption) + HStack { + Text(tournament.locationLabel(displayStyle)) + .font(.caption) + Spacer() + if tournament.isPrivate { + Text("privé").foregroundStyle(.secondary) + } + } } else { Text(tournament.clubLabel()) .font(.caption) diff --git a/PadelClub/Views/Tournament/TournamentInitView.swift b/PadelClub/Views/Tournament/TournamentInitView.swift index 89e7678..c96ff3f 100644 --- a/PadelClub/Views/Tournament/TournamentInitView.swift +++ b/PadelClub/Views/Tournament/TournamentInitView.swift @@ -43,8 +43,11 @@ struct TournamentInitView: View { NavigationLink(value: Screen.broadcast) { LabeledContent { - Image(systemName: tournament.isPrivate ? "tv.slash" : "checkmark") - .foregroundStyle(tournament.isPrivate ? .logoRed : .green) + if tournament.isPrivate { + Text("tournoi privé").foregroundStyle(.logoRed) + } else { + Text("Automatique") + } } label: { Text("Publication") } diff --git a/PadelClubTests/ServerDataTests.swift b/PadelClubTests/ServerDataTests.swift index 5fdf538..6b92cc5 100644 --- a/PadelClubTests/ServerDataTests.swift +++ b/PadelClubTests/ServerDataTests.swift @@ -96,7 +96,7 @@ final class ServerDataTests: XCTestCase { return } - let tournament = Tournament(event: eventId, name: "RG Homme", startDate: Date(), endDate: nil, creationDate: Date(), isPrivate: false, groupStageFormat: MatchFormat.megaTie, roundFormat: MatchFormat.nineGames, loserRoundFormat: MatchFormat.nineGamesDecisivePoint, groupStageSortMode: GroupStageOrderingMode.snake, groupStageCount: 2, rankSourceDate: Date(), dayDuration: 5, teamCount: 3, teamSorting: TeamSortingType.rank, federalCategory: TournamentCategory.mix, federalLevelCategory: TournamentLevel.p1000, federalAgeCategory: FederalTournamentAge.a45, closedRegistrationDate: Date(), groupStageAdditionalQualified: 4, courtCount: 9, prioritizeClubMembers: true, qualifiedPerGroupStage: 1, teamsPerGroupStage: 2, entryFee: 30.0, additionalEstimationDuration: 5, isDeleted: true, publishTeams: true, publishSummons: true, publishGroupStages: true, publishBrackets: true, shouldVerifyBracket: true, shouldVerifyGroupStage: true) + let tournament = Tournament(event: eventId, name: "RG Homme", startDate: Date(), endDate: nil, creationDate: Date(), isPrivate: false, groupStageFormat: MatchFormat.megaTie, roundFormat: MatchFormat.nineGames, loserRoundFormat: MatchFormat.nineGamesDecisivePoint, groupStageSortMode: GroupStageOrderingMode.snake, groupStageCount: 2, rankSourceDate: Date(), dayDuration: 5, teamCount: 3, teamSorting: TeamSortingType.rank, federalCategory: TournamentCategory.mix, federalLevelCategory: TournamentLevel.p1000, federalAgeCategory: FederalTournamentAge.a45, closedRegistrationDate: Date(), groupStageAdditionalQualified: 4, courtCount: 9, prioritizeClubMembers: true, qualifiedPerGroupStage: 1, teamsPerGroupStage: 2, entryFee: 30.0, additionalEstimationDuration: 5, isDeleted: true, publishTeams: true, publishSummons: true, publishGroupStages: true, publishBrackets: true, shouldVerifyBracket: true, shouldVerifyGroupStage: true, hideTeamsWeight: false) let t = try await Store.main.service().post(tournament) assert(t.event == tournament.event) @@ -132,6 +132,7 @@ final class ServerDataTests: XCTestCase { assert(t.publishBrackets == tournament.publishBrackets) assert(t.shouldVerifyBracket == tournament.shouldVerifyBracket) assert(t.shouldVerifyGroupStage == tournament.shouldVerifyGroupStage) + assert(t.hideTeamsWeight == tournament.hideTeamsWeight) } func testGroupStage() async throws { @@ -254,7 +255,7 @@ final class ServerDataTests: XCTestCase { let rounds: [Round] = try await Store.main.service().get() let parentRoundId = rounds.first?.id - let match: Match = Match(round: parentRoundId, groupStage: nil, startDate: Date(), endDate: Date(), index: 2, matchFormat: MatchFormat.twoSets, servingTeamId: teamRegistrationId, winningTeamId: teamRegistrationId, losingTeamId: teamRegistrationId, disabled: true, courtIndex: 1) + let match: Match = Match(round: parentRoundId, groupStage: nil, startDate: Date(), endDate: Date(), index: 2, matchFormat: MatchFormat.twoSets, servingTeamId: teamRegistrationId, winningTeamId: teamRegistrationId, losingTeamId: teamRegistrationId, disabled: true, courtIndex: 1, confirmed: true) let m: Match = try await Store.main.service().post(match) assert(m.round == match.round) @@ -268,7 +269,8 @@ final class ServerDataTests: XCTestCase { assert(m.losingTeamId == match.losingTeamId) assert(m.disabled == match.disabled) assert(m.courtIndex == match.courtIndex) - + assert(m.confirmed == match.confirmed) + } func testTeamScore() async throws { @@ -283,15 +285,11 @@ final class ServerDataTests: XCTestCase { assertionFailure("missing teamRegistrations in database") return } - let playerRegistrations: [PlayerRegistration] = try await Store.main.service().get() - let regs = playerRegistrations.prefix(upTo: 2).map { $0.id } - - let teamScore = TeamScore(match: matchId, teamRegistration: teamRegistrationId, playerRegistrations: regs, score: "6/6", walkOut: 1, luckyLoser: 1) + let teamScore = TeamScore(match: matchId, teamRegistration: teamRegistrationId, score: "6/6", walkOut: 1, luckyLoser: 1) let ts: TeamScore = try await Store.main.service().post(teamScore) assert(ts.match == teamScore.match) assert(ts.teamRegistration == teamScore.teamRegistration) - assert(ts.playerRegistrations == teamScore.playerRegistrations) assert(ts.score == teamScore.score) assert(ts.walkOut == teamScore.walkOut) assert(ts.luckyLoser == teamScore.luckyLoser)