120 lines
2.7 KiB
HTML
120 lines
2.7 KiB
HTML
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
|
<link rel='import' href='../../../bower_components/app-route/app-route.html'>
|
|
|
|
<link rel="import" href="./ha-script-picker.html">
|
|
<link rel="import" href="./ha-script-editor.html">
|
|
|
|
<dom-module id="ha-config-script">
|
|
<template>
|
|
<style>
|
|
ha-script-picker,
|
|
ha-script-editor {
|
|
height: 100%;
|
|
}
|
|
</style>
|
|
<app-route
|
|
route='[[route]]'
|
|
pattern='/edit/:script'
|
|
data="{{_routeData}}"
|
|
active="{{_edittingScript}}"
|
|
></app-route>
|
|
<app-route
|
|
route='[[route]]'
|
|
pattern='/new'
|
|
active="{{_creatingNew}}"
|
|
></app-route>
|
|
|
|
<template is='dom-if' if='[[!showEditor]]'>
|
|
<ha-script-picker
|
|
narrow='[[narrow]]'
|
|
show-menu='[[showMenu]]'
|
|
scripts='[[scripts]]'
|
|
is-wide='[[isWide]]'
|
|
></ha-script-picker>
|
|
</template>
|
|
|
|
<template is='dom-if' if='[[showEditor]]' restamp>
|
|
<ha-script-editor
|
|
hass='[[hass]]'
|
|
script='[[script]]'
|
|
is-wide='[[isWide]]'
|
|
creating-new='[[_creatingNew]]'
|
|
></ha-script-editor>
|
|
</template>
|
|
</template>
|
|
</dom-module>
|
|
|
|
<script>
|
|
Polymer({
|
|
is: 'ha-config-script',
|
|
|
|
properties: {
|
|
hass: Object,
|
|
narrow: Boolean,
|
|
showMenu: Boolean,
|
|
route: Object,
|
|
isWide: Boolean,
|
|
_routeData: Object,
|
|
_routeMatches: Boolean,
|
|
_creatingNew: Boolean,
|
|
_edittingScript: Boolean,
|
|
|
|
scripts: {
|
|
type: Array,
|
|
computed: 'computeScripts(hass)',
|
|
},
|
|
|
|
script: {
|
|
type: Object,
|
|
computed: 'computeScript(scripts, _edittingScript, _routeData)',
|
|
},
|
|
|
|
showEditor: {
|
|
type: Boolean,
|
|
computed: 'computeShowEditor(_edittingScript, _creatingNew)',
|
|
}
|
|
},
|
|
|
|
computeScript: function (scripts, edittingAddon, routeData) {
|
|
if (!scripts || !edittingAddon) {
|
|
return null;
|
|
}
|
|
for (var i = 0; i < scripts.length; i++) {
|
|
if (scripts[i].entity_id === routeData.script) {
|
|
return scripts[i];
|
|
}
|
|
}
|
|
return null;
|
|
},
|
|
|
|
computeScripts: function (hass) {
|
|
var scripts = [];
|
|
|
|
Object.keys(hass.states).forEach(function (key) {
|
|
var entity = hass.states[key];
|
|
|
|
if (window.hassUtil.computeDomain(entity) === 'script') {
|
|
scripts.push(entity);
|
|
}
|
|
});
|
|
|
|
return scripts.sort(function entitySortBy(entityA, entityB) {
|
|
var nameA = window.hassUtil.computeStateName(entityA);
|
|
var nameB = window.hassUtil.computeStateName(entityB);
|
|
|
|
if (nameA < nameB) {
|
|
return -1;
|
|
}
|
|
if (nameA > nameB) {
|
|
return 1;
|
|
}
|
|
return 0;
|
|
});
|
|
},
|
|
|
|
computeShowEditor: function (_edittingScript, _creatingNew) {
|
|
return _creatingNew || _edittingScript;
|
|
},
|
|
});
|
|
</script>
|