Added cron check

This commit is contained in:
Keith Holliday
2017-06-08 17:10:05 -07:00
parent 7422d020b1
commit 36fa3ab06f
4 changed files with 34 additions and 21 deletions

View File

@@ -3,18 +3,26 @@
habitrpg.controller('NotificationCtrl', habitrpg.controller('NotificationCtrl',
['$scope', '$rootScope', 'Shared', 'Content', 'User', 'Guide', 'Notification', 'Analytics', 'Achievement', 'Social', 'Tasks', ['$scope', '$rootScope', 'Shared', 'Content', 'User', 'Guide', 'Notification', 'Analytics', 'Achievement', 'Social', 'Tasks',
function ($scope, $rootScope, Shared, Content, User, Guide, Notification, Analytics, Achievement, Social, Tasks) { function ($scope, $rootScope, Shared, Content, User, Guide, Notification, Analytics, Achievement, Social, Tasks) {
$scope.yesterDailiesModalOpen = false; $rootScope.$watch('user', function (after, before) {
$rootScope.$watch('user.yesterDailies', function (after, before) { runYesterDailies();
if (!after || after.length === 0 || $scope.yesterDailiesModalOpen) return; });
$rootScope.$on('userUpdated', function (after, before) {
runYesterDailies();
});
function runYesterDailies() {
let userLastCron = moment(User.user.lastCron).local();
let userDayStart = moment().startOf('day').add({ hours: User.user.preferences.dayStart });
if (!userLastCron.isBefore(userDayStart)) return;
let dailys = User.user.dailys;
if (!Boolean(dailys) || dailys.length === 0) return;
var yesterDailies = []; var yesterDailies = [];
after.forEach(function (taskId) { dailys.forEach(function (task) {
var dailyFound = _.find(User.user.dailys, function (task) { if (task && task.group.approval && task.group.approval.requested) return;
return taskId === task._id; if (task) yesterDailies.push(task);
});
if (dailyFound && dailyFound.group.approval && dailyFound.group.approval.requested) return;
if (dailyFound) yesterDailies.push(dailyFound);
}); });
if (yesterDailies.length === 0) return; if (yesterDailies.length === 0) return;
@@ -43,18 +51,11 @@ habitrpg.controller('NotificationCtrl',
}); });
$scope.ageDailies = function () { $scope.ageDailies = function () {
Tasks.ageDailies() User.runCron();
.then(function () {
$scope.yesterDailiesModalOpen = false;
User.sync();
});
}; };
}], }],
})
.result.catch(function() {
$scope.yesterDailiesModalOpen = false;
}); });
}); }
$rootScope.$watch('user.stats.hp', function (after, before) { $rootScope.$watch('user.stats.hp', function (after, before) {
if (after <= 0){ if (after <= 0){

View File

@@ -416,6 +416,16 @@ angular.module('habitrpg')
}); });
}, },
runCron: function () {
$http({
method: "POST",
url: 'api/v3/cron',
})
.then(function (response) {
sync();
})
},
setCustomDayStart: function (dayStart) { setCustomDayStart: function (dayStart) {
$http({ $http({
method: "POST", method: "POST",

View File

@@ -12,9 +12,11 @@ let api = {};
*/ */
api.cron = { api.cron = {
method: 'POST', method: 'POST',
url: '/debug/cron', url: '/cron',
middlewares: [authWithHeaders(), cron], middlewares: [authWithHeaders(), cron],
async handler (req, res) { async handler (req, res) {
res.respond(200, {}); res.respond(200, {});
}, },
}; };
module.exports = api;

View File

@@ -13,7 +13,7 @@ div(ng-if='(task.type !== "reward") || task.userId || (!obj.auth && obj.purchase
fieldset.option-group.advanced-option(ng-if='task.type === "daily" && task._edit._advanced') fieldset.option-group.advanced-option(ng-if='task.type === "daily" && task._edit._advanced')
.form-group .form-group
input(type='checkbox', ng-model='task._edit.yesterDaily') input(type='checkbox', ng-model='task._edit.yesterDaily', ng-disabled='$state.includes("options.social.challenges") || $state.includes("options.social.groups")')
legend.option-title legend.option-title
a.hint(href='http://habitica.wikia.com/wiki/Task_Alias', target='_blank', popover-trigger='mouseenter', popover="{{::env.t('yesterDailiesDescription')}}")=env.t('yesterDailiesOptionTitle') a.hint(href='http://habitica.wikia.com/wiki/Task_Alias', target='_blank', popover-trigger='mouseenter', popover="{{::env.t('yesterDailiesDescription')}}")=env.t('yesterDailiesOptionTitle')