Also test subtasks for showing task in collections
Signed-off-by: Raimund Schlüßler <raimund.schluessler@mailbox.org>
This commit is contained in:
parent
1f5a60dc2c
commit
97a4addc2f
1 changed files with 66 additions and 10 deletions
|
@ -28,36 +28,82 @@ import ICAL from 'ical.js'
|
|||
*
|
||||
* @param {Object} task The task to check
|
||||
* @param {String} listId The id of the list in question
|
||||
* @param {Boolean} checkSubtasks Whether we also check if a descendant task matches
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
function isTaskInList(task, listId) {
|
||||
function isTaskInList(task, listId, checkSubtasks = true) {
|
||||
switch (listId) {
|
||||
case 'completed':
|
||||
return task.completed === true
|
||||
case 'all':
|
||||
return task.completed === false
|
||||
case 'current':
|
||||
return task.completed === false && current(task.start, task.due)
|
||||
return task.completed === false && testTask(task, isTaskCurrent, checkSubtasks)
|
||||
case 'starred':
|
||||
return task.completed === false && (task.priority > 0 && task.priority < 5)
|
||||
return task.completed === false && testTask(task, isTaskPriority, checkSubtasks)
|
||||
case 'today':
|
||||
return task.completed === false && (today(task.start) || today(task.due))
|
||||
return task.completed === false && testTask(task, isTaskToday, checkSubtasks)
|
||||
case 'week':
|
||||
return task.completed === false && (week(task.start) || week(task.due))
|
||||
return task.completed === false && testTask(task, isTaskWeek, checkSubtasks)
|
||||
default:
|
||||
return '' + task.calendar.id === '' + listId
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the start or due date have already passed
|
||||
* Checks for a task (and possibly its subtasks) if the given test function returns true
|
||||
*
|
||||
* @param {String} start The start date
|
||||
* @param {String} due The due date
|
||||
* @param {Object} task The task to check
|
||||
* @param {Function} testFunction The function to apply on the task
|
||||
* @param {Boolean} checkSubtasks Whether to check subtasks
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
function current(start, due) {
|
||||
return !valid(start) || moment(start, 'YYYYMMDDTHHmmss').diff(moment(), 'days', true) < 0 || moment(due, 'YYYYMMDDTHHmmss').diff(moment(), 'days', true) < 0
|
||||
function testTask(task, testFunction, checkSubtasks = false) {
|
||||
if (testFunction(task)) {
|
||||
return true
|
||||
}
|
||||
if (checkSubtasks) {
|
||||
for (var key in task.subTasks) {
|
||||
var subTask = task.subTasks[key]
|
||||
if (testFunction(subTask)) {
|
||||
return true
|
||||
}
|
||||
if (testTask(subTask, testFunction, checkSubtasks)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the task has a high priority
|
||||
*
|
||||
* @param {Object} task The task to check
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
function isTaskPriority(task) {
|
||||
return (task.priority > 0 && task.priority < 5)
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the start or due date have already passed
|
||||
*
|
||||
* @param {Object} task The task to check
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
function isTaskCurrent(task) {
|
||||
return !valid(task.start) || moment(task.start, 'YYYYMMDDTHHmmss').diff(moment(), 'days', true) < 0 || moment(task.due, 'YYYYMMDDTHHmmss').diff(moment(), 'days', true) < 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the start or due date of a task are today
|
||||
*
|
||||
* @param {Object} task The task to check
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
function isTaskToday(task) {
|
||||
return (today(task.start) || today(task.due))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,6 +116,16 @@ function today(date) {
|
|||
return valid(date) && moment(date, 'YYYYMMDDTHHmmss').diff(moment().startOf('day'), 'days', true) < 1
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the start or due date of a task are this week
|
||||
*
|
||||
* @param {Object} task The task to check
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
function isTaskWeek(task) {
|
||||
return (week(task.start) || week(task.due))
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a date lies within the next week
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue