generator now publishes directly to a view where you can interact with your new bonfire

This commit is contained in:
Michael Q Larson
2015-01-25 23:10:05 -08:00
parent 7c6cbbf221
commit c20aa1697c
7 changed files with 170 additions and 92 deletions

View File

@@ -15,7 +15,7 @@ exports.index = function(req, res) {
title: 'Learn to code with Bonfire'
});
Bonfire.find({}, null, { sort: { bonfireNumber: 1 } }, function(err, c) {
Bonfire.find({}, null, { sort: { difficulty: 1 } }, function(err, c) {
if (err) {
debug('bonfire err: ', err);
next(err);
@@ -49,8 +49,7 @@ exports.returnBonfire = function(req, res, next) {
completedWith: null,
title: bonfire[bonfireNumber].name,
name: bonfire[bonfireNumber].name,
number: bonfire[bonfireNumber].bonfireNumber,
difficulty: bonfire[bonfireNumber].difficulty,
difficulty: +bonfire[bonfireNumber].difficulty,
brief: bonfire[bonfireNumber].description[0],
details: bonfire[bonfireNumber].description.slice(1),
tests: bonfire[bonfireNumber].tests,
@@ -71,7 +70,7 @@ exports.returnIndividualBonfire = function(req, res, next) {
var bonfireNumber = parseInt(req.params.bonfireNumber) || 0;
if (bonfireNumber > highestBonfireNumber) { bonfireNumber = 0; }
Bonfire.find({}, null, { sort: { bonfireNumber: 1 } }, function(err, bonfire) {
Bonfire.find({}, null, { sort: { difficulty: 1 } }, function(err, bonfire) {
if (err) {
next(err);
}
@@ -79,8 +78,7 @@ exports.returnIndividualBonfire = function(req, res, next) {
completedWith: null,
title: bonfire[bonfireNumber].name,
name: bonfire[bonfireNumber].name,
number: bonfire[bonfireNumber].bonfireNumber,
difficulty: bonfire[bonfireNumber].difficulty,
difficulty: +bonfire[bonfireNumber].difficulty,
brief: bonfire[bonfireNumber].description[0],
details: bonfire[bonfireNumber].description.slice(1),
tests: bonfire[bonfireNumber].tests,
@@ -134,25 +132,33 @@ function randomString() {
*/
exports.testBonfire = function(req, res) {
// TODO: Add stuff here to parse posted variables and feed them back to bonfire playground
var candidateTitle = req.body.bonfireInfo.title;
var candidateName = req.body.bonfireInfo.name;
var candidateDifficulty = req.body.bonfireInfo.difficulty;
var candidateBrief = req.body.bonfireInfo.brief;
var candidateDetails = req.body.bonfireInfo.details;
var candidateTests = req.body.bonfireInfo.tests;
var candidateChallengeSeed = req.body.bonfireInfo.challengeSeed;
var candidateChallengeEntryPoint = req.body.bonfireInfo.challengeSeed;
res.render('bonfire/bonfire', {
title: candidateTitle,
name: candidateName,
difficulty: candidateDifficulty,
brief: candidateBrief,
details: candidateDetails,
tests: candidateTests,
challengeSeed: candidateChallengeSeed,
challengeEntryPoint: candidateChallengeEntryPoint,
bonfireHash: bonfire[bonfireNumber]._id
var bonfireName = req.body.name,
bonfireTests = req.body.tests,
bonfireDifficulty = req.body.difficulty,
bonfireDescription = req.body.description,
bonfireEntryPoint = req.body.challengeEntryPoint,
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,
difficulty: +bonfireDifficulty,
brief: bonfireDescription[0],
details: bonfireDescription.slice(1),
tests: bonfireTests,
challengeSeed: bonfireChallengeSeed,
challengeEntryPoint: bonfireEntryPoint,
cc: req.user ? req.user.bonfiresHash : undefined,
points: req.user ? req.user.points : undefined,
verb: resources.randomVerb(),
phrase: resources.randomPhrase(),
compliment: resources.randomCompliment(),
bonfires: [],
bonfireHash: "test"
});
};
@@ -162,6 +168,10 @@ function getRidOfEmpties(elem) {
}
}
exports.publicGenerator = function(req, res) {
res.render('bonfire/public-generator');
}
exports.generateChallenge = function(req, res) {
var bonfireName = req.body.name,
bonfireTests = req.body.tests,
@@ -177,14 +187,13 @@ exports.generateChallenge = function(req, res) {
var response = {
_id: randomString(),
name: bonfireName,
tests: bonfireTests,
difficulty: bonfireDifficulty,
description: bonfireDescription,
challengeEntryPoint: bonfireEntryPoint,
challengeSeed: bonfireChallengeSeed,
bonfireNumber: 0,
_id: randomString()
tests: bonfireTests
};
res.send(response);
}