Commit de5f9aca authored by Zac Wood's avatar Zac Wood

Little bit of clean up

parent 63cb1356
Pipeline #3840 failed with stage
in 2 minutes and 40 seconds
class CoursesController < ApplicationController
before_action :set_course
def show
@course = Course.find_by subject: @course.subject, course_number: @course.course_number, semester: @semester
end
# Load the course with the id passed in the URL.
@course = Course.find_by_id(params[:id])
# If the user changes the semester while looking at a course,
# we need to display the page for the course with the same subject and course number
# in that semester.
unless @course.semester == @semester
# find the course we should redirect to
@course = Course.find_by(subject: @course.subject, course_number: @course.course_number, semester: @semester)
private
# redirect to the url for that course
redirect_to course_url(@course)
end
def set_course
@course = Course.find_by_id params[:id]
@sections = @course.course_sections
end
end
# HomeController renders the homepage. It currently requires no logic.
class HomeController < ApplicationController
def index; end
end
class InstructorsController < ApplicationController
before_action :set_instructor, only: [:show]
def index
@instructors = Instructor.all
end
def show
sections = CourseSection.where instructor: @instructor
sections = sections.select do |s|
s.course.semester == @semester
end
@instructor = Instructor.find_by_id(params[:id])
# TODO: move this to a model somewhere
@courses = [].to_set
sections.each do |s|
@courses.add s.course
end
# find the courses being taught this semester
sections = CourseSection.where(instructor: @instructor).joins(course: :semester).where("semesters.id = ?", @semester.id)
@courses = Course.build_set(sections)
# build the list of courses the instructor has taught in the past
@past = []
@instructor.course_sections.map(&:course).each do |c|
@past << c unless @past.select { |past| past.full_name == c.full_name }.count.positive?
end
@past.sort_by!(&:full_name)
end
private
def set_instructor
@instructor = Instructor.find_by_id params[:id]
end
end
class SearchController < ApplicationController
def index
redirect_to home_url unless params[:query].length > 1
redirect_to(home_url) unless params[:query].length > 1
results = SearchHelper::GenericItem.fetchall(String.new(params[:query]), semester: @semester).group_by(&:type)
@instructors = results[:instructor]&.map(&:data)
......
class SessionsController < ApplicationController
def update
update_cookie :crns
update_cookie :section_ids
update_cookie :semester_id
head :ok
end
def cart
section_crn = params[:crn]
......@@ -16,25 +8,18 @@ class SessionsController < ApplicationController
@cart << section_crn
end
puts @cart
cookies.permanent[:cart] = @cart.to_json
render json: @cart.to_json
end
def add_bulk
crns = params[:crns].split(',')
crns.each { |crn|
crns.each do |crn|
s = CourseSection.latest_by_crn(crn)
next if s.nil?
@cart << crn.to_s unless @cart.include?(crn.to_s)
}
end
cookies.permanent[:cart] = @cart.to_json
redirect_to schedule_path
end
private
def update_cookie(sym)
cookies[sym] = params[sym] unless params[sym].nil?
redirect_to(schedule_path)
end
end
......@@ -52,4 +52,13 @@ class Course < ApplicationRecord
query
end
# build_set builds
def self.build_set(sections)
courses = [].to_set
sections.each do |s|
courses.add s.course
end
courses
end
end
......@@ -16,7 +16,7 @@
<div class="icon">
<i class="fa fa-bars"></i>
</div>
<%= @course.course_sections.count %> sections
<%= @sections.count %> sections
</div>
</div>
</div>
......@@ -24,7 +24,7 @@
</div>
<div class="col-12 col-lg">
<%= render partial: 'shared/section', collection: @course.course_sections %>
<%= render partial: 'shared/section', collection: @sections %>
</div>
</div>
......
......@@ -5,7 +5,7 @@
<strong>Previously taught: </strong>
<ul>
<% @past.each do |c| %>
<li><%= link_to c.full_name, course_path(c) %></li>
<li><%= link_to(c.full_name, course_path(c)) %></li>
<% end %>
</ul>
<% end %>
......@@ -14,7 +14,7 @@
<div class ="col-lg-8 col-12">
<h3><%= @semester.to_s %></h3>
<% if @courses.any? %>
<%= render partial: 'shared/course', collection: @courses, locals: { expanded: true } %>
<%= render(partial: 'shared/course', collection: @courses, locals: { expanded: true }) %>
<% else %>
<p><%= @instructor.name %> is not teaching any courses this semester...</p>
<% end %>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment