From 38445426515d503a0f6f1f5355ff10c97aa188b5 Mon Sep 17 00:00:00 2001 From: Nathan Leniz Date: Tue, 27 Jan 2015 20:12:51 -0500 Subject: [PATCH] Refactor routing, minor display tweaks --- app.js | 80 ++++++------ public/css/main.less | 17 ++- public/js/lib/codemirror/theme/monokai.css | 2 +- views/bonfire/generator.jade | 4 +- views/bonfire/public-generator.jade | 6 +- views/bonfire/show.jade | 143 +++++++++++---------- 6 files changed, 132 insertions(+), 120 deletions(-) diff --git a/app.js b/app.js index c9e59393f1..16d5307f2b 100644 --- a/app.js +++ b/app.js @@ -265,7 +265,16 @@ app.get( ); app.all('/account', passportConf.isAuthenticated); app.get('/account/api', userController.getAccountAngular); + +/** + * Bonfire related routes + */ app.get('/playground', bonfireController.index); +app.get('/bonfires', bonfireController.returnNextBonfire); +app.get('/bonfire-json-generator', bonfireController.returnGenerator); +app.post('/bonfire-json-generator', bonfireController.generateChallenge); +app.get('/bonfire-challenge-generator', bonfireController.publicGenerator); +app.post('/bonfire-challenge-generator', bonfireController.testBonfire) app.get( '/bonfires/:bonfireName', bonfireController.returnIndividualBonfire @@ -273,48 +282,8 @@ app.get( app.get('/bonfire', function(req, res) { res.redirect(301, '/playground'); }); -app.get('/bonfires', bonfireController.returnNextBonfire); -app.get('/bonfire/generator', bonfireController.returnGenerator); -app.post('/bonfire/generator', bonfireController.generateChallenge); -app.get('/bonfire/public-generator', bonfireController.publicGenerator); -app.post('/bonfire/public-generator', bonfireController.testBonfire) - -// Unique Check API route -app.get('/api/checkUniqueUsername/:username', userController.checkUniqueUsername); -app.get('/api/checkExistingUsername/:username', userController.checkExistingUsername); -app.get('/api/checkUniqueEmail/:email', userController.checkUniqueEmail); -app.get('/account', userController.getAccount); -app.post('/account/profile', userController.postUpdateProfile); -app.post('/account/password', userController.postUpdatePassword); -app.post('/account/delete', userController.postDeleteAccount); -app.get('/account/unlink/:provider', userController.getOauthUnlink); - - -/** - * API examples routes. - * accepts a post request. the challenge id req.body.challengeNumber - * and updates user.challengesHash & user.challengesCompleted - * - */ -app.post('/completed-challenge', function (req, res) { - req.user.challengesHash[parseInt(req.body.challengeNumber)] = - Math.round(+new Date() / 1000); - var timestamp = req.user.challengesHash; - var points = 0; - for (var key in timestamp) { - if (timestamp[key] > 0) { - points += 1; - } - } - req.user.points = points; - req.user.save(); -}); app.post('/completed-bonfire/', function (req, res) { - - // TODO: remove debug statement - debug(req.body.bonfireInfo, 'This is bonfire info we got from posted'); - var isCompletedWith = req.body.bonfireInfo.completedWith || undefined; var isCompletedDate = Math.round(+new Date() / 1000); var bonfireHash = req.body.bonfireInfo.bonfireHash; @@ -376,6 +345,37 @@ app.post('/completed-bonfire/', function (req, res) { }); +// Unique Check API route +app.get('/api/checkUniqueUsername/:username', userController.checkUniqueUsername); +app.get('/api/checkExistingUsername/:username', userController.checkExistingUsername); +app.get('/api/checkUniqueEmail/:email', userController.checkUniqueEmail); +app.get('/account', userController.getAccount); +app.post('/account/profile', userController.postUpdateProfile); +app.post('/account/password', userController.postUpdatePassword); +app.post('/account/delete', userController.postDeleteAccount); +app.get('/account/unlink/:provider', userController.getOauthUnlink); + + +/** + * API examples routes. + * accepts a post request. the challenge id req.body.challengeNumber + * and updates user.challengesHash & user.challengesCompleted + * + */ +app.post('/completed-challenge', function (req, res) { + req.user.challengesHash[parseInt(req.body.challengeNumber)] = + Math.round(+new Date() / 1000); + var timestamp = req.user.challengesHash; + var points = 0; + for (var key in timestamp) { + if (timestamp[key] > 0) { + points += 1; + } + } + req.user.points = points; + req.user.save(); +}); + /** * OAuth sign-in routes. */ diff --git a/public/css/main.less b/public/css/main.less index fe5cd6676f..78b4a42b08 100644 --- a/public/css/main.less +++ b/public/css/main.less @@ -39,8 +39,7 @@ body.top-and-bottom-margins { } body.no-top-and-bottom-margins { - padding-top: 50px; - margin-bottom: 40px; + margin: 70px 20px 50px 20px; } h1, h2 { @@ -624,13 +623,25 @@ form.code span { } div.CodeMirror-scroll { - padding-bottom: 40px; + padding-bottom: 30px; } .test-vertical-center { margin-top: 15px; } +.cm-s-monokai.CodeMirror { + border-radius: 5px; +} +.bonfire-flames { + margin-top: -20px; + margin-bottom: -2px; +} + +.bonfire-top { + margin-top: -30px; +} + //uncomment this to see the dimensions of all elements outlined in red diff --git a/public/js/lib/codemirror/theme/monokai.css b/public/js/lib/codemirror/theme/monokai.css index 2aa742c4ca..8ac80e7ac2 100644 --- a/public/js/lib/codemirror/theme/monokai.css +++ b/public/js/lib/codemirror/theme/monokai.css @@ -1,6 +1,6 @@ /* Based on Sublime Text's Monokai theme */ -.cm-s-monokai.CodeMirror {background: #272822; color: #f8f8f2; border-radius: 5px; height: auto;} +.cm-s-monokai.CodeMirror {background: #272822; color: #f8f8f2; height: auto;} .cm-s-monokai div.CodeMirror-selected {background: #49483E !important;} .cm-s-monokai .CodeMirror-gutters {background: #272822; border-right: 0px;} .cm-s-monokai .CodeMirror-guttermarker { color: white; } diff --git a/views/bonfire/generator.jade b/views/bonfire/generator.jade index 861b8ffee9..63f53f7be1 100644 --- a/views/bonfire/generator.jade +++ b/views/bonfire/generator.jade @@ -4,9 +4,9 @@ block content .col-md-offset-2.col-md-8.col-lg-offset-2.col-lg-8.text-center h1 JSON generator for bonfire challenges - just fill the form out and get the correct format back - .col-xs-12.col-sm-12.col-md-offset-3.col-md-6.col-lg-offset-3-col-lg-6 + .col-xs-12.col-sm-12.col-md-offset-1.col-md-10.col-lg-offset-1-col-lg-10 .panel - form.form-horizontal(method="POST", action="/bonfire/generator", name="bonfireInfo") + form.form-horizontal(method="POST", action="/bonfire-json-generator", name="bonfireInfo") .form-group label.col-sm-2.control-label(for='name') name: .col-sm-10 diff --git a/views/bonfire/public-generator.jade b/views/bonfire/public-generator.jade index 13750a9b4d..c3761fe674 100644 --- a/views/bonfire/public-generator.jade +++ b/views/bonfire/public-generator.jade @@ -2,10 +2,10 @@ extends ../layout block content .row .col-md-offset-2.col-md-8.col-lg-offset-2.col-lg-8.text-center - h1 JSON generator for bonfire challenges - just fill the form out and get the correct format back - .col-xs-12.col-sm-12.col-md-offset-3.col-md-6.col-lg-offset-3-col-lg-6 + h1 Welcome to the challenge generator. Test your ideas out and see them live in bonfire! + .col-xs-12.col-sm-12.col-md-offset-1.col-md-10.col-lg-offset-1-col-lg-10 .panel - form.form-horizontal(method="POST", action="/bonfire/public-generator", name="bonfireInfo") + form.form-horizontal(method="POST", action="/bonfire-challenge-generator", name="bonfireInfo") .form-group label.col-sm-2.control-label(for='name') name: .col-sm-10 diff --git a/views/bonfire/show.jade b/views/bonfire/show.jade index 24e5405698..259634d536 100644 --- a/views/bonfire/show.jade +++ b/views/bonfire/show.jade @@ -18,78 +18,79 @@ block content .row - .col-xs-12.col-sm-12.col-md-3 + .col-xs-12.col-sm-12.col-md-4.bonfire-top #testCreatePanel - h2.text-center #{name} - h2.text-center - if (difficulty == "0") - i.ion-ios-flame-outline - i.ion-ios-flame-outline - i.ion-ios-flame-outline - i.ion-ios-flame-outline - i.ion-ios-flame-outline - if (difficulty == "1") - i.ion-ios-flame - i.ion-ios-flame-outline - i.ion-ios-flame-outline - i.ion-ios-flame-outline - i.ion-ios-flame-outline - if (difficulty == "2") - i.ion-ios-flame - i.ion-ios-flame - i.ion-ios-flame-outline - i.ion-ios-flame-outline - i.ion-ios-flame-outline - if (difficulty == "3") - i.ion-ios-flame - i.ion-ios-flame - i.ion-ios-flame - i.ion-ios-flame-outline - i.ion-ios-flame-outline - if (difficulty == "4") - i.ion-ios-flame - i.ion-ios-flame - i.ion-ios-flame - i.ion-ios-flame - i.ion-ios-flame-outline - if (difficulty == "5") - i.ion-ios-flame - i.ion-ios-flame - i.ion-ios-flame - i.ion-ios-flame - i.ion-ios-flame - .well - .row.text-center - row.text-center - .col-xs-12 - .bonfire-instructions - = brief - #brief-instructions.col-xs-12 - button#more-info.btn.btn-info - span.ion-help-circled - | More information - #long-instructions.row.text-center.hide - .col-xs-12 - .bonfire-instructions - for sentence in details - p!= sentence - button#less-info.btn.btn-info - span.ion-help-circled - | Less information - #submitButton.btn.btn-primary.btn-big.btn-block Run code (ctrl + enter) - br - form.code - .form-group.codeMirrorView - textarea#codeOutput - br - #testSuite - br - script(type="text/javascript"). - var tests = !{JSON.stringify(tests)}; - var challengeSeed = !{JSON.stringify(challengeSeed)}; - var challengeEntryPoint = !{JSON.stringify(challengeEntryPoint)}; - var passedBonfireHash = !{JSON.stringify(bonfireHash)}; - .col-xs-12.col-sm-12.col-md-9 + + h2.text-center= name + h2.text-center.bonfire-flames + if (difficulty == "0") + i.ion-ios-flame-outline + i.ion-ios-flame-outline + i.ion-ios-flame-outline + i.ion-ios-flame-outline + i.ion-ios-flame-outline + if (difficulty == "1") + i.ion-ios-flame + i.ion-ios-flame-outline + i.ion-ios-flame-outline + i.ion-ios-flame-outline + i.ion-ios-flame-outline + if (difficulty == "2") + i.ion-ios-flame + i.ion-ios-flame + i.ion-ios-flame-outline + i.ion-ios-flame-outline + i.ion-ios-flame-outline + if (difficulty == "3") + i.ion-ios-flame + i.ion-ios-flame + i.ion-ios-flame + i.ion-ios-flame-outline + i.ion-ios-flame-outline + if (difficulty == "4") + i.ion-ios-flame + i.ion-ios-flame + i.ion-ios-flame + i.ion-ios-flame + i.ion-ios-flame-outline + if (difficulty == "5") + i.ion-ios-flame + i.ion-ios-flame + i.ion-ios-flame + i.ion-ios-flame + i.ion-ios-flame + .well + .row.text-center + row.text-center + .col-xs-12 + .bonfire-instructions + = brief + #brief-instructions.col-xs-12 + button#more-info.btn.btn-info + span.ion-help-circled + | More information + #long-instructions.row.text-center.hide + .col-xs-12 + .bonfire-instructions + for sentence in details + p!= sentence + button#less-info.btn.btn-info + span.ion-help-circled + | Less information + #submitButton.btn.btn-primary.btn-big.btn-block Run code (ctrl + enter) + br + form.code + .form-group.codeMirrorView + textarea#codeOutput + br + #testSuite + br + script(type="text/javascript"). + var tests = !{JSON.stringify(tests)}; + var challengeSeed = !{JSON.stringify(challengeSeed)}; + var challengeEntryPoint = !{JSON.stringify(challengeEntryPoint)}; + var passedBonfireHash = !{JSON.stringify(bonfireHash)}; + .col-xs-12.col-sm-12.col-md-8 #mainEditorPanel form.code .form-group.codeMirrorView