From 0754c007f29d4023d4c94e1a46d07283f0d09317 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 11 May 2017 22:23:03 -0700 Subject: [PATCH 1/2] Extract loading screen from partial-panel-resolver --- .../layouts/hass-loading-screen.html | 15 ++++---- src/layouts/partial-panel-resolver.html | 38 +++++-------------- 2 files changed, 17 insertions(+), 36 deletions(-) rename panels/hassio/hassio-loading.html => src/layouts/hass-loading-screen.html (86%) diff --git a/panels/hassio/hassio-loading.html b/src/layouts/hass-loading-screen.html similarity index 86% rename from panels/hassio/hassio-loading.html rename to src/layouts/hass-loading-screen.html index 99dff2896e..c0b1674e82 100644 --- a/panels/hassio/hassio-loading.html +++ b/src/layouts/hass-loading-screen.html @@ -4,7 +4,7 @@ - + From 44e925a9ff075f315875ce6c31dfc30dcd2d1daf Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 11 May 2017 23:43:19 -0700 Subject: [PATCH 2/2] Load Hass.io panel from supervisor in prod --- panels/hassio/ha-panel-hassio.html | 175 +++----------------------- panels/hassio/hassio-main.html | 193 +++++++++++++++++++++++++++++ script/vulcanize.js | 20 ++- src/app-core.js | 1 + 4 files changed, 226 insertions(+), 163 deletions(-) create mode 100644 panels/hassio/hassio-main.html diff --git a/panels/hassio/ha-panel-hassio.html b/panels/hassio/ha-panel-hassio.html index c402b8e650..c73c27b7d7 100644 --- a/panels/hassio/ha-panel-hassio.html +++ b/panels/hassio/ha-panel-hassio.html @@ -1,69 +1,19 @@ - - - - - - - + @@ -85,114 +35,19 @@ Polymer({ value: false, }, - addon: { - type: String, - value: '', - }, - - supervisorInfo: { - type: Object, - value: null, - }, - - hostInfo: { - type: Object, - value: null, - }, - - hassInfo: { - type: Object, - value: null, - }, - - forceLoading: { + loaded: { type: Boolean, value: false, }, - - loaded: { - type: Boolean, - computed: 'computeIsLoaded(supervisorInfo, hostInfo, hassInfo, forceLoading)', - }, - - currentPage: { - type: String, - value: 'dashboard', - }, - - lastPage: { - type: String, - value: 'dashboard', - }, }, - listeners: { - 'hassio-select-addon': 'addonSelected', - 'hassio-show-page': 'showPage', - 'hass-api-called': 'apiCalled', - }, - - apiCalled: function (ev) { - if (ev.detail.success) { - var tries = 1; - - var tryUpdate = function () { - this.$.data.refresh().catch(function () { - tries += 1; - setTimeout(tryUpdate, Math.min(tries, 5) * 1000); - }); - }.bind(this); - - tryUpdate(); + attached: function () { + if (!window.HASS_DEV) { + this.importHref('/api/hassio/panel', null, function () { + // eslint-disable-next-line + alert('Failed to load the Hass.io panel from supervisor.'); + }); } }, - - computeIsLoaded: function (supervisorInfo, hostInfo, hassInfo, forceLoading) { - return (supervisorInfo !== null && - hostInfo !== null && - hassInfo !== null && - !forceLoading); - }, - - addonSelected: function (ev) { - var addon = ev.detail.addon; - - if (this.currentPage === this.lastPage) { - this.lastPage = 'dashboard'; - } - - if (addon) { - this.lastPage = this.currentPage; - this.currentPage = 'addon-view'; - this.addon = addon; - } else { - this.currentPage = this.lastPage; - // Give time to cleanup the addon-view panel or it crashes - setTimeout(function () { - this.addon = addon; - }.bind(this), 0); - } - }, - - showPage: function (ev) { - this.currentPage = ev.detail.page; - }, - - dashboardSelected: function (currentPage) { - return currentPage === 'dashboard'; - }, - - addonStoreSelected: function (currentPage) { - return currentPage === 'addon-store'; - }, - - addonViewSelected: function (currentPage) { - return currentPage === 'addon-view'; - }, - - supervisorSelected: function (currentPage) { - return currentPage === 'supervisor'; - }, - }); diff --git a/panels/hassio/hassio-main.html b/panels/hassio/hassio-main.html new file mode 100644 index 0000000000..ff4297ee00 --- /dev/null +++ b/panels/hassio/hassio-main.html @@ -0,0 +1,193 @@ + + + + + + + + + + + + + + + diff --git a/script/vulcanize.js b/script/vulcanize.js index 4200424862..683a9b8d04 100755 --- a/script/vulcanize.js +++ b/script/vulcanize.js @@ -38,7 +38,9 @@ const panelVulcan = new Vulcanize({ inlineCss: true, implicitStrip: true, stripComments: true, - stripExcludes: undefined, + stripExcludes: [ + 'panels/hassio/hassio-main.html' + ], }); const baseExcludes = [ @@ -47,6 +49,7 @@ const baseExcludes = [ ]; const toProcess = [ + // This is the main entry point { source: './src/home-assistant.html', output: './build/frontend.html', @@ -54,9 +57,18 @@ const toProcess = [ stripExcludes: baseExcludes, })), }, + // This is the Hass.io configuration panel + // It's build standalone because it is embedded in the supervisor. + { + source: './panels/hassio/hassio-main.html', + output: './build-temp/hassio-main.html', + vulcan: new Vulcanize(Object.assign({}, baseVulcanOptions, { + stripExcludes: baseExcludes, + })), + }, ]; -fs.readdirSync('./panels').forEach(panel => { +fs.readdirSync('./panels').forEach((panel) => { toProcess.push({ source: `./panels/${panel}/ha-panel-${panel}.html`, output: `./build/panels/ha-panel-${panel}.html`, @@ -85,7 +97,9 @@ hyd.Analyzer.analyze('src/home-assistant.html') .then(function (analyzer) { return analyzer._getDependencies('src/home-assistant.html'); }) - .then(deps => { panelVulcan.stripExcludes = deps; }) + .then((deps) => { + panelVulcan.stripExcludes = panelVulcan.stripExcludes.concat(deps); + }) // Chain all vulcanizing work as promises .then(() => toProcess.reduce( (p, entry) => p.then(() => vulcanizeEntry(entry)), diff --git a/src/app-core.js b/src/app-core.js index 6c37975f6f..663f7298e7 100644 --- a/src/app-core.js +++ b/src/app-core.js @@ -2,6 +2,7 @@ import * as HAWS from 'home-assistant-js-websocket'; window.HAWS = HAWS; window.HASS_DEMO = __DEMO__; +window.HASS_DEV = __DEV__; const init = window.createHassConnection = function (password) { const proto = window.location.protocol === 'https:' ? 'wss' : 'ws';