Migrate main view to app elements

This commit is contained in:
Paulus Schoutsen 2016-07-31 00:32:49 -07:00
parent e5fe5ca0ae
commit a343d3d098
8 changed files with 75 additions and 137 deletions

View File

@ -32,7 +32,7 @@ hass.reactor.batch(function () {
setTimeout(hass.startLocalStoragePreferencesSync, 5000); setTimeout(hass.startLocalStoragePreferencesSync, 5000);
if ('serviceWorker' in navigator) { if ('serviceWorker' in navigator) {
window.addEventListener('load', function() { window.addEventListener('load', function () {
navigator.serviceWorker.register('/service_worker.js'); navigator.serviceWorker.register('/service_worker.js');
}); });
} }

View File

@ -10,15 +10,12 @@
<style> <style>
:host { :host {
display: block; display: block;
background-color: #E5E5E5;
padding-top: 8px;
padding-right: 8px; padding-right: 8px;
} }
.no-badges {
height: 8px;
}
.badges { .badges {
margin-top: 16px;
font-size: 85%; font-size: 85%;
text-align: center; text-align: center;
} }
@ -61,9 +58,6 @@
<ha-badges-card states='[[cards.badges]]' hass='[[hass]]'></ha-badges-card> <ha-badges-card states='[[cards.badges]]' hass='[[hass]]'></ha-badges-card>
</div> </div>
</template> </template>
<template is='dom-if' if='[[!cards.badges]]'>
<div class='no-badges'> </div>
</template>
<div class='horizontal layout center-justified'> <div class='horizontal layout center-justified'>
<template is='dom-repeat' items='[[cards.columns]]' as='column'> <template is='dom-repeat' items='[[cards.columns]]' as='column'>

View File

@ -65,6 +65,7 @@
font-weight: 300; font-weight: 300;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
line-height: normal;
} }
iron-image { iron-image {

View File

@ -6,6 +6,7 @@
<template> <template>
<style> <style>
:host { :host {
display: block;
--paper-tabs-selection-bar-color: #FFF; --paper-tabs-selection-bar-color: #FFF;
} }
paper-tab { paper-tab {

View File

@ -5,7 +5,6 @@
<link rel='import' href='./util/roboto.html'> <link rel='import' href='./util/roboto.html'>
<link rel='import' href='../bower_components/paper-styles/typography.html'> <link rel='import' href='../bower_components/paper-styles/typography.html'>
<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/iron-iconset-svg/iron-iconset-svg.html">
<link rel='import' href='./util/hass-util.html'> <link rel='import' href='./util/hass-util.html'>
<link rel='import' href='./util/hass-behavior.html'> <link rel='import' href='./util/hass-behavior.html'>
@ -16,7 +15,9 @@
<dom-module id='home-assistant'> <dom-module id='home-assistant'>
<template> <template>
<home-assistant-main hass='[[hass]]' hidden$='[[!loaded]]'></home-assistant-main> <template is='dom-if' if='[[loaded]]'>
<home-assistant-main hass='[[hass]]'></home-assistant-main>
</template>
<template is='dom-if' if='[[!loaded]]'> <template is='dom-if' if='[[!loaded]]'>
<login-form <login-form

View File

@ -1,87 +1,36 @@
<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-icon/iron-icon.html"> <link rel="import" href="../../bower_components/iron-icon/iron-icon.html">
<link rel="import" href="../../bower_components/paper-scroll-header-panel/paper-scroll-header-panel.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-toolbar/paper-toolbar.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-scroll-effects/app-scroll-effects.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="../components/ha-menu-button.html">
<link rel="import" href="../components/ha-cards.html"> <link rel="import" href="../components/ha-cards.html">
<link rel="import" href="../components/ha-view-tabs.html"> <link rel="import" href="../components/ha-view-tabs.html">
<dom-module id="partial-cards"> <dom-module id="partial-cards">
<template> <template>
<style is="custom-style" include="iron-flex iron-positioning"></style> <style include="iron-flex iron-positioning ha-style">
<style>
:host { :host {
display: block;
-ms-user-select: none; -ms-user-select: none;
-webkit-user-select: none; -webkit-user-select: none;
-moz-user-select: none; -moz-user-select: none;
} }
paper-scroll-header-panel { ha-view-tabs {
--paper-scroll-header-panel-container: { margin-left: 12px;
background-color: #E5E5E5;
};
}
paper-scroll-header-panel[has-views] paper-toolbar {
height: 104px;
}
paper-toolbar:after {
content: "";
position: absolute;
left: 0px;
right: 0px;
bottom: -5px;
width: 100%;
height: 5px;
pointer-events: none;
opacity: 0;
box-shadow: inset 0px 5px 6px -3px rgba(0, 0, 0, 0.4);
will-change: opacity;
transition: opacity 0.4s;
}
paper-scroll-header-panel.raised paper-toolbar:after {
opacity: 1;
}
.menu-icon {
margin-right: 24px;
}
#menu > .title {
line-height: 40px;
}
#menu > .title > span {
pointer-events: auto;
}
.views {
padding-left: 12px;
--paper-tabs-selection-bar-color: #FFF; --paper-tabs-selection-bar-color: #FFF;
} }
</style> </style>
<paper-scroll-header-panel id='panel' <app-header-layout has-scrolling-region id='layout'>
condenses keep-condensed-header class='fit' has-views$='[[hasViews]]' <app-header effects="waterfall" condenses fixed>
header-height="[[computeHeaderHeight(hasViews, narrow)]]" <app-toolbar>
condensed-header-height="[[computeCondensedHeaderHeight(hasViews, narrow)]]" <ha-menu-button narrow='[[narrow]]' show-menu='[[showMenu]]'></ha-menu-button>
on-paper-header-transform='headerScrollAdjust' <div main-title>[[computeTitle(hasViews, locationName)]]</div>
on-content-scroll='contentScroll'
>
<paper-toolbar>
<div class='flex layout horizontal' id='menu'>
<paper-icon-button icon='mdi:menu' class$='[[computeMenuButtonClass(narrow, showMenu)]]' on-tap='toggleMenu'></paper-icon-button>
<span class='title flex'>
<span on-tap='scrollToTop'>
[[computeTitle(hasViews, locationName)]]
</span>
</span>
<paper-icon-button <paper-icon-button
icon="mdi:refresh" icon="mdi:refresh"
class$="[[computeRefreshButtonClass(isFetching)]]" class$="[[computeRefreshButtonClass(isFetching)]]"
@ -90,19 +39,20 @@
<paper-icon-button <paper-icon-button
icon="mdi:microphone" hidden$='[[!canListen]]' icon="mdi:microphone" hidden$='[[!canListen]]'
on-tap="handleListenClick"></paper-icon-button> on-tap="handleListenClick"></paper-icon-button>
</div> </app-toolbar>
<template is='dom-if' if='[[hasViews]]'> <ha-view-tabs
<div class='fit bottom views'> sticky
<ha-view-tabs hass='[[hass]]' on-view-tapped='scrollToTop'></ha-view-tabs> hass='[[hass]]'
</div> on-view-tapped='scrollToTop'
</template> ></ha-view-tabs>
</paper-toolbar> </app-header>
<ha-cards <ha-cards
show-introduction='[[computeShowIntroduction(currentView, introductionLoaded, states)]]' show-introduction='[[computeShowIntroduction(currentView, introductionLoaded, states)]]'
states='[[states]]' columns='[[columns]]' hass='[[hass]]'></ha-cards> states='[[states]]' columns='[[columns]]' hass='[[hass]]'
</paper-header-panel> ></ha-cards>
</app-header-layout>
</template> </template>
</dom-module> </dom-module>
@ -229,8 +179,43 @@ Polymer({
this.columns = Math.max(1, matchColumns - (!this.narrow && this.showMenu)); this.columns = Math.max(1, matchColumns - (!this.narrow && this.showMenu));
}, },
/**
* Scroll to a specific y coordinate.
*
* Copied from paper-scroll-header-panel.
*
* @method scroll
* @param {number} top The coordinate to scroll to, along the y-axis.
* @param {boolean} smooth true if the scroll position should be smoothly adjusted.
*/
scrollToTop: function () { scrollToTop: function () {
this.$.panel.scrollToTop(true); // the scroll event will trigger _updateScrollState directly,
// However, _updateScrollState relies on the previous `scrollTop` to update the states.
// Calling _updateScrollState will ensure that the states are synced correctly.
var top = 0;
var scroller = this.$.layout.header.scrollTarget;
var easingFn = function easeOutQuad(t, b, c, d) {
/* eslint-disable no-param-reassign, space-infix-ops, no-mixed-operators */
t /= d;
return -c * t*(t-2) + b;
/* eslint-enable no-param-reassign, space-infix-ops, no-mixed-operators */
};
var animationId = Math.random();
var duration = 200;
var startTime = Date.now();
var currentScrollTop = scroller.scrollTop;
var deltaScrollTop = top - currentScrollTop;
this._currentAnimationId = animationId;
(function updateFrame() {
var now = Date.now();
var elapsedTime = now - startTime;
if (elapsedTime > duration) {
scroller.scrollTop = top;
} else if (this._currentAnimationId === animationId) {
scroller.scrollTop = easingFn(elapsedTime, currentScrollTop, deltaScrollTop, duration);
requestAnimationFrame(updateFrame.bind(this));
}
}).call(this);
}, },
handleRefresh: function () { handleRefresh: function () {
@ -241,46 +226,6 @@ Polymer({
this.hass.voiceActions.listen(); this.hass.voiceActions.listen();
}, },
contentScroll: function () {
if (this.debouncedContentScroll) return;
this.debouncedContentScroll = this.async(function () {
this.checkRaised();
this.debouncedContentScroll = false;
}.bind(this), 100);
},
checkRaised: function () {
this.toggleClass(
'raised',
this.$.panel.scroller.scrollTop > (this.hasViews ? 56 : 0),
this.$.panel);
},
headerScrollAdjust: function (ev) {
if (!this.hasViews) return;
this.translate3d('0', '-' + ev.detail.y + 'px', '0', this.$.menu);
// this.toggleClass('condensed', ev.detail.y === 56, this.$.panel);
},
computeHeaderHeight: function (hasViews, narrow) {
if (hasViews) {
return 104;
} else if (narrow) {
return 56;
}
return 64;
},
computeCondensedHeaderHeight: function (hasViews, narrow) {
if (hasViews) {
return 48;
} else if (narrow) {
return 56;
}
return 64;
},
computeMenuButtonClass: function (narrow, showMenu) { computeMenuButtonClass: function (narrow, showMenu) {
return !narrow && showMenu ? 'menu-icon invisible' : 'menu-icon'; return !narrow && showMenu ? 'menu-icon invisible' : 'menu-icon';
}, },
@ -300,9 +245,5 @@ Polymer({
computeHasViews: function (views) { computeHasViews: function (views) {
return views.length > 0; return views.length > 0;
}, },
toggleMenu: function () {
this.fire('open-menu');
},
}); });
</script> </script>

View File

@ -1,12 +1,14 @@
<link rel='import' href='../../bower_components/paper-toolbar/paper-toolbar.html'>
<link rel='import' href='../../bower_components/paper-spinner/paper-spinner.html'> <link rel='import' href='../../bower_components/paper-spinner/paper-spinner.html'>
<link rel="import" href="../../bower_components/app-layout/app-toolbar/app-toolbar.html">
<link rel='import' href='../components/ha-menu-button.html'> <link rel='import' href='../components/ha-menu-button.html'>
<link rel='import' href='../util/hass-behavior.html'> <link rel='import' href='../util/hass-behavior.html'>
<link rel="import" href="../resources/home-assistant-style.html">
<dom-module id='partial-panel-resolver'> <dom-module id='partial-panel-resolver'>
<template> <template>
<style include='iron-flex'> <style include='iron-flex ha-style'>
[hidden] { [hidden] {
display: none !important; display: none !important;
} }
@ -21,9 +23,9 @@
</style> </style>
<div hidden$='[[resolved]]' class='placeholder'> <div hidden$='[[resolved]]' class='placeholder'>
<paper-toolbar> <app-toolbar>
<ha-menu-button narrow='[[narrow]]' show-menu='[[showMenu]]'></ha-menu-button> <ha-menu-button narrow='[[narrow]]' show-menu='[[showMenu]]'></ha-menu-button>
</paper-toolbar> </app-toolbar>
<div class='layout horizontal center-center'> <div class='layout horizontal center-center'>
<template is='dom-if' if='[[!errorLoading]]'> <template is='dom-if' if='[[!errorLoading]]'>
<paper-spinner active></paper-spinner> <paper-spinner active></paper-spinner>

View File

@ -18,8 +18,6 @@
--paper-toggle-button-checked-button-color: #039be5; --paper-toggle-button-checked-button-color: #039be5;
--paper-toggle-button-checked-bar-color: #039be5; --paper-toggle-button-checked-bar-color: #039be5;
--paper-toolbar-background: #03A9F4;
font-size: 14px; font-size: 14px;
} }
@ -57,7 +55,7 @@
@apply(--paper-font-body1); @apply(--paper-font-body1);
} }
app-toolbar { app-header, app-toolbar {
background-color: var(--primary-color); background-color: var(--primary-color);
font-weight: 400; font-weight: 400;
color: white; color: white;