Commit 83a1b1c8 authored by Zac Wood's avatar Zac Wood

Schedule generation is now truly deterministic, made cookies permanent

parent f45f549b
Pipeline #3498 canceled with stages
in 1 minute and 35 seconds
version: "3"
services:
api:
image: schedules_api
ports:
- "3000:3000"
command: ./start.sh
volumes:
- ./schedules_api:/api
web:
image: schedules_web
ports:
- "8080:8080"
command: yarn start
volumes:
- ./schedules_web:/web
#! /bin/bash
# Build the API image
cd schedules_api/
docker build . -t 'schedules_api' -f Dockerfile.dev
# Build the Web image
cd ../schedules_web
docker build . -t 'schedules_web' -f Dockerfile.dev
# Start and link the images together
cd ..
docker-compose up
......@@ -15,12 +15,12 @@ class ApplicationController < ActionController::Base
end
def set_cart
@cart = JSON.parse(cookies[:cart])
@cart = JSON.parse(cookies.permanent[:cart])
@cart = @cart.reject { |crn| CourseSection.find_by_crn(crn).nil? }
cookies[:cart] = @cart.to_json
cookies.permanent[:cart] = @cart.to_json
end
def set_cookies
cookies[:cart] = "[]" if cookies[:cart].nil?
cookies.permanent[:cart] = "[]" if cookies.permanent[:cart].nil?
end
end
......@@ -9,16 +9,14 @@ class SchedulesController < ApplicationController
}
@all = valid_crns.map { |crn|
a = CourseSection.where(crn: crn).sort_by { |s| s.course.semester.id }
a.first
CourseSection.latest_by_crn(crn)
}
@events = generate_fullcalender_events(@all)
end
def view
@all = params[:crns].split(',').map { |crn|
a = CourseSection.where(crn: crn).sort_by { |s| s.course.semester.id }
a.first
CourseSection.latest_by_crn(crn)
}
@events = generate_fullcalender_events(@all)
end
......
......@@ -17,18 +17,18 @@ class SessionsController < ApplicationController
end
puts @cart
cookies[:cart] = @cart.to_json
cookies.permanent[:cart] = @cart.to_json
render json: @cart.to_json
end
def add_bulk
crns = params[:crns].split(',')
crns.each { |crn|
s = CourseSection.find_by_crn(crn)
s = CourseSection.latest_by_crn(crn)
next if s.nil?
@cart << crn.to_s unless @cart.include?(crn.to_s)
}
cookies[:cart] = @cart.to_json
cookies.permanent[:cart] = @cart.to_json
redirect_to schedule_path
end
......
......@@ -17,6 +17,10 @@ class CourseSection < ApplicationRecord
(t1_start <= t2_end && t2_start <= t1_end) && Set.new(days.split).intersect?(Set.new(other.days.split))
end
def self.latest_by_crn(crn)
where(crn: crn).sort_by { |s| s.course.semester.id }.first
end
# Select all course sections that have an instructor that matches the given name
def self.with_instructor(name: "")
joins(:instructor)
......
......@@ -7,7 +7,9 @@ class Schedule
@cal = Icalendar::Calendar.new
@cal.x_wr_calname = 'GMU Schedule'
@course_sections = crns.map { |crn| CourseSection.find_by_crn crn }
@course_sections = crns.map { |crn|
CourseSection.latest_by_crn(crn)
}
@course_sections.compact!
load_events
......
......@@ -21,4 +21,9 @@ class CourseSectionTest < ActiveSupport::TestCase
section = CourseSection.with_instructor.first
assert section.instructor_name != ""
end
test '#latest_by_crn sorts correctly' do
s = CourseSection.latest_by_crn(70192)
assert_equal semesters(:fall2018).id, s.course.semester.id
end
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