From 9fa0323049ef1c164047c211662910d772248917 Mon Sep 17 00:00:00 2001 From: Nathan Leniz Date: Wed, 28 Jan 2015 17:17:45 -0500 Subject: [PATCH 1/2] Sequence request for new bonfire to wait until save operation, making bonfire fetch unsolved bonfires at a much faster rate to ensure data sync --- app.js | 13 +++++-------- controllers/bonfire.js | 2 +- public/js/main.js | 37 ++++++++++++++++++------------------- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/app.js b/app.js index abfa3e5685..cfc2d71966 100644 --- a/app.js +++ b/app.js @@ -287,8 +287,6 @@ app.post('/completed-bonfire/', function (req, res) { var isCompletedDate = Math.round(+new Date() / 1000); var bonfireHash = req.body.bonfireInfo.bonfireHash; var isSolution = req.body.bonfireInfo.solution; - // TODO - debug(isCompletedWith, 'Is completed with'); if (isCompletedWith) { var paired = User.find({"profile.username": isCompletedWith}).limit(1); @@ -328,14 +326,14 @@ app.post('/completed-bonfire/', function (req, res) { throw err; } if (user && paired) { - res.redirect('/bonfires'); + res.send(true); } }) }); - } }) } else { + req.user.completedBonfires.push({ _id: bonfireHash, completedWith: null, @@ -344,21 +342,20 @@ app.post('/completed-bonfire/', function (req, res) { }) var index = req.user.uncompletedBonfires.indexOf(bonfireHash); - if (index > -1) { req.user.uncompletedBonfires.splice(index,1) } + req.user.save(function(err, user) { if (err) { throw err; } if (user) { - res.redirect('/bonfires'); + debug('Saving user'); + res.send(true) } }); - } - }); // Unique Check API route diff --git a/controllers/bonfire.js b/controllers/bonfire.js index 5025e68cf7..d9a2c7967d 100644 --- a/controllers/bonfire.js +++ b/controllers/bonfire.js @@ -37,7 +37,7 @@ exports.returnNextBonfire = function(req, res, next) { return res.redirect('bonfires/meet-bonfire'); } var currentTime = parseInt(+new Date() / 1000); - if (currentTime - req.user.lastContentSync > 86400) { + if (currentTime - req.user.lastContentSync > 10) { req.user.lastContentSync = currentTime; var completed = req.user.completedBonfires.map(function (elem) { return elem._id; diff --git a/public/js/main.js b/public/js/main.js index b8f32d468a..16c03987a9 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -39,21 +39,33 @@ $(document).ready(function() { $('#complete-bonfire-dialog').modal('show'); // Only post to server if there is an authenticated user if ($('.signup-btn-nav').length < 1) { - $.ajax({ - type: 'POST', - data: { + + $.post( + '/completed-bonfire', + { bonfireInfo: { completedWith : didCompleteWith, solution: bonfireSolution, bonfireHash: thisBonfireHash } }, - url: '/completed-bonfire/' - - }); + function(res) { + if (res) { + window.location.href = 'http://localhost:3001/bonfires' + } + }) } } + $('.next-bonfire-button').on('click', function() { + var bonfireSolution = myCodeMirror.getValue(); + var thisBonfireHash = passedBonfireHash || null; + var didCompleteWith = $('#completed-with').val() || null; + + completedBonfire(didCompleteWith, bonfireSolution, thisBonfireHash); + + }); + $('.all-challenges').on('click', function() { $('#all-challenges-dialog').modal('show'); }); @@ -68,19 +80,6 @@ $(document).ready(function() { }); - $('.next-bonfire-button').on('click', function() { - var bonfireSolution = myCodeMirror.getValue(); - var thisBonfireHash = passedBonfireHash || null; - var didCompleteWith = $('#completed-with').val() || null; - - completedBonfire(didCompleteWith, bonfireSolution, thisBonfireHash); - - window.setTimeout(function() { - // TODO - window.location = '/bonfires'; - }, 100); - - }); // Bonfire instructions functions $('#more-info').on('click', function() { From d443f92f3337e9429b8c9e288f7689f789e3c67e Mon Sep 17 00:00:00 2001 From: Nathan Leniz Date: Wed, 28 Jan 2015 17:32:21 -0500 Subject: [PATCH 2/2] Prevent success from showing if no tests or other errors are encountered --- public/js/lib/bonfire/bonfireFramework.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/public/js/lib/bonfire/bonfireFramework.js b/public/js/lib/bonfire/bonfireFramework.js index e7fc90cf28..83a8742b5c 100644 --- a/public/js/lib/bonfire/bonfireFramework.js +++ b/public/js/lib/bonfire/bonfireFramework.js @@ -214,10 +214,12 @@ var runTests = function(err, data) { } } }); - } - if (allTestsPassed) { - allTestsPassed = false; - showCompletion(); + + if (allTestsPassed) { + allTestsPassed = false; + showCompletion(); + } + } };