From 9dfcfc1441fcca22c06ba8e9c96aa248a9e3f731 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Mon, 8 Jul 2024 17:27:41 +0200 Subject: [PATCH] fix stuff --- PadelClub.xcodeproj/project.pbxproj | 8 ++- PadelClub/Data/Tournament.swift | 12 +++- PadelClub/Utils/URLs.swift | 7 +- .../Cashier/Event/EventSettingsView.swift | 36 +++++----- PadelClub/Views/Cashier/Event/EventView.swift | 5 ++ .../Tournament/Screen/BroadcastView.swift | 25 ++++++- .../Screen/Components/CloseDatePicker.swift | 29 ++++++++ .../Components/EventClubSettingsView.swift | 68 ++++++++++++------- .../Screen/InscriptionManagerView.swift | 19 +++++- .../Shared/TournamentBroadcastRowView.swift | 5 +- 10 files changed, 160 insertions(+), 54 deletions(-) create mode 100644 PadelClub/Views/Tournament/Screen/Components/CloseDatePicker.swift diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index 53abfd5..4984739 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -228,6 +228,7 @@ FFC91B012BD85C2F00B29808 /* Court.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFC91B002BD85C2F00B29808 /* Court.swift */; }; FFC91B032BD85E2400B29808 /* CourtView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFC91B022BD85E2400B29808 /* CourtView.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 */; }; FFCFC00C2BBC3D1E00B82851 /* EditScoreView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFCFC0012BBC39A600B82851 /* EditScoreView.swift */; }; FFCFC00E2BBC3D4600B82851 /* PointSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFCFC00D2BBC3D4600B82851 /* PointSelectionView.swift */; }; @@ -562,6 +563,7 @@ FFC91B002BD85C2F00B29808 /* Court.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Court.swift; sourceTree = ""; }; FFC91B022BD85E2400B29808 /* CourtView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourtView.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 = ""; }; FFCFC00D2BBC3D4600B82851 /* PointSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PointSelectionView.swift; sourceTree = ""; }; FFCFC0112BBC3E1A00B82851 /* PointView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PointView.swift; sourceTree = ""; }; @@ -1131,6 +1133,7 @@ FF025AE22BD0EBA900A86CF8 /* TournamentMatchFormatsSettingsView.swift */, FF025AE42BD0EBB800A86CF8 /* TournamentGeneralSettingsView.swift */, FF6087E92BE25EF1004E1E47 /* TournamentStatusView.swift */, + FFCF76062C3BE9BC006C8C3D /* CloseDatePicker.swift */, ); path = Components; sourceTree = ""; @@ -1587,6 +1590,7 @@ C4FC2E2B2C2C0E4D0021F3BF /* TournamentStore.swift in Sources */, FF5647132C0B6F390081F995 /* LoserRoundSettingsView.swift in Sources */, FF3795662B9399AA004EA093 /* Persistence.swift in Sources */, + FFCF76072C3BE9BC006C8C3D /* CloseDatePicker.swift in Sources */, FF1DF49B2BD8D23900822FA0 /* BarButtonView.swift in Sources */, FFF964502BC25E3700EEF017 /* PlanningView.swift in Sources */, FF967CEC2BAECB9900A9A3BD /* Match.swift in Sources */, @@ -1902,7 +1906,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 87; + CURRENT_PROJECT_VERSION = 88; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; @@ -1946,7 +1950,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 87; + CURRENT_PROJECT_VERSION = 88; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_TEAM = BQ3Y44M3Q6; diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index f1f6dd5..32f1a3e 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -801,7 +801,17 @@ defer { } #endif var _sortedTeams : [TeamRegistration] = [] - let _teams = unsortedTeams().filter({ $0.walkOut == false }) + var _teams = unsortedTeams().filter({ $0.walkOut == false }) + + if let closedRegistrationDate { + _teams = _teams.filter({ team in + if let registrationDate = team.registrationDate { + return registrationDate <= closedRegistrationDate + } else { + return true + } + }) + } let defaultSorting : [MySortDescriptor] = _defaultSorting() diff --git a/PadelClub/Utils/URLs.swift b/PadelClub/Utils/URLs.swift index 654493e..cde9451 100644 --- a/PadelClub/Utils/URLs.swift +++ b/PadelClub/Utils/URLs.swift @@ -8,10 +8,11 @@ import Foundation enum URLs: String, Identifiable { - case activationHost = "https://padelclub.app" // xlr.alwaysdata.net + + case activationHost = "https://xlr.alwaysdata.net" // xlr.alwaysdata.net case subscriptions = "https://apple.co/2Th4vqI" - case main = "https://padelclub.app/" - case api = "https://padelclub.app/roads/" + case main = "https://xlr.alwaysdata.net/" + case api = "https://xlr.alwaysdata.net/roads/" case beachPadel = "https://beach-padel.app.fft.fr/beachja/index/" //case padelClub = "https://padelclub.app" case tenup = "https://tenup.fft.fr" diff --git a/PadelClub/Views/Cashier/Event/EventSettingsView.swift b/PadelClub/Views/Cashier/Event/EventSettingsView.swift index c2abce6..593cfe8 100644 --- a/PadelClub/Views/Cashier/Event/EventSettingsView.swift +++ b/PadelClub/Views/Cashier/Event/EventSettingsView.swift @@ -62,25 +62,27 @@ struct EventSettingsView: View { } } - let eventLinksPasteData = eventLinksPasteData() - Section { - Text(eventLinksPasteData) - .italic() - .multilineTextAlignment(.leading) - - let links : [PageLink] = [.teams, .summons, .groupStages, .matches, .rankings] - Picker(selection: $pageLink) { - ForEach(links) { pageLink in - Text(pageLink.localizedLabel()).tag(pageLink) + if event.club != nil { + let eventLinksPasteData = eventLinksPasteData() + Section { + Text(eventLinksPasteData) + .italic() + .multilineTextAlignment(.leading) + + let links : [PageLink] = [.teams, .summons, .groupStages, .matches, .rankings] + Picker(selection: $pageLink) { + ForEach(links) { pageLink in + Text(pageLink.localizedLabel()).tag(pageLink) + } + } label: { + Text("Choisir une page en particulier") } - } label: { - Text("Choisir une page en particulier") + .pickerStyle(.menu) + + ShareLink("Partagez ce message", item: eventLinksPasteData) + } header: { + Text("Liens à partager") } - .pickerStyle(.menu) - - ShareLink("Partagez ce message", item: eventLinksPasteData) - } header: { - Text("Liens à partager") } } .toolbar { diff --git a/PadelClub/Views/Cashier/Event/EventView.swift b/PadelClub/Views/Cashier/Event/EventView.swift index 736d0f4..a45a6c8 100644 --- a/PadelClub/Views/Cashier/Event/EventView.swift +++ b/PadelClub/Views/Cashier/Event/EventView.swift @@ -70,6 +70,11 @@ struct EventView: View { let event: Event @State private var selectedDestination: EventDestination? + init(event: Event) { + self.event = event + _selectedDestination = State(wrappedValue: event.club == nil ? .club(event) : nil) + } + func allDestinations() -> [EventDestination] { [.club(event), .tournaments(event), .cashier] } diff --git a/PadelClub/Views/Tournament/Screen/BroadcastView.swift b/PadelClub/Views/Tournament/Screen/BroadcastView.swift index 09fda0d..b9e181c 100644 --- a/PadelClub/Views/Tournament/Screen/BroadcastView.swift +++ b/PadelClub/Views/Tournament/Screen/BroadcastView.swift @@ -36,7 +36,7 @@ struct BroadcastView: View { Section { ContentUnavailableView { Label("Créer votre compte Padel Club", systemImage: "person.bust") - + } description: { let message = "Un compte est nécessaire pour publier le tournoi sur [Padel Club](\(URLs.main.rawValue)) et profiter de toutes les pages du site, comme le mode TV pour transformer l'expérience de vos tournois !" Text(.init(message)) @@ -51,6 +51,29 @@ struct BroadcastView: View { } } } + } else if tournament.club() == nil { + Section { + ContentUnavailableView { + Text("Aucun club associé à votre tournoi") + } description: { + Text("Vous avez besoin d'associer un club à votre tournoi pour pouvoir publier celui-ci sur Padel Club.") + } actions: { + NavigationLink { + ClubsView() { club in + if let event = tournament.eventObject() { + event.club = club.id + do { + try dataStore.events.addOrUpdate(instance: event) + } catch { + Logger.error(error) + } + } + } + } label: { + Text("Choisir un club") + } + } + } } else { Section { TipView(tournamentPublishingTip) { action in diff --git a/PadelClub/Views/Tournament/Screen/Components/CloseDatePicker.swift b/PadelClub/Views/Tournament/Screen/Components/CloseDatePicker.swift new file mode 100644 index 0000000..a0f92e2 --- /dev/null +++ b/PadelClub/Views/Tournament/Screen/Components/CloseDatePicker.swift @@ -0,0 +1,29 @@ +// +// CloseDatePicker.swift +// PadelClub +// +// Created by Razmig Sarkissian on 08/07/2024. +// + +import SwiftUI +import LeStorage + +struct CloseDatePicker: View { + @State var closedRegistrationDate: Date + @Environment(Tournament.self) var tournament: Tournament + @EnvironmentObject var dataStore: DataStore + + var body: some View { + DatePicker(selection: $closedRegistrationDate) { + Text("Date de clôture") + } + .onChange(of: closedRegistrationDate) { + tournament.closedRegistrationDate = closedRegistrationDate + do { + try dataStore.tournaments.addOrUpdate(instance: tournament) + } catch { + Logger.error(error) + } + } + } +} diff --git a/PadelClub/Views/Tournament/Screen/Components/EventClubSettingsView.swift b/PadelClub/Views/Tournament/Screen/Components/EventClubSettingsView.swift index 503a7e7..c1b56e9 100644 --- a/PadelClub/Views/Tournament/Screen/Components/EventClubSettingsView.swift +++ b/PadelClub/Views/Tournament/Screen/Components/EventClubSettingsView.swift @@ -16,38 +16,45 @@ struct EventClubSettingsView: View { var body: some View { List { - let selectedClub = event.clubObject() - - Section { - NavigationLink { - ClubsView() { club in - event.club = club.id - do { - try dataStore.events.addOrUpdate(instance: event) - } catch { - Logger.error(error) + if let selectedClub = event.clubObject() { + + Section { + NavigationLink { + ClubsView() { club in + _setClub(club: club) } - } - } label: { - if let selectedClub = event.clubObject() { + } label: { ClubRowView(club: selectedClub) - } else { - Text("Choisir un club") } - } - } header: { - Text("Lieu de l'événement") - } footer: { - HStack { - Spacer() - FooterButtonView("détails du club") { - showClubDetail = selectedClub + } header: { + Text("Lieu de l'événement") + } footer: { + HStack { + Spacer() + FooterButtonView("détails du club") { + showClubDetail = selectedClub + } } } - } - - if let selectedClub { + ClubCourtSetupView(club: selectedClub, displayContext: selectedClub.hasBeenCreated(by: StoreCenter.main.userId) ? .edition : .lockedForEditing, selectedCourt: $selectedCourt) + + } else { + Section { + ContentUnavailableView { + Text("Aucun club associé à votre tournoi") + } description: { + Text("Vous avez besoin d'associer un club à votre tournoi pour pouvoir publier celui-ci sur Padel Club.") + } actions: { + NavigationLink { + ClubsView() { club in + _setClub(club: club) + } + } label: { + Text("Choisir un club") + } + } + } } } .navigationDestination(item: $showClubDetail) { club in @@ -57,6 +64,15 @@ struct EventClubSettingsView: View { CourtView(court: court) } } + + private func _setClub(club: Club) { + event.club = club.id + do { + try dataStore.events.addOrUpdate(instance: event) + } catch { + Logger.error(error) + } + } } //#Preview { diff --git a/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift b/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift index 02c20e6..acc889e 100644 --- a/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift +++ b/PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift @@ -511,6 +511,14 @@ struct InscriptionManagerView: View { private func _teamRegisteredView() -> some View { List { + if let closedRegistrationDate = tournament.closedRegistrationDate { + Section { + CloseDatePicker(closedRegistrationDate: closedRegistrationDate) + } footer: { + Text("Toutes les équipes ayant été inscrites après la date de clôture seront en liste d'attente.") + } + } + if presentSearch == false { _rankHandlerView() _relatedTips() @@ -660,6 +668,14 @@ struct InscriptionManagerView: View { @ViewBuilder private func _inscriptionTipsView() -> some View { List { + if let closedRegistrationDate = tournament.closedRegistrationDate { + Section { + CloseDatePicker(closedRegistrationDate: closedRegistrationDate) + } footer: { + Text("Toutes les équipes ayant été inscrites après la date de clôture seront en liste d'attente.") + } + } + Section { TipView(fileTip) { action in @@ -760,9 +776,6 @@ struct InscriptionManagerView: View { } } label: { Text("Problèmes détéctés") - if let closedRegistrationDate = tournament.closedRegistrationDate { - Text("clôturé le " + closedRegistrationDate.formatted()) - } } } } diff --git a/PadelClub/Views/Tournament/Shared/TournamentBroadcastRowView.swift b/PadelClub/Views/Tournament/Shared/TournamentBroadcastRowView.swift index fead95f..beece4c 100644 --- a/PadelClub/Views/Tournament/Shared/TournamentBroadcastRowView.swift +++ b/PadelClub/Views/Tournament/Shared/TournamentBroadcastRowView.swift @@ -13,8 +13,9 @@ struct TournamentBroadcastRowView: View { var body: some View { NavigationLink(value: Screen.broadcast) { + let club = tournament.eventObject()?.club LabeledContent { - if StoreCenter.main.userId == nil { + if StoreCenter.main.userId == nil || club == nil { Image(systemName: "exclamationmark.circle.fill") .foregroundStyle(.logoYellow) } else { @@ -28,6 +29,8 @@ struct TournamentBroadcastRowView: View { Text("Publication") if StoreCenter.main.userId == nil { Text("Créez un compte pour publier !") + } else if club == nil { + Text("Associez un club pour publier !") } } }