From 7a08bda544e2c31ab090615b36f639d7ff68e840 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Wed, 20 Aug 2025 14:09:21 +0200 Subject: [PATCH] =?UTF-8?q?possiblit=C3=A9=20de=20lancer=20l'horaire=20int?= =?UTF-8?q?elligent=20sur=20tous=20les=20tournois=20d'un=20evenement=20en?= =?UTF-8?q?=20une=20fois?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Cashier/Event/EventSettingsView.swift | 16 +++++++ PadelClub/Views/Cashier/Event/EventView.swift | 3 +- PadelClub/Views/Planning/PlanningView.swift | 43 ++++++++++++++++++- 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/PadelClub/Views/Cashier/Event/EventSettingsView.swift b/PadelClub/Views/Cashier/Event/EventSettingsView.swift index d75603a..76a8db2 100644 --- a/PadelClub/Views/Cashier/Event/EventSettingsView.swift +++ b/PadelClub/Views/Cashier/Event/EventSettingsView.swift @@ -18,6 +18,13 @@ struct EventSettingsView: View { @State private var eventStartDate: Date @FocusState private var focusedField: Tournament.CodingKeys? + var visibleOnPadelClub: Binding { + Binding { + event.confirmedTournaments().allSatisfy({ $0.isPrivate == false }) + } set: { _ in + } + } + func eventLinksPasteData() -> String { let tournaments = event.tournaments var link = [String]() @@ -105,6 +112,15 @@ struct EventSettingsView: View { } _saveAllTournaments() } + } + } + + Section { + Toggle(isOn: visibleOnPadelClub) { + Text("Visible sur Padel Club") + } + .onChange(of: visibleOnPadelClub.wrappedValue) { oldValue, newValue in + _saveAllTournaments() } } diff --git a/PadelClub/Views/Cashier/Event/EventView.swift b/PadelClub/Views/Cashier/Event/EventView.swift index e04154a..23caf52 100644 --- a/PadelClub/Views/Cashier/Event/EventView.swift +++ b/PadelClub/Views/Cashier/Event/EventView.swift @@ -99,8 +99,7 @@ struct EventView: View { case .club(let event): EventClubSettingsView(event: event) case .eventPlanning: - let allMatches = event.tournaments.flatMap { $0.allMatches() } - PlanningView(matches: allMatches, selectedScheduleDestination: .constant(nil)) + PlanningView(matches: [], selectedScheduleDestination: .constant(nil), event: event) .environment(\.matchViewStyle, .feedStyle) case .links: EventLinksView(event: event) diff --git a/PadelClub/Views/Planning/PlanningView.swift b/PadelClub/Views/Planning/PlanningView.swift index 33137e2..f6f7a34 100644 --- a/PadelClub/Views/Planning/PlanningView.swift +++ b/PadelClub/Views/Planning/PlanningView.swift @@ -22,9 +22,15 @@ struct PlanningView: View { let updatePlannedDatesTip = UpdatePlannedDatesTip() let allMatches: [Match] let timeSlotMoveOptionTip = TimeSlotMoveOptionTip() + let event: Event? - init(matches: [Match], selectedScheduleDestination: Binding) { - self.allMatches = matches + init(matches: [Match], selectedScheduleDestination: Binding, event: Event? = nil) { + self.event = event + if let event { + self.allMatches = event.confirmedTournaments().flatMap { $0.allMatches() } + } else { + self.allMatches = matches + } _selectedScheduleDestination = selectedScheduleDestination } @@ -132,6 +138,24 @@ struct PlanningView: View { } else { ToolbarItemGroup(placement: .topBarTrailing) { Menu { + if let event { + Menu { + Button { + event.confirmedTournaments().forEach { tournament in + tournament.removeAllDates() + } + } label: { + Text("Effacer tous les horaires") + } + Button { + _planEvent(event: event) + } label: { + Text("Planifier") + } + } label: { + Text("Planifier l'événement") + } + } if notSlots == false { CourtOptionsView(timeSlots: timeSlots, underlined: false) Toggle(isOn: $enableMove) { @@ -226,11 +250,26 @@ struct PlanningView: View { RowButtonView("Horaire intelligent") { selectedScheduleDestination = nil } + } else if let event { + RowButtonView("Planifier automatiquement") { + _planEvent(event: event) + } } } } } } + + private func _planEvent(event: Event) { + event.confirmedTournaments().forEach { tournament in + if let matchScheduler = tournament.matchScheduler() { + _ = matchScheduler.updateSchedule(tournament: tournament) + } else { + let matchScheduler = MatchScheduler(tournament: tournament.id, courtsAvailable: Set(tournament.courtsAvailable())) + _ = matchScheduler.updateSchedule(tournament: tournament) + } + } + } struct BySlotView: View { @Environment(\.filterOption) private var filterOption