Repeatables fixes (#8538)
* Prevented watch functions from being called when task._edit is removed * Added start date support on the UI task summary * Fixed setting of monthly and calculations * Fixed linting issues * Added check for existence * Added existence check * Ensured correct start date is used on update * Hid repeat options from anything not a daily * Added missing locales * Moved repeatables out of advance options
This commit is contained in:
@@ -97,6 +97,9 @@ export function shouldDo (day, dailyTask) {
|
||||
return false;
|
||||
}
|
||||
|
||||
day = moment(day).startOf('day').toDate();
|
||||
let startDate = moment(dailyTask.startDate).startOf('day').toDate();
|
||||
|
||||
let daysOfTheWeek = [];
|
||||
|
||||
if (dailyTask.repeat) {
|
||||
@@ -105,14 +108,13 @@ export function shouldDo (day, dailyTask) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (dailyTask.frequency === 'daily') {
|
||||
if (!dailyTask.everyX) return false; // error condition
|
||||
let schedule = moment(dailyTask.startDate).recur()
|
||||
let schedule = moment(startDate).recur()
|
||||
.every(dailyTask.everyX).days();
|
||||
return schedule.matches(day);
|
||||
} else if (dailyTask.frequency === 'weekly') {
|
||||
let schedule = moment(dailyTask.startDate).recur();
|
||||
let schedule = moment(startDate).recur();
|
||||
|
||||
if (dailyTask.everyX > 1) {
|
||||
schedule = schedule.every(dailyTask.everyX).weeks();
|
||||
@@ -122,21 +124,21 @@ export function shouldDo (day, dailyTask) {
|
||||
|
||||
return schedule.matches(day);
|
||||
} else if (dailyTask.frequency === 'monthly') {
|
||||
let schedule = moment(dailyTask.startDate).recur();
|
||||
let schedule = moment(startDate).recur();
|
||||
|
||||
let differenceInMonths = moment(day).month() + 1 - moment(dailyTask.startDate).month() + 1;
|
||||
let differenceInMonths = moment(day).month() + 1 - moment(startDate).month() + 1;
|
||||
let matchEveryX = differenceInMonths % dailyTask.everyX === 0;
|
||||
|
||||
if (dailyTask.weeksOfMonth) {
|
||||
if (dailyTask.weeksOfMonth && dailyTask.weeksOfMonth.length > 0) {
|
||||
schedule = schedule.every(daysOfTheWeek).daysOfWeek()
|
||||
.every(dailyTask.weeksOfMonth).weeksOfMonthByDay();
|
||||
} else if (dailyTask.daysOfMonth) {
|
||||
} else if (dailyTask.daysOfMonth && dailyTask.daysOfMonth.length > 0) {
|
||||
schedule = schedule.every(dailyTask.daysOfMonth).daysOfMonth();
|
||||
}
|
||||
|
||||
return schedule.matches(day) && matchEveryX;
|
||||
} else if (dailyTask.frequency === 'yearly') {
|
||||
let schedule = moment(dailyTask.startDate).recur();
|
||||
let schedule = moment(startDate).recur();
|
||||
|
||||
schedule = schedule.every(dailyTask.everyX).years();
|
||||
|
||||
|
||||
@@ -34,9 +34,10 @@ module.exports = function taskClasses (task, filters = [], dayStart = 0, lastCro
|
||||
}
|
||||
|
||||
if (type === 'todo' || type === 'daily') {
|
||||
if (completed || (type === 'daily' && !shouldDo(Number(new Date()), task, { // eslint-disable-line no-extra-parens
|
||||
dayStart,
|
||||
}))) {
|
||||
let notDue = !shouldDo(Number(new Date()), task, { dayStart });
|
||||
let isNotDueDaily = type === 'daily' && notDue;
|
||||
|
||||
if (completed || isNotDueDaily) {
|
||||
classes += ' completed';
|
||||
} else {
|
||||
classes += ' uncompleted';
|
||||
|
||||
@@ -22,5 +22,14 @@ module.exports = function updateTask (task, req = {}) {
|
||||
|
||||
merge(task, omit(body, ['_id', 'id', 'type', 'reminders', 'checklist', 'tags']));
|
||||
|
||||
// Ensure arrays are emptied
|
||||
if (body.daysOfMonth && body.daysOfMonth.length === 0) {
|
||||
task.daysOfMonth = [];
|
||||
}
|
||||
|
||||
if (body.weeksOfMonth && body.weeksOfMonth.length === 0) {
|
||||
task.weeksOfMonth = [];
|
||||
}
|
||||
|
||||
return [task];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user