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
15dce333
Commit
15dce333
authored
Dec 15, 2018
by
Zac Wood
Browse files
identify sections by CRN instead of id
parent
c9161a32
Pipeline
#3492
passed with stages
in 26 minutes and 15 seconds
Changes
12
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
schedules/app/assets/javascripts/cart.js
View file @
15dce333
...
...
@@ -33,7 +33,7 @@ class Cart {
}
async
toggleSection
(
section
)
{
const
resp
=
await
fetch
(
`/sessions/cart?&
section_id
=
${
section
.
id
}
`
,
{
cache
:
'
no-store
'
});
const
resp
=
await
fetch
(
`/sessions/cart?&
crn
=
${
section
.
crn
}
`
,
{
cache
:
'
no-store
'
});
const
json
=
await
resp
.
json
();
this
.
courses
=
json
;
}
...
...
@@ -41,7 +41,7 @@ class Cart {
includesSection
(
obj
)
{
for
(
const
key
in
this
.
_courses
)
{
const
list
=
this
.
_courses
[
key
];
if
(
list
.
includes
(
obj
.
id
))
return
true
;
if
(
list
.
includes
(
obj
.
crn
))
return
true
;
}
return
false
;
...
...
schedules/app/assets/javascripts/schedules.js
View file @
15dce333
...
...
@@ -31,18 +31,18 @@ const remove = async item => {
* and sets the link in the modal to it.
*/
const
setUrlInModal
=
()
=>
{
document
.
getElementById
(
'
calendar-link
'
).
innerText
=
`
${
window
.
location
.
protocol
}
//
${
window
.
location
.
hostname
}
/api/schedules?
section_id
s=
${
window
.
cart
.
_courses
.
join
(
'
,
'
)}
`
;
document
.
getElementById
(
'
calendar-link
'
).
innerText
=
`
${
window
.
location
.
protocol
}
//
${
window
.
location
.
hostname
}
/api/schedules?
crn
s=
${
window
.
cart
.
_courses
.
join
(
'
,
'
)}
`
;
};
const
downloadIcs
=
async
()
=>
{
const
response
=
await
fetch
(
`
${
window
.
location
.
protocol
}
//
${
window
.
location
.
hostname
}
/api/schedules?
section_id
s=
${
window
.
cart
.
_courses
.
join
(
'
,
'
)}
`
);
const
response
=
await
fetch
(
`
${
window
.
location
.
protocol
}
//
${
window
.
location
.
hostname
}
/api/schedules?
crn
s=
${
window
.
cart
.
_courses
.
join
(
'
,
'
)}
`
);
const
text
=
await
response
.
text
();
const
blob
=
new
Blob
([
text
],
{
type
:
'
text/calendar;charset=utf-8
'
});
saveAs
(
blob
,
'
GMU Schedule.ics
'
);
};
const
addToSystemCalendar
=
()
=>
{
window
.
open
(
`webcal://
${
window
.
location
.
hostname
}
/api/schedules?
section_id
s=
${
window
.
cart
.
_courses
.
join
(
'
,
'
)}
`
);
window
.
open
(
`webcal://
${
window
.
location
.
hostname
}
/api/schedules?
crn
s=
${
window
.
cart
.
_courses
.
join
(
'
,
'
)}
`
);
};
const
initListeners
=
()
=>
{
...
...
@@ -53,5 +53,5 @@ const initListeners = () => {
document
.
getElementById
(
'
download-ics
'
).
onclick
=
downloadIcs
;
document
.
getElementById
(
'
add-to-system
'
).
onclick
=
addToSystemCalendar
;
document
.
getElementById
(
'
share-url
'
).
innerText
=
`
${
window
.
location
.
protocol
}
//
${
window
.
location
.
hostname
}
/schedule/view?
section_id
s=
${
window
.
cart
.
_courses
.
join
(
'
,
'
)}
`
;
document
.
getElementById
(
'
share-url
'
).
innerText
=
`
${
window
.
location
.
protocol
}
//
${
window
.
location
.
hostname
}
/schedule/view?
crn
s=
${
window
.
cart
.
_courses
.
join
(
'
,
'
)}
`
;
};
schedules/app/controllers/api/schedules_controller.rb
View file @
15dce333
...
...
@@ -5,10 +5,10 @@ class API::SchedulesController < ApplicationController
# Render an iCal file containing the schedules of all the
# course sections with the given CRNs.
api
:GET
,
'/schedules'
,
'Generate an iCal file with events for the given CRNs'
param
:
section_id
s
,
String
,
desc:
'Comma separated list of
section id
s to include as events in the calendar'
,
required:
true
param
:
crn
s
,
String
,
desc:
'Comma separated list of
crn
s to include as events in the calendar'
,
required:
true
def
index
id
s
=
params
[
"
section_id
s"
].
split
','
@schedule
=
Schedule
.
new
id
s
crn
s
=
params
[
"
crn
s"
].
split
','
@schedule
=
Schedule
.
new
crn
s
render
plain:
@schedule
.
to_ical
# render a plaintext iCal file
end
end
schedules/app/controllers/application_controller.rb
View file @
15dce333
...
...
@@ -16,13 +16,11 @@ class ApplicationController < ActionController::Base
def
set_cart
@cart
=
JSON
.
parse
(
cookies
[
:cart
])
@cart
=
@cart
.
reject
{
|
id
|
CourseSection
.
find_by_
id
(
id
).
nil?
}
@cart
=
@cart
.
reject
{
|
crn
|
CourseSection
.
find_by_
crn
(
crn
).
nil?
}
cookies
[
:cart
]
=
@cart
.
to_json
end
def
set_cookies
cookies
[
:crns
]
=
""
if
cookies
[
:crns
].
nil?
cookies
[
:section_ids
]
=
""
if
cookies
[
:section_ids
].
nil?
cookies
[
:cart
]
=
"[]"
if
cookies
[
:cart
].
nil?
end
end
schedules/app/controllers/schedules_controller.rb
View file @
15dce333
...
...
@@ -3,17 +3,23 @@ class SchedulesController < ApplicationController
include
SchedulesHelper
def
show
valid_
id
s
=
@cart
.
reject
{
|
id
|
s
=
CourseSection
.
find_by_
id
(
id
)
valid_
crn
s
=
@cart
.
reject
{
|
crn
|
s
=
CourseSection
.
find_by_
crn
(
crn
)
s
.
nil?
||
s
.
start_time
==
"TBA"
||
s
.
end_time
==
"TBA"
}
@all
=
valid_ids
.
map
{
|
id
|
CourseSection
.
find_by_id
id
}
@events
=
generate_fullcalender_events
(
valid_ids
)
@all
=
valid_crns
.
map
{
|
crn
|
a
=
CourseSection
.
where
(
crn:
crn
).
sort_by
{
|
s
|
s
.
course
.
semester
.
id
}
a
.
first
}
@events
=
generate_fullcalender_events
(
@all
)
end
def
view
@all
=
params
[
:section_ids
].
split
(
','
).
map
{
|
id
|
CourseSection
.
find_by_id
id
.
to_s
}
@events
=
generate_fullcalender_events
(
params
[
:section_ids
].
split
(
','
))
@all
=
params
[
:crns
].
split
(
','
).
map
{
|
crn
|
a
=
CourseSection
.
where
(
crn:
crn
).
sort_by
{
|
s
|
s
.
course
.
semester
.
id
}
a
.
first
}
@events
=
generate_fullcalender_events
(
@all
)
end
end
schedules/app/controllers/sessions_controller.rb
View file @
15dce333
...
...
@@ -8,14 +8,15 @@ class SessionsController < ApplicationController
end
def
cart
section_
id
=
params
[
:
section_id
]
section_
crn
=
params
[
:
crn
]
if
@cart
.
include?
(
section_
id
)
@cart
.
reject!
{
|
id
|
section_
id
==
id
}
if
@cart
.
include?
(
section_
crn
.
to_s
)
@cart
.
reject!
{
|
crn
|
section_
crn
.
to_s
==
crn
.
to_s
}
else
@cart
<<
section_
id
@cart
<<
section_
crn
end
puts
@cart
cookies
[
:cart
]
=
@cart
.
to_json
render
json:
@cart
.
to_json
end
...
...
@@ -25,8 +26,7 @@ class SessionsController < ApplicationController
crns
.
each
{
|
crn
|
s
=
CourseSection
.
find_by_crn
(
crn
)
next
if
s
.
nil?
section_id
=
s
.
id
.
to_s
@cart
<<
section_id
unless
@cart
.
include?
(
section_id
)
@cart
<<
crn
.
to_s
unless
@cart
.
include?
(
crn
.
to_s
)
}
cookies
[
:cart
]
=
@cart
.
to_json
redirect_to
schedule_path
...
...
schedules/app/helpers/schedules_helper.rb
View file @
15dce333
...
...
@@ -9,9 +9,8 @@ module SchedulesHelper
"U"
:
Date
.
new
(
2019
,
1
,
20
)
}.
freeze
def
generate_fullcalender_events
(
section_ids
)
section_ids
.
map
do
|
id
|
s
=
CourseSection
.
find_by_id
id
def
generate_fullcalender_events
(
sections
)
sections
.
map
do
|
s
|
s
.
days
.
split
(
''
).
map
do
|
day
|
formatted_date
=
DAYS
[
day
.
to_sym
].
to_s
.
tr
(
'-'
,
''
)
time
=
Time
.
parse
(
s
.
start_time
).
strftime
(
"%H%M%S"
)
...
...
schedules/app/helpers/search_helper.rb
View file @
15dce333
module
SearchHelper
def
in_cart?
(
id
)
@cart
.
include?
id
.
to_s
def
in_cart?
(
crn
)
@cart
.
include?
crn
.
to_s
end
class
GenericQueryData
...
...
schedules/app/models/schedule.rb
View file @
15dce333
...
...
@@ -3,11 +3,11 @@ require 'time'
# Creates a iCal object given a list of section ids
class
Schedule
def
initialize
(
id
s
)
def
initialize
(
crn
s
)
@cal
=
Icalendar
::
Calendar
.
new
@cal
.
x_wr_calname
=
'GMU Schedule'
@course_sections
=
id
s
.
map
{
|
id
|
CourseSection
.
find_by_
id
id
}
@course_sections
=
crn
s
.
map
{
|
crn
|
CourseSection
.
find_by_
crn
crn
}
@course_sections
.
compact!
load_events
...
...
schedules/app/views/shared/_section.html.erb
View file @
15dce333
...
...
@@ -12,7 +12,7 @@
<p><b
class=
"subj"
>
<%=
"
#{
section
.
name
}
"
%>
</b>
:
<%=
section
.
title
%>
</p>
<%
if
editable
%>
<%
if
in_cart?
section
.
id
%>
<%
if
in_cart?
section
.
crn
%>
<span
class=
"float-right text-center add-remove-btn"
><i
id=
"icon"
class=
"fas fa-minus"
></i><br/><span
class=
"text"
>
Remove
</span></span>
<%
else
%>
<span
class=
"float-right text-center add-remove-btn"
><i
id=
"icon"
class=
"fas fa-plus"
></i><br/><span
class=
"text"
>
Add
</span></span>
...
...
schedules/db/seeds.rb
View file @
15dce333
...
...
@@ -112,7 +112,7 @@ def main
# wipe_db
parser
=
PatriotWeb
::
Parser
.
new
semesters
=
parser
.
parse_semesters
[
0
..
12
]
# expand to include however many semesters you want
semesters
=
parser
.
parse_semesters
[
0
..
6
]
# expand to include however many semesters you want
courses
=
nil
semesters
.
each
do
|
semester
|
...
...
schedules/test/controllers/api/schedules_controller_test.rb
View file @
15dce333
...
...
@@ -2,9 +2,9 @@ require 'test_helper'
class
API::SchedulesControllerTest
<
ActionDispatch
::
IntegrationTest
test
"should generate schedule"
do
id
s
=
[
course_sections
(
:cs112001
).
id
,
course_sections
(
:cs112002
).
id
]
crn
s
=
[
course_sections
(
:cs112001
).
crn
,
course_sections
(
:cs112002
).
crn
]
get
api_schedules_path
section_ids:
id
s
.
join
(
','
),
semester_id:
semesters
(
:fall2018
).
id
get
api_schedules_path
crns:
crn
s
.
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