Repository navigation
Expand file tree
/
Copy pathagenda.js
More file actions
138 lines (120 loc) · 3.43 KB
/
Copy pathagenda.js
File metadata and controls
138 lines (120 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*\
title: $:/plugins/ruivieira/devthing/agenda.js
type: application/javascript
module-type: macro
Generate an agenda
\*/
(function () {
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Information about this macro
*/
exports.name = "agenda";
exports.params = [];
var moment = require("$:/plugins/kixam/moment/moment.js");
let groupStatus = function (filter, dateField) {
let today = [];
let overdue = [];
let future = [];
$tw.wiki.filterTiddlers(filter).map((title) => {
const tiddler = $tw.wiki.getTiddler(title);
const due_date = tiddler.fields[dateField];
if (due_date != undefined) {
const days_diff = moment().diff(moment(due_date, "YYYY-MM-DD"), "days");
if (days_diff == 0) {
today.push(tiddler);
} else if (days_diff > 0) {
overdue.push(tiddler);
} else if (days_diff < 0) {
future.push(tiddler);
}
}
});
return { today: today, overdue: overdue, future: future };
};
let formatDate = function (tiddler, dateField) {
return moment(tiddler.fields[dateField], "YYYY-MM-DD").format("Do MMM");
};
/*
Run the macro
*/
exports.run = function (code) {
// get all issues and tasks
let filterIssues = `[tag[issue]]`;
let taskIssues = `[tag[task]]`;
const issues = groupStatus(filterIssues, "issue.date.due");
const tasks = groupStatus(taskIssues, "task.date.due");
let html = "";
if (issues.overdue.length > 0 || tasks.overdue.length > 0) {
html += "!! Overdue\n";
html += issues.overdue
.map(
(issue) =>
`* [[[${issue.fields["title"]}] - ${
issue.fields["issue.description"]
}|${issue.fields["title"]}]] <span class="date-pill">${formatDate(
issue,
"issue.date.due"
)}</span>`
)
.join("\n");
html += "\n";
html += tasks.overdue
.map(
(issue) =>
`* [[${
issue.fields["title"]
}]] <span class="date-pill">${formatDate(
issue,
"task.date.due"
)}}</span>`
)
.join("\n");
html += "\n";
}
if (issues.today.length > 0 || tasks.today.length > 0) {
html += "!! Today\n";
html += issues.today
.map(
(issue) =>
`* [[[${issue.fields["title"]}] - ${issue.fields["issue.description"]}|${issue.fields["title"]}]]`
)
.join("\n");
html += "\n";
html += tasks.today
.map((issue) => `* [[${issue.fields["title"]}]]`)
.join("\n");
html += "\n";
}
if (issues.future.length > 0 || tasks.future.length > 0) {
html += "!! Future\n";
html += issues.future
.map(
(issue) =>
`* [[[${issue.fields["title"]}] - ${
issue.fields["issue.description"]
}|${issue.fields["title"]}]] <span class="date-pill">${formatDate(
issue,
"issue.date.due"
)}</span>`
)
.join("\n");
html += "\n";
html += tasks.future
.map(
(issue) =>
`* [[${
issue.fields["title"]
}]] <span class="date-pill">${formatDate(
issue,
"task.date.due"
)}</span>`
)
.join("\n");
html += "\n";
}
return html;
};
})();