remove term code campers from codebase - replace with camper. Move bulky function from app.js to bonfire.js

This commit is contained in:
Michael Q Larson
2015-02-01 22:39:59 -08:00
parent afab456ad9
commit 0ee291878a
11 changed files with 252 additions and 186 deletions

View File

@ -148,7 +148,7 @@ Changelog
Contributing
------------
We welcome pull requests from Free Code Camp "Code Campers" (our students) and seasoned JavaScript developers alike!
We welcome pull requests from Free Code Camp "campers" (our students) and seasoned JavaScript developers alike!
1) Check our [public Trello Board](https://trello.com/b/CW5AFr0v/free-code-camp-development)
2) If your issue or feature isn't on the board, either open an issue on this GitHub repo or message Quincy Larson to request to be added to the Trello board.
3) Once your code is ready, submit the pull request. We'll do a quick code review and give you feedback, and iterate from there.

78
app.js
View File

@ -270,7 +270,7 @@ app.get('/account/api', userController.getAccountAngular);
*/
app.get('/playground', bonfireController.index);
app.get('/bonfires', bonfireController.returnNextBonfire);
app.get('/courseware', bonfireController.courseware);
//app.get('/courseware', bonfireController.courseware);
app.get('/bonfire-json-generator', bonfireController.returnGenerator);
app.post('/bonfire-json-generator', bonfireController.generateChallenge);
app.get('/bonfire-challenge-generator', bonfireController.publicGenerator);
@ -283,81 +283,7 @@ app.get('/bonfire', function(req, res) {
res.redirect(301, '/playground');
});
app.post('/completed-bonfire/', function (req, res) {
var isCompletedWith = req.body.bonfireInfo.completedWith || undefined;
var isCompletedDate = Math.round(+new Date() / 1000);
var bonfireHash = req.body.bonfireInfo.bonfireHash;
var isSolution = req.body.bonfireInfo.solution;
if (isCompletedWith) {
var paired = User.find({"profile.username": isCompletedWith}).limit(1);
paired.exec(function(err, pairedWith) {
if (err) {
return err;
} else {
var index = req.user.uncompletedBonfires.indexOf(bonfireHash);
if (index > -1) {
req.user.uncompletedBonfires.splice(index,1)
}
pairedWith = pairedWith.pop();
index = pairedWith.uncompletedBonfires.indexOf(bonfireHash);
if (index > -1) {
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
})
var index = req.user.uncompletedBonfires.indexOf(bonfireHash);
if (index > -1) {
req.user.uncompletedBonfires.splice(index,1)
}
req.user.save(function(err, user) {
if (err) {
throw err;
}
if (user) {
debug('Saving user');
res.send(true)
}
});
}
});
app.post('/completed-bonfire/', bonfireController.completedBonfire);
// Unique Check API route
app.get('/api/checkUniqueUsername/:username', userController.checkUniqueUsername);

View File

@ -8,8 +8,6 @@ var _ = require('lodash'),
* Bonfire controller
*/
var highestBonfireNumber = resources.numberOfBonfires();
exports.bonfireNames = function(req, res) {
res.render('bonfires/showList', {
bonfireList: resources.allBonfireNames()
@ -66,27 +64,9 @@ exports.returnNextBonfire = function(req, res, next) {
if (err) {
next(err);
}
nameString = bonfire[0].name.toLowerCase().replace(/\s/g, '-');
bonfire = bonfire.pop();
nameString = bonfire.name.toLowerCase().replace(/\s/g, '-');
return res.redirect('/bonfires/' + nameString);
//res.render('bonfire/show', {
// completedWith: null,
// title: bonfire[bonfireNumber].name,
// name: bonfire[bonfireNumber].name,
// difficulty: +bonfire[bonfireNumber].difficulty,
// brief: bonfire[bonfireNumber].description[0],
// details: bonfire[bonfireNumber].description.slice(1),
// tests: bonfire[bonfireNumber].tests,
// challengeSeed: bonfire[bonfireNumber].challengeSeed,
// challengeEntryPoint: bonfire[bonfireNumber].challengeEntryPoint,
// cc: req.user ? req.user.bonfiresHash : undefined,
// points: req.user ? req.user.points : undefined,
// verb: resources.randomVerb(),
// phrase: resources.randomPhrase(),
// compliments: resources.randomCompliment(),
// bonfires: bonfire,
// bonfireHash: bonfire[bonfireNumber]._id
//});
});
};
@ -94,7 +74,6 @@ exports.returnIndividualBonfire = function(req, res, next) {
var dashedName = req.params.bonfireName;
bonfireName = dashedName.replace(/\-/g, ' ');
var bonfireNumber = 0;
Bonfire.find({"name" : new RegExp(bonfireName, 'i')}, function(err, bonfire) {
if (err) {
@ -104,26 +83,27 @@ exports.returnIndividualBonfire = function(req, res, next) {
req.flash('errors', {
msg: "404: We couldn't find a bonfire with that name. Please double check the name."
});
return res.redirect('/bonfires/meet-bonfire')
return res.redirect('/bonfires')
} else {
bonfire = bonfire.pop();
res.render('bonfire/show', {
completedWith: null,
title: bonfire[bonfireNumber].name,
title: bonfire.name,
dashedName: dashedName,
name: bonfire[bonfireNumber].name,
difficulty: Math.floor(+bonfire[bonfireNumber].difficulty),
brief: bonfire[bonfireNumber].description[0],
details: bonfire[bonfireNumber].description.slice(1),
tests: bonfire[bonfireNumber].tests,
challengeSeed: bonfire[bonfireNumber].challengeSeed,
challengeEntryPoint: bonfire[bonfireNumber].challengeEntryPoint,
name: bonfire.name,
difficulty: Math.floor(+bonfire.difficulty),
brief: bonfire.description[0],
details: bonfire.description.slice(1),
tests: bonfire.tests,
challengeSeed: bonfire.challengeSeed,
challengeEntryPoint: bonfire.challengeEntryPoint,
cc: !!req.user,
points: req.user ? req.user.points : undefined,
verb: resources.randomVerb(),
phrase: resources.randomPhrase(),
compliment: resources.randomCompliment(),
bonfires: bonfire,
bonfireHash: bonfire[bonfireNumber]._id
bonfireHash: bonfire._id
});
}
@ -160,7 +140,7 @@ function randomString() {
randomstring += chars.substring(rnum,rnum+1);
}
return randomstring;
}
};
/**
*
@ -202,11 +182,11 @@ function getRidOfEmpties(elem) {
if (elem.length > 0) {
return elem;
}
}
};
exports.publicGenerator = function(req, res) {
res.render('bonfire/public-generator');
}
};
exports.generateChallenge = function(req, res) {
var bonfireName = req.body.name,
@ -232,4 +212,80 @@ exports.generateChallenge = function(req, res) {
tests: bonfireTests
};
res.send(response);
}
};
exports.completedBonfire = function (req, res) {
var isCompletedWith = req.body.bonfireInfo.completedWith || undefined;
var isCompletedDate = Math.round(+new Date() / 1000);
var bonfireHash = req.body.bonfireInfo.bonfireHash;
var isSolution = req.body.bonfireInfo.solution;
if (isCompletedWith) {
var paired = User.find({"profile.username": isCompletedWith}).limit(1);
paired.exec(function (err, pairedWith) {
if (err) {
return err;
} else {
var index = req.user.uncompletedBonfires.indexOf(bonfireHash);
if (index > -1) {
req.user.uncompletedBonfires.splice(index, 1)
}
pairedWith = pairedWith.pop();
index = pairedWith.uncompletedBonfires.indexOf(bonfireHash);
if (index > -1) {
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
});
var index = req.user.uncompletedBonfires.indexOf(bonfireHash);
if (index > -1) {
req.user.uncompletedBonfires.splice(index, 1)
}
req.user.save(function (err, user) {
if (err) {
throw err;
}
if (user) {
debug('Saving user');
res.send(true)
}
});
}
};

View File

@ -63,7 +63,7 @@ module.exports = {
to: 'team@freecodecamp.com',
name: 'Completionist',
from: req.body.email,
subject: 'Code Camper at ' + req.body.email + ' has completed the first 100 hours',
subject: 'Camper at ' + req.body.email + ' has completed the first 100 hours',
text: ''
};

View File

@ -1,64 +1,72 @@
var _ = require('lodash'),
debug = require('debug')('freecc:cntr:coursewares'),
Courseware = require('./../models/Courseware'),
debug = require('debug')('freecc:cntr:bonfires'),
Bonfire = require('./../models/Bonfire'),
User = require('./../models/User'),
resources = require('./resources');
/**
* Courseware controller
* Bonfire controller
*/
exports.courseware = function(req, res) {
res.render('courseware/show.jade', {
exports.bonfireNames = function(req, res) {
res.render('bonfires/showList', {
bonfireList: resources.allBonfireNames()
});
};
var highestCourswareNumber = resources.numberOfCoursewares();
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: '',
challengeEntryPoint: '',
cc: req.user ? req.user.bonfiresHash : undefined,
points: req.user ? req.user.points : undefined,
verb: resources.randomVerb(),
phrase: resources.randomPhrase(),
compliments: resources.randomCompliment(),
bonfires: [],
bonfireHash: 'test'
exports.returnNextCourseware = function(req, res, next) {
});
};
exports.returnNextBonfire = function(req, res, next) {
if (!req.user) {
return res.redirect('coursewares/welcome-to-courseware');
return res.redirect('bonfires/meet-bonfire');
}
var completed = req.user.completedBonfires.map(function (elem) {
return elem._id;
});
var currentTime = parseInt(+new Date() / 1000);
if (currentTime - req.user.lastContentSync > 10) {
req.user.lastContentSync = currentTime;
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;
}
});
req.user.save();
req.user.uncompletedBonfires = resources.allBonfireIds().filter(function (elem) {
if (completed.indexOf(elem) === -1) {
return elem;
}
});
req.user.save();
}
var uncompletedCoursewares = req.user.uncompletedCoursewares;
var displayedCoursewares = Courseware.find({'_id': uncompletedCoursewares[0]});
displayedCoursewares.exec(function(err, bonfire) {
var uncompletedBonfires = req.user.uncompletedBonfires;
var displayedBonfires = Bonfire.find({'_id': uncompletedBonfires[0]});
displayedBonfires.exec(function(err, bonfire) {
if (err) {
next(err);
}
courseware = courseware.pop();
nameString = courseware[0].name.toLowerCase().replace(/\s/g, '-');
bonfire = bonfire.pop();
nameString = bonfire.name.toLowerCase().replace(/\s/g, '-');
return res.redirect('/bonfires/' + nameString);
//res.render('bonfire/show', {
// completedWith: null,
// title: bonfire[bonfireNumber].name,
// name: bonfire[bonfireNumber].name,
// difficulty: +bonfire[bonfireNumber].difficulty,
// brief: bonfire[bonfireNumber].description[0],
// details: bonfire[bonfireNumber].description.slice(1),
// tests: bonfire[bonfireNumber].tests,
// challengeSeed: bonfire[bonfireNumber].challengeSeed,
// challengeEntryPoint: bonfire[bonfireNumber].challengeEntryPoint,
// cc: req.user ? req.user.bonfiresHash : undefined,
// points: req.user ? req.user.points : undefined,
// verb: resources.randomVerb(),
// phrase: resources.randomPhrase(),
// compliments: resources.randomCompliment(),
// bonfires: bonfire,
// bonfireHash: bonfire[bonfireNumber]._id
//});
});
};
@ -66,7 +74,6 @@ exports.returnIndividualBonfire = function(req, res, next) {
var dashedName = req.params.bonfireName;
bonfireName = dashedName.replace(/\-/g, ' ');
var bonfireNumber = 0;
Bonfire.find({"name" : new RegExp(bonfireName, 'i')}, function(err, bonfire) {
if (err) {
@ -76,26 +83,27 @@ exports.returnIndividualBonfire = function(req, res, next) {
req.flash('errors', {
msg: "404: We couldn't find a bonfire with that name. Please double check the name."
});
return res.redirect('/bonfires/meet-bonfire')
return res.redirect('/bonfires')
} else {
bonfire = bonfire.pop();
res.render('bonfire/show', {
completedWith: null,
title: bonfire[bonfireNumber].name,
title: bonfire.name,
dashedName: dashedName,
name: bonfire[bonfireNumber].name,
difficulty: Math.floor(+bonfire[bonfireNumber].difficulty),
brief: bonfire[bonfireNumber].description[0],
details: bonfire[bonfireNumber].description.slice(1),
tests: bonfire[bonfireNumber].tests,
challengeSeed: bonfire[bonfireNumber].challengeSeed,
challengeEntryPoint: bonfire[bonfireNumber].challengeEntryPoint,
name: bonfire.name,
difficulty: Math.floor(+bonfire.difficulty),
brief: bonfire.description[0],
details: bonfire.description.slice(1),
tests: bonfire.tests,
challengeSeed: bonfire.challengeSeed,
challengeEntryPoint: bonfire.challengeEntryPoint,
cc: !!req.user,
points: req.user ? req.user.points : undefined,
verb: resources.randomVerb(),
phrase: resources.randomPhrase(),
compliment: resources.randomCompliment(),
bonfires: bonfire,
bonfireHash: bonfire[bonfireNumber]._id
bonfireHash: bonfire._id
});
}
@ -132,7 +140,7 @@ function randomString() {
randomstring += chars.substring(rnum,rnum+1);
}
return randomstring;
}
};
/**
*
@ -174,11 +182,11 @@ function getRidOfEmpties(elem) {
if (elem.length > 0) {
return elem;
}
}
};
exports.publicGenerator = function(req, res) {
res.render('bonfire/public-generator');
}
};
exports.generateChallenge = function(req, res) {
var bonfireName = req.body.name,
@ -204,4 +212,80 @@ exports.generateChallenge = function(req, res) {
tests: bonfireTests
};
res.send(response);
}
};
exports.completedBonfire = function (req, res) {
var isCompletedWith = req.body.bonfireInfo.completedWith || undefined;
var isCompletedDate = Math.round(+new Date() / 1000);
var bonfireHash = req.body.bonfireInfo.bonfireHash;
var isSolution = req.body.bonfireInfo.solution;
if (isCompletedWith) {
var paired = User.find({"profile.username": isCompletedWith}).limit(1);
paired.exec(function (err, pairedWith) {
if (err) {
return err;
} else {
var index = req.user.uncompletedBonfires.indexOf(bonfireHash);
if (index > -1) {
req.user.uncompletedBonfires.splice(index, 1)
}
pairedWith = pairedWith.pop();
index = pairedWith.uncompletedBonfires.indexOf(bonfireHash);
if (index > -1) {
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
});
var index = req.user.uncompletedBonfires.indexOf(bonfireHash);
if (index > -1) {
req.user.uncompletedBonfires.splice(index, 1)
}
req.user.save(function (err, user) {
if (err) {
throw err;
}
if (user) {
debug('Saving user');
res.send(true)
}
});
}
};

View File

@ -140,7 +140,7 @@
"Now go to <a href='http://coderbyte.com/CodingArea/Challenges/#easyChals' target='_blank'>http://coderbyte.com/CodingArea/Challenges/#easyChals</a> and start working through Coderbyte's easy algorithm scripting challenges using JavaScript.",
"When you are finished pair programming, click the X to end the session.",
"Congratulations! You have completed your first pair programming session.",
"You should pair program with different Code Campers until you've completed all the Easy, Medium and Hard CoderByte challenges. This is a big time investment, but the JavaScript practice you'll get, along with the scripting and algorithm experience, are well worth it!",
"You should pair program with different campers until you've completed all the Easy, Medium and Hard CoderByte challenges. This is a big time investment, but the JavaScript practice you'll get, along with the scripting and algorithm experience, are well worth it!",
"You can complete CoderByte problems while you continue to work through Free Code Camp's challenges.",
"Be sure to pair program on these challenges, and remember to apply the RSAP methodology.",
"Click the button below to return to the Pair Programming challenge, then mark it complete."

View File

@ -227,7 +227,7 @@ exports.returnUser = function(req, res, next) {
var user = user[0];
Challenge.find({}, null, {sort: {challengeNumber: 1}}, function (err, c) {
res.render('account/show', {
title: 'Code Camper: ',
title: 'Camper: ',
username: user.profile.username,
name: user.profile.name,
location: user.profile.location,

View File

@ -6,7 +6,7 @@
"description": [
"Click the button below for further instructions.",
"Your goal is to fix the failing test.",
"First, run all the tests by clickin \"Run code\" or by pressing Control + Enter",
"First, run all the tests by clicking \"Run code\" or by pressing Control + Enter",
"The failing test is in red. Fix the code so that all tests pass. Then you can move on to the next Bonfire."
],
"tests": [

View File

@ -24,12 +24,12 @@
"video": "114627322",
"challengeNumber": 1,
"steps": [
"Now we're going to join the Free Code Camp chat room. You can come here any time of day to hang out, ask questions, or find another Code Camper who's on the same challenge as you and wants to pair program.",
"Now we're going to join the Free Code Camp chat room. You can come here any time of day to hang out, ask questions, or find another camper who's on the same challenge as you and wants to pair program.",
"If you don't already have a GitHub account, create one real quick at <a href='https://www.github.com' target='_blank'>https://www.github.com</a>.",
"Be sure to update your biographical information and upload an image. A picture of your face works best. This is how people will see you in the chat room, so put your best foot forward.",
"Now enter the chat room by going to <a href='https://gitter.im/FreeCodeCamp/FreeCodeCamp' target='_blank'>https://gitter.im/FreeCodeCamp/FreeCodeCamp</a> and clicking the \"sign in with GitHub\" button.",
"Introduce yourself to our chat room by typing: \"hello world!\".",
"Tell your fellow Code Campers how you found Free Code Camp. Also tell us why you want to learn to code.",
"Tell your fellow campers how you found Free Code Camp. Also tell us why you want to learn to code.",
"Keep the chat room open while you work through the other challenges. That way you ask for help If you get stuck on a challenge. You can also socialize when you feel like taking a break.",
"Now that you've completed this challenge, you can go directly your most-recently visited chat room by clicking the \"Chat\" button in the navigation bar above."
]
@ -47,7 +47,7 @@
"Click on the \"Introduce yourself here\" discussion.",
"Here you can read through other Free Code Camp community members' self introductions.",
"Go ahead and type a brief self introduction of your own.",
"Click on the \"Categories\" drop-down menu. You should see a category called \"Local Chapters\". Click that. If your city isn't already on the list, create a topic for it. Otherwise, introduce yourself to the other Code Campers from your city.",
"Click on the \"Categories\" drop-down menu. You should see a category called \"Local Chapters\". Click that. If your city isn't already on the list, create a topic for it. Otherwise, introduce yourself to the other campers from your city.",
"Come back here daily to ask questions, engage in discussions, and share links to helpful coding tools.",
"Now that you've completed this challenge, you can go directly to the forum by clicking the \"Forum\" button in the navigation bar above."
]
@ -433,7 +433,7 @@
"Now go to <a href='http://coderbyte.com/CodingArea/Challenges/#easyChals' target='_blank'>http://coderbyte.com/CodingArea/Challenges/#easyChals</a> and start working through Coderbyte's easy algorithm scripting challenges using JavaScript.",
"When you are finished pair programming, end the session in Screen Hero session.",
"Congratulations! You have completed your first pair programming session.",
"You should pair program with different Code Campers until you've completed all the Easy, Medium and Hard CoderByte challenges. This is a big time investment, but the JavaScript practice you'll get, along with the scripting and algorithm experience, are well worth it!",
"You should pair program with different campers until you've completed all the Easy, Medium and Hard CoderByte challenges. This is a big time investment, but the JavaScript practice you'll get, along with the scripting and algorithm experience, are well worth it!",
"You can complete CoderByte problems while you continue to work through Free Code Camp's challenges.",
"Be sure to pair program on these challenges, and remember to apply the RSAP methodology.",
"Mark this challenge as complete and move on."

View File

@ -131,10 +131,10 @@ block content
- else
a.animated.fadeIn.btn.btn-lg.signup-btn.btn-block(href='/login') Sign in so you can save your progress
#all-bonfires-dialog.modal(tabindex='-1')
.modal-dialog.animated.fadeInUp.fast-animation
.modal-content
.modal-header.challenge-list-header Bonfires
a.close.closing-x(href='#', data-dismiss='modal', aria-hidden='true') ×
.modal-body
include ../partials/bonfires
//#all-bonfires-dialog.modal(tabindex='-1')
// .modal-dialog.animated.fadeInUp.fast-animation
// .modal-content
// .modal-header.challenge-list-header Bonfires
// a.close.closing-x(href='#', data-dismiss='modal', aria-hidden='true') ×
// .modal-body
// include ../partials/bonfires

View File

@ -18,7 +18,7 @@
a(href="https://trello.com/b/BA3xVpz9/nonprofit-projects") (view)
.row
.col-xs-6.text-right
h2 Code Campers with at least...
h2 Campers with at least...
.col-xs-6
.row
.col-xs-6.text-right