From 23f0744fe272b6d306dde9592d872c34d53fa6b7 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sat, 29 Jul 2017 10:37:28 -0700 Subject: [PATCH] Shopping list update (#360) * Hardcode how can I help chat * Allow managing shopping list * Lint * Lint --- .../shopping-list/ha-panel-shopping-list.html | 127 +++++++++++++++++- src/dialogs/ha-voice-command-dialog.html | 4 +- 2 files changed, 126 insertions(+), 5 deletions(-) diff --git a/panels/shopping-list/ha-panel-shopping-list.html b/panels/shopping-list/ha-panel-shopping-list.html index 0a6a45162e..40e6a82bc1 100644 --- a/panels/shopping-list/ha-panel-shopping-list.html +++ b/panels/shopping-list/ha-panel-shopping-list.html @@ -3,7 +3,11 @@ - + + + + + @@ -22,6 +26,17 @@ paper-card { display: block; } + paper-item { + --paper-item-focused: { + background-color: white; + } + } + paper-checkbox { + padding: 11px 7px; + } + paper-input { + width: 100%; + } @@ -34,14 +49,43 @@
- +
@@ -61,6 +105,18 @@ Polymer({ type: Array, value: [], }, + _editIndex: { + type: Number, + value: -1, + }, + _editValue: { + type: String, + value: '', + }, + }, + + listeners: { + keydown: '_checkEsc' }, attached: function () { @@ -80,6 +136,69 @@ Polymer({ .then(function (items) { this.items = items; }.bind(this)); - } + }, + + _computeIsEditting(editIndex, index) { + return editIndex === index; + }, + + _itemCompleteTapped: function (ev) { + ev.stopPropagation(); + var item = ev.model.item; + this.hass.callApi('post', 'shopping_list/' + item.id, { + complete: item.complete + }).catch(function () { + this._fetchData(); + }.bind(this)); + }, + + _enableEditting: function (ev) { + var item = ev.model.item; + var index = this.items.indexOf(item); + + if (index === this._editIndex) return; + + this._editValue = item.name; + this._editIndex = index; + }, + + _cancelEditting: function () { + this._editIndex = -1; + this._editValue = ''; + }, + + _finishEditting: function (ev) { + ev.stopPropagation(); + + var index = this._editIndex; + var name = this._editValue; + var item = this.items[index]; + + this._editIndex = -1; + this._editValue = ''; + + if (name === item.name) { + return; + } + + this.set(['items', index, 'name'], name); + this.hass.callApi('post', 'shopping_list/' + item.id, { + name: name + }).catch(function () { + this._fetchData(); + }.bind(this)); + }, + + _editKeyPress: function (ev) { + if (ev.keyCode === 13) { + this._finishEditting(ev); + } + }, + + _checkEsc: function (ev) { + if (ev.keyCode === 27) { + this._cancelEditting(); + } + }, }); diff --git a/src/dialogs/ha-voice-command-dialog.html b/src/dialogs/ha-voice-command-dialog.html index c5f9726aa6..02d64f2750 100644 --- a/src/dialogs/ha-voice-command-dialog.html +++ b/src/dialogs/ha-voice-command-dialog.html @@ -149,7 +149,9 @@ Polymer({ _conversation: { type: Array, - value: function () { return []; }, + value: function () { + return [{ who: 'hass', text: 'How can I help?' }]; + }, observer: '_scrollMessagesBottom', } },