Add enabled to event_schedules
To show scheduled events that have been cancelled/withdrawn as 'cancelled', and consequently also show when an event is their replacement. admin/schedules#show does not show events that were scheduled and then cancelled/withdrawn, however a record in event_schedules exists for those events, but event_schedule.enabled = false
This commit is contained in:
parent
4409610a89
commit
4289f699ac
6 changed files with 35 additions and 2 deletions
|
|
@ -197,6 +197,14 @@ class Event < ApplicationRecord
|
|||
send(transition)
|
||||
end
|
||||
save
|
||||
# If the event was previously scheduled, and then withdrawn or cancelled
|
||||
# its event_schedule will have enabled set to false
|
||||
# If the event is now confirmed again, we want it to be available for scheduling
|
||||
Rails.logger.debug "transition is #{transition}"
|
||||
if transition == :confirm
|
||||
Rails.logger.debug "schedules #{EventSchedule.unscoped.where(event: self, enabled: false)}"
|
||||
EventSchedule.unscoped.where(event: self, enabled: false).destroy_all
|
||||
end
|
||||
rescue Transitions::InvalidTransition => e
|
||||
alert = "Update state failed. #{e.message}"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
class EventSchedule < ApplicationRecord
|
||||
default_scope { where(enabled: true) }
|
||||
belongs_to :schedule
|
||||
belongs_to :event
|
||||
belongs_to :room
|
||||
|
|
@ -33,7 +34,7 @@ class EventSchedule < ApplicationRecord
|
|||
# Returns event schedules that are scheduled in the same room and start_time as event
|
||||
#
|
||||
def intersecting_event_schedules
|
||||
room.event_schedules.where(start_time: start_time, schedule: schedule).where.not(id: id)
|
||||
EventSchedule.unscoped.where(room: room, start_time: start_time, schedule: schedule).where.not(id: id)
|
||||
end
|
||||
|
||||
def replacement?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue