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
Hide whitespace changes
Inline
Side-by-side
schedules/app/assets/javascripts/application.js
View file @
2d45d1b3
...
@@ -30,8 +30,9 @@ document.addEventListener('DOMContentLoaded', () => {
...
@@ -30,8 +30,9 @@ document.addEventListener('DOMContentLoaded', () => {
});
});
const
setSemester
=
async
select
=>
{
const
setSemester
=
async
select
=>
{
const
resp
=
await
fetch
(
`/sessions/update?semester_id=
${
select
.
value
}
`
);
const
url
=
new
URL
(
window
.
location
.
href
);
location
.
reload
(
true
);
url
.
searchParams
.
set
(
'
semester_id
'
,
select
.
value
);
window
.
open
(
url
.
toString
(),
'
_self
'
);
};
};
const
initGlobalListeners
=
()
=>
{
const
initGlobalListeners
=
()
=>
{
...
...
schedules/app/controllers/application_controller.rb
View file @
2d45d1b3
...
@@ -4,13 +4,8 @@ class ApplicationController < ActionController::Base
...
@@ -4,13 +4,8 @@ class ApplicationController < ActionController::Base
before_action
:set_semester
,
:set_cookies
,
:set_cart
before_action
:set_semester
,
:set_cookies
,
:set_cart
def
set_semester
def
set_semester
@semester
=
if
cookies
.
key?
(
:semester_id
)
redirect_to
(
url_for
(
params
.
permit
(
params
.
keys
).
merge
(
semester_id:
Semester
.
first
.
id
)))
unless
params
.
key?
(
:semester_id
)
Semester
.
find_by
(
id:
cookies
[
:semester_id
])
@semester
=
Semester
.
find_by_id
params
[
:semester_id
]
else
sem
=
Semester
.
first
cookies
[
:semester_id
]
=
sem
.
id
sem
end
end
end
def
set_cart
def
set_cart
...
...
schedules/app/models/course.rb
View file @
2d45d1b3
# Contains logic regarding the +Course+ model.
# Contains logic regarding the +Course+ model.
#
# TODO: Add more docs
class
Course
<
ApplicationRecord
class
Course
<
ApplicationRecord
# Each course belongs to a +Semester+
# Each course belongs to a +Semester+
belongs_to
:semester
belongs_to
:semester
...
...
schedules/test/controllers/api/course_listings_controller_test.rb
View file @
2d45d1b3
...
@@ -2,7 +2,7 @@ require 'test_helper'
...
@@ -2,7 +2,7 @@ require 'test_helper'
class
API::CourseListingsControllerTest
<
ActionDispatch
::
IntegrationTest
class
API::CourseListingsControllerTest
<
ActionDispatch
::
IntegrationTest
test
'should grab sections for course'
do
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
assert_response
:success
listing_returned
=
JSON
.
parse
@response
.
body
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'
...
@@ -2,7 +2,7 @@ require 'test_helper'
class
API::CourseSectionsControllerTest
<
ActionDispatch
::
IntegrationTest
class
API::CourseSectionsControllerTest
<
ActionDispatch
::
IntegrationTest
test
'should get index'
do
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
assert_response
:success
sections_returned
=
JSON
.
parse
@response
.
body
sections_returned
=
JSON
.
parse
@response
.
body
...
@@ -12,7 +12,7 @@ class API::CourseSectionsControllerTest < ActionDispatch::IntegrationTest
...
@@ -12,7 +12,7 @@ class API::CourseSectionsControllerTest < ActionDispatch::IntegrationTest
end
end
test
'should filter by crn'
do
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
assert_response
:success
sections_returned
=
JSON
.
parse
@response
.
body
sections_returned
=
JSON
.
parse
@response
.
body
...
@@ -20,7 +20,7 @@ class API::CourseSectionsControllerTest < ActionDispatch::IntegrationTest
...
@@ -20,7 +20,7 @@ class API::CourseSectionsControllerTest < ActionDispatch::IntegrationTest
end
end
test
'should filter by professor'
do
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
assert_response
:success
sections_returned
=
JSON
.
parse
@response
.
body
sections_returned
=
JSON
.
parse
@response
.
body
...
...
schedules/test/controllers/api/courses_controller_test.rb
View file @
2d45d1b3
...
@@ -2,7 +2,7 @@ require 'test_helper'
...
@@ -2,7 +2,7 @@ require 'test_helper'
class
API::CoursesControllerTest
<
ActionDispatch
::
IntegrationTest
class
API::CoursesControllerTest
<
ActionDispatch
::
IntegrationTest
test
'#index should return all courses'
do
test
'#index should return all courses'
do
get
api_courses_url
get
api_courses_url
semester_id:
semesters
(
:fall2018
).
id
assert_response
:success
assert_response
:success
courses_returned
=
JSON
.
parse
@response
.
body
courses_returned
=
JSON
.
parse
@response
.
body
...
@@ -11,7 +11,7 @@ class API::CoursesControllerTest < ActionDispatch::IntegrationTest
...
@@ -11,7 +11,7 @@ class API::CoursesControllerTest < ActionDispatch::IntegrationTest
end
end
test
'#index should return filtered by subject case insensitive'
do
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
assert_response
:success
courses_returned
=
JSON
.
parse
@response
.
body
courses_returned
=
JSON
.
parse
@response
.
body
...
@@ -21,7 +21,7 @@ class API::CoursesControllerTest < ActionDispatch::IntegrationTest
...
@@ -21,7 +21,7 @@ class API::CoursesControllerTest < ActionDispatch::IntegrationTest
end
end
test
'#index should return filtered by subject and course number'
do
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
assert_response
:success
courses_returned
=
JSON
.
parse
@response
.
body
courses_returned
=
JSON
.
parse
@response
.
body
...
@@ -33,7 +33,7 @@ class API::CoursesControllerTest < ActionDispatch::IntegrationTest
...
@@ -33,7 +33,7 @@ class API::CoursesControllerTest < ActionDispatch::IntegrationTest
test
'#show should return course_sections for course'
do
test
'#show should return course_sections for course'
do
cs_112_id
=
courses
(
:cs112
).
id
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
assert_response
:success
sections_returned
=
JSON
.
parse
@response
.
body
sections_returned
=
JSON
.
parse
@response
.
body
...
...
schedules/test/controllers/api/schedules_controller_test.rb
View file @
2d45d1b3
...
@@ -3,7 +3,7 @@ require 'test_helper'
...
@@ -3,7 +3,7 @@ require 'test_helper'
class
API::SchedulesControllerTest
<
ActionDispatch
::
IntegrationTest
class
API::SchedulesControllerTest
<
ActionDispatch
::
IntegrationTest
test
"should generate schedule"
do
test
"should generate schedule"
do
ids
=
[
course_sections
(
:cs112001
).
id
,
course_sections
(
:cs112002
).
id
]
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.
# DTSTAMP and UID lines uniquely identify events, so we can't test against them.
# so remove all the lines starting with 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