diff --git a/PadelClub/Views/Calling/CallView.swift b/PadelClub/Views/Calling/CallView.swift index 0367f2e..514da7f 100644 --- a/PadelClub/Views/Calling/CallView.swift +++ b/PadelClub/Views/Calling/CallView.swift @@ -68,6 +68,24 @@ struct CallView: View { @State var summonParamByMessage: Bool = false @State var summonParamReSummon: Bool = false + let simpleMode : Bool + + init(teams: [TeamRegistration], callDate: Date, matchFormat: MatchFormat, roundLabel: String) { + self.teams = teams + self.callDate = callDate + self.matchFormat = matchFormat + self.roundLabel = roundLabel + self.simpleMode = false + } + + init(teams: [TeamRegistration]) { + self.teams = teams + self.callDate = Date() + self.matchFormat = MatchFormat.nineGames + self.roundLabel = "" + self.simpleMode = true + } + var tournamentStore: TournamentStore { return self.tournament.tournamentStore } @@ -83,6 +101,9 @@ struct CallView: View { } private func _called(_ calledTeams: [TeamRegistration], _ success: Bool) { + if simpleMode { + return + } if success { calledTeams.forEach { team in team.callDate = callDate @@ -96,21 +117,41 @@ struct CallView: View { } func finalMessage(reSummon: Bool) -> String { - ContactType.callingMessage(tournament: tournament, startDate: callDate, roundLabel: roundLabel, matchFormat: matchFormat, reSummon: reSummon) + if simpleMode { + let signature = dataStore.user.summonsMessageSignature ?? dataStore.user.defaultSignature() + return "\n\n\n\n" + signature + } + + return ContactType.callingMessage(tournament: tournament, startDate: callDate, roundLabel: roundLabel, matchFormat: matchFormat, reSummon: reSummon) } var reSummon: Bool { + if simpleMode { + return false + } return self.teams.allSatisfy({ $0.called() }) } + var mainWord: String { + if simpleMode { + return "Contacter" + } else { + return "Convoquer" + } + } + var body: some View { - let callWord : String = (reSummon ? "Reconvoquer" : "Convoquer") + let callWord : String = (reSummon ? "Reconvoquer" : mainWord) HStack { if self.teams.count == 1 { - if let previousCallDate = teams.first?.callDate, Calendar.current.compare(previousCallDate, to: callDate, toGranularity: .minute) != .orderedSame { - Text("Reconvoquer \(self.callDate.localizedDate()) par") - } else { + if simpleMode { Text("\(callWord) cette paire par") + } else { + if let previousCallDate = teams.first?.callDate, Calendar.current.compare(previousCallDate, to: callDate, toGranularity: .minute) != .orderedSame { + Text("Reconvoquer \(self.callDate.localizedDate()) par") + } else { + Text("\(callWord) cette paire par") + } } } else { Text("\(callWord) ces \(self.teams.count) paires par") @@ -222,7 +263,7 @@ struct CallView: View { private func _summonMenu(byMessage: Bool) -> some View { if self.reSummon { Menu { - Button("Convoquer") { + Button(mainWord) { self._summon(byMessage: byMessage, reSummon: false) } diff --git a/PadelClub/Views/Calling/TeamsCallingView.swift b/PadelClub/Views/Calling/TeamsCallingView.swift index f1cf5c3..844459d 100644 --- a/PadelClub/Views/Calling/TeamsCallingView.swift +++ b/PadelClub/Views/Calling/TeamsCallingView.swift @@ -12,12 +12,23 @@ struct TeamsCallingView: View { @Environment(Tournament.self) var tournament: Tournament let teams : [TeamRegistration] + @State private var hideConfirmed: Bool = false + @State private var hideGoodSummoned: Bool = false + @State private var hideSummoned: Bool = false + @State private var searchText: String = "" + var filteredTeams: [TeamRegistration] { - teams.filter({ searchText.isEmpty || $0.contains(searchText) }) + teams + .filter({ hideConfirmed == false || $0.confirmed() == false }) + .filter({ hideSummoned == false || $0.called() == false }) + .filter({ hideGoodSummoned == false || tournament.isStartDateIsDifferentThanCallDate($0) == true }) + .filter({ searchText.isEmpty || $0.contains(searchText) }) + } + + var anyFilterEnabled: Bool { + hideConfirmed || hideGoodSummoned || hideSummoned } - @State private var searchText: String = "" - var body: some View { List { PlayersWithoutContactView(players: teams.flatMap({ $0.unsortedPlayers() }).sorted(by: \.computedRank)) @@ -67,14 +78,40 @@ struct TeamsCallingView: View { .buttonStyle(.plain) .listRowView(isActive: team.confirmed(), color: .green, hideColorVariation: true) } + } header: { + HStack { + Text("Paire\(filteredTeams.count.pluralSuffix)") + Spacer() + Text(filteredTeams.count.formatted()) + } + } footer: { + CallView(teams: filteredTeams) } } else { ContentUnavailableView("Aucune équipe", systemImage: "person.2.slash") } } + .toolbar(content: { + ToolbarItem(placement: .topBarTrailing) { + Menu { + Toggle(isOn: $hideConfirmed) { + Text("Masquer les confirmées") + } + Toggle(isOn: $hideSummoned) { + Text("Masquer les convoquées") + } + Toggle(isOn: $hideGoodSummoned) { + Text("Masquer les convoquées à la bonne heure") + } + } label: { + LabelFilter() + .symbolVariant(anyFilterEnabled ? .fill : .none) + } + } + }) .searchable(text: $searchText, placement: .navigationBarDrawer(displayMode: .always)) .headerProminence(.increased) - .navigationTitle("Statut des équipes") + .navigationTitle("Statut des convocations") .navigationBarTitleDisplayMode(.inline) .toolbarBackground(.visible, for: .navigationBar) } diff --git a/PadelClub/Views/Tournament/Screen/TableStructureView.swift b/PadelClub/Views/Tournament/Screen/TableStructureView.swift index 9571c44..b89c2b5 100644 --- a/PadelClub/Views/Tournament/Screen/TableStructureView.swift +++ b/PadelClub/Views/Tournament/Screen/TableStructureView.swift @@ -370,6 +370,17 @@ struct TableStructureView: View { } } + _checkGroupStagesTeams() + + do { + try dataStore.tournaments.addOrUpdate(instance: tournament) + } catch { + Logger.error(error) + } + dismiss() + } + + private func _checkGroupStagesTeams() { if groupStageCount == 0 { let teams = tournament.unsortedTeams().filter({ $0.inGroupStage() }) teams.forEach { team in @@ -382,12 +393,6 @@ struct TableStructureView: View { Logger.error(error) } } - do { - try dataStore.tournaments.addOrUpdate(instance: tournament) - } catch { - Logger.error(error) - } - dismiss() } private func _save(rebuildEverything: Bool = false) { @@ -412,6 +417,8 @@ struct TableStructureView: View { tournament.deleteGroupStages() tournament.buildGroupStages() } + + _checkGroupStagesTeams() try dataStore.tournaments.addOrUpdate(instance: tournament)