mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Allow individual item deletion in To-do list (#18464)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
parent
37ab5cbdc3
commit
abb5aa348f
@ -1,4 +1,10 @@
|
|||||||
import { mdiDrag, mdiNotificationClearAll, mdiPlus, mdiSort } from "@mdi/js";
|
import {
|
||||||
|
mdiDelete,
|
||||||
|
mdiDrag,
|
||||||
|
mdiNotificationClearAll,
|
||||||
|
mdiPlus,
|
||||||
|
mdiSort,
|
||||||
|
} from "@mdi/js";
|
||||||
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||||
import {
|
import {
|
||||||
CSSResultGroup,
|
CSSResultGroup,
|
||||||
@ -293,6 +299,23 @@ export class HuiTodoListCard
|
|||||||
.itemId=${item.uid}
|
.itemId=${item.uid}
|
||||||
@change=${this._saveEdit}
|
@change=${this._saveEdit}
|
||||||
></ha-textfield>
|
></ha-textfield>
|
||||||
|
${this.todoListSupportsFeature(
|
||||||
|
TodoListEntityFeature.DELETE_TODO_ITEM
|
||||||
|
) &&
|
||||||
|
!this.todoListSupportsFeature(
|
||||||
|
TodoListEntityFeature.UPDATE_TODO_ITEM
|
||||||
|
)
|
||||||
|
? html`<ha-icon-button
|
||||||
|
.title=${this.hass!.localize(
|
||||||
|
"ui.panel.lovelace.cards.todo-list.delete_item"
|
||||||
|
)}
|
||||||
|
class="deleteItemButton"
|
||||||
|
.path=${mdiDelete}
|
||||||
|
.itemId=${item.uid}
|
||||||
|
@click=${this._deleteItem}
|
||||||
|
>
|
||||||
|
</ha-icon-button>`
|
||||||
|
: nothing}
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
)}
|
)}
|
||||||
@ -341,7 +364,23 @@ export class HuiTodoListCard
|
|||||||
>
|
>
|
||||||
</ha-svg-icon>
|
</ha-svg-icon>
|
||||||
`
|
`
|
||||||
: ""}
|
: this.todoListSupportsFeature(
|
||||||
|
TodoListEntityFeature.DELETE_TODO_ITEM
|
||||||
|
) &&
|
||||||
|
!this.todoListSupportsFeature(
|
||||||
|
TodoListEntityFeature.UPDATE_TODO_ITEM
|
||||||
|
)
|
||||||
|
? html`<ha-icon-button
|
||||||
|
.title=${this.hass!.localize(
|
||||||
|
"ui.panel.lovelace.cards.todo-list.delete_item"
|
||||||
|
)}
|
||||||
|
class="deleteItemButton"
|
||||||
|
.path=${mdiDelete}
|
||||||
|
.itemId=${item.uid}
|
||||||
|
@click=${this._deleteItem}
|
||||||
|
>
|
||||||
|
</ha-icon-button>`
|
||||||
|
: nothing}
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
)}
|
)}
|
||||||
@ -431,6 +470,16 @@ export class HuiTodoListCard
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _deleteItem(ev): void {
|
||||||
|
const item = this._getItem(ev.target.itemId);
|
||||||
|
if (!item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
deleteItem(this.hass!, this._entityId!, item.uid).finally(() =>
|
||||||
|
this._fetchData()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private _addKeyPress(ev): void {
|
private _addKeyPress(ev): void {
|
||||||
if (ev.key === "Enter") {
|
if (ev.key === "Enter") {
|
||||||
this._addItem(null);
|
this._addItem(null);
|
||||||
@ -541,6 +590,12 @@ export class HuiTodoListCard
|
|||||||
direction: var(--direction);
|
direction: var(--direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.deleteItemButton {
|
||||||
|
margin-right: -12px;
|
||||||
|
margin-inline-end: -12px;
|
||||||
|
direction: var(--direction);
|
||||||
|
}
|
||||||
|
|
||||||
.reorderButton {
|
.reorderButton {
|
||||||
margin-right: -12px;
|
margin-right: -12px;
|
||||||
margin-inline-end: -12px;
|
margin-inline-end: -12px;
|
||||||
|
@ -4526,7 +4526,8 @@
|
|||||||
"clear_items": "Clear checked items",
|
"clear_items": "Clear checked items",
|
||||||
"add_item": "Add item",
|
"add_item": "Add item",
|
||||||
"reorder_items": "Reorder items",
|
"reorder_items": "Reorder items",
|
||||||
"drag_and_drop": "Drag and drop"
|
"drag_and_drop": "Drag and drop",
|
||||||
|
"delete_item": "Delete item"
|
||||||
},
|
},
|
||||||
"picture-elements": {
|
"picture-elements": {
|
||||||
"hold": "Hold:",
|
"hold": "Hold:",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user