Update to bonfires. Successfully completing triggers a save. "Paired with" form field moved to bonfire view. Controller hardened for checking pair as button is no longer disabled for unfound username
This commit is contained in:
@ -324,6 +324,7 @@ exports.completedBonfire = function (req, res, next) {
|
||||
req.user.uncompletedChallenges.splice(index, 1);
|
||||
}
|
||||
pairedWith = pairedWith.pop();
|
||||
if (pairedWith) {
|
||||
|
||||
index = pairedWith.uncompletedChallenges.indexOf(challengeId);
|
||||
if (index > -1) {
|
||||
@ -349,11 +350,23 @@ exports.completedBonfire = function (req, res, next) {
|
||||
solution: isSolution,
|
||||
challengeType: 5
|
||||
});
|
||||
}
|
||||
// User said they paired, but pair wasn't found
|
||||
req.user.completedChallenges.push({
|
||||
_id: challengeId,
|
||||
name: challengeName,
|
||||
completedWith: null,
|
||||
completedDate: isCompletedDate,
|
||||
solution: isSolution,
|
||||
challengeType: 5
|
||||
});
|
||||
|
||||
|
||||
req.user.save(function (err, user) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
if (pairedWith) {
|
||||
pairedWith.save(function (err, paired) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
@ -362,6 +375,11 @@ exports.completedBonfire = function (req, res, next) {
|
||||
res.send(true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (user) {
|
||||
res.send(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -239,6 +239,20 @@ var runTests = function(err, data) {
|
||||
function showCompletion() {
|
||||
var time = Math.floor(Date.now()) - started;
|
||||
ga('send', 'event', 'Challenge', 'solved', challenge_Name + ', Time: ' + time +', Attempts: ' + attempts);
|
||||
var bonfireSolution = myCodeMirror.getValue();
|
||||
var didCompleteWith = $('#completed-with').val() || null;
|
||||
$.post(
|
||||
'/completed-bonfire/',
|
||||
{
|
||||
challengeInfo: {
|
||||
challengeId: challenge_Id,
|
||||
challengeName: challenge_Name,
|
||||
completedWith: didCompleteWith,
|
||||
challengeType: challengeType,
|
||||
solution: bonfireSolution
|
||||
}
|
||||
}, function(res) {
|
||||
if (res) {
|
||||
$('#complete-courseware-dialog').modal('show');
|
||||
$('#complete-courseware-dialog').keydown(function (e) {
|
||||
if (e.ctrlKey && e.keyCode == 13) {
|
||||
@ -246,3 +260,7 @@ function showCompletion() {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
@ -215,29 +215,10 @@ $(document).ready(function() {
|
||||
});
|
||||
break;
|
||||
case challengeTypes.BONFIRE:
|
||||
var bonfireSolution = myCodeMirror.getValue();
|
||||
var didCompleteWith = $('#completed-with').val() || null;
|
||||
$.post(
|
||||
'/completed-bonfire/',
|
||||
{
|
||||
challengeInfo: {
|
||||
challengeId: challenge_Id,
|
||||
challengeName: challenge_Name,
|
||||
completedWith: didCompleteWith,
|
||||
challengeType: challengeType,
|
||||
solution: bonfireSolution
|
||||
}
|
||||
},
|
||||
function(res) {
|
||||
if (res) {
|
||||
window.location.href = '/challenges/next-challenge';
|
||||
}
|
||||
}
|
||||
);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -16,7 +16,7 @@ block content
|
||||
script(type='text/javascript', src='/js/lib/jailed/jailed.js')
|
||||
script(type='text/javascript', src='/js/lib/coursewares/sandbox.js')
|
||||
|
||||
.row
|
||||
.row(ng-controller="pairedWithController")
|
||||
.col-xs-12.col-sm-12.col-md-4.bonfire-top
|
||||
#testCreatePanel
|
||||
h1#bonfire-name.text-center= name
|
||||
@ -79,6 +79,18 @@ block content
|
||||
span.ion-arrow-up-b
|
||||
| Less information
|
||||
|
||||
if (user)
|
||||
form.form-horizontal(novalidate='novalidate', name='completedWithForm')
|
||||
.form-group.text-center
|
||||
.col-xs-10.col-xs-offset-1.col-sm-8.col-sm-offset-2.col-md-8.col-md-offset-2.animated.fadeIn
|
||||
// extra field to distract password tools like lastpass from injecting css into our username field
|
||||
input.form-control(ng-show="false")
|
||||
label(for="existingUser") If you're pairing with someone, enter their FreeCodeCamp username here
|
||||
input.form-control#completed-with(name="existingUser", placeholder="Pair Username", existing-username='', ng-model="existingUser", autofocus)
|
||||
.col-xs-10.col-xs-offset-1.col-sm-8.col-sm-offset-2.col-md-8.col-md-offset-2(ng-cloak, ng-show="completedWithForm.$error.exists && !completedWithForm.existingUser.$pristine && existingUser.length > 0")
|
||||
alert(type='danger')
|
||||
span.ion-close-circled
|
||||
| Username not found
|
||||
#submitButton.btn.btn-primary.btn-big.btn-block Run code (ctrl + enter)
|
||||
.button-spacer
|
||||
.btn-group.input-group.btn-group-justified
|
||||
@ -122,23 +134,13 @@ block content
|
||||
.modal-content
|
||||
.modal-header.challenge-list-header= compliment
|
||||
a.close.closing-x(href='#', data-dismiss='modal', aria-hidden='true') ×
|
||||
.modal-body(ng-controller="pairedWithController")
|
||||
.modal-body
|
||||
.text-center
|
||||
.animated.zoomInDown.delay-half
|
||||
span.completion-icon.ion-checkmark-circled.text-primary
|
||||
- if (user)
|
||||
form.form-horizontal(novalidate='novalidate', name='completedWithForm')
|
||||
.form-group.text-center
|
||||
.col-xs-10.col-xs-offset-1.col-sm-8.col-sm-offset-2.col-md-8.col-md-offset-2.animated.fadeIn
|
||||
// extra field to distract password tools like lastpass from injecting css into our username field
|
||||
input.form-control(ng-show="false")
|
||||
input.form-control#completed-with(name="existingUser", placeholder="If you paired, enter your pair's username here", existing-username='', ng-model="existingUser", autofocus)
|
||||
.col-xs-10.col-xs-offset-1.col-sm-8.col-sm-offset-2.col-md-8.col-md-offset-2(ng-cloak, ng-show="completedWithForm.$error.exists && !completedWithForm.existingUser.$pristine && existingUser.length > 0")
|
||||
alert(type='danger')
|
||||
span.ion-close-circled
|
||||
| Username not found
|
||||
|
||||
a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block#next-courseware-button(name='_csrf', value=_csrf, ng-disabled='completedWithForm.$invalid && existingUser.length > 0') Go to my next bonfire (ctrl + enter)
|
||||
a.animated.fadeIn.btn.btn-lg.btn-primary.btn-block#next-courseware-button(name='_csrf', value=_csrf) Go to my next challenge (ctrl + enter)
|
||||
|
||||
|
||||
- if (user.progressTimestamps.length > 2)
|
||||
|
Reference in New Issue
Block a user