2015-07-13 01:57:15 +02:00
|
|
|
<link rel="import" href="../../bower_components/polymer/polymer.html">
|
|
|
|
|
|
|
|
<link rel="import" href="../../bower_components/paper-toast/paper-toast.html">
|
|
|
|
|
|
|
|
<dom-module id="notification-manager">
|
|
|
|
<template>
|
2016-07-19 10:19:44 +02:00
|
|
|
<style>
|
|
|
|
paper-toast {
|
|
|
|
z-index: 1;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2016-11-27 08:41:51 +01:00
|
|
|
<paper-toast
|
2016-12-06 07:13:55 +01:00
|
|
|
id="toast"
|
2017-01-30 03:34:45 +01:00
|
|
|
text='[[_text]]'
|
|
|
|
no-cancel-on-outside-click='[[_cancelOnOutsideClick]]'
|
2016-12-06 07:13:55 +01:00
|
|
|
></paper-toast>
|
|
|
|
<paper-toast
|
|
|
|
id='connToast'
|
2016-11-27 08:41:51 +01:00
|
|
|
duration='0'
|
|
|
|
text='Connection lost. Reconnecting…'
|
|
|
|
opened='[[!isStreaming]]'
|
|
|
|
></paper-toast>
|
2015-07-13 01:57:15 +02:00
|
|
|
</template>
|
|
|
|
</dom-module>
|
2016-07-18 08:18:48 +02:00
|
|
|
|
|
|
|
<script>
|
|
|
|
Polymer({
|
|
|
|
is: 'notification-manager',
|
|
|
|
|
|
|
|
properties: {
|
|
|
|
hass: {
|
|
|
|
type: Object,
|
|
|
|
},
|
|
|
|
|
2016-11-27 08:41:51 +01:00
|
|
|
isStreaming: {
|
|
|
|
type: Boolean,
|
2017-01-30 03:34:45 +01:00
|
|
|
computed: 'computeIsStreaming(hass)',
|
2016-11-27 08:41:51 +01:00
|
|
|
},
|
|
|
|
|
2017-01-30 03:34:45 +01:00
|
|
|
_cancelOnOutsideClick: {
|
2016-07-18 08:18:48 +02:00
|
|
|
type: Boolean,
|
|
|
|
value: false,
|
|
|
|
},
|
|
|
|
|
2017-01-30 03:34:45 +01:00
|
|
|
_text: {
|
2016-07-18 08:18:48 +02:00
|
|
|
type: String,
|
2017-01-30 03:34:45 +01:00
|
|
|
readOnly: true,
|
2016-07-18 08:18:48 +02:00
|
|
|
},
|
2016-12-06 07:13:55 +01:00
|
|
|
|
|
|
|
toastClass: {
|
|
|
|
type: String,
|
|
|
|
value: '',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2017-01-30 03:34:45 +01:00
|
|
|
computeIsStreaming: function (hass) {
|
|
|
|
return !hass || hass.connected;
|
|
|
|
},
|
|
|
|
|
2016-12-06 07:13:55 +01:00
|
|
|
created: function () {
|
|
|
|
this.handleWindowChange = this.handleWindowChange.bind(this);
|
|
|
|
this._mediaq = window.matchMedia('(max-width: 599px)');
|
|
|
|
this._mediaq.addListener(this.handleWindowChange);
|
|
|
|
},
|
|
|
|
|
|
|
|
attached: function () {
|
|
|
|
this.handleWindowChange(this._mediaq);
|
|
|
|
},
|
|
|
|
|
|
|
|
detached: function () {
|
|
|
|
this._mediaq.removeListener(this.handleWindowChange);
|
|
|
|
},
|
|
|
|
|
|
|
|
handleWindowChange: function (ev) {
|
|
|
|
this.$.toast.classList.toggle('fit-bottom', ev.matches);
|
|
|
|
this.$.connToast.classList.toggle('fit-bottom', ev.matches);
|
2016-07-18 08:18:48 +02:00
|
|
|
},
|
|
|
|
|
2017-01-30 03:34:45 +01:00
|
|
|
showNotification: function (message) {
|
|
|
|
this._set_text(message);
|
|
|
|
this.$.toast.show();
|
2016-07-18 08:18:48 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|