diff --git a/todoist-card.js b/todoist-card.js
index 70a2a8c..dad42d9 100644
--- a/todoist-card.js
+++ b/todoist-card.js
@@ -71,6 +71,30 @@ class TodoistCardEditor extends LitElement {
return false;
}
+
+ get _sort_by_due_date() {
+ if (this.config) {
+ return this.config.sort_by_due_date || false;
+ }
+
+ return false;
+ }
+
+ get _ascending_order() {
+ if (this.config) {
+ return this.config.ascending_order || false;
+ }
+
+ return false;
+ }
+
+ get _custom_days_filter() {
+ if (this.config) {
+ return this.config.custom_days_filter || -1;
+ }
+
+ return -1;
+ }
setConfig(config) {
this.config = config;
@@ -131,6 +155,7 @@ class TodoistCardEditor extends LitElement {
const entities = this.getEntitiesByType('sensor');
const completedCount = [...Array(16).keys()];
+ const daysOut = [-1, ...Array(90).keys()];
return html`
@@ -231,6 +256,44 @@ class TodoistCardEditor extends LitElement {
Only show today or overdue
+
+
+
+
+ Sort by due date
+
+
+ ${this.config.sort_by_due_date === true ? html`
+
+
+
+ Sort by due date in ascending order, otherwise descending
+
` : null }
+
+ event.stopPropagation()}
+ .configValue=${'custom_days_filter'}
+ .value=${this._custom_days_filter}
+ >
+
+ ${daysOut.map(days => {
+ return html`${days}`;
+ })}
+
+
+
`;
}
@@ -453,6 +516,34 @@ class TodoistCard extends LitElement {
return false;
});
}
+
+ if (this.config.sort_by_due_date) {
+ items.sort((a, b) => {
+ if (a.due && b.due) {
+ if (this.config.ascending_order){
+ return (new Date(a.due.date)).getTime() - (new Date(b.due.date)).getTime();
+ }
+ return (new Date(b.due.date)).getTime() - (new Date(a.due.date)).getTime();
+ }
+
+ return 0;
+ });
+ }
+
+ if (this.config.custom_days_filter !== -1) {
+ const days_out = this.config.custom_days_filter;
+ items = items.filter(item => {
+ if (item.due) {
+ if (/^\d{4}-\d{2}-\d{2}$/.test(item.due.date)) {
+ item.due.date += 'T00:00:00';
+ }
+
+ return (new Date()).setHours(23, 59, 59, 999) + (days_out * 24 * 60 * 60 * 1000) >= (new Date(item.due.date)).getTime();
+ }
+
+ return false;
+ });
+ }
return html`
${(this.config.show_header === undefined) || (this.config.show_header !== false)
@@ -475,10 +566,9 @@ class TodoistCard extends LitElement {
icon="mdi:circle-medium"
>`}
- ${item.description
- ? html`${item.content}
- ${item.description}`
- : item.content}
+ ${item.content ? html`${item.content}` : null}
+ ${item.description ? html`${item.description}` : null}
+ ${item.due ? html`${item.due.date}` : null}
${(this.config.show_item_delete === undefined) || (this.config.show_item_delete !== false)
? html``;
})
- : html`No uncompleted tasks!
`}
+ : html`List empty!
`}
${this.config.show_completed && this.itemsCompleted
? this.itemsCompleted.map(item => {
return html`
@@ -505,10 +595,9 @@ class TodoistCard extends LitElement {
icon="mdi:circle-medium"
>`}
- ${item.description
- ? html`${item.content}
- ${item.description}`
- : item.content}
+ ${item.content ? html`${item.content}` : null}
+ ${item.description ? html`${item.description}` : null}
+ ${item.due ? html`${item.due.date}` : null}
${(this.config.show_item_delete === undefined) || (this.config.show_item_delete !== false)
? html`