Add routing to panels (#329)

* Add routes to Hass.io

* Add routing to automation editor

* Lint
This commit is contained in:
Paulus Schoutsen 2017-07-08 22:37:44 -07:00 committed by GitHub
parent 49afc18818
commit d705bd2e8f
23 changed files with 468 additions and 255 deletions

View File

@ -228,7 +228,8 @@ Polymer({
!confirm('You have unsaved changes. Are you sure you want to leave?')) { !confirm('You have unsaved changes. Are you sure you want to leave?')) {
return; return;
} }
this.fire('hass-automation-picked', { id: null }); history.pushState(null, null, '/automation');
this.fire('location-changed');
}, },
_updateComponent: function () { _updateComponent: function () {
@ -247,9 +248,8 @@ Polymer({
this.dirty = false; this.dirty = false;
if (this.creatingNew) { if (this.creatingNew) {
this.fire('hass-automation-picked', { history.pushState(null, null, '/automation/edit/' + id);
id: id, this.fire('location-changed');
});
} }
}.bind(this), function (errors) { }.bind(this), function (errors) {
this.errors = errors.body.message; this.errors = errors.body.message;

View File

@ -125,13 +125,14 @@ Polymer({
}, },
automationTapped: function (ev) { automationTapped: function (ev) {
this.fire('hass-automation-picked', { history.pushState(
id: this.automations[ev.model.index].attributes.id, null, null, '/automation/edit/' + this.automations[ev.model.index].attributes.id);
}); this.fire('location-changed');
}, },
addAutomation: function () { addAutomation: function () {
this.fire('hass-create-automation'); history.pushState(null, null, '/automation/new');
this.fire('location-changed');
}, },
computeName: function (automation) { computeName: function (automation) {

View File

@ -1,5 +1,6 @@
<link rel="import" href="../../bower_components/polymer/polymer.html"> <link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel='import' href='../../bower_components/iron-media-query/iron-media-query.html'> <link rel='import' href='../../bower_components/iron-media-query/iron-media-query.html'>
<link rel='import' href='../../bower_components/app-route/app-route.html'>
<link rel="import" href="./ha-automation-picker.html"> <link rel="import" href="./ha-automation-picker.html">
<link rel="import" href="./ha-automation-editor.html"> <link rel="import" href="./ha-automation-editor.html">
@ -12,6 +13,17 @@
height: 100%; height: 100%;
} }
</style> </style>
<app-route
route='[[route]]'
pattern='/edit/:automation'
data="{{_routeData}}"
active="{{_edittingAddon}}"
></app-route>
<app-route
route='[[route]]'
pattern='/new'
active="{{_creatingNew}}"
></app-route>
<iron-media-query query="(min-width: 1040px)" query-matches="{{wide}}"> <iron-media-query query="(min-width: 1040px)" query-matches="{{wide}}">
</iron-media-query> </iron-media-query>
@ -30,7 +42,7 @@
hass='[[hass]]' hass='[[hass]]'
automation='[[automation]]' automation='[[automation]]'
is-wide='[[isWide]]' is-wide='[[isWide]]'
creating-new='[[creatingNew]]' creating-new='[[_creatingNew]]'
></ha-automation-editor> ></ha-automation-editor>
</template> </template>
</template> </template>
@ -41,73 +53,49 @@ Polymer({
is: 'ha-panel-automation', is: 'ha-panel-automation',
properties: { properties: {
hass: { hass: Object,
type: Object, narrow: Boolean,
}, showMenu: Boolean,
route: Object,
narrow: { _routeData: Object,
type: Boolean, _routeMatches: Boolean,
}, _creatingNew: Boolean,
_edittingAddon: Boolean,
showMenu: {
type: Boolean,
value: false,
},
automations: { automations: {
type: Array, type: Array,
computed: 'computeAutomations(hass)', computed: 'computeAutomations(hass)',
}, },
automationId: {
type: String,
value: null,
},
automation: { automation: {
type: Object, type: Object,
computed: 'computeAutomation(automations, automationId, creatingNew)', computed: 'computeAutomation(automations, _edittingAddon, _routeData)',
}, },
wide: { wide: Boolean,
type: Boolean, wideSidebar: Boolean,
},
wideSidebar: {
type: Boolean,
},
isWide: { isWide: {
type: Boolean, type: Boolean,
computed: 'computeIsWide(showMenu, wideSidebar, wide)' computed: 'computeIsWide(showMenu, wideSidebar, wide)'
}, },
creatingNew: {
type: Boolean,
value: false,
},
showEditor: { showEditor: {
type: Boolean, type: Boolean,
computed: 'computeShowEditor(automation, creatingNew)', computed: 'computeShowEditor(_edittingAddon, _creatingNew)',
} }
}, },
listeners: {
'hass-automation-picked': 'automationPicked',
'hass-create-automation': 'createAutomation',
},
computeIsWide: function (showMenu, wideSidebar, wide) { computeIsWide: function (showMenu, wideSidebar, wide) {
return showMenu ? wideSidebar : wide; return showMenu ? wideSidebar : wide;
}, },
computeAutomation: function (automations, automationId, creatingNew) { computeAutomation: function (automations, edittingAddon, routeData) {
if (creatingNew || !automations) { if (!automations || !edittingAddon) {
return null; return null;
} }
for (var i = 0; i < automations.length; i++) { for (var i = 0; i < automations.length; i++) {
if (automations[i].attributes.id === automationId) { if (automations[i].attributes.id === routeData.automation) {
return automations[i]; return automations[i];
} }
} }
@ -142,19 +130,8 @@ Polymer({
}); });
}, },
computeShowEditor: function (automation, creatingNew) { computeShowEditor: function (_edittingAddon, _creatingNew) {
return creatingNew || automation; return _creatingNew || _edittingAddon;
},
automationPicked: function (ev) {
this.automationId = ev.detail.id;
if (this.creatingNew) {
this.creatingNew = false;
}
},
createAutomation: function () {
this.creatingNew = true;
}, },
}); });
</script> </script>

View File

@ -52,12 +52,6 @@ Polymer({
addons: { addons: {
type: Array, type: Array,
}, },
selectedAddon: {
type: String,
value: null,
notify: true,
},
}, },
computeShowIntro: function (repo) { computeShowIntro: function (repo) {
@ -74,8 +68,8 @@ Polymer({
}, },
addonTapped: function (ev) { addonTapped: function (ev) {
this.selectedAddon = this.addons[ev.model.index].slug; history.pushState(null, null, '/hassio/store/' + this.addons[ev.model.index].slug);
ev.target.blur(); this.fire('location-changed');
}, },
}); });
</script> </script>

View File

@ -98,8 +98,7 @@ Polymer({
}, },
backTapped: function () { backTapped: function () {
// Closes the store. Needs to be done with app-route. history.back();
this.fire('hassio-select-addon', { addon: null });
}, },
}); });
</script> </script>

View File

@ -128,11 +128,12 @@ Polymer({
}, },
openAddon: function () { openAddon: function () {
this.fire('hassio-select-addon', { addon: this.addon.slug }); history.pushState(null, null, '/hassio/addon/' + this.addon.slug);
this.fire('location-changed');
}, },
backTapped: function () { backTapped: function () {
this.selectedAddon = null; history.back();
}, },
}); });
</script> </script>

View File

@ -3,6 +3,7 @@
<link rel="import" href="../../../bower_components/app-layout/app-header/app-header.html"> <link rel="import" href="../../../bower_components/app-layout/app-header/app-header.html">
<link rel="import" href="../../../bower_components/app-layout/app-toolbar/app-toolbar.html"> <link rel="import" href="../../../bower_components/app-layout/app-toolbar/app-toolbar.html">
<link rel="import" href="../../../bower_components/paper-icon-button/paper-icon-button.html"> <link rel="import" href="../../../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="../../../bower_components/app-route/app-route.html">
<link rel="import" href="../../../src/components/ha-menu-button.html"> <link rel="import" href="../../../src/components/ha-menu-button.html">
@ -13,19 +14,23 @@
<dom-module id="hassio-addon-store"> <dom-module id="hassio-addon-store">
<template> <template>
<template is='dom-if' if='[[selectedAddon]]' restamp> <app-route
route='[[route]]'
pattern='/:addon'
data="{{_routeData}}"
active="{{_routeMatches}}"
></app-route>
<template is='dom-if' if='[[_routeMatches]]' restamp>
<hassio-addon-store-view <hassio-addon-store-view
hass='[[hass]]' hass='[[hass]]'
selected-addon='{{selectedAddon}}'
addon='[[selectedAddonObject]]' addon='[[selectedAddonObject]]'
repo='[[computeActiveRepo(repos, selectedAddonObject)]]' repo='[[computeActiveRepo(repos, selectedAddonObject)]]'
></hassio-addon-store-view> ></hassio-addon-store-view>
</template> </template>
<template is='dom-if' if='[[!selectedAddon]]'> <template is='dom-if' if='[[!_routeMatches]]'>
<hassio-addon-store-overview <hassio-addon-store-overview
hass='[[hass]]' hass='[[hass]]'
selected-addon='{{selectedAddon}}'
addons='[[addons]]' addons='[[addons]]'
repos='[[repos]]' repos='[[repos]]'
></hassio-addon-store-overview> ></hassio-addon-store-overview>
@ -42,14 +47,13 @@ Polymer({
type: Object, type: Object,
}, },
selectedAddon: { route: Object,
type: String, _routeData: Object,
value: null, _routeMatches: Boolean,
},
selectedAddonObject: { selectedAddonObject: {
type: Object, type: Object,
computed: 'computeActiveAddon(addons, selectedAddon)', computed: 'computeActiveAddon(addons, _routeData.addon)',
}, },
addons: { addons: {

View File

@ -2,6 +2,7 @@
<link rel="import" href="../../../bower_components/app-layout/app-header-layout/app-header-layout.html"> <link rel="import" href="../../../bower_components/app-layout/app-header-layout/app-header-layout.html">
<link rel="import" href="../../../bower_components/app-layout/app-header/app-header.html"> <link rel="import" href="../../../bower_components/app-layout/app-header/app-header.html">
<link rel="import" href="../../../bower_components/app-layout/app-toolbar/app-toolbar.html"> <link rel="import" href="../../../bower_components/app-layout/app-toolbar/app-toolbar.html">
<link rel="import" href="../../../bower_components/app-route/app-route.html">
<link rel="import" href="../../../src/components/ha-menu-button.html"> <link rel="import" href="../../../src/components/ha-menu-button.html">
@ -36,6 +37,11 @@
margin-right: 24px; margin-right: 24px;
} }
</style> </style>
<app-route
route='[[route]]'
pattern='/addon/:addon'
data="{{_routeData}}"
></app-route>
<app-header-layout has-scrolling-region> <app-header-layout has-scrolling-region>
<app-header slot="header" fixed> <app-header slot="header" fixed>
<app-toolbar> <app-toolbar>
@ -56,7 +62,7 @@
<hassio-addon-state <hassio-addon-state
hass='[[hass]]' hass='[[hass]]'
addon='[[addon]]' addon='[[_routeData.addon]]'
addon-info='[[addonInfo]]' addon-info='[[addonInfo]]'
addon-state='[[addonState]]' addon-state='[[addonState]]'
></hassio-addon-state> ></hassio-addon-state>
@ -66,13 +72,13 @@
<div class='controls'> <div class='controls'>
<hassio-addon-options <hassio-addon-options
hass='[[hass]]' hass='[[hass]]'
addon='[[addon]]' addon='[[_routeData.addon]]'
addon-state='[[addonState]]' addon-state='[[addonState]]'
></hassio-addon-options> ></hassio-addon-options>
<hassio-addon-logs <hassio-addon-logs
hass='[[hass]]' hass='[[hass]]'
addon='[[addon]]' addon='[[_routeData.addon]]'
></hassio-addon-logs> ></hassio-addon-logs>
</div> </div>
</template> </template>
@ -99,9 +105,10 @@ Polymer({
value: false, value: false,
}, },
addon: { route: Object,
type: String, _routeData: {
observer: 'addonChanged', type: Object,
observer: '_routeDataChanged',
}, },
supervisorInfo: { supervisorInfo: {
@ -110,7 +117,7 @@ Polymer({
addonInfo: { addonInfo: {
type: Object, type: Object,
computed: 'computeAddonInfo(supervisorInfo, addon)', computed: 'computeAddonInfo(supervisorInfo, _routeData.addon)',
}, },
addonState: { addonState: {
@ -134,17 +141,13 @@ Polymer({
if (path.substr(path.lastIndexOf('/') + 1) === 'uninstall') { if (path.substr(path.lastIndexOf('/') + 1) === 'uninstall') {
this.backTapped(); this.backTapped();
} else { } else {
this.addonChanged(this.addon); this._routeDataChanged(this._routeData);
} }
}, },
addonChanged: function (addon) { _routeDataChanged: function (routeData) {
if (!this.hass) { if (!routeData || !routeData.addon) return;
setTimeout(function () { this.addonChanged(addon); }.bind(this), 0); this.hass.callApi('get', 'hassio/addons/' + routeData.addon + '/info')
return;
}
this.hass.callApi('get', 'hassio/addons/' + addon + '/info')
.then(function (info) { .then(function (info) {
this.addonState = info.data; this.addonState = info.data;
}.bind(this), function () { }.bind(this), function () {
@ -163,7 +166,7 @@ Polymer({
}, },
backTapped: function () { backTapped: function () {
this.fire('hassio-select-addon', { addon: null }); history.back();
}, },
}); });
</script> </script>

View File

@ -0,0 +1,107 @@
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../../bower_components/app-layout/app-header-layout/app-header-layout.html">
<link rel="import" href="../../../bower_components/app-layout/app-header/app-header.html">
<link rel="import" href="../../../bower_components/app-layout/app-toolbar/app-toolbar.html">
<link rel="import" href="../../../bower_components/iron-flex-layout/iron-flex-layout-classes.html">
<link rel="import" href="../../../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="../../../src/components/ha-menu-button.html">
<link rel="import" href="./hassio-host-info.html">
<link rel="import" href="./hassio-hass-info.html">
<link rel="import" href="./hassio-supervisor-info.html">
<dom-module id="hassio-advanced">
<template>
<style include="iron-flex ha-style">
.content {
padding: 24px 0 32px;
max-width: 600px;
margin: 0 auto;
}
.status {
@apply(--layout-horizontal);
margin-bottom: 24px;
}
.status > * {
@apply(--layout-flex);
}
.status > *:first-child {
margin-right: 24px;
}
</style>
<app-header-layout has-scrolling-region>
<app-header slot="header" fixed>
<app-toolbar>
<paper-icon-button
icon='mdi:arrow-left'
on-tap='backTapped'
></paper-icon-button>
<div main-title>Advanced Settings</div>
</app-toolbar>
</app-header>
<div class='content'>
<div class='status'>
<hassio-supervisor-info
hass='[[hass]]'
data='[[supervisorInfo]]'
></hassio-supervisor-info>
<hassio-host-info
hass='[[hass]]'
data='[[hostInfo]]'
></hassio-host-info>
</div>
<div class='status'>
<hassio-hass-info
hass='[[hass]]'
data='[[hassInfo]]'
></hassio-hass-info>
<div></div>
</div>
</div>
</app-header-layout>
</template>
</dom-module>
<script>
Polymer({
is: 'hassio-advanced',
properties: {
hass: {
type: Object,
},
narrow: {
type: Boolean,
},
showMenu: {
type: Boolean,
value: false,
},
supervisorInfo: {
type: Object,
value: {},
},
hostInfo: {
type: Object,
value: {},
},
hassInfo: {
type: Object,
value: {},
},
},
backTapped: function () {
history.back();
},
});
</script>

View File

@ -100,7 +100,8 @@ Polymer({
}, },
supervisorLogsTapped: function () { supervisorLogsTapped: function () {
this.fire('hassio-show-page', { page: 'supervisor' }); history.pushState(null, null, '/hassio/supervisor');
this.fire('location-changed');
} }
}); });
</script> </script>

View File

@ -16,7 +16,7 @@
cursor: pointer; cursor: pointer;
} }
</style> </style>
<paper-card heading="Installed Addons"> <paper-card heading="Installed Add-ons">
<template is='dom-if' if='[[!data.length]]'> <template is='dom-if' if='[[!data.length]]'>
<div class='card-content'> <div class='card-content'>
Looks like you don't have any add-ons installed yet. Head over to <a href='#' on-tap='openStore'>the add-on store</a> to get started! Looks like you don't have any add-ons installed yet. Head over to <a href='#' on-tap='openStore'>the add-on store</a> to get started!
@ -60,13 +60,15 @@ Polymer({
}, },
addonTapped: function (ev) { addonTapped: function (ev) {
this.fire('hassio-select-addon', { addon: this.data[ev.model.index].slug }); history.pushState(null, null, '/hassio/addon/' + this.data[ev.model.index].slug);
this.fire('location-changed');
ev.target.blur(); ev.target.blur();
}, },
openStore: function (ev) { openStore: function (ev) {
ev.preventDefault(); history.pushState(null, null, '/hassio/store');
this.fire('hassio-show-page', { page: 'addon-store' }); this.fire('location-changed');
ev.target.blur();
} }
}); });
</script> </script>

View File

@ -5,12 +5,16 @@
<link rel="import" href="../../../bower_components/iron-flex-layout/iron-flex-layout-classes.html"> <link rel="import" href="../../../bower_components/iron-flex-layout/iron-flex-layout-classes.html">
<link rel="import" href="../../../bower_components/paper-icon-button/paper-icon-button.html"> <link rel="import" href="../../../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="../../../bower_components/paper-dropdown-menu/paper-dropdown-menu-light.html">
<link rel="import" href="../../../bower_components/paper-listbox/paper-listbox.html">
<link rel="import" href="../../../bower_components/paper-menu-button/paper-menu-button.html">
<link rel="import" href="../../../bower_components/paper-item/paper-item.html">
<link rel="import" href="../../../src/components/ha-menu-button.html"> <link rel="import" href="../../../src/components/ha-menu-button.html">
<link rel="import" href="./hassio-host-info.html">
<link rel="import" href="./hassio-hass-info.html">
<link rel="import" href="./hassio-supervisor-info.html">
<link rel="import" href="./hassio-addons.html"> <link rel="import" href="./hassio-addons.html">
<link rel="import" href="./hassio-hass-update.html">
<dom-module id="hassio-dashboard"> <dom-module id="hassio-dashboard">
<template> <template>
@ -31,6 +35,10 @@
.status > *:first-child { .status > *:first-child {
margin-right: 24px; margin-right: 24px;
} }
paper-listbox paper-item {
cursor: pointer;
}
</style> </style>
<app-header-layout has-scrolling-region> <app-header-layout has-scrolling-region>
<app-header slot="header" fixed> <app-header slot="header" fixed>
@ -39,30 +47,30 @@
<div main-title>Hass.io</div> <div main-title>Hass.io</div>
<paper-icon-button <paper-icon-button
icon="mdi:shopping" icon="mdi:shopping"
on-tap="storeTapped" on-tap="_openStore"
></paper-icon-button> ></paper-icon-button>
<paper-menu-button
no-animations
horizontal-align="right"
>
<paper-icon-button
icon="mdi:dots-vertical"
slot="dropdown-trigger"
></paper-icon-button>
<paper-listbox slot="dropdown-content">
<paper-item
on-tap='_openAdvanced'
>Advanced Settings</paper-item>
</paper-listbox>
</paper-menu-button>
</app-toolbar> </app-toolbar>
</app-header> </app-header>
<div class='content'> <div class='content'>
<div class='status'> <hassio-hass-update
<hassio-supervisor-info hass='[[hass]]'
hass='[[hass]]' data='[[hassInfo]]'
data='[[supervisorInfo]]' ></hassio-hass-update>
></hassio-supervisor-info>
<hassio-host-info
hass='[[hass]]'
data='[[hostInfo]]'
></hassio-host-info>
</div>
<div class='status'>
<hassio-hass-info
hass='[[hass]]'
data='[[hassInfo]]'
></hassio-hass-info>
<div></div>
</div>
<hassio-addons <hassio-addons
hass='[[hass]]' hass='[[hass]]'
data='[[supervisorInfo.addons]]' data='[[supervisorInfo.addons]]'
@ -95,19 +103,22 @@ Polymer({
value: {}, value: {},
}, },
hostInfo: {
type: Object,
value: {},
},
hassInfo: { hassInfo: {
type: Object, type: Object,
value: {}, value: {},
}, },
}, },
storeTapped: function () { _openStore: function (ev) {
this.fire('hassio-show-page', { page: 'addon-store' }); history.pushState(null, null, '/hassio/store');
this.fire('location-changed');
ev.target.blur();
},
_openAdvanced: function (ev) {
history.pushState(null, null, '/hassio/advanced');
this.fire('location-changed');
ev.target.blur();
}, },
}); });
</script> </script>

View File

@ -0,0 +1,72 @@
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../../bower_components/paper-card/paper-card.html">
<link rel="import" href="../../../src/components/buttons/ha-call-api-button.html">
<link rel="import" href="../../../src/components/buttons/ha-call-service-button.html">
<dom-module id="hassio-hass-update">
<template>
<style include="iron-flex ha-style">
paper-card {
display: block;
height: 100%;
margin-bottom: 32px;
}
.errors {
color: var(--google-red-500);
margin-top: 16px;
}
</style>
<template is='dom-if' if='[[_computeUpdateAvailable(data)]]'>
<paper-card heading='Update Available! 🎉'>
<div class="card-content">
You are currently running Home Assistant version [[data.version]] and [[data.last_version]] is available.
<template is='dom-if' if='[[errors]]'>
<div class='errors'>Error: [[errors]]</div>
</template>
</div>
<div class='card-actions'>
<ha-call-api-button
hass='[[hass]]'
path="hassio/homeassistant/update"
>Update</ha-call-api-button>
</div>
</paper-card>
</template>
</template>
</dom-module>
<script>
Polymer({
is: 'hassio-hass-update',
properties: {
hass: Object,
data: Object,
},
listeners: {
'hass-api-called': 'apiCalled',
},
apiCalled: function (ev) {
if (ev.detail.success) {
this.errors = null;
return;
}
var response = ev.detail.response;
if (typeof response.body === 'object') {
this.errors = response.body.message || 'Unknown error';
} else {
this.errors = response.body;
}
},
_computeUpdateAvailable: function (data) {
return data.version !== data.last_version;
},
});
</script>

View File

@ -13,6 +13,7 @@
hass='[[hass]]' hass='[[hass]]'
narrow='[[narrow]]' narrow='[[narrow]]'
show-menu='[[showMenu]]' show-menu='[[showMenu]]'
route='[[route]]'
></hassio-main> ></hassio-main>
</template> </template>
</dom-module> </dom-module>
@ -22,18 +23,10 @@ Polymer({
is: 'ha-panel-hassio', is: 'ha-panel-hassio',
properties: { properties: {
hass: { hass: Object,
type: Object, narrow: Boolean,
}, showMenu: Boolean,
route: Object,
narrow: {
type: Boolean,
},
showMenu: {
type: Boolean,
value: false,
},
loaded: { loaded: {
type: Boolean, type: Boolean,

View File

@ -1,8 +1,12 @@
<link rel="import" href="../../bower_components/polymer/polymer.html"> <link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/app-route/app-route.html">
<link rel="import" href="../../bower_components/iron-pages/iron-pages.html">
<link rel="import" href="../../src/layouts/hass-loading-screen.html"> <link rel="import" href="../../src/layouts/hass-loading-screen.html">
<link rel="import" href="../../src/layouts/hass-error-screen.html">
<link rel="import" href="./dashboard/hassio-dashboard.html"> <link rel="import" href="./dashboard/hassio-dashboard.html">
<link rel="import" href="./advanced/hassio-advanced.html">
<link rel="import" href="./addon-view/hassio-addon-view.html"> <link rel="import" href="./addon-view/hassio-addon-view.html">
<link rel="import" href="./addon-store/hassio-addon-store.html"> <link rel="import" href="./addon-store/hassio-addon-store.html">
<link rel="import" href="./supervisor/hassio-supervisor.html"> <link rel="import" href="./supervisor/hassio-supervisor.html">
@ -10,6 +14,17 @@
<dom-module id="hassio-main"> <dom-module id="hassio-main">
<template> <template>
<style>
iron-pages {
height: 100%;
}
</style>
<app-route
route='[[route]]'
pattern='/:page'
data="{{_routeData}}"
tail="{{_routeTail}}"
></app-route>
<hassio-data <hassio-data
id='data' id='data'
hass='[[hass]]' hass='[[hass]]'
@ -18,46 +33,68 @@
host='{{hostInfo}}' host='{{hostInfo}}'
></hassio-data> ></hassio-data>
<template is='dom-if' if='[[dashboardSelected(currentPage)]]'> <template is='dom-if' if='[[!loaded]]'>
<template is='dom-if' if='[[!loaded]]'> <hass-loading-screen
<hass-loading-screen narrow='[[narrow]]'
show-menu='[[showMenu]]'
></hass-loading-screen>
</template>
<template is='dom-if' if='[[loaded]]'>
<iron-pages
selected='[[_routeData.page]]'
attr-for-selected='page-name'
fallback-selection='not-found'
selected-attribute='visible'
>
<hassio-addon-view
page-name='addon'
route='[[route]]'
hass='[[hass]]'
supervisor-info='[[supervisorInfo]]'
host-info='[[hostInfo]]'
addon='[[addon]]'
></hassio-addon-view>
<hassio-addon-store
page-name='store'
route='[[_routeTail]]'
hass='[[hass]]'
supervisor-info='[[supervisorInfo]]'
></hassio-addon-store>
<hassio-supervisor
page-name='supervisor'
route='[[_routeTail]]'
hass='[[hass]]'
supervisor-info='[[supervisorInfo]]'
></hassio-supervisor>
<hassio-dashboard
page-name='dashboard'
route='[[_routeTail]]'
hass='[[hass]]'
narrow='[[narrow]]' narrow='[[narrow]]'
show-menu='[[showMenu]]' show-menu='[[showMenu]]'
></hass-loading-screen> supervisor-info='[[supervisorInfo]]'
</template> hass-info='[[hassInfo]]'
<template is='dom-if' if='[[loaded]]'> ></hassio-dashboard>
<hassio-dashboard
<hassio-advanced
page-name='advanced'
route='[[_routeTail]]'
hass='[[hass]]' hass='[[hass]]'
narrow='[[narrow]]' narrow='[[narrow]]'
show-menu='[[showMenu]]' show-menu='[[showMenu]]'
supervisor-info='[[supervisorInfo]]' supervisor-info='[[supervisorInfo]]'
host-info='[[hostInfo]]' host-info='[[hostInfo]]'
hass-info='[[hassInfo]]' hass-info='[[hassInfo]]'
></hassio-dashboard> ></hassio-advanced>
</template>
</template>
<template is='dom-if' if='[[addonViewSelected(currentPage)]]' restamp> <hass-error-screen
<hassio-addon-view page-name='not-found'
hass='[[hass]]' error='Page not found.'
supervisor-info='[[supervisorInfo]]' ></hass-error-screen>
host-info='[[hostInfo]]' </iron-pages>
addon='[[addon]]'
></hassio-addon-view>
</template>
<template is='dom-if' if='[[addonStoreSelected(currentPage)]]'>
<hassio-addon-store
hass='[[hass]]'
supervisor-info='[[supervisorInfo]]'
></hassio-addon-store>
</template>
<template is='dom-if' if='[[supervisorSelected(currentPage)]]'>
<hassio-supervisor
hass='[[hass]]'
supervisor-info='[[supervisorInfo]]'
></hassio-supervisor>
</template> </template>
</template> </template>
</dom-module> </dom-module>
@ -67,18 +104,15 @@ Polymer({
is: 'hassio-main', is: 'hassio-main',
properties: { properties: {
hass: { hass: Object,
narrow: Boolean,
showMenu: Boolean,
route: {
type: Object, type: Object,
observer: '_routeChanged',
}, },
_routeData: Object,
narrow: { _routeTail: Object,
type: Boolean,
},
showMenu: {
type: Boolean,
value: false,
},
addon: { addon: {
type: String, type: String,
@ -100,34 +134,21 @@ Polymer({
value: null, value: null,
}, },
forceLoading: {
type: Boolean,
value: false,
},
loaded: { loaded: {
type: Boolean, type: Boolean,
computed: 'computeIsLoaded(supervisorInfo, hostInfo, hassInfo, forceLoading)', computed: '_computeIsLoaded(supervisorInfo, hostInfo, hassInfo)',
},
currentPage: {
type: String,
value: 'dashboard',
},
lastPage: {
type: String,
value: 'dashboard',
}, },
}, },
listeners: { listeners: {
'hassio-select-addon': 'addonSelected', 'hass-api-called': '_apiCalled',
'hassio-show-page': 'showPage',
'hass-api-called': 'apiCalled',
}, },
apiCalled: function (ev) { attached: function () {
this._routeChanged(this.route);
},
_apiCalled: function (ev) {
if (ev.detail.success) { if (ev.detail.success) {
var tries = 1; var tries = 1;
@ -142,52 +163,17 @@ Polymer({
} }
}, },
computeIsLoaded: function (supervisorInfo, hostInfo, hassInfo, forceLoading) { _computeIsLoaded: function (supervisorInfo, hostInfo, hassInfo) {
return (supervisorInfo !== null && return (supervisorInfo !== null &&
hostInfo !== null && hostInfo !== null &&
hassInfo !== null && hassInfo !== null);
!forceLoading);
}, },
addonSelected: function (ev) { _routeChanged: function (route) {
var addon = ev.detail.addon; if (route.path === '' && route.prefix === '/hassio') {
history.replaceState(null, null, '/hassio/dashboard');
if (this.currentPage === this.lastPage) { this.fire('location-changed');
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';
},
}); });
</script> </script>

View File

@ -81,7 +81,7 @@ Polymer({
}, },
backTapped: function () { backTapped: function () {
this.fire('hassio-select-addon', { addon: null }); history.back();
}, },
}); });
</script> </script>

View File

@ -0,0 +1,62 @@
<link rel='import' href='../../bower_components/paper-button/paper-button.html'>
<link rel="import" href="../../bower_components/iron-flex-layout/iron-flex-layout-classes.html">
<link rel="import" href="../../bower_components/app-layout/app-toolbar/app-toolbar.html">
<dom-module id='hass-error-screen'>
<template>
<style include='iron-flex ha-style'>
.placeholder {
height: 100%;
}
.layout {
height: calc(100% - 64px);
}
paper-button {
font-weight: bold;
color: var(--primary-color);
}
</style>
<div class='placeholder'>
<app-toolbar>
<ha-menu-button narrow='[[narrow]]' show-menu='[[showMenu]]'></ha-menu-button>
<div main-title>Home Assistant</div>
</app-toolbar>
<div class='layout vertical center-center'>
<h3>[[error]]</h3>
<paper-button on-tap='backTapped'>go back</paper-button>
</div>
</div>
</template>
</dom-module>
<script>
Polymer({
is: 'hass-error-screen',
properties: {
narrow: {
type: Boolean,
value: false,
},
showMenu: {
type: Boolean,
value: false,
},
error: {
type: String,
value: 'Oops! It looks like something went wrong.'
},
},
backTapped: function () {
history.back();
},
});
</script>

View File

@ -7,10 +7,6 @@
<dom-module id='hass-loading-screen'> <dom-module id='hass-loading-screen'>
<template> <template>
<style include='iron-flex ha-style'> <style include='iron-flex ha-style'>
[hidden] {
display: none !important;
}
.placeholder { .placeholder {
height: 100%; height: 100%;
} }

View File

@ -56,7 +56,7 @@
narrow='[[narrow]]' narrow='[[narrow]]'
hass='[[hass]]' hass='[[hass]]'
show-menu='[[dockedSidebar]]' show-menu='[[dockedSidebar]]'
route='[[routeTail]]' route='[[route]]'
></partial-cards> ></partial-cards>
<partial-panel-resolver <partial-panel-resolver
@ -129,6 +129,9 @@ Polymer({
attached: function () { attached: function () {
window.removeInitMsg(); window.removeInitMsg();
if (document.location.pathname === '/') {
history.replaceState(null, null, '/states');
}
}, },
computeForceNarrow: function (narrow, dockedSidebar) { computeForceNarrow: function (narrow, dockedSidebar) {

View File

@ -38,7 +38,7 @@
</style> </style>
<app-route <app-route
route="{{route}}" route="{{route}}"
pattern="/:view" pattern="/states/:view"
data="{{routeData}}" data="{{routeData}}"
active="{{routeMatch}}" active="{{routeMatch}}"
></app-route> ></app-route>
@ -264,7 +264,7 @@ Polymer({
var current = this.currentView; var current = this.currentView;
if (view !== current) { if (view !== current) {
var path = this.route.prefix; var path = '/states';
if (view) { if (view) {
path += '/' + view; path += '/' + view;
} }

View File

@ -100,6 +100,7 @@ Polymer({
hass: this.hass, hass: this.hass,
narrow: this.narrow, narrow: this.narrow,
showMenu: this.showMenu, showMenu: this.showMenu,
route: this.routeTail,
panel: panel, panel: panel,
}); });
this.resolved = true; this.resolved = true;