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
416eed08
Commit
416eed08
authored
Dec 31, 2016
by
Mark Stenglein
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'issue25' into '1.0'
solves issue 25 Closes
#25
See merge request
!11
parents
d3a335cd
befd4196
Pipeline
#708
failed with stage
in 42 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
10 deletions
+90
-10
app.js
app.js
+3
-3
helpers/index.js
helpers/index.js
+70
-0
routes/api/v1.js
routes/api/v1.js
+17
-7
No files found.
app.js
View file @
416eed08
...
...
@@ -16,9 +16,9 @@ var bodyParser = require('body-parser')
// Load in Routes
// TODO: Make this a dynamic loading system that simply scans the directory
var
routes
=
require
(
'
./routes/index
'
)
var
docs
=
require
(
'
./routes/docs
'
)
var
apiV1
=
require
(
'
./routes/api/v1
'
)
var
routes
=
require
(
path
.
join
(
__dirname
,
'
routes
'
)
)
var
docs
=
require
(
path
.
join
(
__dirname
,
'
routes
'
,
'
docs
'
)
)
var
apiV1
=
require
(
path
.
join
(
__dirname
,
'
routes
'
,
'
api
'
,
'
v1
'
)
)
// Instantiate the application
var
app
=
express
()
...
...
helpers/index.js
0 → 100644
View file @
416eed08
/*
* Mason SRCT: Schedules || Helpers index.js
*
* - Main file for the supporting functions used in the schedules application.
* - This file aggregates all of the other functions and exports them to the
* calling file's scope.
* - The main idea here is to make it so that any function that might be used
* in multiple places can be put here and easily unit tested, debugged, and
* changed in all places that use the feature.
*
* 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
/*
* A brief note...since this is quite new and I don't know exactly how I want to
* set this up, I'll be making it pretty simple for now. So basically:
*
* TODO: Make this not suck (dynamic loading of other files maybe?)
*/
/**
* Strip all non alpha numeric characters from input.
*
* @param inputString String to be cleaned
* @since 0.0.0
* @returns {String}
*/
var
strClean
=
function
(
inputString
)
{
return
inputString
.
replace
(
/
[^
0-9a-z
]
/gi
,
''
)
}
module
.
exports
.
strClean
=
strClean
/**
* Separate and strip all non alpha numeric characters.
*
* @param rawString String to be split and cleaned
* @param separator Character to be used as the separator (defaults to ',')
* @since 0.0.0
* @returns {Array|String}
*/
var
strSplitClean
=
function
(
rawString
,
separator
)
{
// Validate input for separator
if
(
separator
&&
separator
.
length
!==
1
)
{
throw
'
separator must be a single char
'
}
if
(
!
separator
)
{
separator
=
'
,
'
}
if
(
!
rawString
)
{
return
null
}
var
output
=
[]
rawString
.
split
(
separator
).
forEach
(
function
(
rawSection
)
{
var
nextOutput
=
strClean
(
rawSection
)
if
(
nextOutput
)
{
output
.
push
(
nextOutput
)
}
})
return
output
}
module
.
exports
.
strSplitClean
=
strSplitClean
routes/api/v1.js
View file @
416eed08
...
...
@@ -12,11 +12,13 @@
// Load Environment
var
express
=
require
(
'
express
'
)
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
db
=
require
(
'
models
'
)
// Database Object
var
helpers
=
require
(
path
.
join
(
__dirname
,
'
..
'
,
'
..
'
,
'
helpers
'
))
////////////////////////////////////////////////////////////////////////////////
// JSON API Definitions
...
...
@@ -164,12 +166,7 @@ router.get('/ical/:SCHOOL/:SEMSLUG/:SECTIONS', function (req, res, next) {
// Get Section Information
var
sectionArgs
=
req
.
params
[
'
SECTIONS
'
]
var
semesterSlugs
=
[]
// Parse Section Args
sectionArgs
.
split
(
'
,
'
).
forEach
(
function
(
sectionArg
)
{
semesterSlugs
.
push
(
db
.
sequelize
.
escape
(
sectionArg
))
})
var
semesterSlugs
=
helpers
.
strSplitClean
(
sectionArgs
)
var
sections
=
db
.
Section
.
findAll
({
...
...
@@ -191,8 +188,21 @@ router.get('/ical/:SCHOOL/:SEMSLUG/:SECTIONS', function (req, res, next) {
'
name
'
:
school
.
get
(
'
slug
'
)
+
'
Class Schedule Fall 2016
'
}
)
// Build the rest of the calendar
sections
.
forEach
(
function
(
section
)
{
console
.
log
(
section
.
dataValues
.
name
)
event
=
cal
.
createEvent
({
uid
:
semester
.
dataValues
.
slug
+
'
-
'
+
section
.
dataValues
.
crn
,
start
:
new
Date
(
new
Date
().
getTime
()
+
3600000
),
end
:
new
Date
(
new
Date
().
getTime
()
+
7200000
),
summary
:
'
Example Event
'
,
description
:
'
It works ;)
'
,
organizer
:
'
Organizer
\'
s Name <organizer@example.com>
'
,
url
:
'
http://sebbo.net/
'
});
})
// TODO: build the calendar events
...
...
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