|
|
class taskFunc {
|
|
|
relDateString(d, luxon) {
|
|
|
if (!(d instanceof luxon.DateTime)) return '–'
|
|
|
const now = luxon.DateTime.now()
|
|
|
const days = Math.ceil(d.diff(now, 'days').days)
|
|
|
if (days < 0) return 'Overdue ' + d.toFormat('L/d')
|
|
|
if (days === 0) return 'Today'
|
|
|
if (days === 1) return 'Tomorrow'
|
|
|
if (days < 7) return d.toFormat('cccc')
|
|
|
return d.toFormat('ccc L/d')
|
|
|
}
|
|
|
|
|
|
getButtonStrings(status) {
|
|
|
const completed = status === 'Completed'
|
|
|
const btnStr = completed ? 'Undo' : 'Done'
|
|
|
const updateStr = completed ? 'To-Do' : 'Completed'
|
|
|
return { btnStr, updateStr }
|
|
|
}
|
|
|
|
|
|
getCustomLink(name, target) {
|
|
|
return `[[${target}|${name}]]`
|
|
|
}
|
|
|
|
|
|
getTodayTasks(args) {
|
|
|
const { luxon, dv, that, theme } = args
|
|
|
const finalDate = luxon.DateTime.now().toISODate() //?? dv.current().file.name
|
|
|
return this.getTasksTable({
|
|
|
...args,
|
|
|
filterFn: t => t.DocType == 'Task' && t.Status != 'Completed' && t.DueDate && t.DueDate?.hasSame(luxon.DateTime.fromISO(finalDate), 'day')
|
|
|
})
|
|
|
}
|
|
|
|
|
|
getAllTasks(args) {
|
|
|
const { luxon, dv, that, theme } = args
|
|
|
return this.getTasksTable({
|
|
|
...args,
|
|
|
filterFn: t => t.DocType == 'Task' && t.NextReviewDate
|
|
|
})
|
|
|
}
|
|
|
|
|
|
getOverdueTasks(args) {
|
|
|
const { luxon, dv, that, theme } = args
|
|
|
const finalDate = luxon.DateTime.now().toISODate() //date ?? dv.current().file.name
|
|
|
return this.getTasksTable({
|
|
|
...args,
|
|
|
filterFn: t => t.DocType == 'Task' && t.DueDate && t.DueDate < luxon.DateTime.fromISO(finalDate) && t.Status != 'Completed'
|
|
|
})
|
|
|
}
|
|
|
|
|
|
getLateReviewTasks(args) {
|
|
|
const { luxon, dv, that, theme } = args
|
|
|
const finalDate = luxon.DateTime.now().toISODate() //date ?? dv.current().file.name
|
|
|
return this.getTasksTable({
|
|
|
...args,
|
|
|
filterFn: t => t.DocType == 'Task' && t.NextReviewDate && t.NextReviewDate < luxon.DateTime.fromISO(finalDate) && t.Status != 'Completed'
|
|
|
})
|
|
|
}
|
|
|
|
|
|
getTasksNoDueDate(args) {
|
|
|
return this.getTasksTable({
|
|
|
...args,
|
|
|
// prependText: 'No Due Date',
|
|
|
filterFn: t => t.DocType == 'Task' && !t.DueDate
|
|
|
})
|
|
|
}
|
|
|
|
|
|
getTasksTable(args) {
|
|
|
const {
|
|
|
that,
|
|
|
app,
|
|
|
dv,
|
|
|
luxon,
|
|
|
theme,
|
|
|
getSortProp = t => t.NextReviewDate,
|
|
|
sortOrder = 'asc',
|
|
|
filterFn = t => {t.DocType == 'Task'},
|
|
|
completedCol = false,
|
|
|
prependHeaderLevel = 3,
|
|
|
prependText
|
|
|
} = args;
|
|
|
const { metaedit, buttons } = app.plugins.plugins
|
|
|
const { update } = metaedit.api
|
|
|
const { createButton } = buttons
|
|
|
const pFilter = '#' + theme
|
|
|
|
|
|
|
|
|
const dueStr = completedCol ? 'Completed' : 'Review Date';
|
|
|
const pages = dv.pages(pFilter).sort(getSortProp, sortOrder).where(filterFn)
|
|
|
if (pages.length === 0) {
|
|
|
// console.log('Empty dataview:', args)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if (prependText) {
|
|
|
dv.header(prependHeaderLevel, prependText)
|
|
|
}
|
|
|
|
|
|
dv.table(["Name", "Category", "Priority", dueStr, "", ""], pages
|
|
|
.map(t => {
|
|
|
const { btnStr, updateStr } = this.getButtonStrings(t.Status)
|
|
|
return [
|
|
|
this.getCustomLink(t.file.name, t.file.name),
|
|
|
t.Tag,
|
|
|
t.Priority,
|
|
|
this.relDateString(t.NextReviewDate, luxon),
|
|
|
createButton({
|
|
|
app,
|
|
|
el: that.container,
|
|
|
args: { name: btnStr },
|
|
|
clickOverride: { click: update, params: ['Status', updateStr, t.file.path] }
|
|
|
}),
|
|
|
]
|
|
|
})
|
|
|
)
|
|
|
}
|
|
|
}
|