osem-fcy/app/models/event_schedule.rb
AEtherC0r3 7eea930269 Implement track scheduling
Add track association to schedule
Show schedules in admin sidebar to track organizers
Allow track organizers to manage the schedules of their tracks
Don't allow self-organized track events to be dragged or unscheduled in
a conference schedule
Make scheduled events of self-organized tracks appear semitransparent in
conference schedules
Make the rooms of confirmed self_organized tracks appear semitransparent
and don't allow events to be scheduled to it in the conference schedules
during the dates of its track
Create admin/SchedulesController#new action
Add a button in admin/Schedules#index to create schedules for tracks
Add self_organized scope to Track
Modify Schedules#show to handle track schedules and show a unified
schedule
Allow track organizers to create new schedules for their tracks
Correctly identify scheduled and unscheduled events in Schedules#events
Fix Event#room and Event#time for when the event is scheduled in a track
schedule
Modify Program#selected_event_schedules to include the event_schedules
of selected track schedules
Modify Track#revoke_role_and_cleanup to destroy the track's schedules
and revert its events' state to new
Add tabs for conference and track schedules in admin/Schedules#index
Add button to Create/Show a tracks schedule in Tracks#index and #show
Fix concurrent_events in application_helper because of changes in
Program#selected_event_schedules
Do not take into account cfp_active in Event#valid_track
Modify EventsController#get_tracks accordingly
Enforce cfp_active of track to be enabled for proposals in
ProposalsController#create and #update
Add support for multiple schedules per track
Add selected_schedule_id to Track
Load EventSchedules of selected track schedules for conference schedules
in admin/SchedulesController#show
Modify SchedulesController#show to take into account only the selected
track schedules
Create Event#selected_schedule_id and use it in Event#scheduled? and
Event#time
Validate that an EventSchedule for an event of a self-organized track
belongs to one of the track's schedules
Add 'Manage' button in Tracks#index, #show that sends you to the admin
side of things
Add admin/TracksController#update_selected_schedule to update the
selected_schedule_id of tracks
2017-08-26 00:31:44 +03:00

89 lines
3.1 KiB
Ruby

class EventSchedule < ActiveRecord::Base
belongs_to :schedule
belongs_to :event
belongs_to :room
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
validates :schedule, presence: true
validates :event, presence: true
validates :room, presence: true
validates :start_time, presence: true
validates :event, uniqueness: { scope: :schedule }
validate :start_after_end_hour
validate :start_before_start_hour
validate :same_room_as_track
validate :during_track
validate :valid_schedule
scope :confirmed, -> { joins(:event).where('state = ?', 'confirmed') }
scope :canceled, -> { joins(:event).where('state = ?', 'canceled') }
scope :withdrawn, -> { joins(:event).where('state = ?', 'withdrawn') }
delegate :guid, to: :room, prefix: true
##
# Returns end of the event
#
def end_time
start_time + event.event_type.length.minutes
end
##
# 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)
end
def replacement?
event.state == 'confirmed' && (!intersecting_event_schedules.canceled.empty? || !intersecting_event_schedules.withdrawn.empty?)
end
private
def start_after_end_hour
return unless event && start_time && event.program && event.program.conference && event.program.conference.end_hour
errors.add(:start_time, "can't be after the conference end hour (#{event.program.conference.end_hour})") if start_time.hour >= event.program.conference.end_hour
end
def start_before_start_hour
return unless event && start_time && event.program && event.program.conference && event.program.conference.start_hour
errors.add(:start_time, "can't be before the conference start hour (#{event.program.conference.start_hour})") if start_time.hour < event.program.conference.start_hour
end
def conference_id
schedule.program.conference_id
end
##
# Validates that the event is scheduled in the same room as its track
#
def same_room_as_track
return unless event.try(:track).try(:room)
errors.add(:room, "must be the same as the track's room (#{event.track.room.name})") unless event.track.room == room
end
##
# Validates that the event is scheduled within its track's time slot
#
def during_track
return unless event.try(:track) && start_time
if event.track.try(:start_date) && event.track.start_date > start_time
errors.add(:start_time, "can't be before the track's start date (#{event.track.start_date})")
end
if event.track.try(:end_date) && event.track.end_date + 1.day < end_time
errors.add(:end_time, "can't be after the track's end date (#{event.track.end_date})")
end
end
##
# Validates that the event is scheduled in its self-organized tracks's schedules
#
def valid_schedule
return unless event.try(:track).try(:self_organized?) && schedule
errors.add(:schedule, "must be one of #{event.track.name} track's schedules") unless event.track.schedules.include?(schedule)
end
end