Preparing for bonfire challenges, create Bonfire model, BonfireCompletion model, update bonfire controller, create initial bonfire seed data

This commit is contained in:
Nathan Leniz
2015-01-21 21:32:13 -05:00
parent 9e41b0ca7b
commit 6ea5f5c895
6 changed files with 698 additions and 436 deletions

View File

@@ -1,68 +1,75 @@
var _ = require('lodash'),
debug = require('debug')('freecc:cntr:bonfires');
// bonfire = require('./../models/Bonfire');
debug = require('debug')('freecc:cntr:bonfires'),
Bonfire = require('./../models/Bonfire');
/**
* Bonfire controller
*/
var highestBonfireNumber = 10;
exports.index = function(req, res) {
res.render('bonfire/bonfire.jade', {
title: 'Learn to code with Bonfire'
});
//Bonfire.find({}, null, { sort: { bonfireNumber: 1 } }, function(err, c) {
// if (err) {
// debug('bonfire err: ', err);
// next(err);
// }
//});
res.render('bonfire/bonfire.jade', {
title: 'Learn to code with Bonfire'
});
Bonfire.find({}, null, { sort: { bonfireNumber: 1 } }, function(err, c) {
if (err) {
debug('bonfire err: ', err);
next(err);
}
});
};
//exports.returnBonfire = function(req, res, next) {
// var bonfireNumber = parseInt(req.params.bonfireNumber) || 0;
// var verbs = [
// 'ACED',
// 'NAILED',
// 'ROCKED',
// 'SCORCHED',
// 'DEVASTATED',
// 'OWNED',
// 'CRUSHED',
// 'CONQUERED',
// 'KILLED',
// 'SHREDDED',
// 'ANNIHILATED',
// 'NUKED'
// ];
// var phrases = [
// "Shout it from on top of a mountain",
// "Tell everyone and their dogs",
// "Show them. Show them all!",
// "Inspire your friends",
// "Tell the world of your greatness",
// "Look accomplished on social media",
// "Share news of your grand endeavor",
// "Establish your alibi for the past two hours",
// "Prove to mom that computers aren't just for games"
// ];
// if (bonfireNumber > 53) { bonfireNumber = 0; }
// Bonfire.find({}, null, { sort: { bonfireNumber: 1 } }, function(err, c) {
// if (err) {
// debug('bonfire err: ', err);
// next(err);
// }
// res.render('bonfires/show', {
// //title: 'bonfire: ' + c[bonfireNumber].name,
// //name: c[bonfireNumber].name,
// //video: c[bonfireNumber].video,
// //time: c[bonfireNumber].time,
// //steps: c[bonfireNumber].steps,
// //number: bonfireNumber,
// //categories: c[bonfireNumber].category,
// //cc: req.user ? req.user.bonfiresHash : undefined,
// //points: req.user ? req.user.points : undefined,
// //verb: verbs[Math.floor(Math.random() * verbs.length)],
// //phrase: phrases[Math.floor(Math.random() * phrases.length)],
// //bonfires: c
// });
// });
//};
exports.returnBonfire = function(req, res, next) {
var bonfireNumber = parseInt(req.params.bonfireNumber) || 0;
var verbs = [
'ACED',
'NAILED',
'ROCKED',
'SCORCHED',
'DEVASTATED',
'OWNED',
'CRUSHED',
'CONQUERED',
'KILLED',
'SHREDDED',
'ANNIHILATED',
'NUKED'
];
var phrases = [
"Shout it from on top of a mountain",
"Tell everyone and their dogs",
"Show them. Show them all!",
"Inspire your friends",
"Tell the world of your greatness",
"Look accomplished on social media",
"Share news of your grand endeavor",
"Establish your alibi for the past two hours",
"Prove to mom that computers aren't just for games"
];
if (bonfireNumber > highestBonfireNumber) { bonfireNumber = 0; }
Bonfire.find({}, null, { sort: { bonfireNumber: 1 } }, function(err, c) {
if (err) {
debug('bonfire err: ', err);
next(err);
}
res.render('bonfires/show', {
title: 'bonfire: ' + c[bonfireNumber].name,
name: c[bonfireNumber].name,
number: bonfireNumber,
difficulty: c[bonfireNumber].difficulty,
description: c[bonfireNumber].description,
publicTests: c[bonfireNumber].publicTests,
privateTests: c[bonfireNumber].privateTests,
challengeSeed: c[bonfireNumber].challengeSeed,
cc: req.user ? req.user.bonfiresHash : undefined,
points: req.user ? req.user.points : undefined,
verb: verbs[Math.floor(Math.random() * verbs.length)],
phrase: phrases[Math.floor(Math.random() * phrases.length)],
bonfires: c
});
});
};