Skip to content

Commit

Permalink
Merge pull request #106 from karwosts/filter-date-range
Browse files Browse the repository at this point in the history
Filter on days range
  • Loading branch information
isabellaalstrom authored Apr 19, 2023
2 parents 3b44d16 + 8869457 commit c13b8af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ views:
| entity | string/list | **Required** | | The entity id(s) of your Grocy chores and/or tasks sensor(s). |
| title | string | **Optional** | `"Todo"` | The title of the card. |
| show_quantity | number | **Optional** | | The number of items you want to show in the card. The rest are either hidden or show in the overflow. |
| show_days | number | **Optional** | | E.g. `0` to only show items that are due today, overdue or have no due date. If not specified, shows all items. |
| show_days | number/range | **Optional** | | E.g. `0` to only show items that are due today, overdue or have no due date. If a range is specified show only tasks with a due date in that range; e.g. `1..10` would show tasks due in the next 10 days, but not overdue tasks, or tasks due today. If not specified, shows all items. |
| show_chores_without_due | bool | **Optional** | `true` | Show chores that do not have a due date. |
| show_tasks_without_due | bool | **Optional** | `true` | Show tasks that do not have a due date. |
| user_id | number | **Optional** | `1` | Id of the Grocy user performing the items. Default if not specified is `1`. See further instructions [here](#user_id). |
Expand Down
10 changes: 9 additions & 1 deletion grocy-chores-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,15 @@ class GrocyChoresCard extends LitElement {
} else {
visible = visible || this.show_days == null;
visible = visible || (item.__due_in_days < 0);
visible = visible || (item.__due_in_days <= this.show_days);

if(this.show_days != null) {
const days_range = typeof this.show_days === "number" ? [this.show_days] : this.show_days.split("..", 2);
if(days_range.length === 1) {
visible = visible || (item.__due_in_days <= days_range[0]);
} else {
visible = visible || ((item.__due_in_days <= days_range[1]) && (item.__due_in_days >= days_range[0]));
}
}
}

visible = visible && (this.filter !== undefined ? this._checkMatchNameFilter(item) : true);
Expand Down

0 comments on commit c13b8af

Please sign in to comment.