Commit db9f9d86 authored by Zac Wood's avatar Zac Wood

Merge branch 'semesters' into 'dev-v2'

Semesters

See merge request !30
parents 9821b71c b95c13a2
Pipeline #3064 passed with stage
in 2 minutes and 12 seconds
......@@ -31,3 +31,8 @@ document.addEventListener('DOMContentLoaded', () => {
document.addEventListener('turbolinks:load', () => {
FontAwesome.dom.i2svg();
});
const setSemester = async select => {
const resp = await fetch(`/sessions/update?semester_id=${select.value}`);
location.reload(true);
};
......@@ -12,7 +12,7 @@ class Schedule {
this._ids = ids;
document.getElementById('course-counter').innerText = ids.length;
fetch('/search/update?ids=' + ids.join(','), { cache: 'no-store' });
fetch('/sessions/update?crns=' + ids.join(','), { cache: 'no-store' });
}
toggle() {
......
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
// Place all the styles related to the sessions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
# Configures the application.
class ApplicationController < ActionController::Base
protect_from_forgery with: :null_session
before_action :set_cookies, :set_cart, :set_semester
before_action :set_semester, :set_cookies, :set_cart
def set_semester
@semester = if cookies.key?(:semester_id)
Semester.find_by(id: cookies[:semester_id])
else
Semester.find_by(season: 'Spring', year: '2019')
end
end
def set_cart
@cart = cookies[:ids].split(',').map do |crn|
CourseSection.find_by_crn crn
@cart = cookies[:crns].split(',').map do |crn|
s = CourseSection.find_by_crn(crn)
s if s.course.semester == @semester
end
end
def set_cookies
cookies[:ids] = "" if cookies[:ids].nil?
@cart.compact!
end
def set_semester
@semester = if params.key?(:semester_id)
Semester.find_by(id: params[:semester_id])
else
Semester.find_by(season: 'Fall', year: '2018')
end
def set_cookies
cookies[:crns] = "" if cookies[:crns].nil?
end
end
......@@ -7,6 +7,9 @@ class InstructorsController < ApplicationController
def show
sections = CourseSection.where instructor: @instructor
sections = sections.select do |s|
s.course.semester == @semester
end
# TODO: move this to a model somewhere
@courses = [].to_set
......
......@@ -4,10 +4,4 @@ class SearchController < ApplicationController
course.course_sections.count.positive?
end
end
def update
cookies[:ids] = params[:ids]
head :ok
end
end
class SessionsController < ApplicationController
def update
set_cookie :crns
set_cookie :semester_id
head :ok
end
private
def update_cookie(sym)
cookies[sym] = params[sym] unless params[sym].nil?
end
end
<h1>Sessions#update</h1>
<p>Find me in app/views/sessions/update.html.erb</p>
<div class="container-fluid">
<div class="row align-left align-sm-center align-md-right" id="navbar">
<div class="col-8 col-sm align-center">
<a href="/" id="logo">
<i class="fas fa-calendar-alt"></i>
Schedules
</a>
<div>
<a href="/" id="logo">
<i class="fas fa-calendar-alt"></i>
Schedules
</a>
<select onchange="setSemester(this)">
<% for semester in Semester.all %>
<option value="<%= semester.id %>" <% if @semester == semester %> selected <% end %> >
<%= "#{semester.season} #{semester.year}" %>
</option>
<% end %>
</select>
</div>
</div>
<div class="col-4 col-sm align-center order-0 order-sm-1" onclick="window.schedule.toggle()">
......
# Registers all routes for the app.
Rails.application.routes.draw do
get 'search', to: 'search#index'
get 'search/update', to: 'search#update', as: 'update_cookie'
get 'sessions/update', as: 'update_session'
resources :instructors, only: [:index, :show]
......
......@@ -110,7 +110,7 @@ def main
wipe_db
parser = PatriotWeb::Parser.new
semesters = [parser.parse_semesters.first] # expand to include however many semesters you want
semesters = parser.parse_semesters[0..1] # expand to include however many semesters you want
courses = nil
semesters.each do |semester|
......
......@@ -5,9 +5,4 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
get search_url
assert_response :success
end
test "should update cookie" do
get update_cookie_url crns: '71926,71924'
assert_response :success
end
end
require 'test_helper'
class SessionsControllerTest < ActionDispatch::IntegrationTest
# test "should get update" do
# get update_session_url
# assert_response :success
# 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