Refactor routing, minor display tweaks

This commit is contained in:
Nathan Leniz
2015-01-27 20:12:51 -05:00
parent 547b9757b1
commit 3844542651
6 changed files with 132 additions and 120 deletions

80
app.js
View File

@ -265,7 +265,16 @@ app.get(
); );
app.all('/account', passportConf.isAuthenticated); app.all('/account', passportConf.isAuthenticated);
app.get('/account/api', userController.getAccountAngular); app.get('/account/api', userController.getAccountAngular);
/**
* Bonfire related routes
*/
app.get('/playground', bonfireController.index); 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( app.get(
'/bonfires/:bonfireName', '/bonfires/:bonfireName',
bonfireController.returnIndividualBonfire bonfireController.returnIndividualBonfire
@ -273,48 +282,8 @@ app.get(
app.get('/bonfire', function(req, res) { app.get('/bonfire', function(req, res) {
res.redirect(301, '/playground'); 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) { 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 isCompletedWith = req.body.bonfireInfo.completedWith || undefined;
var isCompletedDate = Math.round(+new Date() / 1000); var isCompletedDate = Math.round(+new Date() / 1000);
var bonfireHash = req.body.bonfireInfo.bonfireHash; 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. * OAuth sign-in routes.
*/ */

View File

@ -39,8 +39,7 @@ body.top-and-bottom-margins {
} }
body.no-top-and-bottom-margins { body.no-top-and-bottom-margins {
padding-top: 50px; margin: 70px 20px 50px 20px;
margin-bottom: 40px;
} }
h1, h2 { h1, h2 {
@ -624,13 +623,25 @@ form.code span {
} }
div.CodeMirror-scroll { div.CodeMirror-scroll {
padding-bottom: 40px; padding-bottom: 30px;
} }
.test-vertical-center { .test-vertical-center {
margin-top: 15px; 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 //uncomment this to see the dimensions of all elements outlined in red

View File

@ -1,6 +1,6 @@
/* Based on Sublime Text's Monokai theme */ /* 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 div.CodeMirror-selected {background: #49483E !important;}
.cm-s-monokai .CodeMirror-gutters {background: #272822; border-right: 0px;} .cm-s-monokai .CodeMirror-gutters {background: #272822; border-right: 0px;}
.cm-s-monokai .CodeMirror-guttermarker { color: white; } .cm-s-monokai .CodeMirror-guttermarker { color: white; }

View File

@ -4,9 +4,9 @@ block content
.col-md-offset-2.col-md-8.col-lg-offset-2.col-lg-8.text-center .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 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 .panel
form.form-horizontal(method="POST", action="/bonfire/generator", name="bonfireInfo") form.form-horizontal(method="POST", action="/bonfire-json-generator", name="bonfireInfo")
.form-group .form-group
label.col-sm-2.control-label(for='name') name: label.col-sm-2.control-label(for='name') name:
.col-sm-10 .col-sm-10

View File

@ -2,10 +2,10 @@ extends ../layout
block content block content
.row .row
.col-md-offset-2.col-md-8.col-lg-offset-2.col-lg-8.text-center .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 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-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 .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 .form-group
label.col-sm-2.control-label(for='name') name: label.col-sm-2.control-label(for='name') name:
.col-sm-10 .col-sm-10

View File

@ -18,78 +18,79 @@ block content
.row .row
.col-xs-12.col-sm-12.col-md-3 .col-xs-12.col-sm-12.col-md-4.bonfire-top
#testCreatePanel #testCreatePanel
h2.text-center #{name}
h2.text-center h2.text-center= name
if (difficulty == "0") h2.text-center.bonfire-flames
i.ion-ios-flame-outline 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 i.ion-ios-flame-outline
i.ion-ios-flame-outline i.ion-ios-flame-outline
if (difficulty == "1") i.ion-ios-flame-outline
i.ion-ios-flame if (difficulty == "1")
i.ion-ios-flame-outline i.ion-ios-flame
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 i.ion-ios-flame-outline
if (difficulty == "2") i.ion-ios-flame-outline
i.ion-ios-flame if (difficulty == "2")
i.ion-ios-flame i.ion-ios-flame
i.ion-ios-flame-outline 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 == "3") i.ion-ios-flame-outline
i.ion-ios-flame if (difficulty == "3")
i.ion-ios-flame i.ion-ios-flame
i.ion-ios-flame i.ion-ios-flame
i.ion-ios-flame-outline i.ion-ios-flame
i.ion-ios-flame-outline i.ion-ios-flame-outline
if (difficulty == "4") i.ion-ios-flame-outline
i.ion-ios-flame if (difficulty == "4")
i.ion-ios-flame i.ion-ios-flame
i.ion-ios-flame i.ion-ios-flame
i.ion-ios-flame i.ion-ios-flame
i.ion-ios-flame-outline i.ion-ios-flame
if (difficulty == "5") i.ion-ios-flame-outline
i.ion-ios-flame if (difficulty == "5")
i.ion-ios-flame i.ion-ios-flame
i.ion-ios-flame i.ion-ios-flame
i.ion-ios-flame i.ion-ios-flame
i.ion-ios-flame i.ion-ios-flame
.well i.ion-ios-flame
.row.text-center .well
row.text-center .row.text-center
.col-xs-12 row.text-center
.bonfire-instructions .col-xs-12
= brief .bonfire-instructions
#brief-instructions.col-xs-12 = brief
button#more-info.btn.btn-info #brief-instructions.col-xs-12
span.ion-help-circled button#more-info.btn.btn-info
| More information span.ion-help-circled
#long-instructions.row.text-center.hide | More information
.col-xs-12 #long-instructions.row.text-center.hide
.bonfire-instructions .col-xs-12
for sentence in details .bonfire-instructions
p!= sentence for sentence in details
button#less-info.btn.btn-info p!= sentence
span.ion-help-circled button#less-info.btn.btn-info
| Less information span.ion-help-circled
#submitButton.btn.btn-primary.btn-big.btn-block Run code (ctrl + enter) | Less information
br #submitButton.btn.btn-primary.btn-big.btn-block Run code (ctrl + enter)
form.code br
.form-group.codeMirrorView form.code
textarea#codeOutput .form-group.codeMirrorView
br textarea#codeOutput
#testSuite br
br #testSuite
script(type="text/javascript"). br
var tests = !{JSON.stringify(tests)}; script(type="text/javascript").
var challengeSeed = !{JSON.stringify(challengeSeed)}; var tests = !{JSON.stringify(tests)};
var challengeEntryPoint = !{JSON.stringify(challengeEntryPoint)}; var challengeSeed = !{JSON.stringify(challengeSeed)};
var passedBonfireHash = !{JSON.stringify(bonfireHash)}; var challengeEntryPoint = !{JSON.stringify(challengeEntryPoint)};
.col-xs-12.col-sm-12.col-md-9 var passedBonfireHash = !{JSON.stringify(bonfireHash)};
.col-xs-12.col-sm-12.col-md-8
#mainEditorPanel #mainEditorPanel
form.code form.code
.form-group.codeMirrorView .form-group.codeMirrorView