Merge branch 'ux-improvements' of https://github.com/terakilobyte/freecodecamp into terakilobyte-ux-improvements

Conflicts:
	controllers/bonfire.js
	controllers/resources.js
	public/js/main.js
	views/bonfire/show.jade
This commit is contained in:
Michael Q Larson
2015-03-29 14:44:49 -07:00
13 changed files with 508 additions and 415 deletions

View File

@ -3,6 +3,7 @@ var _ = require('lodash'),
Bonfire = require('./../models/Bonfire'),
User = require('./../models/User'),
resources = require('./resources'),
MDNlinks = require('./../seed_data/bonfireMDNlinks'),
R = require('ramda');
MDNlinks = require('./../seed_data/bonfireMDNlinks');
@ -161,18 +162,18 @@ function randomString() {
/**
* Helper function to populate the MDN links array.
*/
*/
function getMDNlinks(links) {
// takes in an array of links, which are strings
var populatedLinks = [];
// takes in an array of links, which are strings
var populatedLinks = [];
// for each key value, push the corresponding link from the MDNlinks object into a new array
links.forEach(function(value, index) {
populatedLinks.push(MDNlinks[value]);
});
// for each key value, push the corresponding link from the MDNlinks object into a new array
links.forEach(function(value, index) {
populatedLinks.push(MDNlinks[value]);
});
return populatedLinks;
return populatedLinks;
};
@ -182,15 +183,15 @@ function getMDNlinks(links) {
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', '');
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,
@ -223,15 +224,15 @@ exports.publicGenerator = function(req, res) {
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', '');
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 = {

View File

@ -100,7 +100,8 @@ exports.returnIndividualCourseware = function(req, res, next) {
phrase: resources.randomPhrase(),
compliment: resources.randomCompliment(),
coursewareHash: courseware._id,
environment: resources.whichEnvironment()
environment: resources.whichEnvironment(),
challengeType: courseware.challengeType
});
},
@ -117,7 +118,7 @@ exports.returnIndividualCourseware = function(req, res, next) {
phrase: resources.randomPhrase(),
compliment: resources.randomCompliment(),
coursewareHash: courseware._id,
challengeType: courseware.challengeType
});
},
@ -133,7 +134,7 @@ exports.returnIndividualCourseware = function(req, res, next) {
phrase: resources.randomPhrase(),
compliment: resources.randomCompliment(),
coursewareHash: courseware._id,
challengeType: 'video'
challengeType: courseware.challengeType
});
},
@ -160,16 +161,16 @@ 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 = coursewareTests.split('\r\n');
coursewareDescription = coursewareDescription.split('\r\n');
coursewareTests.filter(getRidOfEmpties);
coursewareDescription.filter(getRidOfEmpties);
coursewareChallengeSeed = coursewareChallengeSeed.replace('\r', '');
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);
coursewareDescription.filter(getRidOfEmpties);
coursewareChallengeSeed = coursewareChallengeSeed.replace('\r', '');
res.render('courseware/show', {
completedWith: null,
title: coursewareName,
@ -233,7 +234,9 @@ exports.completedCourseware = function (req, res, next) {
req.user.completedCoursewares.push({
_id: coursewareHash,
completedDate: isCompletedDate,
name: req.body.coursewareInfo.coursewareName
name: req.body.coursewareInfo.coursewareName,
solution: null,
githubLink: null
});
var index = req.user.completedCoursewares.indexOf(coursewareHash);
@ -247,19 +250,26 @@ exports.completedCourseware = function (req, res, next) {
return next(err);
}
if (user) {
res.send(true);
res.sendStatus(200);
}
});
};
exports.completedZiplineOrBasejump = function (req, res, next) {
var isCompletedWith = req.body.bonfireInfo.completedWith || false;
debug('Inside controller for completed zipline or basejump with data %s',
req.body.coursewareInfo);
var isCompletedWith = req.body.coursewareInfo.completedWith || false;
var isCompletedDate = Math.round(+new Date());
var coursewareHash = req.body.coursewareInfo.coursewareHash;
var solutionLink = req.body.coursewareInfo.solutionLink;
if (!solutionLink) {
// flash error and redirect
return next(new Error('No solution provided'));
var solutionLink = req.body.coursewareInfo.publicURL;
var githubLink = req.body.coursewareInfo.challengeType === 4
? req.body.coursewareInfo.githubURL : true;
if (!solutionLink || !githubLink) {
req.flash('errors', {
msg: 'You haven\'t supplied the necessary URLs for us to inspect ' +
'your work.'
});
return res.sendStatus(403);
}
if (isCompletedWith) {
@ -275,37 +285,47 @@ exports.completedZiplineOrBasejump = function (req, res, next) {
}
pairedWith = pairedWith.pop();
index = pairedWith.uncompletedCoursewares.indexOf(coursewareHash);
if (index > -1) {
pairedWith.progressTimestamps.push(Date.now() || 0);
pairedWith.uncompletedCoursewares.splice(index, 1);
}
pairedWith.completedCoursewares.push({
_id: coursewareHash,
completedWith: req.user._id,
completedDate: isCompletedDate,
solution: solutionLink
});
req.user.completedCoursewares.push({
_id: coursewareHash,
completedWith: pairedWith._id,
completedDate: isCompletedDate,
solution: solutionLink
solution: solutionLink,
githubLink: githubLink
});
req.user.save(function (err, user) {
if (err) {
return next(err);
}
debug('this is the user object returned %s,' +
' this is the req.user._id %s, ' +
'this is the pairedWith._id %s', user, req.user._id, pairedWith._id);
debug(req.user._id.toString() === pairedWith._id.toString());
if (req.user._id.toString() === pairedWith._id.toString()) {
return res.sendStatus(200);
}
index = pairedWith.uncompletedCoursewares.indexOf(coursewareHash);
if (index > -1) {
pairedWith.progressTimestamps.push(Date.now() || 0);
pairedWith.uncompletedCoursewares.splice(index, 1);
}
pairedWith.completedCoursewares.push({
_id: coursewareHash,
completedWith: req.user._id,
completedDate: isCompletedDate,
solution: solutionLink,
githubLink: githubLink
});
pairedWith.save(function (err, paired) {
if (err) {
return next(err);
}
if (user && paired) {
return res.send(true);
return res.sendStatus(200);
}
});
});
@ -317,10 +337,11 @@ exports.completedZiplineOrBasejump = function (req, res, next) {
_id: coursewareHash,
completedWith: null,
completedDate: isCompletedDate,
solution: solutionLink
solution: solutionLink,
githubLink: githubLink
});
var index = req.user.uncompletedCourse.indexOf(coursewareHash);
var index = req.user.uncompletedCoursewares.indexOf(coursewareHash);
if (index > -1) {
req.user.progressTimestamps.push(Date.now() || 0);
req.user.uncompletedCoursewares.splice(index, 1);
@ -331,8 +352,7 @@ exports.completedZiplineOrBasejump = function (req, res, next) {
return next(err);
}
if (user) {
debug('Saving user');
return res.send(true);
return res.sendStatus(200);
}
});
}

View File

@ -176,6 +176,21 @@ module.exports = {
});
},
trelloCalls: function(req, res, next) {
request('https://trello.com/1/boards/BA3xVpz9/cards?key=' + secrets.trello.key, function(err, status, trello) {
if (err) { return next(err); }
trello = (status && status.statusCode === 200) ? (JSON.parse(trello)) : "Can't connect to to Trello";
res.end(JSON.stringify(trello));
});
},
bloggerCalls: function(req, res, next) {
request('https://www.googleapis.com/blogger/v3/blogs/2421288658305323950/posts?key=' + secrets.blogger.key, function (err, status, blog) {
if (err) { return next(err); }
blog = (status && status.statusCode === 200) ? JSON.parse(blog) : "Can't connect to Blogger";
res.end(JSON.stringify(blog));
});
},
about: function(req, res, next) {
if (req.user) {
if (!req.user.profile.picture || req.user.profile.picture === "https://s3.amazonaws.com/freecodecamp/favicons/apple-touch-icon-180x180.png") {
@ -183,8 +198,9 @@ module.exports = {
req.user.save();
}
}
var date1 = new Date('10/15/2014');
var date1 = new Date("10/15/2014");
var date2 = new Date();
var progressTimestamps = req.user.progressTimestamps;
var now = Date.now() || 0;
@ -231,6 +247,7 @@ module.exports = {
if (progressTimestamps[progressTimestamps.length - 1] <= (now - 43200)) {
req.user.progressTimestamps.push(now);
}
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var daysRunning = Math.ceil(timeDiff / (1000 * 3600 * 24));
var announcements = resources.announcements;
@ -259,6 +276,7 @@ module.exports = {
});
},
randomPhrase: function() {
var phrases = resources.phrases;
return phrases[Math.floor(Math.random() * phrases.length)];