@@ -10,10 +10,10 @@
|
||||
|
||||
<link rel="import" href="../../src/components/ha-menu-button.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/ha-style.html">
|
||||
|
||||
<link rel="import" href="./ha-logbook.html">
|
||||
<link rel="import" href="./ha-logbook-data.html">
|
||||
|
||||
<dom-module id="ha-panel-logbook">
|
||||
<template>
|
||||
@@ -31,15 +31,18 @@
|
||||
}
|
||||
</style>
|
||||
|
||||
<ha-logbook-data
|
||||
hass='[[hass]]'
|
||||
is-loading='{{isLoading}}'
|
||||
entries='{{entries}}'
|
||||
filter-date='[[_computeFilterDate(_selectedDate)]]'
|
||||
></ha-logbook-data>
|
||||
|
||||
<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>
|
||||
|
||||
@@ -48,7 +51,7 @@
|
||||
<paper-input
|
||||
label='Showing entries for'
|
||||
id='datePicker'
|
||||
value='[[selectedDateStr]]'
|
||||
value='[[_computeDateDisplay(_selectedDate)]]'
|
||||
on-focus='datepickerFocus'
|
||||
></paper-input>
|
||||
|
||||
@@ -68,8 +71,6 @@
|
||||
Polymer({
|
||||
is: 'ha-panel-logbook',
|
||||
|
||||
behaviors: [window.hassBehavior],
|
||||
|
||||
properties: {
|
||||
hass: {
|
||||
type: Object,
|
||||
@@ -85,50 +86,19 @@ Polymer({
|
||||
value: false,
|
||||
},
|
||||
|
||||
selectedDate: {
|
||||
_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 window.hassUtil.formatDate(dateObj);
|
||||
},
|
||||
];
|
||||
value: function () {
|
||||
return new Date();
|
||||
},
|
||||
},
|
||||
|
||||
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: {
|
||||
@@ -136,18 +106,6 @@ Polymer({
|
||||
},
|
||||
},
|
||||
|
||||
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();
|
||||
},
|
||||
@@ -158,7 +116,15 @@ Polymer({
|
||||
// field value with its internal formatting.
|
||||
field: document.createElement('input'),
|
||||
trigger: this.$.datePicker.inputElement,
|
||||
onSelect: this.hass.logbookActions.changeCurrentDate,
|
||||
onSelect: function (newDate) {
|
||||
newDate.setDate(newDate.getDate() + 1);
|
||||
|
||||
if (newDate > new Date()) {
|
||||
newDate = new Date();
|
||||
}
|
||||
|
||||
this._selectedDate = newDate;
|
||||
}.bind(this),
|
||||
});
|
||||
// Set the initial datePicker date, without triggering onSelect handler.
|
||||
this.datePicker.setDate(this.selectedDate, true);
|
||||
@@ -168,5 +134,12 @@ Polymer({
|
||||
this.datePicker.destroy();
|
||||
},
|
||||
|
||||
_computeDateDisplay: function (date) {
|
||||
return window.hassUtil.formatDate(new Date(date));
|
||||
},
|
||||
|
||||
_computeFilterDate: function (_selectedDate) {
|
||||
return _selectedDate.toISOString();
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user