Merge pull request #3187 from QuincyLarson/learn-button

add learn button
This commit is contained in:
Quincy Larson
2015-09-09 18:30:22 -07:00
10 changed files with 73 additions and 98 deletions

View File

@ -471,7 +471,7 @@ function showCompletion() {
}, },
function(res) { function(res) {
if (res) { if (res) {
window.location = '/challenges/next-challenge'; window.location = '/challenges/next-challenge?id=' + challenge_Id;
} }
} }
); );

View File

@ -141,7 +141,7 @@ $(document).ready(function() {
}).success( }).success(
function(res) { function(res) {
if (res) { if (res) {
window.location.href = '/challenges/next-challenge'; window.location.href = '/challenges/next-challenge?id=' + challenge_Id;
} }
}).fail( }).fail(
function() { function() {
@ -164,7 +164,7 @@ $(document).ready(function() {
} }
}).success( }).success(
function() { function() {
window.location.href = '/challenges/next-challenge'; window.location.href = '/challenges/next-challenge?id=' + challenge_Id;
}).fail( }).fail(
function() { function() {
window.location.href = '/challenges'; window.location.href = '/challenges';
@ -187,13 +187,13 @@ $(document).ready(function() {
verified: false verified: false
} }
}).success(function() { }).success(function() {
window.location.href = '/challenges/next-challenge'; window.location.href = '/challenges/next-challenge?id=' + challenge_Id;
}).fail(function() { }).fail(function() {
window.location.replace(window.location.href); window.location.replace(window.location.href);
}); });
break; break;
case challengeTypes.BONFIRE: case challengeTypes.BONFIRE:
window.location.href = '/challenges/next-challenge'; window.location.href = '/challenges/next-challenge?id=' + challenge_Id;
default: default:
break; break;
} }

View File

@ -14,7 +14,6 @@ import {
import { import {
userMigration, userMigration,
ifNoUserRedirectTo,
ifNoUserSend ifNoUserSend
} from '../utils/middleware'; } from '../utils/middleware';
@ -100,9 +99,6 @@ module.exports = function(app) {
const userCount$ = observeMethod(User, 'count'); const userCount$ = observeMethod(User, 'count');
const send200toNonUser = ifNoUserSend(true); const send200toNonUser = ifNoUserSend(true);
const redirectNonUser = ifNoUserRedirectTo(
'/challenges/learn-how-free-code-camp-works'
);
router.post( router.post(
'/completed-challenge/', '/completed-challenge/',
@ -125,26 +121,17 @@ module.exports = function(app) {
router.get('/map', challengeMap); router.get('/map', challengeMap);
router.get( router.get(
'/challenges/next-challenge', '/challenges/next-challenge',
redirectNonUser,
returnNextChallenge returnNextChallenge
); );
router.get('/challenges/:challengeName', returnIndividualChallenge); router.get('/challenges/:challengeName', returnIndividualChallenge);
router.get(
'/challenges/',
redirectNonUser,
returnCurrentChallenge
);
app.use(router); app.use(router);
function returnNextChallenge(req, res, next) { function returnNextChallenge(req, res, next) {
let nextChallengeName = firstChallenge; let nextChallengeName = firstChallenge;
const challengeId = req.user.currentChallenge ? const challengeId = req.query.id;
req.user.currentChallenge.challengeId :
'bd7123c8c441eddfaeb5bdef';
// find challenge // find challenge
return challenge$ return challenge$
@ -199,16 +186,13 @@ module.exports = function(app) {
nextChallengeName = nextChallenge.dashedName; nextChallengeName = nextChallenge.dashedName;
return nextChallengeName; return nextChallengeName;
}) })
.flatMap(() => {
return saveUser(req.user);
})
.subscribe( .subscribe(
function() {}, function() {},
next, next,
function() { function() {
debug('next challengeName', nextChallengeName); debug('next challengeName', nextChallengeName);
if (!nextChallengeName || nextChallengeName === firstChallenge) { if (!nextChallengeName || nextChallengeName === firstChallenge) {
req.flash('errors', { req.flash('info', {
msg: dedent` msg: dedent`
Once you have completed all of our challenges, you should Once you have completed all of our challenges, you should
join our <a href=\"//gitter.im/freecodecamp/HalfWayClub\" join our <a href=\"//gitter.im/freecodecamp/HalfWayClub\"
@ -223,34 +207,6 @@ module.exports = function(app) {
); );
} }
function returnCurrentChallenge(req, res, next) {
Observable.just(req.user)
.flatMap(user => {
if (!req.user.currentChallenge) {
return challenge$
.first()
.flatMap(challenge => {
user.currentChallenge = {
challengeId: challenge.id,
challengeName: challenge.name,
dashedName: challenge.dashedName
};
return saveUser(user);
});
}
return Observable.just(user);
})
.map(user => user.currentChallenge.dashedName)
.subscribe(
function(challengeName) {
res.redirect('/challenges/' + challengeName);
},
next,
function() {
}
);
}
function returnIndividualChallenge(req, res, next) { function returnIndividualChallenge(req, res, next) {
const origChallengeName = req.params.challengeName; const origChallengeName = req.params.challengeName;
const unDashedName = unDasherize(origChallengeName); const unDashedName = unDasherize(origChallengeName);
@ -285,40 +241,29 @@ module.exports = function(app) {
return Observable.just('/challenges/' + dasherize(challenge.name)); return Observable.just('/challenges/' + dasherize(challenge.name));
} }
if (challenge) { // save user does nothing if user does not exist
if (req.user) { return Observable.just({
req.user.currentChallenge = { title: challenge.name,
challengeId: challenge.id, dashedName: origChallengeName,
challengeName: challenge.name, name: challenge.name,
dashedName: challenge.dashedName details: challenge.description,
}; tests: challenge.tests,
} challengeSeed: challenge.challengeSeed,
verb: utils.randomVerb(),
// save user does nothing if user does not exist phrase: utils.randomPhrase(),
return saveUser(req.user) compliment: utils.randomCompliment(),
.map(() => ({ challengeId: challenge.id,
title: challenge.name, challengeType: challenge.challengeType,
dashedName: origChallengeName, // video challenges
name: challenge.name, video: challenge.challengeSeed[0],
details: challenge.description, // bonfires specific
tests: challenge.tests, difficulty: Math.floor(+challenge.difficulty),
challengeSeed: challenge.challengeSeed, bonfires: challenge,
verb: utils.randomVerb(), MDNkeys: challenge.MDNlinks,
phrase: utils.randomPhrase(), MDNlinks: getMDNLinks(challenge.MDNlinks),
compliment: utils.randomCompliment(), // htmls specific
challengeId: challenge.id, environment: utils.whichEnvironment()
challengeType: challenge.challengeType, });
// video challenges
video: challenge.challengeSeed[0],
// bonfires specific
difficulty: Math.floor(+challenge.difficulty),
bonfires: challenge,
MDNkeys: challenge.MDNlinks,
MDNlinks: getMDNLinks(challenge.MDNlinks),
// htmls specific
environment: utils.whichEnvironment()
}));
}
}) })
.subscribe( .subscribe(
function(data) { function(data) {

View File

@ -114,6 +114,7 @@ block content
var challenge_Name = !{JSON.stringify(name)}; var challenge_Name = !{JSON.stringify(name)};
var started = Math.floor(Date.now()); var started = Math.floor(Date.now());
var challengeType = !{JSON.stringify(challengeType)}; var challengeType = !{JSON.stringify(challengeType)};
var dashedName = !{JSON.stringify(dashedName)};
var _ = R; var _ = R;
var dashed = !{JSON.stringify(dashedName)}; var dashed = !{JSON.stringify(dashedName)};
@ -140,14 +141,14 @@ block content
.spacer .spacer
.row .row
if (user) if (user)
#submit-challenge.animated.fadeIn.btn.btn-lg.btn-primary.btn-block Submit and go to next challenge #submit-challenge.animated.fadeIn.btn.btn-lg.btn-primary.btn-block Submit and go to my next challenge
if (user.progressTimestamps.length > 2) if (user.progressTimestamps.length > 2)
a.animated.fadeIn.btn.btn-lg.btn-block.btn-twitter(target="_blank", href="https://twitter.com/intent/tweet?text=I%20just%20#{verb}%20%40FreeCodeCamp%20#{name}&url=http%3A%2F%2Ffreecodecamp.com/challenges/#{dashedName}&hashtags=LearnToCode, JavaScript") a.animated.fadeIn.btn.btn-lg.btn-block.btn-twitter(target="_blank", href="https://twitter.com/intent/tweet?text=I%20just%20#{verb}%20%40FreeCodeCamp%20#{name}&url=http%3A%2F%2Ffreecodecamp.com/challenges/#{dashedName}&hashtags=LearnToCode, JavaScript")
i.fa.fa-twitter &thinsp; i.fa.fa-twitter &thinsp;
= phrase = phrase
else else
a.animated.fadeIn.btn.btn-lg.signup-btn.btn-block(href='/login') Sign in so you can save your progress a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block(href='/challenges/next-challenge?id=' + challengeId) Go to my next challenge
#reset-modal.modal(tabindex='-1') #reset-modal.modal(tabindex='-1')
.modal-dialog.animated.fadeInUp.fast-animation .modal-dialog.animated.fadeInUp.fast-animation
.modal-content .modal-content

View File

@ -62,6 +62,7 @@ block content
var challenge_Id = !{JSON.stringify(challengeId)}; var challenge_Id = !{JSON.stringify(challengeId)};
var challenge_Name = !{JSON.stringify(name)}; var challenge_Name = !{JSON.stringify(name)};
var prodOrDev = !{JSON.stringify(environment)}; var prodOrDev = !{JSON.stringify(environment)};
var dashedName = !{JSON.stringify(dashedName)};
var challengeType = !{JSON.stringify(challengeType)}; var challengeType = !{JSON.stringify(challengeType)};
var started = Math.floor(Date.now()); var started = Math.floor(Date.now());
.col-xs-12.col-sm-12.col-md-5.col-lg-6 .col-xs-12.col-sm-12.col-md-5.col-lg-6
@ -91,7 +92,7 @@ block content
span.completion-icon.ion-checkmark-circled.text-primary span.completion-icon.ion-checkmark-circled.text-primary
.spacer .spacer
if(user) if(user)
#submit-challenge.animated.fadeIn.btn.btn-lg.btn-primary.btn-block Submit and go to next challenge #submit-challenge.animated.fadeIn.btn.btn-lg.btn-primary.btn-block Submit and go to my next challenge
else else
a.animated.fadeIn.btn.btn-lg.signup-btn.btn-block(href='/login') Sign in so you can save your progress a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block(href='/challenges/next-challenge?id=' + challengeId) Go to my next challenge
include ../partials/challenge-modals include ../partials/challenge-modals

View File

@ -61,6 +61,7 @@ block content
var challengeSeed = !{JSON.stringify(challengeSeed)}; var challengeSeed = !{JSON.stringify(challengeSeed)};
var challenge_Id = !{JSON.stringify(challengeId)}; var challenge_Id = !{JSON.stringify(challengeId)};
var challenge_Name = !{JSON.stringify(name)}; var challenge_Name = !{JSON.stringify(name)};
var dashedName = !{JSON.stringify(dashedName)};
var started = Math.floor(Date.now()); var started = Math.floor(Date.now());
var challengeType = !{JSON.stringify(challengeType)}; var challengeType = !{JSON.stringify(challengeType)};
var _ = R; var _ = R;
@ -93,7 +94,7 @@ block content
i.fa.fa-twitter &thinsp; i.fa.fa-twitter &thinsp;
= phrase = phrase
else else
a.animated.fadeIn.btn.btn-lg.signup-btn.btn-block(href='/login') Sign in so you can save your progress a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block(href='/challenges/next-challenge?id=' + challengeId) Go to my next challenge
include ../partials/challenge-modals include ../partials/challenge-modals
script. script.
var MDNlinks = !{JSON.stringify(MDNlinks)}; var MDNlinks = !{JSON.stringify(MDNlinks)};

View File

@ -17,7 +17,7 @@ block content
iframe.embed-responsive-item(src='//player.vimeo.com/video/#{video}') iframe.embed-responsive-item(src='//player.vimeo.com/video/#{video}')
br br
if (user) if (user)
a.btn.btn-primary.btn-big.btn-block#completed-courseware-editorless I've completed this challenge (ctrl + enter) a.btn.btn-primary.btn-big.btn-block#completed-courseware-editorless I've completed this challenge (ctrl + enter)
script. script.
var userLoggedIn = true; var userLoggedIn = true;
.button-spacer .button-spacer
@ -30,6 +30,8 @@ block content
| &nbsp; Report a bug | &nbsp; Report a bug
.button-spacer .button-spacer
else else
a.animated.fadeIn.btn.btn-big.btn-primary.btn-block(href='/challenges/next-challenge?id=' + challengeId) Go to my next challenge (ctrl + enter)
.button-spacer
a.btn.btn-big.signup-btn.btn-block(href='/login') Sign in so you can save your progress a.btn.btn-big.signup-btn.btn-block(href='/login') Sign in so you can save your progress
script. script.
var userLoggedIn = false; var userLoggedIn = false;
@ -64,7 +66,7 @@ block content
.animated.zoomInDown.delay-half .animated.zoomInDown.delay-half
span.completion-icon.ion-checkmark-circled.text-primary span.completion-icon.ion-checkmark-circled.text-primary
if (user) if (user)
a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block#next-courseware-button(name='_csrf', value=_csrf) On to my next challenge (ctrl + enter) a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block#next-courseware-button(name='_csrf', value=_csrf) Go to my next challenge
script. script.
$('#complete-courseware-editorless-dialog').bind('keypress', modalControlEnterHandler); $('#complete-courseware-editorless-dialog').bind('keypress', modalControlEnterHandler);
@ -74,12 +76,12 @@ block content
i.fa.fa-twitter &thinsp; i.fa.fa-twitter &thinsp;
= phrase = phrase
else else
a.animated.fadeIn.btn.btn-lg.signup-btn.btn-block(href='/login') Sign in so you can save your progress a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block(href='/challenges/next-challenge?id=' + challengeId) Go to my next challenge
h1 #{name}
script. script.
$('body').bind('keypress', controlEnterHandler); $('body').bind('keypress', controlEnterHandler);
script. script.
var challenge_Id = !{JSON.stringify(challengeId)}; var challenge_Id = !{JSON.stringify(challengeId)};
var challenge_Name = !{JSON.stringify(name)}; var challenge_Name = !{JSON.stringify(name)};
var challengeType = !{JSON.stringify(challengeType)}; var challengeType = !{JSON.stringify(challengeType)};
var dashedName = !{JSON.stringify(dashedName)};
include ../partials/challenge-modals include ../partials/challenge-modals

View File

@ -17,7 +17,7 @@ block content
iframe.embed-responsive-item(src='//player.vimeo.com/video/#{video}') iframe.embed-responsive-item(src='//player.vimeo.com/video/#{video}')
br br
if (user) if (user)
a.btn.btn-primary.btn-big.btn-block#completed-zipline-or-basejump I've completed this challenge (ctrl + enter) a.btn.btn-primary.btn-big.btn-block#completed-zipline-or-basejump I've completed this challenge (ctrl + enter)
.button-spacer .button-spacer
.btn-group.input-group.btn-group-justified .btn-group.input-group.btn-group-justified
.btn.btn-success.btn-big#trigger-help-modal .btn.btn-success.btn-big#trigger-help-modal
@ -33,7 +33,8 @@ block content
script. script.
var userLoggedIn = true; var userLoggedIn = true;
else else
a.btn.btn-lg.signup-btn.btn-block(href='/login') Sign in so you can save your progress a.animated.fadeIn.btn.btn-big.btn-primary.btn-block(href='/challenges/next-challenge?id=' + challengeId) Go to my next challenge (ctrl + enter)
a.btn.btn-big.signup-btn.btn-block(href='/login') Sign in so you can save your progress
script. script.
var userLoggedIn = false; var userLoggedIn = false;
br br
@ -41,6 +42,7 @@ block content
var challenge_Id = !{JSON.stringify(challengeId)}; var challenge_Id = !{JSON.stringify(challengeId)};
var challenge_Name = !{JSON.stringify(name)}; var challenge_Name = !{JSON.stringify(name)};
var started = Math.floor(Date.now()); var started = Math.floor(Date.now());
var dashedName = !{JSON.stringify(dashedName)};
var challengeType = !{JSON.stringify(challengeType)}; var challengeType = !{JSON.stringify(challengeType)};
var controlEnterHandler = function (e) { var controlEnterHandler = function (e) {
$('body').unbind('keypress'); $('body').unbind('keypress');
@ -87,11 +89,12 @@ block content
| Username not found | Username not found
if (user) if (user)
a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block#next-courseware-button(name='_csrf', value=_csrf, ng-disabled='completedWithForm.$invalid') Go to my next challenge (ctrl + enter) a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block#next-courseware-button(name='_csrf', value=_csrf, ng-disabled='completedWithForm.$invalid') Go to my next challenge
.button-spacer
script. script.
$('#complete-zipline-or-basejump-dialog').on('keypress', modalControlEnterHandler); $('#complete-zipline-or-basejump-dialog').on('keypress', modalControlEnterHandler);
else else
a.animated.fadeIn.btn.btn-lg.signup-btn.btn-block(href='/login') Sign in so you can save your progress a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block(href='/challenges/next-challenge?id=' + challengeId) Go to my next challenge
script. script.
$('body').on('keypress', controlEnterHandler); $('body').on('keypress', controlEnterHandler);
include ../partials/challenge-modals include ../partials/challenge-modals

View File

@ -47,3 +47,7 @@
h3 This will restore your code editor to its original state. h3 This will restore your code editor to its original state.
a.btn.btn-lg.btn-info.btn-block#reset-button(href='#', data-dismiss='modal', aria-hidden='true') Clear my code a.btn.btn-lg.btn-info.btn-block#reset-button(href='#', data-dismiss='modal', aria-hidden='true') Clear my code
a.btn.btn-lg.btn-primary.btn-block(href='#', data-dismiss='modal', aria-hidden='true') Cancel a.btn.btn-lg.btn-primary.btn-block(href='#', data-dismiss='modal', aria-hidden='true') Cancel
script.
if (typeof localStorage !== 'undefined') {
localStorage.setItem('currentDashedName', dashedName);
}

View File

@ -7,6 +7,8 @@ nav.navbar.navbar-default.navbar-fixed-top.nav-height
img.img-responsive.nav-logo(src='https://s3.amazonaws.com/freecodecamp/freecodecamp_logo.svg', alt='learn to code javascript at Free Code Camp logo') img.img-responsive.nav-logo(src='https://s3.amazonaws.com/freecodecamp/freecodecamp_logo.svg', alt='learn to code javascript at Free Code Camp logo')
.collapse.navbar-collapse .collapse.navbar-collapse
ul.nav.navbar-nav.navbar-right.hamburger-dropdown ul.nav.navbar-nav.navbar-right.hamburger-dropdown
li
a.learn-btn(href='#') Learn
li li
a(href='/map') Map a(href='/map') Map
li li
@ -32,3 +34,19 @@ nav.navbar.navbar-default.navbar-fixed-top.nav-height
.hidden-xs.hidden-sm .hidden-xs.hidden-sm
a(href='/account') a(href='/account')
img.profile-picture.float-right(src='#{user.picture}') img.profile-picture.float-right(src='#{user.picture}')
script.
$(document).ready(function() {
$('.learn-btn').click(function(e) {
var challengeDashedName = null;
e.preventDefault();
if (typeof dashedName === "string") {
return location.reload();
}
if (typeof localStorage !== 'undefined') {
challengeDashedName = localStorage.getItem('currentDashedName');
}
window.location = challengeDashedName ?
'/challenges/' + challengeDashedName :
'/map';
});
});