mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-14 18:22:21 +00:00
shared helpers.dayMapping
This commit is contained in:
parent
f78cd64218
commit
b63ac10657
4 changed files with 18 additions and 27 deletions
|
|
@ -1,5 +1,5 @@
|
|||
// Generated by CoffeeScript 1.3.3
|
||||
var moment;
|
||||
var dayMapping, moment;
|
||||
|
||||
moment = require('moment');
|
||||
|
||||
|
|
@ -7,20 +7,21 @@ module.exports.daysBetween = function(a, b) {
|
|||
return Math.abs(moment(a).sod().diff(moment(b).sod(), 'days'));
|
||||
};
|
||||
|
||||
module.exports.dayMapping = dayMapping = {
|
||||
0: 'su',
|
||||
1: 'm',
|
||||
2: 't',
|
||||
3: 'w',
|
||||
4: 'th',
|
||||
5: 'f',
|
||||
6: 's',
|
||||
7: 'su'
|
||||
};
|
||||
|
||||
module.exports.viewHelpers = function(view) {
|
||||
view.fn('taskClasses', function(type, completed, value, repeat) {
|
||||
var classes, dayMapping;
|
||||
var classes;
|
||||
classes = type;
|
||||
dayMapping = {
|
||||
0: 'su',
|
||||
1: 'm',
|
||||
2: 't',
|
||||
3: 'w',
|
||||
4: 'th',
|
||||
5: 'f',
|
||||
6: 's',
|
||||
7: 'su'
|
||||
};
|
||||
if (completed || (repeat && repeat[dayMapping[moment().day()]] === false)) {
|
||||
classes += " completed";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ cron = function() {
|
|||
todoTally = 0;
|
||||
hpTally = 0;
|
||||
tallyTask = function(taskObj, callback) {
|
||||
var absVal, completed, dayMapping, daysFailed, id, repeat, task, type, value;
|
||||
var absVal, completed, daysFailed, id, repeat, task, type, value;
|
||||
id = taskObj.id, type = taskObj.type, completed = taskObj.completed, repeat = taskObj.repeat;
|
||||
if (id == null) {
|
||||
return callback('a task had a null id during cron, this should not be happening');
|
||||
|
|
@ -226,21 +226,11 @@ cron = function() {
|
|||
if (!completed) {
|
||||
daysFailed = daysPassed;
|
||||
if (type === 'daily' && repeat) {
|
||||
dayMapping = {
|
||||
0: 'su',
|
||||
1: 'm',
|
||||
2: 't',
|
||||
3: 'w',
|
||||
4: 'th',
|
||||
5: 'f',
|
||||
6: 's',
|
||||
7: 'su'
|
||||
};
|
||||
daysFailed = 0;
|
||||
_.times(daysPassed, function(n) {
|
||||
var thatDay;
|
||||
thatDay = moment().subtract('days', n + 1);
|
||||
if (repeat[dayMapping[thatDay.day()]] === true) {
|
||||
if (repeat[helpers.dayMapping[thatDay.day()]] === true) {
|
||||
return daysFailed++;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ moment = require('moment')
|
|||
# Absolute diff between two dates, based on 12am for both days
|
||||
module.exports.daysBetween = (a, b) ->
|
||||
Math.abs(moment(a).sod().diff(moment(b).sod(), 'days'))
|
||||
|
||||
module.exports.dayMapping = dayMapping = {0:'su',1:'m',2:'t',3:'w',4:'th',5:'f',6:'s',7:'su'}
|
||||
|
||||
module.exports.viewHelpers = (view) ->
|
||||
view.fn 'taskClasses', (type, completed, value, repeat) ->
|
||||
|
|
@ -10,7 +12,6 @@ module.exports.viewHelpers = (view) ->
|
|||
classes = type
|
||||
|
||||
# show as completed if completed (naturally) or not required for today
|
||||
dayMapping = {0:'su',1:'m',2:'t',3:'w',4:'th',5:'f',6:'s',7:'su'}
|
||||
if completed or (repeat and repeat[dayMapping[moment().day()]]==false)
|
||||
classes += " completed"
|
||||
|
||||
|
|
|
|||
|
|
@ -210,11 +210,10 @@ cron = ->
|
|||
# however, for dailys which have repeat dates, need
|
||||
# to calculate how many they've missed according to their own schedule
|
||||
if type=='daily' && repeat
|
||||
dayMapping = {0:'su',1:'m',2:'t',3:'w',4:'th',5:'f',6:'s',7:'su'}
|
||||
daysFailed = 0
|
||||
_.times daysPassed, (n) ->
|
||||
thatDay = moment().subtract('days', n+1)
|
||||
if repeat[dayMapping[thatDay.day()]]==true
|
||||
if repeat[helpers.dayMapping[thatDay.day()]]==true
|
||||
daysFailed++
|
||||
hpTally += score(id, 'down', {cron:true, times:daysFailed})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue