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
b95c13a2
Commit
b95c13a2
authored
Oct 01, 2018
by
Zac Wood
Browse files
Semesters
parent
9821b71c
Changes
15
Hide whitespace changes
Inline
Side-by-side
schedules/app/assets/javascripts/application.js
View file @
b95c13a2
...
...
@@ -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
);
};
schedules/app/assets/javascripts/schedule.js
View file @
b95c13a2
...
...
@@ -12,7 +12,7 @@ class Schedule {
this
.
_ids
=
ids
;
document
.
getElementById
(
'
course-counter
'
).
innerText
=
ids
.
length
;
fetch
(
'
/se
arch
/update?
id
s=
'
+
ids
.
join
(
'
,
'
),
{
cache
:
'
no-store
'
});
fetch
(
'
/se
ssions
/update?
crn
s=
'
+
ids
.
join
(
'
,
'
),
{
cache
:
'
no-store
'
});
}
toggle
()
{
...
...
schedules/app/assets/javascripts/sessions.js
0 → 100644
View file @
b95c13a2
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
schedules/app/assets/stylesheets/sessions.scss
0 → 100644
View file @
b95c13a2
// 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/
schedules/app/controllers/application_controller.rb
View file @
b95c13a2
# 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
schedules/app/controllers/instructors_controller.rb
View file @
b95c13a2
...
...
@@ -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
...
...
schedules/app/controllers/search_controller.rb
View file @
b95c13a2
...
...
@@ -4,10 +4,4 @@ class SearchController < ApplicationController
course
.
course_sections
.
count
.
positive?
end
end
def
update
cookies
[
:ids
]
=
params
[
:ids
]
head
:ok
end
end
schedules/app/controllers/sessions_controller.rb
0 → 100644
View file @
b95c13a2
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
schedules/app/helpers/sessions_helper.rb
0 → 100644
View file @
b95c13a2
module
SessionsHelper
end
schedules/app/views/sessions/update.html.erb
0 → 100644
View file @
b95c13a2
<h1>
Sessions#update
</h1>
<p>
Find me in app/views/sessions/update.html.erb
</p>
schedules/app/views/shared/_navbar.html.erb
View file @
b95c13a2
<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()"
>
...
...
schedules/config/routes.rb
View file @
b95c13a2
# Registers all routes for the app.
Rails
.
application
.
routes
.
draw
do
get
'search'
,
to:
'search#index'
get
'se
arch/update'
,
to:
'search#
update'
,
as:
'update_
cookie
'
get
'se
ssions/
update'
,
as:
'update_
session
'
resources
:instructors
,
only:
[
:index
,
:show
]
...
...
schedules/db/seeds.rb
View file @
b95c13a2
...
...
@@ -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
|
...
...
schedules/test/controllers/search_controller_test.rb
View file @
b95c13a2
...
...
@@ -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
schedules/test/controllers/sessions_controller_test.rb
0 → 100644
View file @
b95c13a2
require
'test_helper'
class
SessionsControllerTest
<
ActionDispatch
::
IntegrationTest
# test "should get update" do
# get update_session_url
# assert_response :success
# end
end
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