Streak display in account/show.jade, refactor courseware.json for error handling and linting
This commit is contained in:
6
app.js
6
app.js
@ -39,8 +39,6 @@ var express = require('express'),
|
||||
resourcesController = require('./controllers/resources'),
|
||||
userController = require('./controllers/user'),
|
||||
contactController = require('./controllers/contact'),
|
||||
ziplineController = require('./controllers/ziplines'),
|
||||
basejumpController = require('./controllers/basejumps'),
|
||||
nonprofitController = require('./controllers/nonprofits'),
|
||||
bonfireController = require('./controllers/bonfire'),
|
||||
coursewareController = require('./controllers/courseware'),
|
||||
@ -48,7 +46,7 @@ var express = require('express'),
|
||||
/**
|
||||
* Stories
|
||||
*/
|
||||
storyController = require('./controllers/story');
|
||||
storyController = require('./controllers/story'),
|
||||
|
||||
/**
|
||||
* API keys and Passport configuration.
|
||||
@ -398,8 +396,6 @@ app.post(
|
||||
app.all('/account', passportConf.isAuthenticated);
|
||||
app.get('/account/api', userController.getAccountAngular);
|
||||
|
||||
app.get('/user/streak', userController.getStreak);
|
||||
|
||||
/**
|
||||
* API routes
|
||||
*/
|
||||
|
@ -1,142 +1,145 @@
|
||||
var _ = require('lodash'),
|
||||
debug = require('debug')('freecc:cntr:bonfires'),
|
||||
Bonfire = require('./../models/Bonfire'),
|
||||
User = require('./../models/User'),
|
||||
resources = require('./resources'),
|
||||
R = require('ramda');
|
||||
debug = require('debug')('freecc:cntr:bonfires'),
|
||||
Bonfire = require('./../models/Bonfire'),
|
||||
User = require('./../models/User'),
|
||||
resources = require('./resources'),
|
||||
R = require('ramda');
|
||||
|
||||
/**
|
||||
* Bonfire controller
|
||||
*/
|
||||
|
||||
exports.showAllBonfires = function(req, res) {
|
||||
var completedBonfires = req.user.completedBonfires.map(function(elem) {
|
||||
return elem._id;
|
||||
});
|
||||
var completedBonfires = req.user.completedBonfires.map(function(elem) {
|
||||
return elem._id;
|
||||
});
|
||||
|
||||
var noDuplicateBonfires = R.uniq(completedBonfires);
|
||||
var data = {};
|
||||
data.bonfireList = resources.allBonfireNames();
|
||||
data.completedList = noDuplicateBonfires;
|
||||
res.send(data);
|
||||
var noDuplicateBonfires = R.uniq(completedBonfires);
|
||||
var data = {};
|
||||
data.bonfireList = resources.allBonfireNames();
|
||||
data.completedList = noDuplicateBonfires;
|
||||
res.send(data);
|
||||
};
|
||||
|
||||
exports.index = function(req, res) {
|
||||
res.render('bonfire/show.jade', {
|
||||
completedWith: null,
|
||||
title: 'Bonfire Playground',
|
||||
name: 'Bonfire Playground',
|
||||
difficulty: 0,
|
||||
brief: 'Feel free to play around!',
|
||||
details: '',
|
||||
tests: [],
|
||||
challengeSeed: '',
|
||||
cc: req.user ? req.user.bonfiresHash : undefined,
|
||||
progressTimestamps: req.user ? req.user.progressTimestamps : undefined,
|
||||
verb: resources.randomVerb(),
|
||||
phrase: resources.randomPhrase(),
|
||||
compliments: resources.randomCompliment(),
|
||||
bonfires: [],
|
||||
bonfireHash: 'test'
|
||||
res.render('bonfire/show.jade', {
|
||||
completedWith: null,
|
||||
title: 'Bonfire Playground',
|
||||
name: 'Bonfire Playground',
|
||||
difficulty: 0,
|
||||
brief: 'Feel free to play around!',
|
||||
details: '',
|
||||
tests: [],
|
||||
challengeSeed: '',
|
||||
cc: req.user ? req.user.bonfiresHash : undefined,
|
||||
progressTimestamps: req.user ? req.user.progressTimestamps : undefined,
|
||||
verb: resources.randomVerb(),
|
||||
phrase: resources.randomPhrase(),
|
||||
compliments: resources.randomCompliment(),
|
||||
bonfires: [],
|
||||
bonfireHash: 'test'
|
||||
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports.returnNextBonfire = function(req, res) {
|
||||
if (!req.user) {
|
||||
return res.redirect('../bonfires/meet-bonfire');
|
||||
exports.returnNextBonfire = function(req, res, next) {
|
||||
if (!req.user) {
|
||||
return res.redirect('../bonfires/meet-bonfire');
|
||||
}
|
||||
var completed = req.user.completedBonfires.map(function (elem) {
|
||||
return elem._id;
|
||||
});
|
||||
|
||||
req.user.uncompletedBonfires = resources.allBonfireIds().filter(function (elem) {
|
||||
if (completed.indexOf(elem) === -1) {
|
||||
return elem;
|
||||
}
|
||||
var completed = req.user.completedBonfires.map(function (elem) {
|
||||
return elem._id;
|
||||
});
|
||||
});
|
||||
req.user.save();
|
||||
|
||||
req.user.uncompletedBonfires = resources.allBonfireIds().filter(function (elem) {
|
||||
if (completed.indexOf(elem) === -1) {
|
||||
return elem;
|
||||
}
|
||||
});
|
||||
req.user.save();
|
||||
var uncompletedBonfires = req.user.uncompletedBonfires;
|
||||
|
||||
var uncompletedBonfires = req.user.uncompletedBonfires;
|
||||
|
||||
var displayedBonfires = Bonfire.find({'_id': uncompletedBonfires[0]});
|
||||
displayedBonfires.exec(function(err, bonfire) {
|
||||
if (err) {
|
||||
next(err);
|
||||
}
|
||||
bonfire = bonfire.pop();
|
||||
if (bonfire === undefined) {
|
||||
req.flash('errors', {
|
||||
msg: "It looks like you've completed all the bonfires we have available. Good job!"
|
||||
});
|
||||
return res.redirect('../bonfires/meet-bonfire');
|
||||
}
|
||||
nameString = bonfire.name.toLowerCase().replace(/\s/g, '-');
|
||||
return res.redirect('../bonfires/' + nameString);
|
||||
});
|
||||
var displayedBonfires = Bonfire.find({'_id': uncompletedBonfires[0]});
|
||||
displayedBonfires.exec(function(err, bonfire) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
bonfire = bonfire.pop();
|
||||
if (bonfire === undefined) {
|
||||
req.flash('errors', {
|
||||
msg: "It looks like you've completed all the bonfires we have available. Good job!"
|
||||
});
|
||||
return res.redirect('../bonfires/meet-bonfire');
|
||||
}
|
||||
var nameString = bonfire.name.toLowerCase().replace(/\s/g, '-');
|
||||
return res.redirect('../bonfires/' + nameString);
|
||||
});
|
||||
};
|
||||
|
||||
exports.returnIndividualBonfire = function(req, res, next) {
|
||||
var dashedName = req.params.bonfireName;
|
||||
var dashedName = req.params.bonfireName;
|
||||
|
||||
bonfireName = dashedName.replace(/\-/g, ' ');
|
||||
var bonfireName = dashedName.replace(/\-/g, ' ');
|
||||
|
||||
Bonfire.find({"name" : new RegExp(bonfireName, 'i')}, function(err, bonfire) {
|
||||
if (err) {
|
||||
next(err);
|
||||
}
|
||||
Bonfire.find({'name': new RegExp(bonfireName, 'i')}, function(err, bonfire) {
|
||||
if (err) {
|
||||
next(err);
|
||||
}
|
||||
|
||||
|
||||
if (bonfire.length < 1) {
|
||||
req.flash('errors', {
|
||||
msg: "404: We couldn't find a bonfire with that name. Please double check the name."
|
||||
});
|
||||
if (bonfire.length < 1) {
|
||||
req.flash('errors', {
|
||||
msg: "404: We couldn't find a bonfire with that name. Please double check the name."
|
||||
});
|
||||
|
||||
return res.redirect('/bonfires');
|
||||
}
|
||||
return res.redirect('/bonfires');
|
||||
}
|
||||
|
||||
bonfire = bonfire.pop();
|
||||
var dashedNameFull = bonfire.name.toLowerCase().replace(/\s/g, '-');
|
||||
if (dashedNameFull != dashedName) {
|
||||
return res.redirect('../bonfires/' + dashedNameFull);
|
||||
}
|
||||
bonfire = bonfire.pop();
|
||||
var dashedNameFull = bonfire.name.toLowerCase().replace(/\s/g, '-');
|
||||
if (dashedNameFull != dashedName) {
|
||||
return res.redirect('../bonfires/' + dashedNameFull);
|
||||
}
|
||||
|
||||
res.render('bonfire/show', {
|
||||
completedWith: null,
|
||||
title: bonfire.name,
|
||||
dashedName: dashedName,
|
||||
name: bonfire.name,
|
||||
difficulty: Math.floor(+bonfire.difficulty),
|
||||
brief: bonfire.description[0],
|
||||
details: bonfire.description.slice(1),
|
||||
tests: bonfire.tests,
|
||||
challengeSeed: bonfire.challengeSeed,
|
||||
cc: !!req.user,
|
||||
progressTimestamps: req.user ? req.user.progressTimestamps : undefined,
|
||||
verb: resources.randomVerb(),
|
||||
phrase: resources.randomPhrase(),
|
||||
compliment: resources.randomCompliment(),
|
||||
bonfires: bonfire,
|
||||
bonfireHash: bonfire._id
|
||||
|
||||
});
|
||||
res.render('bonfire/show', {
|
||||
completedWith: null,
|
||||
title: bonfire.name,
|
||||
dashedName: dashedName,
|
||||
name: bonfire.name,
|
||||
difficulty: Math.floor(+bonfire.difficulty),
|
||||
brief: bonfire.description[0],
|
||||
details: bonfire.description.slice(1),
|
||||
tests: bonfire.tests,
|
||||
challengeSeed: bonfire.challengeSeed,
|
||||
cc: !!req.user,
|
||||
progressTimestamps: req.user ? req.user.progressTimestamps : undefined,
|
||||
verb: resources.randomVerb(),
|
||||
phrase: resources.randomPhrase(),
|
||||
compliment: resources.randomCompliment(),
|
||||
bonfires: bonfire,
|
||||
bonfireHash: bonfire._id
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Bonfire generator
|
||||
* Bonfire Generator
|
||||
* @param req Request Object
|
||||
* @param res Response Object
|
||||
* @returns void
|
||||
*/
|
||||
|
||||
exports.returnGenerator = function(req, res) {
|
||||
res.render('bonfire/generator', {
|
||||
title: null,
|
||||
name: null,
|
||||
difficulty: null,
|
||||
brief: null,
|
||||
details: null,
|
||||
tests: null,
|
||||
challengeSeed: null,
|
||||
bonfireHash: randomString()
|
||||
});
|
||||
res.render('bonfire/generator', {
|
||||
title: null,
|
||||
name: null,
|
||||
difficulty: null,
|
||||
brief: null,
|
||||
details: null,
|
||||
tests: null,
|
||||
challengeSeed: null,
|
||||
bonfireHash: randomString()
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
@ -144,162 +147,164 @@ exports.returnGenerator = function(req, res) {
|
||||
*/
|
||||
|
||||
function randomString() {
|
||||
var chars = "0123456789abcdef";
|
||||
var string_length = 23;
|
||||
var randomstring = 'a';
|
||||
for (var i=0; i<string_length; i++) {
|
||||
var rnum = Math.floor(Math.random() * chars.length);
|
||||
randomstring += chars.substring(rnum,rnum+1);
|
||||
}
|
||||
return randomstring;
|
||||
};
|
||||
var chars = '0123456789abcdef';
|
||||
var string_length = 23;
|
||||
var randomstring = 'a';
|
||||
for (var i = 0; i < string_length; i++) {
|
||||
var rnum = Math.floor(Math.random() * chars.length);
|
||||
randomstring += chars.substring(rnum, rnum + 1);
|
||||
}
|
||||
return randomstring;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
exports.testBonfire = function(req, res) {
|
||||
var bonfireName = req.body.name,
|
||||
bonfireTests = req.body.tests,
|
||||
bonfireDifficulty = req.body.difficulty,
|
||||
bonfireDescription = req.body.description,
|
||||
bonfireChallengeSeed = req.body.challengeSeed;
|
||||
bonfireTests = bonfireTests.split('\r\n');
|
||||
bonfireDescription = bonfireDescription.split('\r\n');
|
||||
bonfireTests.filter(getRidOfEmpties);
|
||||
bonfireDescription.filter(getRidOfEmpties);
|
||||
bonfireChallengeSeed = bonfireChallengeSeed.replace('\r', '');
|
||||
res.render('bonfire/show', {
|
||||
completedWith: null,
|
||||
title: bonfireName,
|
||||
name: bonfireName,
|
||||
difficulty: +bonfireDifficulty,
|
||||
brief: bonfireDescription[0],
|
||||
details: bonfireDescription.slice(1),
|
||||
tests: bonfireTests,
|
||||
challengeSeed: bonfireChallengeSeed,
|
||||
cc: req.user ? req.user.bonfiresHash : undefined,
|
||||
progressTimestamps: req.user ? req.user.progressTimestamps : undefined,
|
||||
verb: resources.randomVerb(),
|
||||
phrase: resources.randomPhrase(),
|
||||
compliment: resources.randomCompliment(),
|
||||
bonfires: [],
|
||||
bonfireHash: "test"
|
||||
});
|
||||
var bonfireName = req.body.name,
|
||||
bonfireTests = req.body.tests,
|
||||
bonfireDifficulty = req.body.difficulty,
|
||||
bonfireDescription = req.body.description,
|
||||
bonfireChallengeSeed = req.body.challengeSeed;
|
||||
bonfireTests = bonfireTests.split('\r\n');
|
||||
bonfireDescription = bonfireDescription.split('\r\n');
|
||||
bonfireTests.filter(getRidOfEmpties);
|
||||
bonfireDescription.filter(getRidOfEmpties);
|
||||
bonfireChallengeSeed = bonfireChallengeSeed.replace('\r', '');
|
||||
|
||||
res.render('bonfire/show', {
|
||||
completedWith: null,
|
||||
title: bonfireName,
|
||||
name: bonfireName,
|
||||
difficulty: +bonfireDifficulty,
|
||||
brief: bonfireDescription[0],
|
||||
details: bonfireDescription.slice(1),
|
||||
tests: bonfireTests,
|
||||
challengeSeed: bonfireChallengeSeed,
|
||||
cc: req.user ? req.user.bonfiresHash : undefined,
|
||||
progressTimestamps: req.user ? req.user.progressTimestamps : undefined,
|
||||
verb: resources.randomVerb(),
|
||||
phrase: resources.randomPhrase(),
|
||||
compliment: resources.randomCompliment(),
|
||||
bonfires: [],
|
||||
bonfireHash: 'test'
|
||||
});
|
||||
};
|
||||
|
||||
function getRidOfEmpties(elem) {
|
||||
if (elem.length > 0) {
|
||||
return elem;
|
||||
}
|
||||
};
|
||||
if (elem.length > 0) {
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
|
||||
exports.publicGenerator = function(req, res) {
|
||||
res.render('bonfire/public-generator');
|
||||
res.render('bonfire/public-generator');
|
||||
};
|
||||
|
||||
exports.generateChallenge = function(req, res) {
|
||||
var bonfireName = req.body.name,
|
||||
bonfireTests = req.body.tests,
|
||||
bonfireDifficulty = req.body.difficulty,
|
||||
bonfireDescription = req.body.description,
|
||||
bonfireChallengeSeed = req.body.challengeSeed;
|
||||
bonfireTests = bonfireTests.split('\r\n');
|
||||
bonfireDescription = bonfireDescription.split('\r\n');
|
||||
bonfireTests.filter(getRidOfEmpties);
|
||||
bonfireDescription.filter(getRidOfEmpties);
|
||||
bonfireChallengeSeed = bonfireChallengeSeed.replace('\r', '');
|
||||
var bonfireName = req.body.name,
|
||||
bonfireTests = req.body.tests,
|
||||
bonfireDifficulty = req.body.difficulty,
|
||||
bonfireDescription = req.body.description,
|
||||
bonfireChallengeSeed = req.body.challengeSeed;
|
||||
bonfireTests = bonfireTests.split('\r\n');
|
||||
bonfireDescription = bonfireDescription.split('\r\n');
|
||||
bonfireTests.filter(getRidOfEmpties);
|
||||
bonfireDescription.filter(getRidOfEmpties);
|
||||
bonfireChallengeSeed = bonfireChallengeSeed.replace('\r', '');
|
||||
|
||||
|
||||
var response = {
|
||||
_id: randomString(),
|
||||
name: bonfireName,
|
||||
difficulty: bonfireDifficulty,
|
||||
description: bonfireDescription,
|
||||
challengeSeed: bonfireChallengeSeed,
|
||||
tests: bonfireTests
|
||||
};
|
||||
res.send(response);
|
||||
var response = {
|
||||
_id: randomString(),
|
||||
name: bonfireName,
|
||||
difficulty: bonfireDifficulty,
|
||||
description: bonfireDescription,
|
||||
challengeSeed: bonfireChallengeSeed,
|
||||
tests: bonfireTests
|
||||
};
|
||||
res.send(response);
|
||||
};
|
||||
|
||||
exports.completedBonfire = function (req, res) {
|
||||
var isCompletedWith = req.body.bonfireInfo.completedWith || undefined;
|
||||
var isCompletedDate = Math.round(+new Date());
|
||||
var bonfireHash = req.body.bonfireInfo.bonfireHash;
|
||||
var isSolution = req.body.bonfireInfo.solution;
|
||||
|
||||
if (isCompletedWith) {
|
||||
var paired = User.find({"profile.username": isCompletedbWith.toLowerCase()}).limit(1);
|
||||
paired.exec(function (err, pairedWith) {
|
||||
if (err) {
|
||||
return err;
|
||||
} else {
|
||||
var index = req.user.uncompletedBonfires.indexOf(bonfireHash);
|
||||
if (index > -1) {
|
||||
|
||||
req.user.progressTimestamps.push(Date.now() || 0);
|
||||
req.user.uncompletedBonfires.splice(index, 1)
|
||||
}
|
||||
pairedWith = pairedWith.pop();
|
||||
|
||||
index = pairedWith.uncompletedBonfires.indexOf(bonfireHash);
|
||||
if (index > -1) {
|
||||
|
||||
pairedWith.progressTimestamps.push(Date.now() || 0);
|
||||
pairedWith.uncompletedBonfires.splice(index, 1);
|
||||
|
||||
}
|
||||
|
||||
pairedWith.completedBonfires.push({
|
||||
_id: bonfireHash,
|
||||
completedWith: req.user._id,
|
||||
completedDate: isCompletedDate,
|
||||
solution: isSolution
|
||||
});
|
||||
|
||||
req.user.completedBonfires.push({
|
||||
_id: bonfireHash,
|
||||
completedWith: pairedWith._id,
|
||||
completedDate: isCompletedDate,
|
||||
solution: isSolution
|
||||
});
|
||||
|
||||
req.user.save(function (err, user) {
|
||||
pairedWith.save(function (err, paired) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
if (user && paired) {
|
||||
res.send(true);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
})
|
||||
} else {
|
||||
|
||||
req.user.completedBonfires.push({
|
||||
_id: bonfireHash,
|
||||
completedWith: null,
|
||||
completedDate: isCompletedDate,
|
||||
solution: isSolution
|
||||
});
|
||||
exports.completedBonfire = function (req, res, next) {
|
||||
var isCompletedWith = req.body.bonfireInfo.completedWith || '';
|
||||
var isCompletedDate = Math.round(+new Date());
|
||||
var bonfireHash = req.body.bonfireInfo.bonfireHash;
|
||||
var isSolution = req.body.bonfireInfo.solution;
|
||||
|
||||
if (isCompletedWith) {
|
||||
var paired = User.find({'profile.username': isCompletedWith
|
||||
.toLowerCase()}).limit(1);
|
||||
paired.exec(function (err, pairedWith) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
} else {
|
||||
var index = req.user.uncompletedBonfires.indexOf(bonfireHash);
|
||||
if (index > -1) {
|
||||
req.user.progressTimestamps.push(Date.now() || 0);
|
||||
req.user.uncompletedBonfires.splice(index, 1);
|
||||
}
|
||||
pairedWith = pairedWith.pop();
|
||||
|
||||
index = pairedWith.uncompletedBonfires.indexOf(bonfireHash);
|
||||
if (index > -1) {
|
||||
pairedWith.progressTimestamps.push(Date.now() || 0);
|
||||
pairedWith.uncompletedBonfires.splice(index, 1);
|
||||
|
||||
req.user.progressTimestamps.push(Date.now() || 0);
|
||||
req.user.uncompletedBonfires.splice(index, 1)
|
||||
}
|
||||
|
||||
req.user.save(function (err, user) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
if (user) {
|
||||
debug('Saving user');
|
||||
res.send(true)
|
||||
}
|
||||
pairedWith.completedBonfires.push({
|
||||
_id: bonfireHash,
|
||||
completedWith: req.user._id,
|
||||
completedDate: isCompletedDate,
|
||||
solution: isSolution
|
||||
});
|
||||
|
||||
req.user.completedBonfires.push({
|
||||
_id: bonfireHash,
|
||||
completedWith: pairedWith._id,
|
||||
completedDate: isCompletedDate,
|
||||
solution: isSolution
|
||||
});
|
||||
|
||||
req.user.save(function (err, user) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
pairedWith.save(function (err, paired) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
if (user && paired) {
|
||||
res.send(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
req.user.completedBonfires.push({
|
||||
_id: bonfireHash,
|
||||
completedWith: null,
|
||||
completedDate: isCompletedDate,
|
||||
solution: isSolution
|
||||
});
|
||||
|
||||
var index = req.user.uncompletedBonfires.indexOf(bonfireHash);
|
||||
if (index > -1) {
|
||||
|
||||
req.user.progressTimestamps.push(Date.now() || 0);
|
||||
req.user.uncompletedBonfires.splice(index, 1);
|
||||
}
|
||||
|
||||
req.user.save(function (err, user) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
if (user) {
|
||||
debug('Saving user');
|
||||
res.send(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
@ -1,10 +1,10 @@
|
||||
var _ = require('lodash'),
|
||||
debug = require('debug')('freecc:cntr:courseware'),
|
||||
Courseware = require('./../models/Courseware'),
|
||||
User = require('./../models/User'),
|
||||
resources = require('./resources'),
|
||||
R = require('ramda'),
|
||||
moment = require('moment');
|
||||
debug = require('debug')('freecc:cntr:courseware'),
|
||||
Courseware = require('./../models/Courseware'),
|
||||
User = require('./../models/User'),
|
||||
resources = require('./resources'),
|
||||
R = require('ramda'),
|
||||
moment = require('moment');
|
||||
|
||||
/**
|
||||
* Courseware controller
|
||||
@ -22,7 +22,7 @@ exports.showAllCoursewares = function(req, res) {
|
||||
res.send(data);
|
||||
};
|
||||
|
||||
exports.returnNextCourseware = function(req, res) {
|
||||
exports.returnNextCourseware = function(req, res, next) {
|
||||
if (!req.user) {
|
||||
return res.redirect('../challenges/learn-how-free-code-camp-works');
|
||||
}
|
||||
@ -30,7 +30,8 @@ exports.returnNextCourseware = function(req, res) {
|
||||
return elem._id;
|
||||
});
|
||||
|
||||
req.user.uncompletedCoursewares = resources.allCoursewareIds().filter(function (elem) {
|
||||
req.user.uncompletedCoursewares = resources.allCoursewareIds()
|
||||
.filter(function (elem) {
|
||||
if (completed.indexOf(elem) === -1) {
|
||||
return elem;
|
||||
}
|
||||
@ -40,16 +41,17 @@ exports.returnNextCourseware = function(req, res) {
|
||||
var uncompletedCoursewares = req.user.uncompletedCoursewares.shift();
|
||||
|
||||
|
||||
var displayedCoursewares = Courseware.find({'_id': uncompletedCoursewares});
|
||||
var displayedCoursewares = Courseware.find({'_id': uncompletedCoursewares});
|
||||
displayedCoursewares.exec(function(err, courseware) {
|
||||
if (err) {
|
||||
next(err);
|
||||
return next(err);
|
||||
}
|
||||
|
||||
courseware = courseware.pop();
|
||||
if (courseware === undefined) {
|
||||
req.flash('errors', {
|
||||
msg: "It looks like you've completed all the courses we have available. Good job!"
|
||||
msg: "It looks like you've completed all the courses we have " +
|
||||
"available. Good job!"
|
||||
});
|
||||
return res.redirect('../challenges/learn-how-free-code-camp-works');
|
||||
}
|
||||
@ -61,16 +63,18 @@ exports.returnNextCourseware = function(req, res) {
|
||||
exports.returnIndividualCourseware = function(req, res, next) {
|
||||
var dashedName = req.params.coursewareName;
|
||||
|
||||
coursewareName = dashedName.replace(/\-/g, ' ');
|
||||
var coursewareName = dashedName.replace(/\-/g, ' ');
|
||||
|
||||
Courseware.find({"name" : new RegExp(coursewareName, 'i')}, function(err, courseware) {
|
||||
Courseware.find({'name': new RegExp(coursewareName, 'i')},
|
||||
function(err, courseware) {
|
||||
if (err) {
|
||||
next(err);
|
||||
}
|
||||
// Handle not found
|
||||
if (courseware.length < 1) {
|
||||
req.flash('errors', {
|
||||
msg: "404: We couldn't find a challenge with that name. Please double check the name."
|
||||
msg: "404: We couldn't find a challenge with that name. " +
|
||||
"Please double check the name."
|
||||
});
|
||||
return res.redirect('/challenges');
|
||||
}
|
||||
@ -83,7 +87,7 @@ exports.returnIndividualCourseware = function(req, res, next) {
|
||||
}
|
||||
|
||||
var challengeType = {
|
||||
0 : function() {
|
||||
0: function() {
|
||||
res.render('coursewares/showHTML', {
|
||||
title: courseware.name,
|
||||
dashedName: dashedName,
|
||||
@ -100,7 +104,7 @@ exports.returnIndividualCourseware = function(req, res, next) {
|
||||
});
|
||||
},
|
||||
|
||||
1 : function() {
|
||||
1: function() {
|
||||
res.render('coursewares/showJS', {
|
||||
title: courseware.name,
|
||||
dashedName: dashedName,
|
||||
@ -134,7 +138,7 @@ exports.returnIndividualCourseware = function(req, res, next) {
|
||||
},
|
||||
|
||||
3: function() {
|
||||
res.render('coursewares/showVideo', {
|
||||
res.render('coursewares/showZipline', {
|
||||
title: courseware.name,
|
||||
dashedName: dashedName,
|
||||
name: courseware.name,
|
||||
@ -150,7 +154,7 @@ exports.returnIndividualCourseware = function(req, res, next) {
|
||||
},
|
||||
|
||||
4: function() {
|
||||
res.render('coursewares/showVideo', {
|
||||
res.render('coursewares/showBasejump', {
|
||||
title: courseware.name,
|
||||
dashedName: dashedName,
|
||||
name: courseware.name,
|
||||
@ -173,11 +177,11 @@ exports.returnIndividualCourseware = function(req, res, next) {
|
||||
|
||||
exports.testCourseware = function(req, res) {
|
||||
var coursewareName = req.body.name,
|
||||
coursewareTests = req.body.tests,
|
||||
coursewareDifficulty = req.body.difficulty,
|
||||
coursewareDescription = req.body.description,
|
||||
coursewareEntryPoint = req.body.challengeEntryPoint,
|
||||
coursewareChallengeSeed = req.body.challengeSeed;
|
||||
coursewareTests = req.body.tests,
|
||||
coursewareDifficulty = req.body.difficulty,
|
||||
coursewareDescription = req.body.description,
|
||||
coursewareEntryPoint = req.body.challengeEntryPoint,
|
||||
coursewareChallengeSeed = req.body.challengeSeed;
|
||||
coursewareTests = coursewareTests.split('\r\n');
|
||||
coursewareDescription = coursewareDescription.split('\r\n');
|
||||
coursewareTests.filter(getRidOfEmpties);
|
||||
@ -190,8 +194,8 @@ exports.testCourseware = function(req, res) {
|
||||
difficulty: +coursewareDifficulty,
|
||||
brief: coursewareDescription[0],
|
||||
details: coursewareDescription.slice(1),
|
||||
tests: coursewareTests,
|
||||
challengeSeed: coursewareChallengeSeed,
|
||||
tests: coursewareTests,
|
||||
challengeSeed: coursewareChallengeSeed,
|
||||
challengeEntryPoint: coursewareEntryPoint,
|
||||
cc: req.user ? req.user.coursewaresHash : undefined,
|
||||
progressTimestamps: req.user ? req.user.progressTimestamps : undefined,
|
||||
@ -199,7 +203,7 @@ exports.testCourseware = function(req, res) {
|
||||
phrase: resources.randomPhrase(),
|
||||
compliment: resources.randomCompliment(),
|
||||
coursewares: [],
|
||||
coursewareHash: "test"
|
||||
coursewareHash: 'test'
|
||||
});
|
||||
};
|
||||
|
||||
@ -207,7 +211,7 @@ function getRidOfEmpties(elem) {
|
||||
if (elem.length > 0) {
|
||||
return elem;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.publicGenerator = function(req, res) {
|
||||
res.render('courseware/public-generator');
|
||||
@ -215,11 +219,11 @@ exports.publicGenerator = function(req, res) {
|
||||
|
||||
exports.generateChallenge = function(req, res) {
|
||||
var coursewareName = req.body.name,
|
||||
coursewareTests = req.body.tests,
|
||||
coursewareDifficulty = req.body.difficulty,
|
||||
coursewareDescription = req.body.description,
|
||||
coursewareEntryPoint = req.body.challengeEntryPoint,
|
||||
coursewareChallengeSeed = req.body.challengeSeed;
|
||||
coursewareTests = req.body.tests,
|
||||
coursewareDifficulty = req.body.difficulty,
|
||||
coursewareDescription = req.body.description,
|
||||
coursewareEntryPoint = req.body.challengeEntryPoint,
|
||||
coursewareChallengeSeed = req.body.challengeSeed;
|
||||
coursewareTests = coursewareTests.split('\r\n');
|
||||
coursewareDescription = coursewareDescription.split('\r\n');
|
||||
coursewareTests.filter(getRidOfEmpties);
|
||||
@ -243,34 +247,26 @@ exports.completedCourseware = function (req, res, next) {
|
||||
var isCompletedDate = Math.round(+new Date());
|
||||
var coursewareHash = req.body.coursewareInfo.coursewareHash;
|
||||
|
||||
debug('this is the coursewarehash we got', coursewareHash);
|
||||
|
||||
req.user.completedCoursewares.push({
|
||||
_id: coursewareHash,
|
||||
completedDate: isCompletedDate,
|
||||
name: req.body.coursewareInfo.coursewareName
|
||||
});
|
||||
|
||||
var index = req.user.completedCoursewares.indexOf(coursewareHash);
|
||||
|
||||
if (index === -1) {
|
||||
|
||||
req.user.progressTimestamps.push(Date.now() || 0);
|
||||
req.user.uncompletedCoursewares.splice(index, 1);
|
||||
}
|
||||
|
||||
exports.completedBasejump = function (req, res, next) {
|
||||
var isCompletedWith = req.body.bonfireInfo.completedWith || undefined;
|
||||
var isCompletedDate = Math.round(+new Date());
|
||||
var coursewareHash = req.body.coursewareInfo.coursewareHash;
|
||||
var solutionLink = req.body.coursewareInfo.solutionLink;
|
||||
if(!solutionLink) {
|
||||
// flash error and redirect
|
||||
req.user.save(function (err, user) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
if (user) {
|
||||
res.send(true);
|
||||
}
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
exports.completedZiplineOrBasejump = function (req, res, next) {
|
||||
|
@ -196,50 +196,6 @@ exports.postEmailSignup = function(req, res, next) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* For Calendar display
|
||||
*/
|
||||
|
||||
exports.getStreak = function(req, res, next) {
|
||||
|
||||
req.user.progressTimestamps = req.user.progressTimestamps.sort(function(a, b) {
|
||||
return a - b;
|
||||
});
|
||||
|
||||
var timeObject = Object.create(null);
|
||||
R.forEach(function(time) {
|
||||
timeObject[moment(time).format('YYYY-MM-DD')] = time;
|
||||
}, req.user.progressTimestamps);
|
||||
|
||||
var tmpLongest = 1;
|
||||
var timeKeys = R.keys(timeObject);
|
||||
for (var i = 1; i <= timeKeys.length; i++) {
|
||||
if (moment(timeKeys[i - 1]).add(1, 'd').toString()
|
||||
=== moment(timeKeys[i]).toString()) {
|
||||
tmpLongest++;
|
||||
if (tmpLongest > req.user.currentStreak) {
|
||||
req.user.currentStreak = tmpLongest;
|
||||
}
|
||||
if ( req.user.currentStreak > req.user.longestStreak) {
|
||||
req.user.longestStreak = req.user.currentStreak;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
req.user.save(function(err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
});
|
||||
s
|
||||
var payload = {
|
||||
longest: req.user.longestStreak,
|
||||
timeObject: timeObject
|
||||
};
|
||||
|
||||
return res.send(payload);
|
||||
};
|
||||
|
||||
/**
|
||||
* GET /account
|
||||
* Profile page.
|
||||
@ -314,6 +270,36 @@ exports.returnUser = function(req, res, next) {
|
||||
if (user[0]) {
|
||||
var user = user[0];
|
||||
|
||||
user.progressTimestamps = user.progressTimestamps.sort(function(a, b) {
|
||||
return a - b;
|
||||
});
|
||||
|
||||
var timeObject = Object.create(null);
|
||||
R.forEach(function(time) {
|
||||
timeObject[moment(time).format('YYYY-MM-DD')] = time;
|
||||
}, user.progressTimestamps);
|
||||
|
||||
var tmpLongest = 1;
|
||||
var timeKeys = R.keys(timeObject);
|
||||
for (var i = 1; i <= timeKeys.length; i++) {
|
||||
if (moment(timeKeys[i - 1]).add(1, 'd').toString()
|
||||
=== moment(timeKeys[i]).toString()) {
|
||||
tmpLongest++;
|
||||
if (tmpLongest > user.currentStreak) {
|
||||
user.currentStreak = tmpLongest;
|
||||
}
|
||||
if ( user.currentStreak > user.longestStreak) {
|
||||
user.longestStreak = user.currentStreak;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
user.save(function(err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
});
|
||||
|
||||
var data = {};
|
||||
var progressTimestamps = user.progressTimestamps;
|
||||
for (var i = 0; i < progressTimestamps.length; i++) {
|
||||
@ -344,7 +330,9 @@ exports.returnUser = function(req, res, next) {
|
||||
website3Image: user.portfolio.website3Image,
|
||||
ch: user.challengesHash,
|
||||
calender: data,
|
||||
moment: moment
|
||||
moment: moment,
|
||||
longestStreak: user.longestStreak,
|
||||
currentStreak: user.currentStreak
|
||||
});
|
||||
|
||||
} else {
|
||||
|
@ -48,6 +48,7 @@
|
||||
"moment": "^2.8.4",
|
||||
"mongodb": "^1.4.33",
|
||||
"mongoose": "^4.0.0",
|
||||
"mongoose-long": "0.0.2",
|
||||
"morgan": "^1.5.0",
|
||||
"newrelic": "^1.13.3",
|
||||
"nodemailer": "^1.3.0",
|
||||
|
@ -21,13 +21,13 @@ block content
|
||||
img.img-center.img-responsive.public-profile-img(src='https://s3.amazonaws.com/freecodecamp/camper-image-placeholder.png')
|
||||
h1.text-center.negative-5
|
||||
- if (twitterHandle)
|
||||
a.ion-social-twitter.text-primary(title="@#{username}'s Twitter Profile", href="http://twitter.com/#{twitterHandle}", target='_blank')
|
||||
a.ion-social-twitter.text-primary(title="@#{username}'s Twitter Profile", href="http://twitter.com/#{twitterHandle}", target='_blank')
|
||||
- if (githubProfile)
|
||||
a.ion-social-github.text-primary(title="@#{username}'s GitHub Profile", href=githubProfile, target='_blank')
|
||||
a.ion-social-github.text-primary(title="@#{username}'s GitHub Profile", href=githubProfile, target='_blank')
|
||||
- if (linkedinProfile)
|
||||
a.ion-social-linkedin.text-primary(title="@#{username}'s LinkedIn Profile", href=linkedinProfile, target='_blank')
|
||||
a.ion-social-linkedin.text-primary(title="@#{username}'s LinkedIn Profile", href=linkedinProfile, target='_blank')
|
||||
- if (codepenProfile)
|
||||
a.ion-social-codepen.text-primary(title="@#{username}'s CodePen Profile", href=codepenProfile, target='_blank')
|
||||
a.ion-social-codepen.text-primary(title="@#{username}'s CodePen Profile", href=codepenProfile, target='_blank')
|
||||
.visible-md.visible-lg
|
||||
.col-xs-12.col-sm-12.col-md-4.text-justify
|
||||
h1.flat-top.wrappable= name
|
||||
@ -119,3 +119,16 @@ block content
|
||||
legendColors: ["#cccccc", "#215f1e"],
|
||||
legend: [1, 2, 3]
|
||||
});
|
||||
.row
|
||||
.hidden-xs.col-sm-12.text-center
|
||||
.row
|
||||
h3.col-sm-6.text-center
|
||||
.center-block.
|
||||
#{longestStreak}
|
||||
.center-block.
|
||||
Longest Streak
|
||||
h3.col-sm-6.text-center
|
||||
.center-block.
|
||||
#{currentStreak}
|
||||
.center-block.
|
||||
Current Streak
|
Reference in New Issue
Block a user