From b64c9548bca0f773b2c9a224b277b83c7789bf3f Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 28 Jun 2017 22:46:00 -0700 Subject: [PATCH] Update Hass.io panel with store details page --- .../addon-store/hassio-addon-repository.html | 10 +- .../hassio-addon-store-overview.html | 105 +++++++++++++ .../addon-store/hassio-addon-store-view.html | 138 ++++++++++++++++++ .../addon-store/hassio-addon-store.html | 99 ++++++------- .../hassio/addon-view/hassio-addon-state.html | 102 ++++++------- .../hassio/addon-view/hassio-addon-view.html | 10 +- 6 files changed, 345 insertions(+), 119 deletions(-) create mode 100644 panels/hassio/addon-store/hassio-addon-store-overview.html create mode 100644 panels/hassio/addon-store/hassio-addon-store-view.html diff --git a/panels/hassio/addon-store/hassio-addon-repository.html b/panels/hassio/addon-store/hassio-addon-repository.html index 35f9a56712..3460e46349 100644 --- a/panels/hassio/addon-store/hassio-addon-repository.html +++ b/panels/hassio/addon-store/hassio-addon-repository.html @@ -51,7 +51,13 @@ Polymer({ addons: { type: Array, - } + }, + + selectedAddon: { + type: String, + value: null, + notify: true, + }, }, computeShowIntro: function (repo) { @@ -63,7 +69,7 @@ Polymer({ }, addonTapped: function (ev) { - this.fire('hassio-select-addon', { addon: this.addons[ev.model.index].slug }); + this.selectedAddon = this.addons[ev.model.index].slug; ev.target.blur(); }, }); diff --git a/panels/hassio/addon-store/hassio-addon-store-overview.html b/panels/hassio/addon-store/hassio-addon-store-overview.html new file mode 100644 index 0000000000..1343e49bcb --- /dev/null +++ b/panels/hassio/addon-store/hassio-addon-store-overview.html @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + diff --git a/panels/hassio/addon-store/hassio-addon-store-view.html b/panels/hassio/addon-store/hassio-addon-store-view.html new file mode 100644 index 0000000000..992c50f9a0 --- /dev/null +++ b/panels/hassio/addon-store/hassio-addon-store-view.html @@ -0,0 +1,138 @@ + + + + + + + + + + + + + diff --git a/panels/hassio/addon-store/hassio-addon-store.html b/panels/hassio/addon-store/hassio-addon-store.html index f0f06a8430..e693f66c4d 100644 --- a/panels/hassio/addon-store/hassio-addon-store.html +++ b/panels/hassio/addon-store/hassio-addon-store.html @@ -8,51 +8,28 @@ + + @@ -65,13 +42,14 @@ Polymer({ type: Object, }, - narrow: { - type: Boolean, + selectedAddon: { + type: String, + value: null, }, - showMenu: { - type: Boolean, - value: false, + selectedAddonObject: { + type: Object, + computed: 'computeActiveAddon(addons, selectedAddon)', }, addons: { @@ -91,6 +69,7 @@ Polymer({ listeners: { 'hass-api-called': 'apiCalled', + 'hassio-store-refresh': 'refreshData', }, apiCalled: function (ev) { @@ -114,21 +93,31 @@ Polymer({ }.bind(this)); }, - computeAddOns: function (repo) { - return this.addons.filter(function (addon) { - return addon.repository === repo; - }); + computeActiveAddon: function (addons, selectedAddon) { + for (var i = 0; i < addons.length; i++) { + if (addons[i].slug === selectedAddon) { + return addons[i]; + } + } + return null; }, - refreshTapped: function () { + computeActiveRepo: function (repos, selectedAddonObject) { + if (!selectedAddonObject) return null; + + for (var i = 0; i < repos.length; i++) { + if (repos[i].slug === selectedAddonObject.repository) { + return repos[i]; + } + } + return null; + }, + + refreshData: function () { this.hass.callApi('post', 'hassio/supervisor/reload') .then(function () { this.loadData(); }.bind(this)); }, - - backTapped: function () { - this.fire('hassio-select-addon', { addon: null }); - }, }); diff --git a/panels/hassio/addon-view/hassio-addon-state.html b/panels/hassio/addon-view/hassio-addon-state.html index 42eae8abf2..7efdae14ca 100644 --- a/panels/hassio/addon-view/hassio-addon-state.html +++ b/panels/hassio/addon-view/hassio-addon-state.html @@ -14,67 +14,53 @@ } - + + Uninstall + @@ -128,10 +114,6 @@ Polymer({ return 'hassio/addons/' + addon + '/restart'; }, - pathInstall: function (addon) { - return 'hassio/addons/' + addon + '/install'; - }, - pathUninstall: function (addon) { return 'hassio/addons/' + addon + '/uninstall'; }, diff --git a/panels/hassio/addon-view/hassio-addon-view.html b/panels/hassio/addon-view/hassio-addon-view.html index 6f097396db..a65bc56765 100644 --- a/panels/hassio/addon-view/hassio-addon-view.html +++ b/panels/hassio/addon-view/hassio-addon-view.html @@ -128,8 +128,14 @@ Polymer({ 'hass-api-called': 'apiCalled', }, - apiCalled: function () { - this.addonChanged(this.addon); + apiCalled: function (ev) { + var path = ev.detail.path; + + if (path.substr(path.lastIndexOf('/') + 1) === 'uninstall') { + this.backTapped(); + } else { + this.addonChanged(this.addon); + } }, addonChanged: function (addon) {