mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 09:16:38 +00:00
Add clearing of checked items to shopping-list-card (#2034)
This commit is contained in:
parent
e580dbe7f2
commit
efbd97f9a4
@ -26,3 +26,6 @@ export const completeItem = (
|
|||||||
hass.callApi("POST", "shopping_list/item/" + itemId, {
|
hass.callApi("POST", "shopping_list/item/" + itemId, {
|
||||||
complete,
|
complete,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const clearItems = (hass: HomeAssistant): Promise<void> =>
|
||||||
|
hass.callApi("POST", "shopping_list/clear_completed");
|
||||||
|
@ -5,6 +5,7 @@ import "@polymer/paper-checkbox/paper-checkbox";
|
|||||||
import "@polymer/paper-input/paper-input";
|
import "@polymer/paper-input/paper-input";
|
||||||
|
|
||||||
import "../../../components/ha-card";
|
import "../../../components/ha-card";
|
||||||
|
import "../../../components/ha-icon";
|
||||||
|
|
||||||
import { hassLocalizeLitMixin } from "../../../mixins/lit-localize-mixin";
|
import { hassLocalizeLitMixin } from "../../../mixins/lit-localize-mixin";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
@ -14,6 +15,7 @@ import {
|
|||||||
completeItem,
|
completeItem,
|
||||||
saveEdit,
|
saveEdit,
|
||||||
ShoppingListItem,
|
ShoppingListItem,
|
||||||
|
clearItems,
|
||||||
} from "../../../data/shopping-list";
|
} from "../../../data/shopping-list";
|
||||||
|
|
||||||
interface Config extends LovelaceConfig {
|
interface Config extends LovelaceConfig {
|
||||||
@ -106,12 +108,25 @@ class HuiShoppingListCard extends hassLocalizeLitMixin(LitElement)
|
|||||||
this._checkedItems!.length > 0
|
this._checkedItems!.length > 0
|
||||||
? html`
|
? html`
|
||||||
<div class="divider"></div>
|
<div class="divider"></div>
|
||||||
<div class="label">
|
<div class="checked">
|
||||||
${
|
<span class="label">
|
||||||
this.localize(
|
${
|
||||||
"ui.panel.lovelace.cards.shopping-list.checked_items"
|
this.localize(
|
||||||
)
|
"ui.panel.lovelace.cards.shopping-list.checked_items"
|
||||||
}
|
)
|
||||||
|
}
|
||||||
|
</span>
|
||||||
|
<ha-icon
|
||||||
|
class="clearall"
|
||||||
|
@click="${this._clearItems}"
|
||||||
|
icon="hass:notification-clear-all"
|
||||||
|
.title="${
|
||||||
|
this.localize(
|
||||||
|
"ui.panel.lovelace.cards.shopping-list.clear_items"
|
||||||
|
)
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
</ha-icon>
|
||||||
</div>
|
</div>
|
||||||
${
|
${
|
||||||
repeat(
|
repeat(
|
||||||
@ -170,17 +185,25 @@ class HuiShoppingListCard extends hassLocalizeLitMixin(LitElement)
|
|||||||
position: relative;
|
position: relative;
|
||||||
top: 1px;
|
top: 1px;
|
||||||
}
|
}
|
||||||
.label {
|
.checked {
|
||||||
color: var(--primary-color);
|
|
||||||
margin-left: 17px;
|
margin-left: 17px;
|
||||||
margin-bottom: 11px;
|
margin-bottom: 11px;
|
||||||
margin-top: 11px;
|
margin-top: 11px;
|
||||||
}
|
}
|
||||||
|
.label {
|
||||||
|
color: var(--primary-color);
|
||||||
|
}
|
||||||
.divider {
|
.divider {
|
||||||
height: 1px;
|
height: 1px;
|
||||||
background-color: var(--divider-color);
|
background-color: var(--divider-color);
|
||||||
margin: 10px;
|
margin: 10px;
|
||||||
}
|
}
|
||||||
|
.clearall {
|
||||||
|
cursor: pointer;
|
||||||
|
margin-bottom: 3px;
|
||||||
|
float: right;
|
||||||
|
padding-right: 10px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@ -215,6 +238,12 @@ class HuiShoppingListCard extends hassLocalizeLitMixin(LitElement)
|
|||||||
|
|
||||||
ev.target.blur();
|
ev.target.blur();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _clearItems(): void {
|
||||||
|
if (this.hass) {
|
||||||
|
clearItems(this.hass).catch(() => this._fetchData());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@ -760,7 +760,8 @@
|
|||||||
"lovelace": {
|
"lovelace": {
|
||||||
"cards": {
|
"cards": {
|
||||||
"shopping-list": {
|
"shopping-list": {
|
||||||
"checked_items": "Checked items"
|
"checked_items": "Checked items",
|
||||||
|
"clear_items": "Clear checked items"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user