Skip to content

Commit

Permalink
Merge pull request #70 from isabellaalstrom/add_toast
Browse files Browse the repository at this point in the history
Add toast when tracking
  • Loading branch information
isabellaalstrom authored Jun 9, 2022
2 parents 2a82316 + 38c2719 commit eb2f37f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ views:
| show_track_button | bool | **Optional** | `true` | Show track (complete) button
| show_empty | bool | **Optional** | `true` | Set to false to hide card when no items
| show_create_task | bool | **Optional** | `false` | Set to true to show ability to add a task in Grocy directly from the card.
| browser_mod | bool | **Optional** | `false` | Set to true _if you have installed [browser_mod](https://github.com/thomasloven/hass-browser_mod)_ and want feedback when tracking, in the form of a native toast bar.

## Advanced options
It is possible to translate the following English strings in the card to whatever you like.
Expand All @@ -66,6 +67,7 @@ custom_translation:
'Add task': "Lägg till"
'Optional due date/time': "Valfritt datum/tid"
"'Name' can't be empty": "Fyll i namn"
Tracked: "Färdigställt"
```

## <a name="user_id"></a> How to get the correct user id?
Expand Down
22 changes: 17 additions & 5 deletions grocy-chores-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { html, LitElement } from "https://unpkg.com/lit?module";
}

static getStubConfig() {
return { entity: "sensor.grocy_chores", title: null, show_quantity: null, show_days: null, show_assigned: true, show_last_tracked: true, show_last_tracked_by: true, show_track_button: true }
return { entity: "sensor.grocy_chores", title: null, show_quantity: null, show_days: null, show_assigned: true, show_last_tracked: true, show_last_tracked_by: true, show_track_button: true, browser_mod: false }
}

setConfig(config) {
Expand Down Expand Up @@ -156,13 +156,13 @@ import { html, LitElement } from "https://unpkg.com/lit?module";
${item.type == "chore" ? html
`
<div>
<mwc-button @click=${ev => this._trackChore(item.id)}>${this.translate("Track")}</mwc-button>
<mwc-button @click=${ev => this._trackChore(item.id, item.name)}>${this.translate("Track")}</mwc-button>
</div>
`
: html
`
<div>
<mwc-button @click=${ev => this._trackTask(item.id)}>${this.translate("Track")}</mwc-button>
<mwc-button @click=${ev => this._trackTask(item.id, item.name)}>${this.translate("Track")}</mwc-button>
</div>
`}
`
Expand Down Expand Up @@ -197,17 +197,29 @@ import { html, LitElement } from "https://unpkg.com/lit?module";
return datetime;
}

_trackChore(choreId){
_trackChore(choreId, choreName){
this._hass.callService("grocy", "execute_chore", {
chore_id: choreId,
done_by: this.userId
});
this._showToast(choreName);
}

_trackTask(taskId){
_trackTask(taskId, taskName){
this._hass.callService("grocy", "complete_task", {
task_id: taskId
});
this._showToast(taskName);
}

_showToast(name){
if(this.config.browser_mod != null && this.config.browser_mod === true)
{
this._hass.callService("browser_mod", "toast", {
message: `${this.translate("Tracked")} "${name}".`,
duration: 3000
});
}
}

_toggleAddTask(){
Expand Down

0 comments on commit eb2f37f

Please sign in to comment.