From 9b459e37f368dd64e7c0e33b8417b7a2a2b83c88 Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Fri, 6 Dec 2013 21:43:25 +0100 Subject: [PATCH] fix siteVerion check & reload page after batchUpdate if needed, @lefnire let me know what do you think and if it needs to be applied to other routes too --- public/js/services/userServices.js | 9 ++++++++- src/middleware.js | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/public/js/services/userServices.js b/public/js/services/userServices.js index bf9b605a87..157aa322fd 100644 --- a/public/js/services/userServices.js +++ b/public/js/services/userServices.js @@ -56,7 +56,7 @@ angular.module('userServices', []). sent.push(queue.shift()); }); - $http.post(API_URL + '/api/v1/user/batch-update', sent, {params: {data:+new Date, _v:user._v}}) + $http.post(API_URL + '/api/v1/user/batch-update', sent, {params: {data:+new Date, _v:user._v, siteVersion: $window.env.siteVersion}}) .success(function (data, status, heacreatingders, config) { //make sure there are no pending actions to sync. If there are any it is not safe to apply model from server as we may overwrite user data. if (!queue.length) { @@ -84,6 +84,13 @@ angular.module('userServices', []). syncQueue(); // call syncQueue to check if anyone pushed more actions to the queue while we were talking to server. }) .error(function (data, status, headers, config) { + if(status === 400 && data.needRefresh === true){ + alert("The site has been updated and the page needs to refresh. " + + "The last action has not been recorded, please do it again once the page reloads." + ); + + return location.reload(); + } //move sent actions back to queue _.times(sent.length, function () { queue.push(sent.shift()) diff --git a/src/middleware.js b/src/middleware.js index 7eccd2d423..e03f08a88f 100644 --- a/src/middleware.js +++ b/src/middleware.js @@ -26,7 +26,7 @@ module.exports.cors = function(req, res, next) { var siteVersion = 0; module.exports.forceRefresh = function(req, res, next){ - if(req.query.siteVersion && req.query.siteVersion !== siteVersion){ + if(req.query.siteVersion && req.query.siteVersion != siteVersion){ return res.json(400, {needRefresh: true}); }