From 3fa3b491dc8ce0d4235aa7aaa660dd8940a8a843 Mon Sep 17 00:00:00 2001 From: carolstone Date: Fri, 17 Jul 2015 21:17:07 -0400 Subject: [PATCH] Modified common/script/index.coffee to display dayStart, but send back a variable of dayStart for processing, instead of having the object directly updated at the time of edit. Modified website/views/options/settings.jade to allow a timestamp to be cast to an iso timestamp because lastCron is saved as an iso timestamp, and as a straight moment()-based timestamp in order to compare timestamps. Modified website/public/js/controllers/settingsCtrl.js to do the following: Accept the new proposed dayStart Calculate the timestamp of the old dayStart and the new dayStart These two steps were necessary because dayStart is an integer between and including 0 and 23. I tested and confirmed the current production dayStart does not allow 24 to be entered but does allow 0. I was careful to NOT change how that worked. Cast the old dayStart, the new dayStart and lastCron to the moment() version of time so they could be compared. Cast the new dayStart to the iso timestamp for storage in lastCron The important change is the following: if oldDayStart < lastCron AND lastCron < newDayStart then lastCron should be set to newDayStart. I modified this to include if oldDayStart = lastCron, although I think that's pretty unlikely to be possible. When I tested this, my lastCron was a mere 17 seconds after my oldDayStart, so it seemed to me that the equal case should be included with the less than case. --- common/script/index.coffee | 12 ++++++++++++ website/public/js/controllers/settingsCtrl.js | 17 ++++++++++++++--- website/views/options/settings.jade | 4 ++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/common/script/index.coffee b/common/script/index.coffee index 789ba7ecae..af7f1efe3d 100644 --- a/common/script/index.coffee +++ b/common/script/index.coffee @@ -349,6 +349,18 @@ Friendly timestamp ### api.friendlyTimestamp = (timestamp) -> moment(timestamp).format('MM/DD h:mm:ss a') +### +ISO timestamp +### +api.isoTimestamp = (timestamp) -> moment(timestamp).toISOString() + +### +plain timestamp +### +api.momentTimestamp = (timestamp) -> moment(timestamp) + + + ### Does user have new chat messages? ### diff --git a/website/public/js/controllers/settingsCtrl.js b/website/public/js/controllers/settingsCtrl.js index 5c83b5756c..c59fe7bb3b 100644 --- a/website/public/js/controllers/settingsCtrl.js +++ b/website/public/js/controllers/settingsCtrl.js @@ -66,12 +66,23 @@ habitrpg.controller('SettingsCtrl', User.set({'flags.newStuff':true}); } - $scope.saveDayStart = function(){ - var dayStart = +User.user.preferences.dayStart; - if (_.isNaN(dayStart) || dayStart < 0 || dayStart > 24) { + $scope.passDayStart = User.user.preferences.dayStart; + + $scope.saveDayStart = function(newDayStart){ + var oldDayStart = User.user.preferences.dayStart; + var dayStart = newDayStart; + var lastCron = User.user.lastCron; + var getOldStart = Shared.startOfDay({ dayStart: oldDayStart}); + var getNewStart = Shared.startOfDay({ dayStart: dayStart}); + var isoNewStart = Shared.isoTimestamp(getNewStart); + + if (dayStart == undefined || _.isNaN(dayStart) || dayStart < 0 || dayStart > 24) { dayStart = 0; return alert(window.env.t('enterNumber')); } + if (Shared.momentTimestamp(getOldStart) <= Shared.momentTimestamp(lastCron) && Shared.momentTimestamp(lastCron) < Shared.momentTimestamp(getNewStart)) { + User.set({ 'lastCron' : isoNewStart}); + } User.set({'preferences.dayStart': dayStart}); } diff --git a/website/views/options/settings.jade b/website/views/options/settings.jade index 8aafb9529f..9b7ffb8628 100644 --- a/website/views/options/settings.jade +++ b/website/views/options/settings.jade @@ -83,7 +83,7 @@ script(type='text/ng-template', id='partials/options.settings.settings.html') h5(ng-if='showCustomDayStartInfo')!=env.t('customDayStartInfo4') .form-group .input-group - input.form-control(type='number', min='0', max='23', ng-model='user.preferences.dayStart', ng-blur='saveDayStart()') + input.form-control(type='number', min='0', max='23', ng-model='passDayStart', ng-blur='saveDayStart(passDayStart)') span.input-group-addon= ':00 (' + env.t('24HrClock') + ')' .personal-options.col-md-6 @@ -270,7 +270,7 @@ script(id='partials/options.settings.notifications.html', type="text/ng-template =env.t('emailNotifications') .panel-body - each notification in ['newPM', 'wonChallenge', 'giftedGems', 'giftedSubscription', 'invitedParty', 'invitedGuild', 'kickedGroup', 'questStarted', 'invitedQuest', 'inactivityEmails', 'weeklyRecaps'] + each notification in ['newPM', 'wonChallenge', 'giftedGems', 'giftedSubscription', 'invitedParty', 'invitedGuild', 'kickedGroup', 'questStarted', 'invitedQuest', 'inactivityEmails', 'weeklyRecaps'] -var preference = 'user.preferences.emailNotifications.' + notification -var unsubscribeFromAll = 'user.preferences.emailNotifications.unsubscribeFromAll'