improve bonfire and start adding model and controller

This commit is contained in:
Michael Q Larson
2015-01-17 18:52:58 -08:00
parent 7722c20877
commit bae9e41b42
7 changed files with 109 additions and 36 deletions

25
app.js
View File

@ -214,10 +214,6 @@ app.get(
'/pair-program-with-team-viewer', '/pair-program-with-team-viewer',
resourcesController.pairProgramWithTeamViewer resourcesController.pairProgramWithTeamViewer
); );
app.get(
'/done-with-first-100-hours',
resourcesController.doneWithFirst100Hours
);
app.get('/learn-to-code', resourcesController.about); app.get('/learn-to-code', resourcesController.about);
app.get('/login', userController.getLogin); app.get('/login', userController.getLogin);
app.post('/login', userController.postLogin); app.post('/login', userController.postLogin);
@ -253,6 +249,11 @@ app.get(
); );
app.all('/account', passportConf.isAuthenticated); app.all('/account', passportConf.isAuthenticated);
app.get('/account/api', userController.getAccountAngular); app.get('/account/api', userController.getAccountAngular);
app.get('/bonfire', bonfireController.index);
//app.get(
// '/bonfire/:bonfireNumber',
// bonfireController.returnBonfire
//);
// Unique Check API route // Unique Check API route
app.get('/api/checkUniqueUsername/:username', userController.checkUniqueUsername); app.get('/api/checkUniqueUsername/:username', userController.checkUniqueUsername);
@ -263,11 +264,6 @@ app.post('/account/password', userController.postUpdatePassword);
app.post('/account/delete', userController.postDeleteAccount); app.post('/account/delete', userController.postDeleteAccount);
app.get('/account/unlink/:provider', userController.getOauthUnlink); app.get('/account/unlink/:provider', userController.getOauthUnlink);
//put this route last
app.get(
'/:username',
userController.returnUser
);
/** /**
* API examples routes. * API examples routes.
@ -298,7 +294,7 @@ var passportOptions = {
failureRedirect: '/login' failureRedirect: '/login'
}; };
app.get('/auth/twitter', passport.authorize('twitter')); app.get('/auth/twitter', passport.authenticate('twitter'));
app.get( app.get(
'/auth/twitter/callback', '/auth/twitter/callback',
passport.authenticate('twitter', { passport.authenticate('twitter', {
@ -350,10 +346,11 @@ app.get(
} }
); );
/** //put this route last
* Bonfire routing app.get(
*/ '/:username',
app.get('/bonfire', bonfireController.index); userController.returnUser
);
/** /**

View File

@ -1,20 +1,67 @@
var _ = require('lodash'), var _ = require('lodash'),
debug = require('debug')('freecc:cntr:challenges'), debug = require('debug')('freecc:cntr:bonfires'),
Challenge = require('./../models/Challenge'); bonfire = require('./../models/bonfire');
/** /**
* Bonfire controller * Bonfire controller
*/ */
exports.index = function(req, res) { exports.index = function(req, res) {
Challenge.find({}, null, { sort: { challengeNumber: 1 } }, function(err, c) {
if (err) {
debug('Challenge err: ', err);
next(err);
}
res.render('bonfire/bonfire.jade', { res.render('bonfire/bonfire.jade', {
challenges: c,
cc: req.user ? req.user.challengesHash : undefined
});
}); });
//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
// });
// });
//};

View File

@ -161,7 +161,7 @@ module.exports = {
}); });
}); });
}); });
}, }
}; };

14
models/Bonfire.js Normal file
View File

@ -0,0 +1,14 @@
var mongoose = require('mongoose');
var secrets = require('../config/secrets');
var bonfireSchema = new mongoose.Schema({
name: {
type: String,
unique: true
},
link: String,
time: String,
bonfireNumber: Number
});
module.exports = mongoose.model('Bonfire', bonfireSchema);

View File

@ -525,6 +525,10 @@ thead {
} }
} }
form.code {
font-size: 22px;
}
//uncomment this to see the dimensions of all elements outlined in red //uncomment this to see the dimensions of all elements outlined in red
//* { //* {
// border-color: red; // border-color: red;

View File

@ -15,9 +15,9 @@ block content
script(src='/js/lib/bonfire/bonfire.js') script(src='/js/lib/bonfire/bonfire.js')
.row .row
.col-sm-12.col-md-8.col-xs-12 .col-sm-12.col-md-12.col-xs-12
.panel.panel-primary .panel.panel-primary
.panel-heading Title .panel-heading.text-center Bonfire Playground
.panel.panel-body .panel.panel-body
form.code form.code
.form-group.codeMirrorView .form-group.codeMirrorView
@ -26,7 +26,7 @@ block content
.form-group.codeMirrorView .form-group.codeMirrorView
textarea#codeOutput textarea#codeOutput
#submitButton.btn.btn-primary.btn-big.btn-block Run my code #submitButton.btn.btn-primary.btn-big.btn-block Run my code
#hintButton.btn.btn-info.btn-big.btn-block Show me hints //#hintButton.btn.btn-info.btn-big.btn-block Show me hints
script. script.
var widgets = []; var widgets = [];
@ -38,16 +38,26 @@ block content
lint: true, lint: true,
matchBrackets: true, matchBrackets: true,
autoCloseBrackets: true, autoCloseBrackets: true,
cursorHeight: 0.85,
lineWrapping: true,
gutters: ["CodeMirror-lint-markers"], gutters: ["CodeMirror-lint-markers"],
onKeyEvent : doLinting onKeyEvent : doLinting
}); });
var editor = myCodeMirror; var editor = myCodeMirror;
myCodeMirror.setValue('2*2'); myCodeMirror.setValue('/*Welcome to Bonfire, Free Code Camp\'s future CoderByte replacement.\n'+
'Please feel free to use Bonfire as an in-browser playground and linting tool.*/\n\n\n' +
'function test() {\n' +
' return [1,2,3].map(function(elem) {\n' +
' return elem * elem;\n' +
' });\n' +
'}\n\n' +
'test();');
myCodeMirror.setSize("100%", 500); myCodeMirror.setSize("100%", 500);
var codeOutput = CodeMirror.fromTextArea(document.getElementById("codeOutput"), { var codeOutput = CodeMirror.fromTextArea(document.getElementById("codeOutput"), {
lineNumbers: false, lineNumbers: false,
mode: "javascript", mode: "text",
theme: 'monokai', theme: 'monokai',
readOnly: 'nocursor' readOnly: 'nocursor'
}); });
@ -85,8 +95,3 @@ block content
submit(js); submit(js);
}); });
.col-sm-12.col-md-4.col-xs-12
include ../partials/challenges

View File

@ -0,0 +1,6 @@
h3
ol(start='0')
for bonfire in bonfires
li
a(href="/bonfire/#{bonfire.bonfireNumber}", class="#{ (cc && cc[bonfire.bonfireNumber] > 0) ? 'strikethrough' : '' }") #{bonfire.name}
|   (#{bonfire.time} mins)