ha-frontend/src/layouts/partial-panel-resolver.html

128 lines
2.8 KiB
HTML
Raw Normal View History

<link rel='import' href='../../bower_components/paper-spinner/paper-spinner.html'>
2016-08-02 18:06:22 +02:00
<link rel="import" href="../../bower_components/iron-flex-layout/iron-flex-layout-classes.html">
2016-07-31 09:32:49 +02:00
<link rel="import" href="../../bower_components/app-layout/app-toolbar/app-toolbar.html">
<link rel='import' href='../components/ha-menu-button.html'>
2016-08-02 18:06:22 +02:00
<link rel="import" href="../resources/ha-style.html">
<dom-module id='partial-panel-resolver'>
<template>
2016-07-31 09:32:49 +02:00
<style include='iron-flex ha-style'>
[hidden] {
display: none !important;
}
.placeholder {
height: 100%;
}
.layout {
height: calc(100% - 64px);
}
</style>
<div hidden$='[[resolved]]' class='placeholder'>
2016-07-31 09:32:49 +02:00
<app-toolbar>
<ha-menu-button narrow='[[narrow]]' show-menu='[[showMenu]]'></ha-menu-button>
2016-07-31 09:32:49 +02:00
</app-toolbar>
<div class='layout horizontal center-center'>
<template is='dom-if' if='[[!errorLoading]]'>
<paper-spinner active></paper-spinner>
</template>
<template is='dom-if' if='[[errorLoading]]'>
Error loading panel :(
</template>
</div>
</div>
2016-07-29 08:58:42 +02:00
<span id='panel' hidden$='[[!resolved]]'></span>
</template>
</dom-module>
2016-07-17 08:19:49 +02:00
<script>
Polymer({
is: 'partial-panel-resolver',
properties: {
hass: {
type: Object,
observer: 'updateAttributes',
},
narrow: {
type: Boolean,
value: false,
observer: 'updateAttributes',
},
showMenu: {
type: Boolean,
value: false,
observer: 'updateAttributes',
},
resolved: {
type: Boolean,
value: false,
},
errorLoading: {
type: Boolean,
value: false,
},
2016-07-17 08:19:49 +02:00
panel: {
type: Object,
computed: 'computeCurrentPanel(hass)',
2016-07-17 08:19:49 +02:00
observer: 'panelChanged',
},
},
computeCurrentPanel: function (hass) {
return hass.config.panels[hass.currentPanel];
},
2016-07-17 08:19:49 +02:00
panelChanged: function (panel) {
2016-07-31 22:04:01 +02:00
if (!panel) {
if (this.$.panel.lastChild) {
this.$.panel.removeChild(this.$.panel.lastChild);
}
return;
}
2016-07-17 08:19:49 +02:00
this.resolved = false;
this.errorLoading = false;
2016-07-28 18:21:02 +02:00
this.importHref(
panel.url,
2016-07-28 18:21:02 +02:00
function success() {
window.hassUtil.dynamicContentUpdater(
this.$.panel, 'ha-panel-' + panel.component_name, {
2016-07-28 18:21:02 +02:00
hass: this.hass,
narrow: this.narrow,
showMenu: this.showMenu,
panel: panel,
2016-07-28 18:21:02 +02:00
});
this.resolved = true;
}.bind(this),
function error() {
this.errorLoading = true;
}.bind(this),
true /* async */);
2016-07-17 08:19:49 +02:00
},
updateAttributes: function () {
var customEl = Polymer.dom(this.$.panel).lastChild;
2016-07-17 08:19:49 +02:00
if (!customEl) return;
customEl.hass = this.hass;
customEl.narrow = this.narrow;
customEl.showMenu = this.showMenu;
},
});
</script>