Commit c402270a authored by Mark Stenglein's avatar Mark Stenglein

add standard js linting

parent 657d6281
{
"name": "schedules",
"version": "1.0.0",
"description": "Schedules is a web app that allows students to import their class schedules into popular calendar managers.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git@git.gmu.edu:srct/schedules.git"
},
"author": "GMU Student Run Computing and Technology",
"license": "MIT",
"dependencies": {
}
}
////////////////////////////////////////////////////////////////////////////////
// Mason SRCT: Schedules Application Main File
// - This is the main file for the schedules app, which loads in all of the
// configuration and routing files. Essentially, any other file eventually
// leads here.
// - Take care with this file, it can hurt if you mess it up.
////////////////////////////////////////////////////////////////////////////////
// Load in the different packages
require('app-module-path').addPath(__dirname);
var express = require('express');
var path = require('path');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var Sequelize = require('sequelize');
require('app-module-path').addPath(__dirname)
var express = require('express')
var path = require('path')
var logger = require('morgan')
var cookieParser = require('cookie-parser')
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('./routes/index')
var docs = require('./routes/docs')
var apiV1 = require('./routes/api/v1')
// Instantiate the application
var app = express();
var app = express()
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'pug')
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(logger('dev'))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(cookieParser())
app.use(require('node-sass-middleware')({
src: path.join(__dirname, 'public'),
dest: path.join(__dirname, 'public'),
indentedSyntax: true,
sourceMap: true
}));
app.use(express.static(path.join(__dirname, 'public')));
}))
app.use(express.static(path.join(__dirname, 'public')))
// Initialize the Database and Connection
var db = require(path.join(__dirname, 'models'));
var db = require(path.join(__dirname, 'models'))
db.sequelize.sync({force: true})
// Populate initial data
// TODO: populate the information
// Actually use the loaded routes
// TODO: make this automatic instead of being manually entered
app.use('/', routes);
app.use('/docs', docs);
app.use('/api/v1', apiV1);
app.use('/', routes)
app.use('/docs', docs)
app.use('/api/v1', apiV1)
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
app.use(function (req, res, next) {
var err = new Error('Not Found')
err.status = 404
next(err)
})
// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
app.use(function (err, req, res, next) {
res.status(err.status || 500)
res.render('error', {
message: err.message,
error: err
});
});
})
})
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
app.use(function (err, req, res, next) {
res.status(err.status || 500)
res.render('error', {
message: err.message,
error: {}
});
});
})
})
module.exports = app;
module.exports = app
#!/bin/bash
NPMBIN="$(npm bin)"
$NPMBIN/standard --verbose | $NPMBIN/snazzy
......@@ -17,7 +17,7 @@ general :
sequelize :
dialect : "sqlite"
storage : "./db.development/.sqlite"
storage : "./.devDB/schedules.sqlite"
# Data Sources etc
......
module.exports = function(sequelize, DataTypes) {
return sequelize.define("Section", {
module.exports = function (sequelize, DataTypes) {
return sequelize.define('Section', {
// unique index/key
crn : {
type: DataTypes.STRING,
unique: true
},
crn: {
type: DataTypes.STRING,
unique: true
},
name : DataTypes.STRING,
title : DataTypes.STRING,
section : DataTypes.STRING,
name: DataTypes.STRING,
title: DataTypes.STRING,
section: DataTypes.STRING,
instructor : DataTypes.STRING,
instructor: DataTypes.STRING,
campus : DataTypes.STRING,
location : DataTypes.STRING,
campus: DataTypes.STRING,
location: DataTypes.STRING,
class_type : DataTypes.STRING,
class_type: DataTypes.STRING,
// Start Time Information
startDate : DataTypes.DATE,
endDate : DataTypes.DATE,
Msession : {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
},
MtimeStart : DataTypes.TIME,
MtimeEnd : DataTypes.TIME,
Tsession : {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
},
TtimeStart : DataTypes.TIME,
TtimeEnd : DataTypes.TIME,
Wsession : {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
},
WtimeStart : DataTypes.TIME,
WtimeEnd : DataTypes.TIME,
Rsession : {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
},
RtimeStart : DataTypes.TIME,
RtimeEnd : DataTypes.TIME,
Fsession : {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
},
FtimeStart : DataTypes.TIME,
FtimeEnd : DataTypes.TIME
}, {
validate: {
Msession_validate: function(value) {
if ((Msession === true) &&
(MtimeStart === null || MtimeEnd === null)) {
throw new Error('Start and end times must be defined for' +
' Monday if class is set to true.');
}
},
Tsession_validate: function(value) {
if ((Tsession === true) &&
(TtimeStart === null || TtimeEnd === null)) {
throw new Error('Start and end times must be defined for' +
' Tuesday if class is set to true.');
}
},
Wsession_validate: function(value) {
if ((Wsession === true) &&
(WtimeStart === null || WtimeEnd === null)) {
throw new Error('Start and end times must be defined for' +
' Wednesday if class is set to true.');
}
},
Rsession_validate: function(value) {
if ((Rsession === true) &&
(RtimeStart === null || RtimeEnd === null)) {
throw new Error('Start and end times must be defined for' +
' Thursday if class is set to true.');
}
},
Fsession_validate: function(value) {
if ((Fsession === true) &&
(FtimeStart === null || FtimeEnd === null)) {
throw new Error('Start and end times must be defined for' +
' Friday if class is set to true.');
}
}
startDate: DataTypes.DATE,
endDate: DataTypes.DATE,
Msession: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
},
MtimeStart: DataTypes.TIME,
MtimeEnd: DataTypes.TIME,
Tsession: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
},
TtimeStart: DataTypes.TIME,
TtimeEnd: DataTypes.TIME,
Wsession: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
},
WtimeStart: DataTypes.TIME,
WtimeEnd: DataTypes.TIME,
Rsession: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
},
RtimeStart: DataTypes.TIME,
RtimeEnd: DataTypes.TIME,
Fsession: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
},
FtimeStart: DataTypes.TIME,
FtimeEnd: DataTypes.TIME
}, {
validate: {
Msession_validate: function (value) {
if ((this.Msession === true) &&
(this.MtimeStart === null || this.MtimeEnd === null)) {
throw new Error('Start and end times must be defined for' +
' Monday if class is set to true.')
}
}, {
indexes: [
{
unique: true,
fields: ['crn']
},
{
unique: false,
fields: ['instructor']
},
{
unique: false,
fields: ['campus']
},
{
unique: false,
fields: ['location']
},
{
unique: false,
fields: ['title']
}
]
})
},
Tsession_validate: function (value) {
if ((this.Tsession === true) &&
(this.TtimeStart === null || this.TtimeEnd === null)) {
throw new Error('Start and end times must be defined for' +
' Tuesday if class is set to true.')
}
},
Wsession_validate: function (value) {
if ((this.Wsession === true) &&
(this.WtimeStart === null || this.WtimeEnd === null)) {
throw new Error('Start and end times must be defined for' +
' Wednesday if class is set to true.')
}
},
Rsession_validate: function (value) {
if ((this.Rsession === true) &&
(this.RtimeStart === null || this.RtimeEnd === null)) {
throw new Error('Start and end times must be defined for' +
' Thursday if class is set to true.')
}
},
Fsession_validate: function (value) {
if ((this.Fsession === true) &&
(this.FtimeStart === null || this.FtimeEnd === null)) {
throw new Error('Start and end times must be defined for' +
' Friday if class is set to true.')
}
}
}
}, {
indexes: [
{
unique: true,
fields: ['crn']
},
{
unique: false,
fields: ['instructor']
},
{
unique: false,
fields: ['campus']
},
{
unique: false,
fields: ['location']
},
{
unique: false,
fields: ['title']
}
]
})
}
module.exports = function(sequelize, DataTypes) {
var Semester = sequelize.define("Semester", {
slug: {
type: DataTypes.STRING,
unique: true
},
module.exports = function (sequelize, DataTypes) {
var Semester = sequelize.define('Semester', {
slug: {
type: DataTypes.STRING,
unique: true
},
name: DataTypes.STRING,
name: DataTypes.STRING,
universitySlug: {
type: DataTypes.STRING
//references: {
universitySlug: {
type: DataTypes.STRING
// references: {
// model: University,
// key: slug
//}
}
}, {
classMethods: {
associate: function(models) {
Semester.belongsTo(models.University, { foreignKey: 'slug' } );
}
}
});
// }
}
}, {
classMethods: {
associate: function (models) {
Semester.belongsTo(models.University, { foreignKey: 'slug' })
}
}
})
return Semester;
return Semester
}
module.exports = function(sequelize, DataTypes) {
var University = sequelize.define("University", {
slug: {
type: DataTypes.STRING,
allowNull: false,
unique: true
},
module.exports = function (sequelize, DataTypes) {
var University = sequelize.define('University', {
slug: {
type: DataTypes.STRING,
allowNull: false,
unique: true
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
name: {
type: DataTypes.STRING,
allowNull: false
},
website: {
type: DataTypes.STRING,
allowNull: false
}
}, {
classMethods: {
associate: function(models) {
University.hasMany(models.Semester, { foreignKey: 'slug' } );
}
}
});
website: {
type: DataTypes.STRING,
allowNull: false
}
}, {
classMethods: {
associate: function (models) {
University.hasMany(models.Semester, { foreignKey: 'slug' })
}
}
})
return University;
return University
}
var fs = require('fs');
var path = require('path');
var Sequelize = require('sequelize');
var config = require('config');
var path = require('path')
var Sequelize = require('sequelize')
var config = require('config')
// get configuration for sequelize
// worth noting that this changes depending on the environment
var sequelizeConf = config.get('sequelize');
var sequelizeConf = config.get('sequelize')
// make the new connection
var sequelize = new Sequelize(sequelizeConf);
var sequelize = new Sequelize(sequelizeConf)
// empty variable to load entire database into
var db = {};
var db = {}
var modelNames = [
'Section',
'Semester',
'University'
'Section',
'Semester',
'University'
]
// this section load every model file in the `models` dir into the database
modelNames.forEach(function(modelName) {
var model = sequelize.import(path.join(__dirname, modelName));
db[model.name] = model;
});
modelNames.forEach(function (modelName) {
var model = sequelize.import(path.join(__dirname, modelName))
db[model.name] = model
})
// TODO: figure out exactly what this is doing
Object.keys(db).forEach(function(modelName) {
if ("associate" in db[modelName]) {
db[modelName].associate(db);
}
Object.keys(db).forEach(function (modelName) {
if ('associate' in db[modelName]) {
db[modelName].associate(db)
}
})
// add the configs and module to the `db` object
db.sequelize = sequelize;
db.Sequelize = Sequelize;
db.sequelize = sequelize
db.Sequelize = Sequelize
// return the finished database object to the calling module
module.exports = db;
module.exports = db
......@@ -3,7 +3,8 @@
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
"start": "node ./bin/www",
"test": "./bin/lint"
},
"dependencies": {
"app-module-path": "^2.1.0",
......@@ -26,6 +27,15 @@
"chai": "^3.5.0",
"mocha": "^3.0.2",
"mockery": "^1.7.0",
"sinon": "^1.17.6"
"sinon": "^1.17.6",
"snazzy": "^5.0.0",
"standard": "^8.5.0"
},
"standard": {
"ignore": [
"/public/javascripts/bootstrap.js",
"/public/javascripts/bootstrap/",
"/public/javascripts/fontawesome.js"
]
}
}
/* globals $ Option */
// Expose the school data globally.
var schoolData = {};
// var schoolData = {}
// Expose the semester data globally
var semesterData = {};
var semesterData = {}
$(document).ready(function() {
$(document).ready(function () {
// Convert table to DataTable
$('#classSearch').DataTable();
$('#classSearch').DataTable()
// Get schoolData and populate the selection menus
$.getJSON('/api/v1/json/schools', function(schoolSlugs) {
semesterData = schoolSlugs;
populateBoxes();
});
$('#selectSchool').change(function() {
populateSemesterSelect();
});
} );
function populateBoxes() {
var schoolSelect = document.getElementById('selectSchool');
for (i = 0; i < semesterData.schools.length; i++) {
var schoolName = semesterData[semesterData.schools[i]];
schoolSelect.add(new Option(schoolName.longName, i));
$.getJSON('/api/v1/json/schools', function (schoolSlugs) {
semesterData = schoolSlugs
populateBoxes()
})
$('#selectSchool').change(function () {
populateSemesterSelect()
})
})
function populateBoxes () {
var schoolSelect = document.getElementById('selectSchool')
for (var i = 0; i < semesterData.schools.length; i++) {
var schoolName = semesterData[semesterData.schools[i]]
schoolSelect.add(new Option(schoolName.longName, i))
}
populateSemesterSelect();
populateSemesterSelect()
}
function populateSemesterSelect() {
var schoolSelect = $('#selectSchool');
var selectSemester = document.getElementById('selectSemester');
function populateSemesterSelect () {
// var schoolSelect = $('#selectSchool')
var selectSemester = document.getElementById('selectSemester')
// Clear Select Semester
selectSemester.innerHTML = "";
selectSemester.innerHTML = ''
var schoolID = $('#selectSchool option:selected').val();
var schoolSlug = semesterData.schools[schoolID];
var school = semesterData[schoolSlug];
var schoolID = $('#selectSchool option:selected').val()
var schoolSlug = semesterData.schools[schoolID]
var school = semesterData[schoolSlug]
for (i = 0; i < school.semesters.length; i++) {
var semesterName = school.semesters[i];
selectSemester.add(new Option(semesterName.longName, i));
for (var i = 0; i < school.semesters.length; i++) {
var semesterName = school.semesters[i]
selectSemester.add(new Option(semesterName.longName, i))
}
}
////////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////
// Mason SRCT: Schedules API v1
// - This API supports the Schedules project at schedules.gmu.edu as the backend
// data source for the application sent on the front end.
////////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////////
var express = require('express');
var router = express.Router();
var Semester = require('../../models/Semester');
var ical = require('ical-generator');
var db = require('models');
var config = require('config');
var express = require('express')
var router = express.Router()
// var Semester = require('../../models/Semester')
var ical = require('ical-generator')
// var db = require('models')
var config = require('config')