From 378277f0e1479dfc970aa4d418fb7b288b205ca3 Mon Sep 17 00:00:00 2001 From: Nathan Leniz Date: Thu, 22 Jan 2015 13:20:46 -0500 Subject: [PATCH] More steps towards building the bonfire challenge interface --- app.js | 8 ++-- controllers/bonfire.js | 37 +++++++++-------- models/Bonfire.js | 4 +- seed_data/seed.js | 1 + views/bonfire/bonfire.jade | 2 +- views/bonfire/show.jade | 74 ++++++++++++++++++---------------- views/partials/bonfires.jade | 43 +++++++++++++++++++- views/partials/challenges.jade | 6 ++- 8 files changed, 111 insertions(+), 64 deletions(-) diff --git a/app.js b/app.js index fea606ba01..5b4a51980f 100644 --- a/app.js +++ b/app.js @@ -251,10 +251,10 @@ app.get( app.all('/account', passportConf.isAuthenticated); app.get('/account/api', userController.getAccountAngular); app.get('/bonfire', bonfireController.index); -//app.get( -// '/bonfire/:bonfireNumber', -// bonfireController.returnBonfire -//); +app.get( + '/bonfire/:bonfireNumber', + bonfireController.returnBonfire +); // Unique Check API route app.get('/api/checkUniqueUsername/:username', userController.checkUniqueUsername); diff --git a/controllers/bonfire.js b/controllers/bonfire.js index 42a843c430..809899100c 100644 --- a/controllers/bonfire.js +++ b/controllers/bonfire.js @@ -48,29 +48,32 @@ exports.returnBonfire = function(req, res, next) { "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) { + Bonfire.find({}, null, { sort: { bonfireNumber: 1 } }, function(err, bonfire) { if (err) { debug('bonfire err: ', err); next(err); } + res.render('bonfire/show', { + title: bonfire[bonfireNumber].name, + name: bonfire[bonfireNumber].name, + number: bonfire[bonfireNumber].bonfireNumber, + difficulty: bonfire[bonfireNumber].difficulty, + description: bonfire[bonfireNumber].description, + publicTests: bonfire[bonfireNumber].publicTests, + privateTests: bonfire[bonfireNumber].privateTests, + challengeSeed: bonfire[bonfireNumber].challengeSeed, + challengeEntryPoint: bonfire[bonfireNumber].challengeEntryPoint, + //title: bonfire.name, + //name: bonfire.name, + //description: bonfire.description, - 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, - challengeEntryPoint: c[bonfireNumber].challengeEntryPoint, - - 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 + //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: bonfire }); }); }; \ No newline at end of file diff --git a/models/Bonfire.js b/models/Bonfire.js index 3e4bfadde2..c30e132f4f 100644 --- a/models/Bonfire.js +++ b/models/Bonfire.js @@ -6,9 +6,7 @@ var secrets = require('../config/secrets'); * @type {exports.Schema} */ -//new Schema({ _id: String }) -//var ObjectId = require('mongoose').Types.ObjectId; -//var myObjectId = ObjectId.fromString('myhexstring'); + var bonfireSchema = new mongoose.Schema({ name: { diff --git a/seed_data/seed.js b/seed_data/seed.js index 54b9f619bd..dacd5aa11e 100644 --- a/seed_data/seed.js +++ b/seed_data/seed.js @@ -22,6 +22,7 @@ Challenge.remove({}, function(err, data) { } }); }); + Bonfire.remove({}, function(err, data) { if (err) { console.error(err); diff --git a/views/bonfire/bonfire.jade b/views/bonfire/bonfire.jade index 2619a1a693..8fcf04a9ed 100644 --- a/views/bonfire/bonfire.jade +++ b/views/bonfire/bonfire.jade @@ -12,7 +12,7 @@ block content link(rel='stylesheet', href='/js/lib/codemirror/theme/monokai.css') link(rel="stylesheet", href="http://fonts.googleapis.com/css?family=Ubuntu+Mono") script(src='/js/lib/codemirror/mode/javascript/javascript.js') - script(src='js/lib/jailed/jailed.js') + script(src='/js/lib/jailed/jailed.js') script(src='/js/lib/bonfire/bonfireInit.js') .row #mainEditorPanel.col-sm-12.col-md-7.col-xs-12 diff --git a/views/bonfire/show.jade b/views/bonfire/show.jade index 6b10d316c5..f4263c81e5 100644 --- a/views/bonfire/show.jade +++ b/views/bonfire/show.jade @@ -1,39 +1,43 @@ extends ../layout block content + + script(src='/js/lib/codemirror/lib/codemirror.js') + script(src='/js/lib/codemirror/addon/edit/closebrackets.js') + script(src='/js/lib/codemirror/addon/edit/matchbrackets.js') + script(src='/js/lib/codemirror/addon/lint/lint.js') + script(src='/js/lib/codemirror/addon/lint/javascript-lint.js') + script(src='//ajax.aspnetcdn.com/ajax/jshint/r07/jshint.js') + script(src='/js/lib/chai/chai.js') + link(rel='stylesheet', href='/js/lib/codemirror/lib/codemirror.css') + link(rel='stylesheet', href='/js/lib/codemirror/addon/lint/lint.css') + link(rel='stylesheet', href='/js/lib/codemirror/theme/monokai.css') + link(rel="stylesheet", href="http://fonts.googleapis.com/css?family=Ubuntu+Mono") + script(src='/js/lib/codemirror/mode/javascript/javascript.js') + script(src='/js/lib/jailed/jailed.js') + script(src='/js/lib/bonfire/bonfireInit.js') .row - .col-sm-12.col-md-12.col-xs-12 - .panel.panel-primary - .panel-heading.text-center #{name} (Level #{difficulty} bonfire) + #mainEditorPanel.col-sm-12.col-md-7.col-xs-12 + .panel.panel-primary.panel-bonfire + .panel-heading.text-center #{name} (Level #{difficulty} bonfire) + .panel.panel-body + form.code + h3 Details + h5 + ol + for sentence in description + li!= sentence + .form-group.codeMirrorView + textarea#codeEditor(autofocus=true) + #testCreatePanel.col-sm-12.col-md-5.col-xs-12 + .panel.panel-primary.panel-bonfire + .panel-heading.text-center Output .panel.panel-body - .col-xs-12.col-sm-10.col-sm-offset-1.col-md-8.col-md-offset-2 - h3 Details - h4 - ol - for sentence in description - li!= sentence - .ten-pixel-break - .btn.btn-success.btn-big.btn-block.all-challenges Show me all the challenges - #complete-dialog.modal(tabindex='-1') - .modal-dialog.animated.zoomIn.fast-animation - .modal-content - .modal-header.challenge-list-header Nicely done! - a.close.closing-x(href='#', data-dismiss='modal', aria-hidden='true') × - .modal-body - .text-center - .animated.zoomInDown.delay-half - span.landing-icon.ion-checkmark-circled.text-primary - - if (cc) - a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block.next-button(name='_csrf', value=_csrf, aria-hidden='true') Take me to my next challenge - - if (points && points > 2) - a.animated.fadeIn.btn.btn-lg.btn-block.btn-twitter(href="https://twitter.com/intent/tweet?text=I%20just%20#{verb}%20Free%20Code%20Camp%20Challenge%20%23#{number}:%20#{name}&url=http%3A%2F%2Ffreecodecamp.com/challenges/#{number}&hashtags=learntocode, javascript" target="_blank") - i.fa.fa-twitter   - = phrase - - else - a.animated.fadeIn.btn.btn-lg.signup-btn.btn-block(href='/login') Sign in so you can save your progress - #all-challenges-dialog.modal(tabindex='-1') - .modal-dialog.animated.fadeInUp.fast-animation - .modal-content - .modal-header.challenge-list-header Challenges - a.close.closing-x(href='#', data-dismiss='modal', aria-hidden='true') × - .modal-body - include ../partials/bonfires \ No newline at end of file + #submitButton.btn.btn-primary.btn-big.btn-block Run code (ctrl + enter) + br + form.code + .form-group.codeMirrorView + textarea#codeOutput + br + ul#testSuite.list-group + br + script(src='/js/lib/bonfire/bonfireFramework.js') \ No newline at end of file diff --git a/views/partials/bonfires.jade b/views/partials/bonfires.jade index 41f9bbe9dd..dfa484708a 100644 --- a/views/partials/bonfires.jade +++ b/views/partials/bonfires.jade @@ -2,5 +2,44 @@ 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) \ No newline at end of file + a(href="/bonfire/#{bonfire.bonfireNumber}") #{bonfire.name} + |   (Level #{bonfire.difficulty}) + + block content + script(src='/js/lib/codemirror/lib/codemirror.js') + script(src='/js/lib/codemirror/addon/edit/closebrackets.js') + script(src='/js/lib/codemirror/addon/edit/matchbrackets.js') + script(src='/js/lib/codemirror/addon/lint/lint.js') + script(src='/js/lib/codemirror/addon/lint/javascript-lint.js') + script(src='//ajax.aspnetcdn.com/ajax/jshint/r07/jshint.js') + script(src='/js/lib/chai/chai.js') + link(rel='stylesheet', href='/js/lib/codemirror/lib/codemirror.css') + link(rel='stylesheet', href='/js/lib/codemirror/addon/lint/lint.css') + link(rel='stylesheet', href='/js/lib/codemirror/theme/monokai.css') + link(rel="stylesheet", href="http://fonts.googleapis.com/css?family=Ubuntu+Mono") + script(src='/js/lib/codemirror/mode/javascript/javascript.js') + script(src='/js/lib/jailed/jailed.js') + script(src='/js/lib/bonfire/bonfireInit.js') + .row + #mainEditorPanel.col-sm-12.col-md-7.col-xs-12 + .panel.panel-primary.panel-bonfire + .panel-heading.text-center Bonfire Playground + .panel.panel-body + form.code + .form-group.codeMirrorView + textarea#codeEditor(autofocus=true) + + + #testCreatePanel.col-sm-12.col-md-5.col-xs-12 + .panel.panel-primary.panel-bonfire + .panel-heading.text-center Output + .panel.panel-body + #submitButton.btn.btn-primary.btn-big.btn-block Run code (ctrl + enter) + br + form.code + .form-group.codeMirrorView + textarea#codeOutput + br + ul#testSuite.list-group + br + script(src='/js/lib/bonfire/bonfireFramework.js') \ No newline at end of file diff --git a/views/partials/challenges.jade b/views/partials/challenges.jade index cb93b2deeb..cef62c9d57 100644 --- a/views/partials/challenges.jade +++ b/views/partials/challenges.jade @@ -2,5 +2,7 @@ h3 ol(start='0') for challenge in challenges li - a(href="/bonfire/#{bonfire.bonfireNumber}", class="#{ (cc && cc[bonfire.bonfireNumber] > 0) ? 'strikethrough' : '' }") #{bonfire.name} - |   (Level #{bonfire.difficulty}) + a(href="/challenges/#{challenge.challengeNumber}", class="#{ (cc && cc[challenge.challengeNumber] > 0) ? 'strikethrough' : '' }") #{challenge.name} + |   (#{challenge.time} mins) + +a.btn.btn-lg.btn-primary.btn-block(href="/done-with-first-100-hours", class="#{ ((cc && cc[53] === 0) || (!cc)) ? 'disabled' : '' }") I'm done with all the challenges! \ No newline at end of file