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
5d22bf87
Commit
5d22bf87
authored
Aug 30, 2018
by
Zac Wood
Browse files
Merge branch '19-webcal' into 'master'
Resolve "Add webcal endpoint" Closes
#19
See merge request
!13
parents
4aaceed0
b6c67429
Pipeline
#2796
passed with stage
in 2 minutes and 59 seconds
Changes
11
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
schedules_api/app/assets/javascripts/calendar_generator.js
deleted
100644 → 0
View file @
4aaceed0
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
schedules_api/app/assets/stylesheets/calendar_generator.scss
deleted
100644 → 0
View file @
4aaceed0
// Place all the styles related to the CalendarGenerator controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
schedules_api/app/controllers/schedules_controller.rb
0 → 100644
View file @
5d22bf87
require
'icalendar'
require
'time'
# Contains functionality for generating schedules.
class
SchedulesController
<
ApplicationController
# Render an iCal file containing the schedules of all the
# course sections with the given CRNs.
def
index
crns
=
params
[
"crns"
].
split
','
@schedule
=
Schedule
.
new
crns
render
plain:
@schedule
.
to_ical
# render a plaintext iCal file
end
end
schedules_api/app/helpers/calendar_generator_helper.rb
deleted
100644 → 0
View file @
4aaceed0
module
CalendarGeneratorHelper
end
schedules_api/app/
controllers/calendar_generator_control
le
r
.rb
→
schedules_api/app/
models/schedu
le.rb
View file @
5d22bf87
require
'icalendar'
require
'time'
# Contains functionality for generating schedules.
class
CalendarGeneratorController
<
ApplicationController
# Render an iCal file containing the schedules of all the
# course sections with the given CRNs.
def
new
cal
=
Icalendar
::
Calendar
.
new
# the intended format for the json is a list of CRNs
params
[
:_json
].
each
do
|
crn
|
# for each CRN sent by the post request
section
=
CourseSection
.
find_by_crn
(
crn
)
class
Schedule
def
initialize
(
crns
)
@cal
=
Icalendar
::
Calendar
.
new
@cal
.
x_wr_calname
=
'GMU Fall 2018'
@course_sections
=
crns
.
map
do
|
crn
|
CourseSection
.
find_by
crn:
crn
end
@course_sections
.
compact!
load_events
end
def
to_ical
@cal
.
to_ical
end
private
def
load_events
@course_sections
.
each
do
|
section
|
unless
section
.
start_time
==
"TBA"
||
section
.
end_time
==
"TBA"
event
=
generate_event_from_section
(
section
)
cal
.
add_event
(
event
)
@
cal
.
add_event
(
event
)
end
if
section
.
days
.
start_with?
"M"
col_day_makeup
=
generate_event_after_columbus_day
(
section
)
cal
.
add_event
(
col_day_makeup
)
@
cal
.
add_event
(
col_day_makeup
)
end
end
render
plain:
cal
.
to_ical
# render a plaintext iCal file
end
private
# Configures a calendar event from a given section
# @param section [CourseSection]
def
generate_event_from_section
(
section
)
...
...
schedules_api/app/views/calendar_generator/generate.html.erb
deleted
100644 → 0
View file @
4aaceed0
<h1>
CalendarGenerator#generate
</h1>
<p>
Find me in app/views/calendar_generator/generate.html.erb
</p>
schedules_api/config/routes.rb
View file @
5d22bf87
...
...
@@ -3,8 +3,7 @@ Rails.application.routes.draw do
scope
:api
do
# Register /api routes
resources
:courses
,
only:
[
:index
,
:show
]
resources
:course_sections
,
only:
[
:index
]
post
'generate'
,
controller:
'calendar_generator'
,
action:
'new'
resources
:schedules
,
only:
[
:index
]
end
root
'courses#index'
# Set the root to be the courses API endpoint
...
...
schedules_api/test/controllers/
calendar_generator
_controller_test.rb
→
schedules_api/test/controllers/
schedules
_controller_test.rb
View file @
5d22bf87
require
'test_helper'
class
CalendarGenerator
Controller
T
est
<
ActionDispatch
::
IntegrationTest
test
"should
get
generate"
do
class
Schedules
Controller
t
est
<
ActionDispatch
::
IntegrationTest
test
"should generate
schedule
"
do
crns
=
[
course_sections
(
:cs112001
).
crn
,
course_sections
(
:cs112002
).
crn
]
pos
t
"/api/
generate"
,
params:
crns
.
to_json
,
headers:
{
'CONTENT_TYPE'
=>
'application/json'
}
ge
t
"/api/
schedules?crns=
#{
crns
.
join
(
','
)
}
"
# DTSTAMP and UID lines uniquely identify events, so we can't test against them.
# so remove all the lines starting with them.
...
...
schedules_api/test/test.ics
View file @
5d22bf87
...
...
@@ -2,6 +2,7 @@ BEGIN:VCALENDAR
VERSION:2.0
PRODID:icalendar-ruby
CALSCALE:GREGORIAN
X-WR-CALNAME:GMU Fall 2018
BEGIN:VEVENT
DTSTART:20180521T120000
DTEND:20180521T130000
...
...
schedules_web/src/components/ScheduleRoot.tsx
View file @
5d22bf87
...
...
@@ -9,10 +9,9 @@ interface ScheduleRootProps {
removeCourseSection
:
(
courseSection
:
CourseSection
)
=>
any
;
}
const
generateSchedule
=
async
(
schedule
:
CourseSection
[])
:
Promise
<
void
>
=>
{
const
generateSchedule
=
async
(
schedule
:
CourseSection
[])
=>
{
const
crns
=
schedule
.
map
(
section
=>
section
.
crn
);
const
calendar
=
await
ApiService
.
generateCalendar
(
crns
);
downloadFile
(
calendar
,
'
GMU Fall 2018.ics
'
);
ApiService
.
subscribeToCalendar
(
crns
);
};
const
ScheduleRoot
=
({
schedule
,
removeCourseSection
}:
ScheduleRootProps
)
=>
(
...
...
schedules_web/src/util/ApiService.ts
View file @
5d22bf87
...
...
@@ -7,8 +7,8 @@ class ApiService {
searchCourseSections
=
async
(
crn
:
string
):
Promise
<
any
[]
>
=>
fetchJson
(
`
${
this
.
apiRoot
}
/course_sections?crn=
${
crn
}
`
);
generate
Calendar
=
async
(
crns
:
string
[])
:
Promise
<
string
>
=>
postJson
(
`
${
this
.
apiRoot
}
/generate`
,
crns
).
then
(
response
=>
response
.
text
()
);
subscribeTo
Calendar
=
(
crns
:
string
[])
=>
window
.
open
(
`webcal://localhost:3000/api/schedules?crns=
${
crns
.
join
(
'
,
'
)}
`
,
'
_self
'
);
}
const
fetchJson
=
async
(
url
:
string
):
Promise
<
any
>
=>
fetch
(
url
).
then
(
response
=>
response
.
json
());
...
...
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