Commit 416eed08 authored by Mark Stenglein's avatar Mark Stenglein

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
......@@ -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()
......
/*
* 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
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment