ha-frontend/src/dialogs/more-info-dialog.html

191 lines
5.1 KiB
HTML
Raw Normal View History

2015-07-13 01:57:15 +02:00
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/paper-dialog/paper-dialog.html">
<link rel="import" href="../../bower_components/paper-dialog-scrollable/paper-dialog-scrollable.html">
<!-- <link rel="import" href="../../bower_components/neon-animation/animations/slide-up-animation.html">
<link rel="import" href="../../bower_components/neon-animation/animations/slide-down-animation.html">
-->
2015-08-13 07:19:02 +02:00
<link rel="import" href="../state-summary/state-card-content.html">
2015-07-13 01:57:15 +02:00
<link rel="import" href="../components/state-history-charts.html">
<link rel="import" href="../more-infos/more-info-content.html">
<link rel="import" href="../data/ha-state-history-data.html">
2015-07-13 01:57:15 +02:00
<dom-module id="more-info-dialog">
2016-07-19 10:19:44 +02:00
<template>
<style>
paper-dialog {
font-size: 14px;
width: 365px;
}
paper-dialog[data-domain=camera] {
width: auto;
2016-07-19 10:19:44 +02:00
}
2015-08-27 09:37:19 +02:00
2016-07-19 10:19:44 +02:00
state-history-charts {
position: relative;
z-index: 1;
max-width: 365px;
2016-07-19 10:19:44 +02:00
}
2016-06-11 04:44:03 +02:00
2016-07-19 10:19:44 +02:00
state-card-content {
margin-bottom: 24px;
font-size: 14px;
}
2015-07-13 01:57:15 +02:00
2016-08-23 09:05:33 +02:00
@media all and (max-width: 450px), all and (max-height: 500px) {
2016-07-19 10:19:44 +02:00
paper-dialog {
margin: 0;
width: 100%;
max-height: calc(100% - 64px);
2015-07-13 01:57:15 +02:00
2016-07-19 10:19:44 +02:00
position: fixed !important;
bottom: 0px;
left: 0px;
right: 0px;
overflow: scroll;
}
2015-07-13 01:57:15 +02:00
}
2016-07-19 10:19:44 +02:00
</style>
2015-07-13 01:57:15 +02:00
<!-- entry-animation='slide-up-animation' exit-animation='slide-down-animation' -->
<paper-dialog id="dialog" with-backdrop opened='{{dialogOpen}}' data-domain$='[[computeDomain(stateObj)]]'>
2016-05-28 10:32:39 +02:00
<h2>
<state-card-content
state-obj="[[stateObj]]"
hass='[[hass]]' in-dialog></state-card-content>
</h2>
2016-08-23 09:05:33 +02:00
<template is='dom-if' if="[[showHistoryComponent]]">
<div>
<ha-state-history-data
hass='[[hass]]'
filter-type='[[_filterType]]'
filter-value='[[stateObj.entity_id]]'
data='{{stateHistory}}'
is-loading='{{stateHistoryLoading}}'
></ha-state-history-data>
<state-history-charts history-data="[[stateHistory]]"
is-loading-data="[[isLoadingHistoryData]]"></state-history-charts>
</div>
2016-08-23 09:05:33 +02:00
</template>
2016-07-17 08:19:49 +02:00
<paper-dialog-scrollable id='scrollable'>
<more-info-content
state-obj="[[stateObj]]" hass='[[hass]]'></more-info-content>
</paper-dialog-scrollable>
2015-07-13 01:57:15 +02:00
</paper-dialog>
</template>
</dom-module>
2016-07-18 08:18:48 +02:00
<script>
Polymer({
is: 'more-info-dialog',
properties: {
hass: {
type: Object,
},
stateObj: {
type: Object,
computed: 'computeStateObj(hass)',
2016-07-18 08:18:48 +02:00
observer: 'stateObjChanged',
},
stateHistory: {
type: Object,
},
stateHistoryLoading: {
2016-07-18 08:18:48 +02:00
type: Boolean,
},
isLoadingHistoryData: {
2016-07-18 08:18:48 +02:00
type: Boolean,
computed: 'computeIsLoadingHistoryData(delayedDialogOpen, stateHistoryLoading)',
2016-07-18 08:18:48 +02:00
},
hasHistoryComponent: {
type: Boolean,
computed: 'computeHasHistoryComponent(hass)',
2016-07-18 08:18:48 +02:00
},
showHistoryComponent: {
type: Boolean,
value: false,
computed: 'computeShowHistoryComponent(hasHistoryComponent, stateObj)',
},
dialogOpen: {
type: Boolean,
value: false,
observer: 'dialogOpenChanged',
},
delayedDialogOpen: {
type: Boolean,
value: false,
},
_filterType: {
type: String,
value: 'recent-entity',
},
2016-07-18 08:18:48 +02:00
},
ready: function () {
this.$.scrollable.dialogElement = this.$.dialog;
},
computeDomain: function (stateObj) {
return stateObj ? window.hassUtil.computeDomain(stateObj) : '';
},
computeStateObj: function (hass) {
return hass.states[hass.moreInfoEntityId] || null;
},
2016-07-18 08:18:48 +02:00
/**
* We depend on a delayed dialogOpen value to tell the chart component
* that the data is there. Otherwise the chart component will render
* before the dialog is attached to the screen and is unable to determine
* graph size resulting in scroll bars.
*/
computeIsLoadingHistoryData: function (delayedDialogOpen, stateHistoryLoading) {
return !delayedDialogOpen || stateHistoryLoading;
2016-07-18 08:18:48 +02:00
},
computeHasHistoryComponent: function (hass) {
return window.hassUtil.isComponentLoaded(hass, 'history');
2016-07-18 08:18:48 +02:00
},
computeShowHistoryComponent: function (hasHistoryComponent, stateObj) {
return this.hasHistoryComponent && stateObj &&
window.hassUtil.DOMAINS_WITH_NO_HISTORY.indexOf(
window.hassUtil.computeDomain(stateObj)) === -1;
2016-07-18 08:18:48 +02:00
},
stateObjChanged: function (newVal) {
if (!newVal) {
this.dialogOpen = false;
return;
}
this.async(function () {
// allow dialog to render content before showing it so it is
// positioned correctly.
this.dialogOpen = true;
}.bind(this), 10);
},
dialogOpenChanged: function (newVal) {
if (newVal) {
this.async(function () { this.delayedDialogOpen = true; }.bind(this), 10);
} else if (!newVal && this.stateObj) {
this.fire('hass-more-info', { entityId: null });
2016-07-18 08:18:48 +02:00
this.delayedDialogOpen = false;
}
},
});
</script>