From be91849d20928c7bfee8439782a8f12a46b99950 Mon Sep 17 00:00:00 2001 From: Nathan Leniz Date: Sat, 21 Mar 2015 14:28:00 +0900 Subject: [PATCH] coursewares properly push timestamps to user object --- app.js | 14 +------------ controllers/courseware.js | 10 +++++---- public/js/main.js | 35 +++++++++++++++++--------------- views/coursewares/showVideo.jade | 2 +- 4 files changed, 27 insertions(+), 34 deletions(-) diff --git a/app.js b/app.js index 0c2546d754..29a3c7966b 100644 --- a/app.js +++ b/app.js @@ -447,19 +447,7 @@ app.get('/sitemap.xml', resourcesController.sitemap); * 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 && req.body.challengeNumber < 54) { - points += 1; - } - } - req.user.points = points; - req.user.save(); -}); + /** * OAuth sign-in routes. diff --git a/controllers/courseware.js b/controllers/courseware.js index 2cf3390d46..9c32518c80 100644 --- a/controllers/courseware.js +++ b/controllers/courseware.js @@ -216,16 +216,18 @@ exports.completedCourseware = function (req, res) { var isCompletedDate = Math.round(+new Date() / 1000); var coursewareHash = req.body.coursewareInfo.coursewareHash; + debug('this is the coursewarehash we got', coursewareHash); req.user.completedCoursewares.push({ _id: coursewareHash, completedDate: isCompletedDate }); - var index = req.user.uncompletedCoursewares.indexOf(coursewareHash); - if (index > -1) { + var index = req.user.completedCoursewares.indexOf(coursewareHash); + debug('this is the index of the found courseware', index); + if (index === -1) { req.user.progressTimestamps.push(Date.now() / 1000 | 0); - req.user.uncompletedCoursewares.splice(index, 1) + req.user.uncompletedCoursewares.splice(index, 1); } req.user.save(function (err, user) { @@ -233,7 +235,7 @@ exports.completedCourseware = function (req, res) { throw err; } if (user) { - res.send(true) + res.send(true); } }); }; \ No newline at end of file diff --git a/public/js/main.js b/public/js/main.js index 22f983766b..1543899859 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -30,19 +30,19 @@ $(document).ready(function() { .addClass('animated fadeInDown'); }); - $('.completed-challenge').on('click', function() { - $('#complete-challenge-dialog').modal('show'); - // Only post to server if there is an authenticated user - if ($('.signup-btn-nav').length < 1) { - l = location.pathname.split('/'); - cn = l[l.length - 1]; - $.ajax({ - type: 'POST', - data: {challengeNumber: cn}, - url: '/completed-challenge/' - }); - } - }); + //$('.completed-challenge').on('click', function() { + // $('#complete-challenge-dialog').modal('show'); + // // Only post to server if there is an authenticated user + // if ($('.signup-btn-nav').length < 1) { + // l = location.pathname.split('/'); + // cn = l[l.length - 1]; + // $.ajax({ + // type: 'POST', + // data: {challengeNumber: cn}, + // url: '/completed-challenge/' + // }); + // } + //}); function completedBonfire(didCompleteWith, bonfireSolution, thisBonfireHash) { @@ -105,18 +105,21 @@ $(document).ready(function() { editor.focus(); }); $('#next-courseware-button').on('click', function() { + console.log(passedCoursewareHash); if ($('.signup-btn-nav').length < 1) { $.post( - '/completed-courseware', + '/completed-courseware/', { coursewareInfo: { coursewareHash: passedCoursewareHash } }).success( - function() { + function(res) { + if (res) { window.location.href = '/coursewares'; + } } - ) + ); } }); diff --git a/views/coursewares/showVideo.jade b/views/coursewares/showVideo.jade index e80b8cc179..d55993d2b1 100644 --- a/views/coursewares/showVideo.jade +++ b/views/coursewares/showVideo.jade @@ -30,7 +30,7 @@ block content .modal-dialog.animated.zoomIn.fast-animation .modal-content .modal-header.challenge-list-header= compliment - a.close.closing-x(href='#', data-dismiss='modal', aria-hidden='true') × + a.close.closing-x(href='#', data-dismiss='modal', aria-hidden='true') × .modal-body(ng-controller="pairedWithController") .text-center .animated.zoomInDown.delay-half