Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
schedules
Commits
2d45d1b3
Commit
2d45d1b3
authored
Oct 31, 2018
by
Zac Wood
Browse files
Keep track of semester by query param instead of cookie
parent
45df0731
Changes
7
Show whitespace changes
Inline
Side-by-side
schedules/app/assets/javascripts/application.js
View file @
2d45d1b3
...
...
@@ -30,8 +30,9 @@ document.addEventListener('DOMContentLoaded', () => {
});
const
setSemester
=
async
select
=>
{
const
resp
=
await
fetch
(
`/sessions/update?semester_id=
${
select
.
value
}
`
);
location
.
reload
(
true
);
const
url
=
new
URL
(
window
.
location
.
href
);
url
.
searchParams
.
set
(
'
semester_id
'
,
select
.
value
);
window
.
open
(
url
.
toString
(),
'
_self
'
);
};
const
initGlobalListeners
=
()
=>
{
...
...
schedules/app/controllers/application_controller.rb
View file @
2d45d1b3
...
...
@@ -4,13 +4,8 @@ class ApplicationController < ActionController::Base
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
sem
=
Semester
.
first
cookies
[
:semester_id
]
=
sem
.
id
sem
end
redirect_to
(
url_for
(
params
.
permit
(
params
.
keys
).
merge
(
semester_id:
Semester
.
first
.
id
)))
unless
params
.
key?
(
:semester_id
)
@semester
=
Semester
.
find_by_id
params
[
:semester_id
]
end
def
set_cart
...
...
schedules/app/models/course.rb
View file @
2d45d1b3
# Contains logic regarding the +Course+ model.
#
# TODO: Add more docs
class
Course
<
ApplicationRecord
# Each course belongs to a +Semester+
belongs_to
:semester
...
...
schedules/test/controllers/api/course_listings_controller_test.rb
View file @
2d45d1b3
...
...
@@ -2,7 +2,7 @@ require 'test_helper'
class
API::CourseListingsControllerTest
<
ActionDispatch
::
IntegrationTest
test
'should grab sections for course'
do
get
course_listings_url
course_id:
courses
(
:cs112
).
id
get
course_listings_url
course_id:
courses
(
:cs112
).
id
,
semester_id:
semesters
(
:fall2018
).
id
assert_response
:success
listing_returned
=
JSON
.
parse
@response
.
body
...
...
schedules/test/controllers/api/course_sections_controller_test.rb
View file @
2d45d1b3
...
...
@@ -2,7 +2,7 @@ require 'test_helper'
class
API::CourseSectionsControllerTest
<
ActionDispatch
::
IntegrationTest
test
'should get index'
do
get
api_course_sections_url
course_id:
courses
(
:cs112
).
id
get
api_course_sections_url
course_id:
courses
(
:cs112
).
id
,
semester_id:
semesters
(
:fall2018
).
id
assert_response
:success
sections_returned
=
JSON
.
parse
@response
.
body
...
...
@@ -12,7 +12,7 @@ class API::CourseSectionsControllerTest < ActionDispatch::IntegrationTest
end
test
'should filter by crn'
do
get
api_course_sections_url
crn:
course_sections
(
:cs112001
).
crn
get
api_course_sections_url
crn:
course_sections
(
:cs112001
).
crn
,
semester_id:
semesters
(
:fall2018
).
id
assert_response
:success
sections_returned
=
JSON
.
parse
@response
.
body
...
...
@@ -20,7 +20,7 @@ class API::CourseSectionsControllerTest < ActionDispatch::IntegrationTest
end
test
'should filter by professor'
do
get
api_course_sections_url
instructor:
"king"
get
api_course_sections_url
instructor:
"king"
,
semester_id:
semesters
(
:fall2018
).
id
assert_response
:success
sections_returned
=
JSON
.
parse
@response
.
body
...
...
schedules/test/controllers/api/courses_controller_test.rb
View file @
2d45d1b3
...
...
@@ -2,7 +2,7 @@ require 'test_helper'
class
API::CoursesControllerTest
<
ActionDispatch
::
IntegrationTest
test
'#index should return all courses'
do
get
api_courses_url
get
api_courses_url
semester_id:
semesters
(
:fall2018
).
id
assert_response
:success
courses_returned
=
JSON
.
parse
@response
.
body
...
...
@@ -11,7 +11,7 @@ class API::CoursesControllerTest < ActionDispatch::IntegrationTest
end
test
'#index should return filtered by subject case insensitive'
do
get
api_courses_url
subject:
"Cs"
get
api_courses_url
subject:
"Cs"
,
semester_id:
semesters
(
:fall2018
).
id
assert_response
:success
courses_returned
=
JSON
.
parse
@response
.
body
...
...
@@ -21,7 +21,7 @@ class API::CoursesControllerTest < ActionDispatch::IntegrationTest
end
test
'#index should return filtered by subject and course number'
do
get
api_courses_url
subject:
"CS"
,
course_number:
"112"
get
api_courses_url
subject:
"CS"
,
course_number:
"112"
,
semester_id:
semesters
(
:fall2018
).
id
assert_response
:success
courses_returned
=
JSON
.
parse
@response
.
body
...
...
@@ -33,7 +33,7 @@ class API::CoursesControllerTest < ActionDispatch::IntegrationTest
test
'#show should return course_sections for course'
do
cs_112_id
=
courses
(
:cs112
).
id
get
api_course_url
id:
cs_112_id
get
api_course_url
id:
cs_112_id
,
semester_id:
semesters
(
:fall2018
).
id
assert_response
:success
sections_returned
=
JSON
.
parse
@response
.
body
...
...
schedules/test/controllers/api/schedules_controller_test.rb
View file @
2d45d1b3
...
...
@@ -3,7 +3,7 @@ require 'test_helper'
class
API::SchedulesControllerTest
<
ActionDispatch
::
IntegrationTest
test
"should generate schedule"
do
ids
=
[
course_sections
(
:cs112001
).
id
,
course_sections
(
:cs112002
).
id
]
get
"/api/schedules?section_ids=
#{
ids
.
join
(
','
)
}
"
get
"/api/schedules?section_ids=
#{
ids
.
join
(
','
)
}
&semester_id=
#{
semesters
(
:fall2018
).
id
}
"
# DTSTAMP and UID lines uniquely identify events, so we can't test against them.
# so remove all the lines starting with them.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment