diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index 260a2b6..2b2d759 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -227,6 +227,7 @@ FFC91AF92BD6A09100B29808 /* FortuneWheelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFC91AF82BD6A09100B29808 /* FortuneWheelView.swift */; }; FFC91B012BD85C2F00B29808 /* Court.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFC91B002BD85C2F00B29808 /* Court.swift */; }; FFC91B032BD85E2400B29808 /* CourtView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFC91B022BD85E2400B29808 /* CourtView.swift */; }; + FFCD16B32C3E5E590092707B /* TeamsCallingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFCD16B22C3E5E590092707B /* TeamsCallingView.swift */; }; FFCEDA4C2C2C08EA00F8C0F2 /* PlayersWithoutContactView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFCEDA4B2C2C08EA00F8C0F2 /* PlayersWithoutContactView.swift */; }; FFCF76072C3BE9BC006C8C3D /* CloseDatePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFCF76062C3BE9BC006C8C3D /* CloseDatePicker.swift */; }; FFCFBFFE2BBBE86600B82851 /* Algorithms in Frameworks */ = {isa = PBXBuildFile; productRef = FFCFBFFD2BBBE86600B82851 /* Algorithms */; }; @@ -562,6 +563,7 @@ FFC91AF82BD6A09100B29808 /* FortuneWheelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FortuneWheelView.swift; sourceTree = ""; }; FFC91B002BD85C2F00B29808 /* Court.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Court.swift; sourceTree = ""; }; FFC91B022BD85E2400B29808 /* CourtView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourtView.swift; sourceTree = ""; }; + FFCD16B22C3E5E590092707B /* TeamsCallingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TeamsCallingView.swift; sourceTree = ""; }; FFCEDA4B2C2C08EA00F8C0F2 /* PlayersWithoutContactView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayersWithoutContactView.swift; sourceTree = ""; }; FFCF76062C3BE9BC006C8C3D /* CloseDatePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CloseDatePicker.swift; sourceTree = ""; }; FFCFC0012BBC39A600B82851 /* EditScoreView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditScoreView.swift; sourceTree = ""; }; @@ -1143,6 +1145,7 @@ children = ( FF9267FE2BCE94830080F940 /* CallSettingsView.swift */, FF9268002BCE94920080F940 /* SeedsCallingView.swift */, + FFCD16B22C3E5E590092707B /* TeamsCallingView.swift */, FF9268022BCE94A30080F940 /* GroupStageCallingView.swift */, FF9268082BCEDC2C0080F940 /* CallView.swift */, FF1162792BCF8109000C4809 /* CallMessageCustomizationView.swift */, @@ -1537,6 +1540,7 @@ FFE103082C353B7600684FC9 /* EventClubSettingsView.swift in Sources */, C4A47DB32B86387500ADC637 /* AccountView.swift in Sources */, FFCEDA4C2C2C08EA00F8C0F2 /* PlayersWithoutContactView.swift in Sources */, + FFCD16B32C3E5E590092707B /* TeamsCallingView.swift in Sources */, FF1CBC1D2BB53DC10036DAAB /* Calendar+Extensions.swift in Sources */, FF967CF22BAECC0B00A9A3BD /* TeamScore.swift in Sources */, FF1162832BCFBE4E000C4809 /* EditablePlayerView.swift in Sources */, diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index fc680c2..8c3ec89 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -1637,11 +1637,6 @@ defer { func resetBracketPosition() { unsortedTeams().forEach({ $0.bracketPosition = nil }) - do { - try self.tournamentStore.teamRegistrations.addOrUpdate(contentOfs: unsortedTeams()) - } catch { - Logger.error(error) - } } func deleteGroupStages() { diff --git a/PadelClub/Views/Calling/CallSettingsView.swift b/PadelClub/Views/Calling/CallSettingsView.swift index 038d34d..7834e0e 100644 --- a/PadelClub/Views/Calling/CallSettingsView.swift +++ b/PadelClub/Views/Calling/CallSettingsView.swift @@ -58,7 +58,7 @@ struct CallSettingsView: View { // #if DEBUG Section { - RowButtonView("Annuler toutes les convocations", role: .destructive) { + RowButtonView("Retirer toutes les convocations", role: .destructive) { let teams = tournament.unsortedTeams() teams.forEach { team in team.callDate = nil @@ -69,13 +69,17 @@ struct CallSettingsView: View { Logger.error(error) } } + } footer: { + Text("Retire l'horaire de convocation enregistré pour toutes les équipes.") } Section { RowButtonView("Tout le monde a été convoqué", role: .destructive) { let teams = tournament.unsortedTeams() teams.forEach { team in - team.callDate = team.expectedSummonDate() + if team.callDate == nil { + team.callDate = team.expectedSummonDate() + } } do { try tournamentStore.teamRegistrations.addOrUpdate(contentOfs: teams) @@ -83,6 +87,8 @@ struct CallSettingsView: View { Logger.error(error) } } + } footer: { + Text("Pour toutes les équipes sans convocation, les indiquer comme ayant été convoquée.") } //#endif } diff --git a/PadelClub/Views/Calling/TeamsCallingView.swift b/PadelClub/Views/Calling/TeamsCallingView.swift new file mode 100644 index 0000000..656351a --- /dev/null +++ b/PadelClub/Views/Calling/TeamsCallingView.swift @@ -0,0 +1,28 @@ +// +// TeamsCallingView.swift +// PadelClub +// +// Created by razmig on 10/07/2024. +// + +import SwiftUI + +struct TeamsCallingView: View { + @Environment(Tournament.self) var tournament: Tournament + + var body: some View { + List { + let teams = tournament.selectedSortedTeams() + Section { + ForEach(teams) { team in + TeamRowView(team: team, displayCallDate: true) + } + } + } + .headerProminence(.increased) + .navigationTitle("Statut des équipes") + .navigationBarTitleDisplayMode(.inline) + .toolbarBackground(.visible, for: .navigationBar) + } + +} diff --git a/PadelClub/Views/Cashier/CashierView.swift b/PadelClub/Views/Cashier/CashierView.swift index af0414b..b406a85 100644 --- a/PadelClub/Views/Cashier/CashierView.swift +++ b/PadelClub/Views/Cashier/CashierView.swift @@ -315,7 +315,7 @@ struct CashierView: View { } } footer: { if let callDate = team.callDate { - Text("convoqué") + Text(callDate.localizedDate()) + Text("convocation : ") + Text(callDate.localizedDate()) } } } @@ -345,11 +345,13 @@ struct CashierView: View { EditablePlayerView(player: player, editingOptions: [.licenceId, .name, .payment]) } } header: { - Text(key.localizedDate()) - } footer: { if displayTournamentTitle, let tournamentTitle = team.tournamentObject()?.tournamentTitle() { Text(tournamentTitle) } + } footer: { + if let callDate = team.callDate { + Text("convocation : ") + Text(callDate.localizedDate()) + } } } } diff --git a/PadelClub/Views/Team/EditingTeamView.swift b/PadelClub/Views/Team/EditingTeamView.swift index e7061b2..27b0c73 100644 --- a/PadelClub/Views/Team/EditingTeamView.swift +++ b/PadelClub/Views/Team/EditingTeamView.swift @@ -14,6 +14,7 @@ struct EditingTeamView: View { var team: TeamRegistration @State private var registrationDate : Date + @State private var callDate : Date @State private var name: String @Environment(Tournament.self) var tournament: Tournament @@ -25,6 +26,7 @@ struct EditingTeamView: View { self.team = team _name = .init(wrappedValue: team.name ?? "") _registrationDate = State(wrappedValue: team.registrationDate ?? Date()) + _callDate = State(wrappedValue: team.callDate ?? Date()) } var body: some View { @@ -52,7 +54,21 @@ struct EditingTeamView: View { } header: { Text("Date d'inscription") } - + + Section { + if let callDate = team.callDate { + LabeledContent() { + Text(callDate.localizedDate()) + } label: { + Text("OK") + } + } else { + Text("Cette équipe n'a pas été convoquée") + } + } header: { + Text("Statut de la convocation") + } + Section { Toggle(isOn: hasArrived) { Text("Équipe sur place") diff --git a/PadelClub/Views/Team/TeamRowView.swift b/PadelClub/Views/Team/TeamRowView.swift index 65b0ce0..16c75ef 100644 --- a/PadelClub/Views/Team/TeamRowView.swift +++ b/PadelClub/Views/Team/TeamRowView.swift @@ -24,11 +24,18 @@ struct TeamRowView: View { Text(player.playerLabel()) } } - if let callDate = team.callDate, displayCallDate { - Text("Déjà convoquée \(callDate.localizedDate())") - .foregroundStyle(.logoRed) - .italic() - .font(.caption) + if displayCallDate { + if let callDate = team.callDate { + Text("Déjà convoquée \(callDate.localizedDate())") + .foregroundStyle(.logoRed) + .italic() + .font(.caption) + } else { + Text("Pas encore convoquée") + .foregroundStyle(.logoYellow) + .italic() + .font(.caption) + } } } } diff --git a/PadelClub/Views/Tournament/Screen/TableStructureView.swift b/PadelClub/Views/Tournament/Screen/TableStructureView.swift index 5c28461..55db055 100644 --- a/PadelClub/Views/Tournament/Screen/TableStructureView.swift +++ b/PadelClub/Views/Tournament/Screen/TableStructureView.swift @@ -276,7 +276,7 @@ struct TableStructureView: View { tournament.qualifiedPerGroupStage = qualifiedPerGroupStage tournament.groupStageAdditionalQualified = groupStageAdditionalQualified - if (rebuildEverything == false && requirements.contains(.all)) || rebuildEverything { + if rebuildEverything { tournament.deleteAndBuildEverything() } else if (rebuildEverything == false && requirements.contains(.groupStage)) { tournament.deleteGroupStages() diff --git a/PadelClub/Views/Tournament/Screen/TournamentCallView.swift b/PadelClub/Views/Tournament/Screen/TournamentCallView.swift index 4afa906..94cc2dd 100644 --- a/PadelClub/Views/Tournament/Screen/TournamentCallView.swift +++ b/PadelClub/Views/Tournament/Screen/TournamentCallView.swift @@ -13,12 +13,14 @@ enum CallDestination: Identifiable, Selectable, Equatable { return lhs.id == rhs.id } - + case teams(Tournament) case seeds(Tournament) case groupStages(Tournament) var id: String { switch self { + case .teams: + return "teams" case .seeds: return "seed" case .groupStages: @@ -28,6 +30,8 @@ enum CallDestination: Identifiable, Selectable, Equatable { func selectionLabel(index: Int) -> String { switch self { + case .teams: + return "Statut" case .seeds: return "Têtes de série" case .groupStages: @@ -37,6 +41,9 @@ enum CallDestination: Identifiable, Selectable, Equatable { func badgeValue() -> Int? { switch self { + case .teams(let tournament): + let allSeedCalled = tournament.selectedSortedTeams().filter({ tournament.isStartDateIsDifferentThanCallDate($0) || $0.callDate == nil }) + return allSeedCalled.count case .seeds(let tournament): let allSeedCalled = tournament.seeds().filter({ tournament.isStartDateIsDifferentThanCallDate($0) || $0.callDate == nil }) return allSeedCalled.count @@ -52,6 +59,9 @@ enum CallDestination: Identifiable, Selectable, Equatable { func badgeImage() -> Badge? { switch self { + case .teams(let tournament): + let allSeedCalled = tournament.selectedSortedTeams().allSatisfy({ tournament.isStartDateIsDifferentThanCallDate($0) == false }) + return allSeedCalled ? .checkmark : nil case .seeds(let tournament): let allSeedCalled = tournament.seeds().allSatisfy({ tournament.isStartDateIsDifferentThanCallDate($0) == false }) return allSeedCalled ? .checkmark : nil @@ -83,6 +93,7 @@ struct TournamentCallView: View { self._selectedDestination = State(wrappedValue: .seeds(tournament)) } } + destinations.append(.teams(tournament)) self.allDestinations = destinations } @@ -94,6 +105,8 @@ struct TournamentCallView: View { CallSettingsView() case .some(let selectedCall): switch selectedCall { + case .teams: + TeamsCallingView() case .groupStages: GroupStageCallingView() case .seeds: