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
This commit is contained in:
AEtherC0r3 2017-08-09 18:12:20 +03:00 committed by Stella Rouzi
parent af7efdb6fe
commit 7eea930269
37 changed files with 443 additions and 118 deletions

View file

@ -307,5 +307,18 @@ class AdminAbility
can :manage, Event, track_id: track_ids_for_track_organizer
can :manage, Commercial, commercialable_type: 'Event',
commercialable_id: Event.where(track_id: track_ids_for_track_organizer).pluck(:id)
# Show Scheduless in the admin sidebar
can :update, Schedule do |schedule|
schedule.new_record? && conf_ids_for_track_organizer.include?(schedule.program.conference_id)
end
# Show new track schedule button
can :new, Schedule do |schedule|
schedule.new_record? && conf_ids_for_track_organizer.include?(schedule.program.conference_id) && schedule.track.try(:new_record?)
end
can :manage, Schedule, track_id: track_ids_for_track_organizer
can :manage, EventSchedule, schedule: { track_id: track_ids_for_track_organizer }
end
end

View file

@ -45,7 +45,7 @@ class Event < ActiveRecord::Base
validates :max_attendees, numericality: { only_integer: true, greater_than_or_equal_to: 1, allow_nil: true }
validate :max_attendees_no_more_than_room_size
validate :acceptable_track
validate :valid_track
scope :confirmed, -> { where(state: 'confirmed') }
scope :canceled, -> { where(state: 'canceled') }
@ -85,7 +85,7 @@ class Event < ActiveRecord::Base
# ====Returns
# * +true+ or +false+
def scheduled?
event_schedules.find_by(schedule_id: program.selected_schedule_id).present?
event_schedules.find_by(schedule_id: selected_schedule_id).present?
end
def registration_possible?
@ -243,14 +243,18 @@ class Event < ActiveRecord::Base
def room
# We use try(:selected_schedule_id) because this function is used for
# validations so program could not be present there
event_schedules.find_by(schedule_id: program.try(:selected_schedule_id)).try(:room)
if track.try(:self_organized?)
track.room
else
event_schedules.find_by(schedule_id: program.try(:selected_schedule_id)).try(:room)
end
end
##
# Returns the start time at which this event is scheduled
#
def time
event_schedules.find_by(schedule_id: program.selected_schedule_id).try(:start_time)
event_schedules.find_by(schedule_id: selected_schedule_id).try(:start_time)
end
def conference
@ -306,9 +310,23 @@ class Event < ActiveRecord::Base
end
##
# Allow only confirmed tracks that belong to the same program and are included in the cfp
def acceptable_track
# Allow only confirmed tracks that belong to the same program as the event
#
def valid_track
return unless track && track.program && program
errors.add(:track, 'is invalid') unless track.confirmed? && track.cfp_active && track.program == program
errors.add(:track, 'is invalid') unless track.confirmed? && track.program == program
end
##
# Return the id of the selected schedule
#
# ====Returns
# * +Integer+ -> selected_schedule_id of self-organized track or program
def selected_schedule_id
if track.try(:self_organized?)
track.selected_schedule_id
else
program.selected_schedule_id
end
end
end

View file

@ -12,8 +12,9 @@ class EventSchedule < ActiveRecord::Base
validates :event, uniqueness: { scope: :schedule }
validate :start_after_end_hour
validate :start_before_start_hour
validate :room_of_track
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') }
@ -56,24 +57,33 @@ class EventSchedule < ActiveRecord::Base
end
##
# Validates that the event is scheduled in the same room as it's track
# Validates that the event is scheduled in the same room as its track
#
def room_of_track
if event && event.track.try(:room) && event.track.room != room
errors.add(:room, "must be the same as the track's room (#{event.track.room.name})")
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 within it's track's time slot
# Validates that the event is scheduled in its self-organized tracks's schedules
#
def during_track
if event && 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 && 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
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

View file

@ -71,7 +71,11 @@ class Program < ActiveRecord::Base
# Returns all event_schedules for the selected schedule ordered by start_time
def selected_event_schedules
selected_schedule.event_schedules.order(start_time: :asc) if selected_schedule
event_schedules = selected_schedule.event_schedules.order(start_time: :asc) if selected_schedule
tracks.self_organized.confirmed.order(start_date: :asc).each do |track|
event_schedules += track.selected_schedule.event_schedules.order(start_time: :asc) if track.selected_schedule
end
event_schedules.sort_by(&:start_time) if event_schedules
end
##

View file

@ -1,5 +1,6 @@
class Schedule < ActiveRecord::Base
belongs_to :program
belongs_to :track
has_many :event_schedules, dependent: :destroy
has_many :events, through: :event_schedules

View file

@ -7,7 +7,9 @@ class Track < ActiveRecord::Base
belongs_to :program
belongs_to :submitter, class_name: 'User'
belongs_to :room
belongs_to :selected_schedule, class_name: 'Schedule'
has_many :events, dependent: :nullify
has_many :schedules
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
@ -38,6 +40,7 @@ class Track < ActiveRecord::Base
scope :accepted, -> { where(state: 'accepted') }
scope :confirmed, -> { where(state: 'confirmed') }
scope :cfp_active, -> { where(cfp_active: true) }
scope :self_organized, -> { where.not(submitter: nil) }
state_machine initial: :pending do
state :new
@ -102,7 +105,10 @@ class Track < ActiveRecord::Base
submitter.add_role 'track_organizer', self
end
# Revokes the track organizer role and removes the track from events that have it set
##
# Revokes the track organizer role, destroys the track's schedule, removes the
# track from events that have it set and reverts their state to new
#
def revoke_role_and_cleanup
role = Role.find_by(name: 'track_organizer', resource: self)
@ -112,8 +118,14 @@ class Track < ActiveRecord::Base
end
end
self.selected_schedule_id = nil
save!
schedules.each(&:destroy!)
events.each do |event|
event.track = nil
event.state = 'new'
event.save!
end
end