Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
schedules-legacy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
17
Issues
17
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SRCT
schedules-legacy
Commits
a9931416
Commit
a9931416
authored
Dec 31, 2016
by
Mark Stenglein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Linting and cleanup
parent
fb25f4aa
Pipeline
#712
failed with stage
in 43 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
27 deletions
+29
-27
app.js
app.js
+2
-1
data/index.js
data/index.js
+1
-1
helpers/index.js
helpers/index.js
+4
-5
models/Semester.js
models/Semester.js
+2
-1
routes/api/v1.js
routes/api/v1.js
+20
-19
No files found.
app.js
View file @
a9931416
...
...
@@ -41,7 +41,8 @@ app.use(require('node-sass-middleware')({
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'
public
'
)))
// Initialize the Database and Connection
var
db
=
require
(
path
.
join
(
__dirname
,
'
models
'
))
// Not used currently so it's commented out
// var db = require(path.join(__dirname, 'models'))
// Populate initial data
require
(
path
.
join
(
__dirname
,
'
data
'
))
...
...
data/index.js
View file @
a9931416
...
...
@@ -81,7 +81,7 @@ var syncSections = function (semester) {
for
(
var
z
=
0
;
z
<
rawSections
.
classes
.
length
;
z
++
)
{
var
rawSection
=
rawSections
.
classes
[
z
]
var
sectionDateRange
=
rawSection
.
session_templates
[
0
].
date_range
var
sectionDateRange
=
rawSection
[
'
session_templates
'
][
0
][
'
date_range
'
]
var
section
=
{
'
crn
'
:
rawSection
.
crn
,
...
...
helpers/index.js
View file @
a9931416
...
...
@@ -11,9 +11,9 @@
* tl;dr: Forget staying thirsty, "Stay DRY, my friends."
*/
var
ical
=
require
(
'
ical-generator
'
)
// ical-generator library
var
config
=
require
(
'
config
'
)
// Site wide configs
var
db
=
require
(
'
../models
'
)
// Database Object
//
var ical = require('ical-generator') // ical-generator library
//
var config = require('config') // Site wide configs
//
var db = require('../models') // Database Object
/*
* A brief note...since this is quite new and I don't know exactly how I want to
...
...
@@ -43,10 +43,9 @@ module.exports.strClean = strClean
* @returns {Array|String}
*/
var
strSplitClean
=
function
(
rawString
,
separator
)
{
// Validate input for separator
if
(
separator
&&
separator
.
length
!==
1
)
{
throw
'
separator must be a single char
'
throw
{
message
:
'
separator must be a single char
'
}
}
if
(
!
separator
)
{
separator
=
'
,
'
...
...
models/Semester.js
View file @
a9931416
...
...
@@ -22,7 +22,8 @@ module.exports = function (sequelize, DataTypes) {
unique
:
true
,
fields
:
[
'
slug
'
]
}
],
classMethods
:
{
],
classMethods
:
{
associate
:
function
(
models
)
{
models
.
Semester
.
belongsTo
(
models
.
University
,
{
foreignKey
:
'
university
'
})
models
.
Semester
.
hasMany
(
models
.
Section
,
{
foreignKey
:
'
semester
'
})
...
...
routes/api/v1.js
View file @
a9931416
...
...
@@ -16,14 +16,13 @@ var path = require('path')
var
router
=
express
.
Router
()
var
ical
=
require
(
'
ical-generator
'
)
// ical-generator library
var
config
=
require
(
'
config
'
)
// Site wide configs
var
schoolSlugs
=
config
.
get
(
'
schoolSlugs
'
)
// Configured School Slugs
//
var schoolSlugs = config.get('schoolSlugs') // Configured School Slugs
var
db
=
require
(
'
models
'
)
// Database Object
var
helpers
=
require
(
path
.
join
(
__dirname
,
'
..
'
,
'
..
'
,
'
helpers
'
))
var
moment
=
require
(
'
moment
'
)
var
_
=
require
(
'
lodash
'
)
//
var _ = require('lodash')
////////////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////
// JSON API Definitions
// TODO: separate out into its own file
...
...
@@ -40,8 +39,7 @@ router.get('/json/schools', function (req, res, next) {
db
.
University
.
findAll
({
attributes
:
[
'
slug
'
,
'
name
'
,
'
website
'
]
}).
then
(
function
(
query
)
{
var
schools
res
.
json
(
query
)
res
.
json
(
query
.
dataValues
)
})
})
...
...
@@ -92,8 +90,8 @@ router.get('/json/classes/:SEMSLUG', function (req, res, next) {
router
.
get
(
'
/json/classes/:SEMESTER/:CRN
'
,
function
(
req
,
res
,
next
)
{
db
.
Section
.
findAll
({
where
:
{
'
crn
'
:
req
.
params
[
'
CRN
'
],
'
semester
'
:
req
.
params
([
'
SEMESTER
'
])
'
crn
'
:
req
.
params
[
'
CRN
'
],
'
semester
'
:
req
.
params
([
'
SEMESTER
'
])
}
}).
then
(
function
(
query
)
{
res
.
json
(
query
)
...
...
@@ -182,7 +180,7 @@ router.get('/ical/:SCHOOL/:SEMSLUG/:SECTIONS', function (req, res, next) {
})
// TODO: look into separating this out into it's own helper file
var
makeCalendar
=
function
(
school
,
semester
,
sections
)
{
var
makeCalendar
=
function
(
school
,
semester
,
sections
)
{
// Generate blank calendar
var
cal
=
ical
(
{
...
...
@@ -221,9 +219,9 @@ router.get('/ical/:SCHOOL/:SEMSLUG/:SECTIONS', function (req, res, next) {
}
var
processTime
=
function
(
time
)
{
var
hour
=
parseInt
(
time
.
substring
(
0
,
2
))
var
min
=
parseInt
(
time
.
substring
(
3
,
5
))
if
(
time
.
substring
(
6
,
8
)
===
'
pm
'
&&
hour
!==
12
)
{
var
hour
=
parseInt
(
time
.
substring
(
0
,
2
))
var
min
=
parseInt
(
time
.
substring
(
3
,
5
))
if
(
time
.
substring
(
6
,
8
)
===
'
pm
'
&&
hour
!==
12
)
{
hour
+=
12
}
return
{
'
hour
'
:
hour
,
'
min
'
:
min
}
...
...
@@ -239,7 +237,7 @@ router.get('/ical/:SCHOOL/:SEMSLUG/:SECTIONS', function (req, res, next) {
startDateFinish
.
hour
(
endTime
.
hour
)
startDateFinish
.
minute
(
endTime
.
min
)
event
=
cal
.
createEvent
({
var
event
=
cal
.
createEvent
({
uid
:
semester
.
get
(
'
slug
'
)
+
'
-
'
+
section
.
get
(
'
crn
'
),
start
:
startDate
.
utc
(
true
).
toDate
(),
end
:
startDateFinish
.
utc
(
true
).
toDate
(),
...
...
@@ -249,16 +247,19 @@ router.get('/ical/:SCHOOL/:SEMSLUG/:SECTIONS', function (req, res, next) {
until
:
endDate
.
utc
(
true
).
toDate
()
},
summary
:
section
.
get
(
'
name
'
),
description
:
section
.
get
(
'
name
'
)
+
'
:
'
+
section
.
get
(
'
title
'
)
+
'
(
'
+
section
.
get
(
'
class_type
'
)
+
'
)
\n
Section:
'
+
section
.
get
(
'
section
'
)
+
'
\n
Instructors:
'
+
section
.
get
(
'
instructor
'
),
description
:
(
section
.
get
(
'
name
'
)
+
'
:
'
+
section
.
get
(
'
title
'
)
+
'
(
'
+
section
.
get
(
'
class_type
'
)
+
'
)
\n
Section:
'
+
section
.
get
(
'
section
'
)
+
'
\n
Instructors:
'
+
section
.
get
(
'
instructor
'
)
),
organizer
:
'
Mason SRCT <schedules@lists.srct.gmu.edu>
'
,
url
:
'
https://schedules.gmu.edu
'
})
;
})
})
})
// TODO: build the calendar events
return
cal
...
...
@@ -271,10 +272,10 @@ router.get('/ical/:SCHOOL/:SEMSLUG/:SECTIONS', function (req, res, next) {
).
then
(
function
(
queries
)
{
// Check for invalid responses and throw appropriate errors
if
(
!
queries
[
0
])
{
throw
'
Invalid School Given!
'
throw
{
message
:
'
Invalid School Given!
'
}
}
if
(
!
queries
[
1
])
{
throw
'
Invalid Semester Given
'
throw
{
message
:
'
Invalid Semester Given
'
}
}
// Generate the calendar
...
...
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