From 97ccf72abd45a3cc7a009678d83d4167735464e4 Mon Sep 17 00:00:00 2001 From: Carlos Cristobal Date: Tue, 17 Jan 2023 18:00:14 -0700 Subject: [PATCH 1/9] Update todoist-card.js Add an option to force sorting by due date Add the due date to the displayed card --- todoist-card.js | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/todoist-card.js b/todoist-card.js index 70a2a8c..d58e574 100644 --- a/todoist-card.js +++ b/todoist-card.js @@ -71,6 +71,14 @@ class TodoistCardEditor extends LitElement { return false; } + + get _sort_by_due_date() { + if (this.config) { + return this.config.sort_by_due_date || false; + } + + return false; + } setConfig(config) { this.config = config; @@ -231,6 +239,16 @@ class TodoistCardEditor extends LitElement { Only show today or overdue + +
+ + + Sort by due date +
`; } @@ -453,6 +471,16 @@ class TodoistCard extends LitElement { return false; }); } + + if (this.config.sort_by_due_date) { + items.sort((a, b) => { + if (a.due && b.due) { + return (new Date(a.due.date)).getTime() - (new Date(b.due.date)).getTime(); + } + + return 0; + }); + } return html` ${(this.config.show_header === undefined) || (this.config.show_header !== false) @@ -475,10 +503,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`
@@ -581,6 +608,13 @@ class TodoistCard extends LitElement { font-size: 12px !important; margin: -15px 0; } + + .todoist-item-due { + display: block; + opacity: 0.5; + font-size: 12px !important; + margin: -15px 0; + } .todoist-item-close { color: #008000; From 4541720f906a70e4502572107145399cc223ab56 Mon Sep 17 00:00:00 2001 From: Carlos Cristobal Date: Tue, 17 Jan 2023 21:16:08 -0700 Subject: [PATCH 2/9] Add option to reverse due date ordering --- todoist-card.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/todoist-card.js b/todoist-card.js index d58e574..f789940 100644 --- a/todoist-card.js +++ b/todoist-card.js @@ -79,6 +79,14 @@ class TodoistCardEditor extends LitElement { return false; } + + get _newest_first() { + if (this.config) { + return this.config.newest_first || false; + } + + return false; + } setConfig(config) { this.config = config; @@ -249,6 +257,17 @@ class TodoistCardEditor extends LitElement { Sort by due date
+ + ${this.config.sort_by_due_date === true ? html` +
+ + + Sort by due date with the newest first, otherwise oldest first +
` : null } `; } @@ -474,8 +493,11 @@ class TodoistCard extends LitElement { if (this.config.sort_by_due_date) { items.sort((a, b) => { - if (a.due && b.due) { - return (new Date(a.due.date)).getTime() - (new Date(b.due.date)).getTime(); + if (a.due && b.due) { + if (this.config.newest_first){ + 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; From 62bf44884d8923505a8dc60a8a66e354c3691886 Mon Sep 17 00:00:00 2001 From: Carlos Cristobal Date: Tue, 17 Jan 2023 21:21:17 -0700 Subject: [PATCH 3/9] Rewording --- todoist-card.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/todoist-card.js b/todoist-card.js index f789940..fe05892 100644 --- a/todoist-card.js +++ b/todoist-card.js @@ -80,9 +80,9 @@ class TodoistCardEditor extends LitElement { return false; } - get _newest_first() { + get _ascending_order() { if (this.config) { - return this.config.newest_first || false; + return this.config.ascending_order || false; } return false; @@ -261,12 +261,12 @@ class TodoistCardEditor extends LitElement { ${this.config.sort_by_due_date === true ? html`
- Sort by due date with the newest first, otherwise oldest first + Sort by due date in ascending order, otherwise descending
` : null } `; } @@ -494,7 +494,7 @@ class TodoistCard extends LitElement { if (this.config.sort_by_due_date) { items.sort((a, b) => { if (a.due && b.due) { - if (this.config.newest_first){ + 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(); From ecedde3c786897cbab7b9bf1d8513a86329e6ef0 Mon Sep 17 00:00:00 2001 From: Carlos Cristobal Date: Tue, 17 Jan 2023 21:30:12 -0700 Subject: [PATCH 4/9] Adding due dates to completed items --- todoist-card.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/todoist-card.js b/todoist-card.js index fe05892..3d4bb0f 100644 --- a/todoist-card.js +++ b/todoist-card.js @@ -554,10 +554,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` Date: Sat, 21 Jan 2023 17:52:05 -0700 Subject: [PATCH 5/9] Update todoist-card.js --- todoist-card.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/todoist-card.js b/todoist-card.js index 70a2a8c..c67e80c 100644 --- a/todoist-card.js +++ b/todoist-card.js @@ -71,6 +71,14 @@ class TodoistCardEditor extends LitElement { return false; } + + get _custom_days_filter() { + if (this.config) { + return this.config.custom_days_filter || -1; + } + + return -1; + } setConfig(config) { this.config = config; @@ -231,6 +239,17 @@ class TodoistCardEditor extends LitElement { Only show today or overdue + +
+ + + Only show tasks due within the next X days +
+ `; } @@ -453,6 +472,21 @@ class TodoistCard extends LitElement { return false; }); } + + 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) From 0ee937636e331bb14bcb8061b5e036c4f51c16ba Mon Sep 17 00:00:00 2001 From: Carlos Cristobal Date: Sat, 21 Jan 2023 18:02:50 -0700 Subject: [PATCH 6/9] Update todoist-card.js --- todoist-card.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/todoist-card.js b/todoist-card.js index c67e80c..a1bca3c 100644 --- a/todoist-card.js +++ b/todoist-card.js @@ -241,13 +241,16 @@ class TodoistCardEditor extends LitElement {
- event.stopPropagation()} .configValue=${'custom_days_filter'} - @change=${this.valueChanged} + .value=${this._custom_days_filter} > - - Only show tasks due within the next X days +
`; From 6adbb73120f9206857aa41385a45e68db43408b6 Mon Sep 17 00:00:00 2001 From: Carlos Cristobal Date: Sat, 21 Jan 2023 23:47:39 -0700 Subject: [PATCH 7/9] Update todoist-card.js --- todoist-card.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/todoist-card.js b/todoist-card.js index a1bca3c..97491c3 100644 --- a/todoist-card.js +++ b/todoist-card.js @@ -139,6 +139,7 @@ class TodoistCardEditor extends LitElement { const entities = this.getEntitiesByType('sensor'); const completedCount = [...Array(16).keys()]; + const daysOut = [...Array(90).keys()]; return html`
@@ -241,15 +242,25 @@ class TodoistCardEditor extends LitElement {
- event.stopPropagation()} + + event.stopPropagation()} + .configValue=${'custom_days_filter'} + .value=${this._custom_days_filter} + > + + ${daysOut.map(days => { + return html`${days}`; + })} +
From bdacb0247783bdeb07ce01511c5547a4cb18668d Mon Sep 17 00:00:00 2001 From: Carlos Cristobal Date: Sat, 21 Jan 2023 23:54:11 -0700 Subject: [PATCH 8/9] Update todoist-card.js --- todoist-card.js | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/todoist-card.js b/todoist-card.js index 97491c3..c395c91 100644 --- a/todoist-card.js +++ b/todoist-card.js @@ -139,7 +139,7 @@ class TodoistCardEditor extends LitElement { const entities = this.getEntitiesByType('sensor'); const completedCount = [...Array(16).keys()]; - const daysOut = [...Array(90).keys()]; + const daysOut = [-1, ...Array(90).keys()]; return html`
@@ -242,26 +242,20 @@ class TodoistCardEditor extends LitElement {
- event.stopPropagation()} .configValue=${'custom_days_filter'} - @change=${this.valueChanged} + .value=${this._custom_days_filter} > - event.stopPropagation()} - .configValue=${'custom_days_filter'} - .value=${this._custom_days_filter} - > - + ${daysOut.map(days => { return html`${days}`; })} -
`; From 5a7e8a89c6b000627033ab29d534f8b8a95b24c5 Mon Sep 17 00:00:00 2001 From: Carlos Cristobal Date: Sat, 21 Jan 2023 23:58:13 -0700 Subject: [PATCH 9/9] Update todoist-card.js --- todoist-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/todoist-card.js b/todoist-card.js index c395c91..ecbddf1 100644 --- a/todoist-card.js +++ b/todoist-card.js @@ -245,7 +245,7 @@ class TodoistCardEditor extends LitElement { event.stopPropagation()} .configValue=${'custom_days_filter'}