From bd03321cc0bbbc8933736d55d1a06c92bab05bea Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Thu, 16 Oct 2025 09:19:39 +0200 Subject: [PATCH] improve export data capability for teams / players --- .../PlayersWithoutContactView.swift | 4 +-- PadelClub/Views/Calling/SendToAllView.swift | 4 +-- PadelClub/Views/Cashier/CashierView.swift | 2 +- .../Views/GroupStage/GroupStageView.swift | 1 - PadelClub/Views/Match/MatchSetupView.swift | 1 - PadelClub/Views/Player/PlayerDetailView.swift | 2 +- .../Views/Shared/LearnMoreSheetView.swift | 2 +- PadelClub/Views/Team/EditingTeamView.swift | 2 +- .../Screen/InscriptionManagerView.swift | 29 ++++++++++++++----- 9 files changed, 30 insertions(+), 17 deletions(-) diff --git a/PadelClub/Views/Calling/Components/PlayersWithoutContactView.swift b/PadelClub/Views/Calling/Components/PlayersWithoutContactView.swift index 07b2747..d670b41 100644 --- a/PadelClub/Views/Calling/Components/PlayersWithoutContactView.swift +++ b/PadelClub/Views/Calling/Components/PlayersWithoutContactView.swift @@ -14,7 +14,7 @@ struct PlayersWithoutContactView: View { var body: some View { Section { - let withoutEmails = players.filter({ $0.email?.isEmpty == true || $0.email == nil }) + let withoutEmails = players.filter({ $0.hasMail() == false }) DisclosureGroup { ForEach(withoutEmails) { player in NavigationLink { @@ -32,7 +32,7 @@ struct PlayersWithoutContactView: View { } } - let withoutPhones = players.filter({ $0.phoneNumber?.isEmpty == true || $0.phoneNumber == nil || $0.phoneNumber?.isMobileNumber() == false }) + let withoutPhones = players.filter({ $0.hasMobilePhone() == false }) DisclosureGroup { ForEach(withoutPhones) { player in NavigationLink { diff --git a/PadelClub/Views/Calling/SendToAllView.swift b/PadelClub/Views/Calling/SendToAllView.swift index 41c82ce..3b464e8 100644 --- a/PadelClub/Views/Calling/SendToAllView.swift +++ b/PadelClub/Views/Calling/SendToAllView.swift @@ -273,9 +273,9 @@ struct SendToAllView: View { self._verifyUser { if contactMethod == 0 { - contactType = .message(date: nil, recipients: _teams().flatMap { $0.unsortedPlayers() }.compactMap { $0.phoneNumber }, body: finalMessage(), tournamentBuild: nil) + contactType = .message(date: nil, recipients: _teams().flatMap { $0.unsortedPlayers() }.flatMap { [$0.phoneNumber, $0.contactPhoneNumber] }.compactMap({ $0 }), body: finalMessage(), tournamentBuild: nil) } else { - contactType = .mail(date: nil, recipients: tournament.umpireMail(), bccRecipients: _teams().flatMap { $0.unsortedPlayers() }.compactMap { $0.email }, body: finalMessage(), subject: tournament.mailSubject(), tournamentBuild: nil) + contactType = .mail(date: nil, recipients: tournament.umpireMail(), bccRecipients: _teams().flatMap { $0.unsortedPlayers() }.flatMap { [$0.email, $0.contactEmail] }.compactMap({ $0 }), body: finalMessage(), subject: tournament.mailSubject(), tournamentBuild: nil) } } diff --git a/PadelClub/Views/Cashier/CashierView.swift b/PadelClub/Views/Cashier/CashierView.swift index 5433655..f175f52 100644 --- a/PadelClub/Views/Cashier/CashierView.swift +++ b/PadelClub/Views/Cashier/CashierView.swift @@ -18,7 +18,7 @@ struct ShareableObject { func sharedData() async -> Data? { let _players = players.filter({ cashierViewModel._shouldDisplayPlayer($0) }) .map { - [$0.pasteData()] + [$0.pasteData(type: .payment)] .compacted() .joined(separator: "\n") } diff --git a/PadelClub/Views/GroupStage/GroupStageView.swift b/PadelClub/Views/GroupStage/GroupStageView.swift index ac06bfa..d1956d3 100644 --- a/PadelClub/Views/GroupStage/GroupStageView.swift +++ b/PadelClub/Views/GroupStage/GroupStageView.swift @@ -245,7 +245,6 @@ struct GroupStageView: View { Text("#\(index + 1)") .font(.caption) TeamPickerView(groupStagePosition: index, pickTypeContext: .groupStage, teamPicked: { team in - print(team.pasteData()) team.groupStage = groupStage.id team.groupStagePosition = index groupStage._matches().forEach({ $0.updateTeamScores() }) diff --git a/PadelClub/Views/Match/MatchSetupView.swift b/PadelClub/Views/Match/MatchSetupView.swift index 67cd78c..364d912 100644 --- a/PadelClub/Views/Match/MatchSetupView.swift +++ b/PadelClub/Views/Match/MatchSetupView.swift @@ -65,7 +65,6 @@ struct MatchSetupView: View { HStack { let luckyLosers = walkOutSpot ? match.luckyLosers() : [] TeamPickerView(shouldConfirm: shouldConfirm, round: match.roundObject, pickTypeContext: matchTypeContext == .bracket ? .bracket : .loserBracket, luckyLosers: luckyLosers, teamPicked: { team in - print(team.pasteData()) if walkOutSpot || team.bracketPosition != nil || matchTypeContext == .loserBracket { match.setLuckyLoser(team: team, teamPosition: teamPosition) do { diff --git a/PadelClub/Views/Player/PlayerDetailView.swift b/PadelClub/Views/Player/PlayerDetailView.swift index 93a1688..2671928 100644 --- a/PadelClub/Views/Player/PlayerDetailView.swift +++ b/PadelClub/Views/Player/PlayerDetailView.swift @@ -372,7 +372,7 @@ struct PlayerDetailView: View { .toolbarBackground(.visible, for: .navigationBar) .toolbar { ToolbarItem(placement: .topBarTrailing) { - ShareLink(item: player.pasteData()) { + ShareLink(item: player.pasteData(type: .sharing)) { Label("Partager", systemImage: "square.and.arrow.up") } } diff --git a/PadelClub/Views/Shared/LearnMoreSheetView.swift b/PadelClub/Views/Shared/LearnMoreSheetView.swift index 47ab4ef..fbe4b00 100644 --- a/PadelClub/Views/Shared/LearnMoreSheetView.swift +++ b/PadelClub/Views/Shared/LearnMoreSheetView.swift @@ -28,7 +28,7 @@ struct LearnMoreSheetView: View { """) } actions: { - ShareLink(item: tournament.pasteDataForImporting().createFile(tournament.tournamentTitle(.short))) { + ShareLink(item: tournament.pasteDataForImporting(type: .sharing).createFile(tournament.tournamentTitle(.short))) { Text("Exporter les inscriptions") } diff --git a/PadelClub/Views/Team/EditingTeamView.swift b/PadelClub/Views/Team/EditingTeamView.swift index ab9b3f9..811607f 100644 --- a/PadelClub/Views/Team/EditingTeamView.swift +++ b/PadelClub/Views/Team/EditingTeamView.swift @@ -116,7 +116,7 @@ struct EditingTeamView: View { } } footer: { HStack { - CopyPasteButtonView(pasteValue: team.playersPasteData()) + CopyPasteButtonView(pasteValue: team.playersPasteData(type: .sharing)) Spacer() if team.isWildCard(), team.unsortedPlayers().isEmpty { TeamPickerView(pickTypeContext: .wildcard) { teamregistration in diff --git a/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift b/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift index 5bd37aa..96bc4e8 100644 --- a/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift +++ b/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift @@ -547,11 +547,25 @@ struct InscriptionManagerView: View { private func _sharingTeamsMenuView() -> some View { Menu { - ShareLink(item: teamPaste(), preview: .init("Inscriptions")) { - Text("En texte") + Menu { + ShareLink(item: teamPaste(.rawText, type: .sharing), preview: .init(ExportType.sharing.localizedString().capitalized)) { + Text("En texte") + } + ShareLink(item: teamPaste(.csv, type: .sharing), preview: .init(ExportType.sharing.localizedString().capitalized)) { + Text("En csv") + } + } label: { + Text("Pour diffusion") } - ShareLink(item: teamPaste(.csv), preview: .init("Inscriptions")) { - Text("En csv") + Menu { + ShareLink(item: teamPaste(.rawText, type: .payment), preview: .init(ExportType.payment.localizedString().capitalized)) { + Text("En texte") + } + ShareLink(item: teamPaste(.csv, type: .payment), preview: .init(ExportType.payment.localizedString().capitalized)) { + Text("En csv") + } + } label: { + Text("Pour encaissement") } } label: { Label("Exporter les paires", systemImage: "square.and.arrow.up") @@ -575,8 +589,8 @@ struct InscriptionManagerView: View { tournament.unsortedTeamsWithoutWO() } - func teamPaste(_ exportFormat: ExportFormat = .rawText) -> TournamentShareFile { - TournamentShareFile(tournament: tournament, exportFormat: exportFormat) + func teamPaste(_ exportFormat: ExportFormat = .rawText, type: ExportType) -> TournamentShareFile { + TournamentShareFile(tournament: tournament, exportFormat: exportFormat, type: type) } var unsortedPlayers: [PlayerRegistration] { @@ -1251,10 +1265,11 @@ struct TournamentGroupStageShareContent: Transferable { struct TournamentShareFile: Transferable { let tournament: Tournament let exportFormat: ExportFormat + let type: ExportType func shareFile() -> URL { print("Generating URL...") - return tournament.pasteDataForImporting(exportFormat).createFile(self.tournament.tournamentTitle()+"-inscriptions", exportFormat) + return tournament.pasteDataForImporting(exportFormat, type: type).createFile(self.tournament.tournamentTitle()+"-"+type.localizedString(), exportFormat) } static var transferRepresentation: some TransferRepresentation {