schedules_controller.rb 983 Bytes
Newer Older
1
2
# Contains functionality for generating schedules.
class SchedulesController < ApplicationController
3
  include SchedulesHelper
4

Zac Wood's avatar
Zac Wood committed
5
  def show; end
6

Zac Wood's avatar
Zac Wood committed
7
8
  def view
    @all = params[:crns].split(',').map { |crn|
9
      CourseSection.latest_by_crn(crn)
10
    }
Zac Wood's avatar
Zac Wood committed
11
    @all.reject!(&:nil?)
Zac Wood's avatar
Zac Wood committed
12
13
14
15
    @without_online = @all.reject { |s|
      s.start_time == "TBA" || s.end_time == "TBA"
    }
    @events = generate_fullcalender_events(@without_online)
16
  end
Zac Wood's avatar
Zac Wood committed
17

Zac Wood's avatar
Zac Wood committed
18
19
20
21
22
23
  def events
    @cart = params[:crns].split(',')
                         .map { |crn| CourseSection.latest_by_crn(crn) }
                         .reject(&:nil?)

    @without_online = @cart.reject { |s|
Zac Wood's avatar
Zac Wood committed
24
25
      s.start_time == "TBA" || s.end_time == "TBA"
    }
Zac Wood's avatar
Zac Wood committed
26

Zac Wood's avatar
Zac Wood committed
27
    @events = generate_fullcalender_events(@without_online)
Zac Wood's avatar
Zac Wood committed
28
29
30
31
    sections = @cart.map do |s|
      s.serializable_hash.merge(instructor_name: s.instructor.name, instructor_url: instructor_url(s.instructor))
    end
    render json: { events: @events, sections: sections }
Zac Wood's avatar
Zac Wood committed
32
  end
33
end