ha-frontend-cdce8p/panels/dev-event/ha-panel-dev-event.js
Paulus Schoutsen a4afc2e37a
Polymer 3 modulize (#1154)
* Version bump to 20180510.1

* Fix hass util

* Fix translations

* Bye paper-time-input

* Add webpack config

* Add webpack to package.json

* Fix translation import

* Disable web animations polyfill bad import

* Disable importHref import

* Update webpack config to build authorize.js

* Build translations json

* Build frontend correctly

* Run eslint --fix

* Load markdown JS on demand (#1155)

* Add HTML imports (#1160)

* Fix localize (#1161)

* Fix Roboto in build (#1162)

* Load web animations polyfill (#1163)

* P3: Fix chart js (#1164)

* P3: Fix Chart JS

* Update timeline package

* P3: panel resolver (#1165)

* WIP

* Initial importing of panels

* Fix panel resolver

* Fix automation and script editor (#1166)

* Expose Polymer and Polymer.Element on window (#1167)

* Remove unused import

* eslint --fix

* Es5 build (#1168)

* Build for ES5

* Fix build_frontend

* Remove stale comment

* Migrate to use paper-material-styles (#1170)

* Send parsed date to history/logbook (#1171)

* Fork app storage behavior (#1172)

* Add paper input with type time (#1173)

* Fix authorize

* Lint

* Sort imports

* Lint

* Remove eslint-html

* Do not lint authorize.html

* Fix polymer lint

* Try chrome 62 for wct

* P3: Add patched iconset (#1175)

* Add patched iconset

* Lint

* Test with latest Chrome again

* Use less window.hassUtil

* Teporarily use my fecha fork

* Import correct intl.messageFormat

* Update wct-browser-legacy to 1.0.0

* Include polyfill in right place

* Fix IntlMessageFormat

* Fix test not having a global scope

* Rollup <_<

* Fork app-localize-behavior

* Disable wct tests

* Lint
2018-05-15 13:31:47 -04:00

132 lines
3.3 KiB
JavaScript

import '@polymer/app-layout/app-header-layout/app-header-layout.js';
import '@polymer/app-layout/app-header/app-header.js';
import '@polymer/app-layout/app-toolbar/app-toolbar.js';
import '@polymer/iron-flex-layout/iron-flex-layout-classes.js';
import '@polymer/paper-button/paper-button.js';
import '@polymer/paper-input/paper-input.js';
import '@polymer/paper-input/paper-textarea.js';
import { html } from '@polymer/polymer/lib/utils/html-tag.js';
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../../src/components/ha-menu-button.js';
import '../../src/resources/ha-style.js';
import '../../src/util/hass-mixins.js';
import './events-list.js';
class HaPanelDevEvent extends window.hassMixins.EventsMixin(PolymerElement) {
static get template() {
return html`
<style is="custom-style" include="ha-style iron-flex iron-positioning"></style>
<style>
:host {
-ms-user-select: initial;
-webkit-user-select: initial;
-moz-user-select: initial;
}
.content {
@apply --paper-font-body1;
padding: 16px;
}
.ha-form {
margin-right: 16px;
}
.header {
@apply --paper-font-title;
}
</style>
<app-header-layout has-scrolling-region>
<app-header slot="header" fixed>
<app-toolbar>
<ha-menu-button narrow='[[narrow]]' show-menu='[[showMenu]]'></ha-menu-button>
<div main-title>Events</div>
</app-toolbar>
</app-header>
<div class$='[[computeFormClasses(narrow)]]'>
<div class='flex'>
<p>
Fire an event on the event bus.
</p>
<div class='ha-form'>
<paper-input label="Event Type" autofocus required value='{{eventType}}'></paper-input>
<paper-textarea label="Event Data (JSON, optional)" value='{{eventData}}'></paper-textarea>
<paper-button on-click='fireEvent' raised>Fire Event</paper-button>
</div>
</div>
<div>
<div class='header'>Available Events</div>
<events-list on-event-selected='eventSelected' hass='[[hass]]'></events-list>
</div>
</div>
</app-header-layout>
`;
}
static get is() { return 'ha-panel-dev-event'; }
static get properties() {
return {
hass: {
type: Object,
},
narrow: {
type: Boolean,
value: false,
},
showMenu: {
type: Boolean,
value: false,
},
eventType: {
type: String,
value: '',
},
eventData: {
type: String,
value: '',
},
};
}
eventSelected(ev) {
this.eventType = ev.detail.eventType;
}
fireEvent() {
var eventData;
try {
eventData = this.eventData ? JSON.parse(this.eventData) : {};
} catch (err) {
/* eslint-disable no-alert */
alert('Error parsing JSON: ' + err);
/* eslint-enable no-alert */
return;
}
this.hass.callApi('POST', 'events/' + this.eventType, eventData)
.then(function () {
this.fire('hass-notification', {
message: 'Event ' + this.eventType + ' successful fired!',
});
}.bind(this));
}
computeFormClasses(narrow) {
return narrow ?
'content fit' : 'content fit layout horizontal';
}
}
customElements.define(HaPanelDevEvent.is, HaPanelDevEvent);