mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 17:26:42 +00:00
Merge script and automation editor JS (#693)
* Merge script and automation editor JS * Also consolidate the files
This commit is contained in:
parent
27046b00c6
commit
90e6f59a74
@ -68,16 +68,17 @@ gulp.task('run_rollup_es5', () => gulp.src([
|
|||||||
'demo_data/demo_data.js',
|
'demo_data/demo_data.js',
|
||||||
])
|
])
|
||||||
.pipe(rollupEach(getRollupInputOptions(/* es6= */ false), rollupOutputOptions))
|
.pipe(rollupEach(getRollupInputOptions(/* es6= */ false), rollupOutputOptions))
|
||||||
|
.on('error', err => console.error(err.message))
|
||||||
.pipe(gulp.dest('build-temp-es5')));
|
.pipe(gulp.dest('build-temp-es5')));
|
||||||
|
|
||||||
gulp.task('run_rollup', () => gulp.src([
|
gulp.task('run_rollup', () => gulp.src([
|
||||||
'js/core.js',
|
'js/core.js',
|
||||||
'js/automation-editor/automation-editor.js',
|
'js/panel-config/panel-config.js',
|
||||||
'js/util.js',
|
'js/util.js',
|
||||||
'js/script-editor/script-editor.js',
|
|
||||||
'demo_data/demo_data.js',
|
'demo_data/demo_data.js',
|
||||||
])
|
])
|
||||||
.pipe(rollupEach(getRollupInputOptions(/* es6= */ true), rollupOutputOptions))
|
.pipe(rollupEach(getRollupInputOptions(/* es6= */ true), rollupOutputOptions))
|
||||||
|
.on('error', err => console.error(err.message))
|
||||||
.pipe(gulp.dest('build-temp')));
|
.pipe(gulp.dest('build-temp')));
|
||||||
|
|
||||||
gulp.task('ru_all_es5', ['run_rollup_es5'], () => {
|
gulp.task('ru_all_es5', ['run_rollup_es5'], () => {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { h, Component } from 'preact';
|
import { h, Component } from 'preact';
|
||||||
|
|
||||||
import Trigger from './trigger/index.js';
|
import Trigger from './trigger/index.js';
|
||||||
import Condition from '../common/component/condition/index.js';
|
import Condition from './condition/index.js';
|
||||||
import Script from '../common/component/script/index.js';
|
import Script from './script/index.js';
|
||||||
|
|
||||||
export default class Automation extends Component {
|
export default class Automation extends Component {
|
||||||
constructor() {
|
constructor() {
|
@ -1,6 +1,6 @@
|
|||||||
import { h, Component } from 'preact';
|
import { h, Component } from 'preact';
|
||||||
|
|
||||||
import { onChangeEvent } from '../../util/event.js';
|
import { onChangeEvent } from '../../common/util/event.js';
|
||||||
|
|
||||||
export default class NumericStateCondition extends Component {
|
export default class NumericStateCondition extends Component {
|
||||||
constructor() {
|
constructor() {
|
@ -1,6 +1,6 @@
|
|||||||
import { h, Component } from 'preact';
|
import { h, Component } from 'preact';
|
||||||
|
|
||||||
import { onChangeEvent } from '../../util/event.js';
|
import { onChangeEvent } from '../../common/util/event.js';
|
||||||
|
|
||||||
export default class StateCondition extends Component {
|
export default class StateCondition extends Component {
|
||||||
constructor() {
|
constructor() {
|
@ -1,6 +1,6 @@
|
|||||||
import { h, Component } from 'preact';
|
import { h, Component } from 'preact';
|
||||||
|
|
||||||
import { onChangeEvent } from '../../util/event.js';
|
import { onChangeEvent } from '../../common/util/event.js';
|
||||||
|
|
||||||
export default class SunCondition extends Component {
|
export default class SunCondition extends Component {
|
||||||
constructor() {
|
constructor() {
|
@ -1,6 +1,6 @@
|
|||||||
import { h, Component } from 'preact';
|
import { h, Component } from 'preact';
|
||||||
|
|
||||||
import { onChangeEvent } from '../../util/event.js';
|
import { onChangeEvent } from '../../common/util/event.js';
|
||||||
|
|
||||||
export default class TemplateCondition extends Component {
|
export default class TemplateCondition extends Component {
|
||||||
constructor() {
|
constructor() {
|
@ -1,6 +1,6 @@
|
|||||||
import { h, Component } from 'preact';
|
import { h, Component } from 'preact';
|
||||||
|
|
||||||
import { onChangeEvent } from '../../util/event.js';
|
import { onChangeEvent } from '../../common/util/event.js';
|
||||||
|
|
||||||
export default class TimeCondition extends Component {
|
export default class TimeCondition extends Component {
|
||||||
constructor() {
|
constructor() {
|
@ -1,8 +1,8 @@
|
|||||||
import { h, Component } from 'preact';
|
import { h, Component } from 'preact';
|
||||||
|
|
||||||
import { onChangeEvent } from '../../util/event.js';
|
import { onChangeEvent } from '../../common/util/event.js';
|
||||||
import { hasLocation } from '../../util/location.js';
|
import { hasLocation } from '../../common/util/location.js';
|
||||||
import computeStateDomain from '../../util/compute_state_domain.js';
|
import computeStateDomain from '../../common/util/compute_state_domain.js';
|
||||||
|
|
||||||
function zoneAndLocationFilter(stateObj) {
|
function zoneAndLocationFilter(stateObj) {
|
||||||
return hasLocation(stateObj) && computeStateDomain(stateObj) !== 'zone';
|
return hasLocation(stateObj) && computeStateDomain(stateObj) !== 'zone';
|
@ -1,5 +1,10 @@
|
|||||||
import { h, render } from 'preact';
|
import { h, render } from 'preact';
|
||||||
import Automation from './automation.js';
|
import Automation from './automation.js';
|
||||||
|
import Script from './script.js';
|
||||||
|
|
||||||
|
window.ScriptEditor = function (mountEl, props, mergeEl) {
|
||||||
|
return render(h(Script, props), mountEl, mergeEl);
|
||||||
|
};
|
||||||
|
|
||||||
window.AutomationEditor = function (mountEl, props, mergeEl) {
|
window.AutomationEditor = function (mountEl, props, mergeEl) {
|
||||||
return render(h(Automation, props), mountEl, mergeEl);
|
return render(h(Automation, props), mountEl, mergeEl);
|
@ -1,6 +1,6 @@
|
|||||||
import { h, Component } from 'preact';
|
import { h, Component } from 'preact';
|
||||||
|
|
||||||
import Script from '../common/component/script/index.js';
|
import Script from './script/index.js';
|
||||||
|
|
||||||
export default class ScriptEditor extends Component {
|
export default class ScriptEditor extends Component {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -24,7 +24,7 @@ export default class ScriptEditor extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
render({ script, isWide }) {
|
render({ script, isWide, hass }) {
|
||||||
const { alias, sequence } = script;
|
const { alias, sequence } = script;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -54,7 +54,11 @@ export default class ScriptEditor extends Component {
|
|||||||
Learn more about available actions.
|
Learn more about available actions.
|
||||||
</a></p>
|
</a></p>
|
||||||
</span>
|
</span>
|
||||||
<Script script={sequence} onChange={this.sequenceChanged} />
|
<Script
|
||||||
|
script={sequence}
|
||||||
|
onChange={this.sequenceChanged}
|
||||||
|
hass={hass}
|
||||||
|
/>
|
||||||
</ha-config-section>
|
</ha-config-section>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
@ -1,5 +1,5 @@
|
|||||||
import { h, Component } from 'preact';
|
import { h, Component } from 'preact';
|
||||||
import { onChangeEvent } from '../../util/event.js';
|
import { onChangeEvent } from '../../common/util/event.js';
|
||||||
|
|
||||||
export default class DelayAction extends Component {
|
export default class DelayAction extends Component {
|
||||||
constructor() {
|
constructor() {
|
@ -1,7 +1,7 @@
|
|||||||
import { h, Component } from 'preact';
|
import { h, Component } from 'preact';
|
||||||
|
|
||||||
import JSONTextArea from '../json_textarea.js';
|
import JSONTextArea from '../json_textarea.js';
|
||||||
import { onChangeEvent } from '../../util/event.js';
|
import { onChangeEvent } from '../../common/util/event.js';
|
||||||
|
|
||||||
export default class EventAction extends Component {
|
export default class EventAction extends Component {
|
||||||
constructor() {
|
constructor() {
|
@ -1,5 +1,5 @@
|
|||||||
import { h, Component } from 'preact';
|
import { h, Component } from 'preact';
|
||||||
import { onChangeEvent } from '../../util/event.js';
|
import { onChangeEvent } from '../../common/util/event.js';
|
||||||
|
|
||||||
export default class WaitAction extends Component {
|
export default class WaitAction extends Component {
|
||||||
constructor() {
|
constructor() {
|
@ -1,6 +1,6 @@
|
|||||||
import { h, Component } from 'preact';
|
import { h, Component } from 'preact';
|
||||||
|
|
||||||
import JSONTextArea from '../../common/component/json_textarea.js';
|
import JSONTextArea from '../json_textarea.js';
|
||||||
import { onChangeEvent } from '../../common/util/event.js';
|
import { onChangeEvent } from '../../common/util/event.js';
|
||||||
|
|
||||||
export default class EventTrigger extends Component {
|
export default class EventTrigger extends Component {
|
@ -1,10 +0,0 @@
|
|||||||
import { h, render } from 'preact';
|
|
||||||
import Script from './script.js';
|
|
||||||
|
|
||||||
window.ScriptEditor = function (mountEl, props, mergeEl) {
|
|
||||||
return render(h(Script, props), mountEl, mergeEl);
|
|
||||||
};
|
|
||||||
|
|
||||||
window.unmountPreact = function (mountEl, mergeEl) {
|
|
||||||
render(() => null, mountEl, mergeEl);
|
|
||||||
};
|
|
@ -22,8 +22,7 @@
|
|||||||
<link rel='import' href='../../../src/util/hass-mixins.html'>
|
<link rel='import' href='../../../src/util/hass-mixins.html'>
|
||||||
|
|
||||||
<link rel="import" href="../ha-config-section.html">
|
<link rel="import" href="../ha-config-section.html">
|
||||||
|
<link rel="import" href="../ha-config-js.html">
|
||||||
<script src='../../../build-temp/automation-editor.js'></script>
|
|
||||||
|
|
||||||
<dom-module id="ha-automation-editor">
|
<dom-module id="ha-automation-editor">
|
||||||
<template>
|
<template>
|
||||||
|
1
panels/config/ha-config-js.html
Normal file
1
panels/config/ha-config-js.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
<script src='../../build-temp/panel-config.js'></script>
|
@ -15,12 +15,14 @@
|
|||||||
<link rel="import" href="../../../bower_components/paper-fab/paper-fab.html">
|
<link rel="import" href="../../../bower_components/paper-fab/paper-fab.html">
|
||||||
<link rel="import" href="../../../bower_components/iron-autogrow-textarea/iron-autogrow-textarea.html">
|
<link rel="import" href="../../../bower_components/iron-autogrow-textarea/iron-autogrow-textarea.html">
|
||||||
|
|
||||||
<link rel='import' href='../../../src/util/hass-mixins.html'>
|
<link rel='import' href='../../../src/components/entity/ha-entity-picker.html'>
|
||||||
|
<link rel='import' href='../../../src/components/ha-combo-box.html'>
|
||||||
<link rel='import' href='../../../src/layouts/ha-app-layout.html'>
|
<link rel='import' href='../../../src/layouts/ha-app-layout.html'>
|
||||||
|
<link rel='import' href='../../../src/util/hass-mixins.html'>
|
||||||
|
|
||||||
<link rel="import" href="../ha-config-section.html">
|
<link rel="import" href="../ha-config-section.html">
|
||||||
|
|
||||||
<script src='../../../build-temp/script-editor.js'></script>
|
<link rel="import" href="../ha-config-js.html">
|
||||||
|
|
||||||
<dom-module id="ha-script-editor">
|
<dom-module id="ha-script-editor">
|
||||||
<template>
|
<template>
|
||||||
@ -159,13 +161,18 @@ class HaScriptEditor extends window.hassMixins.EventsMixin(Polymer.Element) {
|
|||||||
|
|
||||||
isWide: {
|
isWide: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
observer: 'isWideChanged',
|
observer: '_updateComponent',
|
||||||
},
|
},
|
||||||
|
|
||||||
_rendered: {
|
_rendered: {
|
||||||
type: Object,
|
type: Object,
|
||||||
value: null,
|
value: null,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_renderScheduled: {
|
||||||
|
type: Boolean,
|
||||||
|
value: false,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +201,7 @@ class HaScriptEditor extends window.hassMixins.EventsMixin(Polymer.Element) {
|
|||||||
scriptChanged(newVal, oldVal) {
|
scriptChanged(newVal, oldVal) {
|
||||||
if (!newVal) return;
|
if (!newVal) return;
|
||||||
if (!this.hass) {
|
if (!this.hass) {
|
||||||
setTimeout(this.scriptChanged.bind(this, newVal, oldVal), 0);
|
setTimeout(() => this.scriptChanged(newVal, oldVal), 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (oldVal && oldVal.entity_id === newVal.entity_id) {
|
if (oldVal && oldVal.entity_id === newVal.entity_id) {
|
||||||
@ -229,11 +236,6 @@ class HaScriptEditor extends window.hassMixins.EventsMixin(Polymer.Element) {
|
|||||||
this._updateComponent();
|
this._updateComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
isWideChanged() {
|
|
||||||
if (this.config === null) return;
|
|
||||||
this._updateComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
backTapped() {
|
backTapped() {
|
||||||
if (this.dirty &&
|
if (this.dirty &&
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
@ -244,11 +246,17 @@ class HaScriptEditor extends window.hassMixins.EventsMixin(Polymer.Element) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_updateComponent() {
|
_updateComponent() {
|
||||||
this._rendered = window.ScriptEditor(this.$.root, {
|
if (this._renderScheduled || !this.hass || !this.config) return;
|
||||||
script: this.config,
|
this._renderScheduled = true;
|
||||||
onChange: this.configChanged,
|
Promise.resolve().then(() => {
|
||||||
isWide: this.isWide,
|
this._rendered = window.ScriptEditor(this.$.root, {
|
||||||
}, this._rendered);
|
script: this.config,
|
||||||
|
onChange: this.configChanged,
|
||||||
|
isWide: this.isWide,
|
||||||
|
hass: this.hass,
|
||||||
|
}, this._rendered);
|
||||||
|
this._renderScheduled = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
saveScript() {
|
saveScript() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user