Clean up cloud routing (#909)

* Clean up cloud routing

* Lint
This commit is contained in:
Paulus Schoutsen 2018-02-21 11:48:28 -08:00 committed by GitHub
parent ea57e71c8b
commit bb946d9eec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 19 deletions

View File

@ -132,7 +132,7 @@ class HaConfigCloudAccount extends window.hassMixins.EventsMixin(Polymer.Element
} }
_accountChanged(newAccount) { _accountChanged(newAccount) {
if (newAccount.cloud !== 'connecting') { if (!newAccount || newAccount.cloud !== 'connecting') {
if (this._accountUpdater) { if (this._accountUpdater) {
clearTimeout(this._accountUpdater); clearTimeout(this._accountUpdater);
this._accountUpdater = null; this._accountUpdater = null;

View File

@ -11,11 +11,6 @@
<dom-module id="ha-config-cloud"> <dom-module id="ha-config-cloud">
<template> <template>
<style>
iron-pages {
height: 100%;
}
</style>
<app-route <app-route
route='[[route]]' route='[[route]]'
pattern='/cloud/:page' pattern='/cloud/:page'
@ -23,7 +18,7 @@
tail="{{_routeTail}}" tail="{{_routeTail}}"
></app-route> ></app-route>
<template is='dom-if' if='[[_equals(routeData.page, "account")]]' restamp> <template is='dom-if' if='[[_equals(_routeData.page, "account")]]' restamp>
<ha-config-cloud-account <ha-config-cloud-account
hass='[[hass]]' hass='[[hass]]'
account='[[account]]' account='[[account]]'
@ -62,6 +57,15 @@
<script> <script>
{ {
const LOGGED_IN_URLS = [
'/cloud/account',
];
const NOT_LOGGED_IN_URLS = [
'/cloud/login',
'/cloud/register',
'/cloud/forgot-password',
];
class HaConfigCloud extends window.hassMixins.NavigateMixin(Polymer.Element) { class HaConfigCloud extends window.hassMixins.NavigateMixin(Polymer.Element) {
static get is() { return 'ha-config-cloud'; } static get is() { return 'ha-config-cloud'; }
@ -75,7 +79,6 @@
}, },
account: { account: {
type: Object, type: Object,
value: null,
}, },
route: Object, route: Object,
@ -92,15 +95,20 @@
]; ];
} }
_checkRoute(route, account) { _checkRoute(route) {
if (!route || route.path.substr(0, 6) !== '/cloud') return; if (!route || route.path.substr(0, 6) !== '/cloud') return;
if (!account && ['/cloud/forgot-password', '/cloud/register'].indexOf(route.path) === -1) { this._debouncer = Polymer.Debouncer.debounce(
setTimeout(() => this.navigate('/config/cloud/login', true), 0); this._debouncer,
} else if (account && Polymer.Async.timeOut.after(0),
['/cloud/login', '/cloud/register', '/cloud/forgot-password'].indexOf(route.path) !== -1) { () => {
setTimeout(() => this.navigate('/config/cloud/account', true), 0); if (!this.account && !NOT_LOGGED_IN_URLS.includes(route.path)) {
} this.navigate('/config/cloud/login', true);
} else if (this.account && !LOGGED_IN_URLS.includes(route.path)) {
this.navigate('/config/cloud/account', true);
}
}
);
} }
_equals(a, b) { _equals(a, b) {

View File

@ -108,10 +108,7 @@ class HaPanelConfig extends window.hassMixins.NavigateMixin(Polymer.Element) {
hass: Object, hass: Object,
narrow: Boolean, narrow: Boolean,
showMenu: Boolean, showMenu: Boolean,
account: { account: Object,
type: Object,
value: null,
},
route: { route: {
type: Object, type: Object,