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