diff --git a/home-assistant-js b/home-assistant-js index 28b2e7ab6e..11a648c293 160000 --- a/home-assistant-js +++ b/home-assistant-js @@ -1 +1 @@ -Subproject commit 28b2e7ab6e9fecef769382f462b3c5c7c9964c49 +Subproject commit 11a648c2931f4f381af439b1c52d9ff028bd0626 diff --git a/src/components/ha-cards.html b/src/components/ha-cards.html index 7f5f934989..092f569498 100644 --- a/src/components/ha-cards.html +++ b/src/components/ha-cards.html @@ -128,7 +128,11 @@ type: Object, }, - paneVisible: { + panelVisible: { + type: Boolean, + }, + + viewVisible: { type: Boolean, }, @@ -138,13 +142,19 @@ }, observers: [ - 'updateCards(columns, states, showIntroduction, paneVisible)', + 'updateCards(columns, states, showIntroduction, panelVisible, viewVisible)', ], - updateCards: function (columns, states, showIntroduction, paneVisible) { - if (!paneVisible) { + updateCards: function (columns, states, showIntroduction, + panelVisible, viewVisible) { + if (!panelVisible || !viewVisible) { + console.log('cancelling update cards', + this.getAttribute('data-view') || 'default-view', + panelVisible, viewVisible); return; } + console.log('updateCards', this.getAttribute('data-view') || 'default-view', + panelVisible, viewVisible); this.debounce( 'updateCards', function () { this.cards = this.computeCards(columns, states, @@ -153,6 +163,11 @@ }, computeCards: function (columns, states, showIntroduction) { + // Things might have changed since it got scheduled. + if (!this.panelVisible || !this.viewVisible) { + return; + } + console.error('computeCards', this.getAttribute('data-view') || 'default-view', states.size, this.viewVisible) var hass = this.hass; var byDomain = states.groupBy(function (entity) { return entity.domain; }); var hasGroup = {}; diff --git a/src/components/ha-view-tabs.html b/src/components/ha-view-tabs.html deleted file mode 100644 index 1228dcd23c..0000000000 --- a/src/components/ha-view-tabs.html +++ /dev/null @@ -1,93 +0,0 @@ - - - - - - - - - diff --git a/src/layouts/home-assistant-main.html b/src/layouts/home-assistant-main.html index 0bc3bc0da2..09bb5bb662 100644 --- a/src/layouts/home-assistant-main.html +++ b/src/layouts/home-assistant-main.html @@ -30,7 +30,7 @@ attr-for-selected='id' fallback-selection='panel-resolver' selected='[[activePane]]' - selected-attribute='pane-visible' + selected-attribute='panel-visible' > + @@ -9,7 +10,6 @@ - @@ -80,9 +121,20 @@ Polymer({ value: false, }, - paneVisible: { + showMenu: { type: Boolean, value: false, + observer: 'handleWindowChange', + }, + + panelVisible: { + type: Boolean, + value: false, + }, + + _columns: { + type: Number, + value: 1, }, isFetching: { @@ -126,12 +178,6 @@ Polymer({ }, }, - showMenu: { - type: Boolean, - value: false, - observer: 'windowChange', - }, - currentView: { type: String, bindNuclear: function (hass) { @@ -142,12 +188,16 @@ Polymer({ }, }, - hasViews: { - type: Boolean, + views: { + type: Array, bindNuclear: function (hass) { return [ hass.viewGetters.views, - function (views) { return views.size > 0; }, + function (views) { + return views.valueSeq() + .sortBy(function (view) { return view.attributes.order; }) + .toArray(); + }, ]; }, }, @@ -158,37 +208,31 @@ Polymer({ return hass.viewGetters.currentViewEntities; }, }, - - columns: { - type: Number, - value: 1, - }, }, created: function () { - var sizes = []; + var sizes = [300, 600, 900, 1200]; var col; - this.windowChange = this.windowChange.bind(this); - for (col = 0; col < 5; col++) { - sizes.push(300 + (col * 300)); - } + this.handleWindowChange = this.handleWindowChange.bind(this); this.mqls = sizes.map(function (width) { var mql = window.matchMedia('(min-width: ' + width + 'px)'); - mql.addListener(this.windowChange); + mql.addListener(this.handleWindowChange); return mql; }.bind(this)); }, detached: function () { this.mqls.forEach(function (mql) { - mql.removeListener(this.windowChange); + mql.removeListener(this.handleWindowChange); }); }, - windowChange: function () { - var matchColumns = this.mqls.reduce(function (cols, mql) { return cols + mql.matches; }, 0); + handleWindowChange: function () { + var matchColumns = this.mqls.reduce(function (cols, mql) { + return cols + mql.matches; + }, 0); // Do -1 column if the menu is docked and open - this.columns = Math.max(1, matchColumns - (!this.narrow && this.showMenu)); + this._columns = Math.max(1, matchColumns - (!this.narrow && this.showMenu)); }, /** @@ -238,24 +282,31 @@ Polymer({ this.hass.voiceActions.listen(); }, - computeMenuButtonClass: function (narrow, showMenu) { - return !narrow && showMenu ? 'menu-icon invisible' : 'menu-icon'; + handleViewSelected: function (ev) { + var view = ev.detail.item.getAttribute('data-entity') || null; + var current = this.currentView || null; + if (view !== current) { + this.async(function () { + console.warn('changing view') + this.hass.viewActions.selectView(view); + }.bind(this), 0); + } + }, + + handleViewTapped: function (ev) { + this.scrollToTop(); }, computeRefreshButtonClass: function (isFetching) { return isFetching ? 'ha-spin' : ''; }, - computeTitle: function (hasViews, locationName) { - return hasViews ? 'Home Assistant' : locationName; + computeTitle: function (views, locationName) { + return views.length > 0 ? 'Home Assistant' : locationName; }, computeShowIntroduction: function (currentView, introductionLoaded, states) { return currentView === '' && (introductionLoaded || states.size === 0); }, - - computeHasViews: function (views) { - return views.length > 0; - }, }); diff --git a/src/layouts/partial-panel-resolver.html b/src/layouts/partial-panel-resolver.html index bf9e3ce772..15ee8368f6 100644 --- a/src/layouts/partial-panel-resolver.html +++ b/src/layouts/partial-panel-resolver.html @@ -84,7 +84,12 @@ Polymer({ }, panelChanged: function (panel) { - if (!panel) return; + if (!panel) { + if (this.$.panel.lastChild) { + this.$.panel.removeChild(this.$.panel.lastChild); + } + return; + } this.resolved = false; this.errorLoading = false;