ha-frontend-cdce8p/panels/logbook/ha-panel-logbook.html
2016-07-30 22:48:39 -07:00

168 lines
4.2 KiB
HTML

<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="../../bower_components/paper-input/paper-input.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-header/app-header.html">
<link rel="import" href="../../bower_components/app-layout/app-toolbar/app-toolbar.html">
<link rel="import" href="../../src/components/ha-menu-button.html">
<link rel="import" href="../../src/components/loading-box.html">
<link rel="import" href="../../src/resources/pikaday-js.html">
<link rel="import" href="../../src/util/hass-behavior.html">
<link rel="import" href="../../src/resources/home-assistant-style.html">
<link rel="import" href="./ha-logbook.html">
<dom-module id="ha-panel-logbook">
<template>
<style include="ha-style">
.selected-date-container {
padding: 0 16px;
}
paper-input {
max-width: 200px;
}
[hidden] {
display: none !important;
}
</style>
<app-header-layout has-scrolling-region>
<app-header fixed>
<app-toolbar>
<ha-menu-button narrow='[[narrow]]' show-menu='[[showMenu]]'></ha-menu-button>
<div main-title>Logbook</div>
<paper-icon-button
icon="mdi:refresh"
on-tap="handleRefresh"
></paper-icon-button>
</app-toolbar>
</app-header>
<div>
<div class='selected-date-container'>
<paper-input
label='Showing entries for'
id='datePicker'
value='[[selectedDateStr]]'
on-focus='datepickerFocus'
></paper-input>
<loading-box hidden$='[[!isLoading]]'>Loading logbook entries</loading-box>
</div>
<ha-logbook hass='[[hass]]' entries="[[entries]]" hidden$='[[isLoading]]'></ha-logbook>
</div>
</app-header-layout>
</template>
</dom-module>
<script>
Polymer({
is: 'ha-panel-logbook',
behaviors: [window.hassBehavior],
properties: {
hass: {
type: Object,
},
narrow: {
type: Boolean,
value: false,
},
showMenu: {
type: Boolean,
value: false,
},
selectedDate: {
type: String,
bindNuclear: function (hass) {
return hass.logbookGetters.currentDate;
},
},
selectedDateStr: {
type: String,
value: null,
bindNuclear: function (hass) {
return [
hass.logbookGetters.currentDate,
function (currentDate) {
var dateObj = new Date(currentDate);
return dateObj.toLocaleDateString();
},
];
},
},
isLoading: {
type: Boolean,
bindNuclear: function (hass) {
return hass.logbookGetters.isLoadingEntries;
},
},
isStale: {
type: Boolean,
bindNuclear: function (hass) {
return hass.logbookGetters.isCurrentStale;
},
observer: 'isStaleChanged',
},
entries: {
type: Array,
bindNuclear: function (hass) {
return [
hass.logbookGetters.currentEntries,
function (entries) { return entries.reverse().toArray(); },
];
},
},
datePicker: {
type: Object,
},
},
isStaleChanged: function (newVal) {
if (newVal) {
this.async(function () {
this.hass.logbookActions.fetchDate(this.selectedDate);
}.bind(this), 1);
}
},
handleRefresh: function () {
this.hass.logbookActions.fetchDate(this.selectedDate);
},
datepickerFocus: function () {
this.datePicker.adjustPosition();
},
attached: function () {
this.datePicker = new window.Pikaday({
// Bind field to dummy input to prevent pikaday from overwriting
// field value with its internal formatting.
field: document.createElement('input'),
trigger: this.$.datePicker.inputElement,
onSelect: this.hass.logbookActions.changeCurrentDate,
});
// Set the initial datePicker date, without triggering onSelect handler.
this.datePicker.setDate(this.selectedDate, true);
},
detached: function () {
this.datePicker.destroy();
},
});
</script>