mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-18 14:56:37 +00:00
Allow creating new automations.
This commit is contained in:
parent
2b14b206ab
commit
9bc67bd0cf
@ -141,6 +141,11 @@ Polymer({
|
|||||||
observer: 'automationChanged',
|
observer: 'automationChanged',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
creatingNew: {
|
||||||
|
type: Boolean,
|
||||||
|
observer: 'creatingNewChanged',
|
||||||
|
},
|
||||||
|
|
||||||
name: {
|
name: {
|
||||||
type: String,
|
type: String,
|
||||||
computed: 'computeName(automation)'
|
computed: 'computeName(automation)'
|
||||||
@ -152,7 +157,7 @@ Polymer({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
attached: function () {
|
created: function () {
|
||||||
this.configChanged = this.configChanged.bind(this);
|
this.configChanged = this.configChanged.bind(this);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -194,6 +199,23 @@ Polymer({
|
|||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
creatingNewChanged: function (newVal) {
|
||||||
|
if (!newVal) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.dirty = false;
|
||||||
|
this.config = {
|
||||||
|
alias: 'New Automation',
|
||||||
|
trigger: [
|
||||||
|
{ platform: 'state' },
|
||||||
|
],
|
||||||
|
action: [
|
||||||
|
{ service: '' },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
this._updateComponent();
|
||||||
|
},
|
||||||
|
|
||||||
isWideChanged: function () {
|
isWideChanged: function () {
|
||||||
if (this.config === null) return;
|
if (this.config === null) return;
|
||||||
this._updateComponent();
|
this._updateComponent();
|
||||||
@ -218,10 +240,16 @@ Polymer({
|
|||||||
},
|
},
|
||||||
|
|
||||||
saveAutomation: function () {
|
saveAutomation: function () {
|
||||||
|
var id = this.creatingNew ? '' + Date.now() : this.automation.attributes.id;
|
||||||
this.hass.callApi(
|
this.hass.callApi(
|
||||||
'post', 'config/automation/config/' + this.automation.attributes.id,
|
'post', 'config/automation/config/' + id, this.config).then(function () {
|
||||||
this.config).then(function () {
|
|
||||||
this.dirty = false;
|
this.dirty = false;
|
||||||
|
|
||||||
|
if (this.creatingNew) {
|
||||||
|
this.fire('hass-automation-picked', {
|
||||||
|
id: id,
|
||||||
|
});
|
||||||
|
}
|
||||||
}.bind(this), function (errors) {
|
}.bind(this), function (errors) {
|
||||||
this.errors = errors.body.message;
|
this.errors = errors.body.message;
|
||||||
throw errors;
|
throw errors;
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
<link rel="import" href="../../bower_components/paper-card/paper-card.html">
|
<link rel="import" href="../../bower_components/paper-card/paper-card.html">
|
||||||
<link rel="import" href="../../bower_components/paper-item/paper-item.html">
|
<link rel="import" href="../../bower_components/paper-item/paper-item.html">
|
||||||
<link rel="import" href="../../bower_components/paper-item/paper-item-body.html">
|
<link rel="import" href="../../bower_components/paper-item/paper-item-body.html">
|
||||||
|
<link rel="import" href="../../bower_components/paper-fab/paper-fab.html">
|
||||||
|
|
||||||
<dom-module id="ha-automation-picker">
|
<dom-module id="ha-automation-picker">
|
||||||
<template>
|
<template>
|
||||||
@ -31,6 +32,18 @@
|
|||||||
paper-item {
|
paper-item {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
paper-fab {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 16px;
|
||||||
|
right: 16px;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
paper-fab[is-wide] {
|
||||||
|
bottom: 24px;
|
||||||
|
right: 24px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<app-header-layout has-scrolling-region>
|
<app-header-layout has-scrolling-region>
|
||||||
@ -64,6 +77,13 @@
|
|||||||
</paper-item>
|
</paper-item>
|
||||||
</template>
|
</template>
|
||||||
</paper-card>
|
</paper-card>
|
||||||
|
|
||||||
|
<paper-fab
|
||||||
|
is-wide$='[[isWide]]'
|
||||||
|
icon='mdi:plus'
|
||||||
|
title='Add Automation'
|
||||||
|
on-tap='addAutomation'
|
||||||
|
></paper-fab>
|
||||||
</div>
|
</div>
|
||||||
</app-header-layout>
|
</app-header-layout>
|
||||||
|
|
||||||
@ -91,6 +111,10 @@ Polymer({
|
|||||||
automations: {
|
automations: {
|
||||||
type: Array,
|
type: Array,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
isWide: {
|
||||||
|
type: Boolean,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
automationTapped: function (ev) {
|
automationTapped: function (ev) {
|
||||||
@ -99,6 +123,10 @@ Polymer({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
addAutomation: function () {
|
||||||
|
this.fire('hass-create-automation');
|
||||||
|
},
|
||||||
|
|
||||||
computeName: function (automation) {
|
computeName: function (automation) {
|
||||||
return window.hassUtil.computeStateName(automation);
|
return window.hassUtil.computeStateName(automation);
|
||||||
},
|
},
|
||||||
|
@ -18,17 +18,19 @@
|
|||||||
<iron-media-query query="(min-width: 1296px)" query-matches="{{wideSidebar}}">
|
<iron-media-query query="(min-width: 1296px)" query-matches="{{wideSidebar}}">
|
||||||
</iron-media-query>
|
</iron-media-query>
|
||||||
|
|
||||||
<template is='dom-if' if='[[!automation]]'>
|
<template is='dom-if' if='[[!showEditor]]'>
|
||||||
<ha-automation-picker
|
<ha-automation-picker
|
||||||
automations='[[automations]]'
|
automations='[[automations]]'
|
||||||
|
is-wide='[[isWide]]'
|
||||||
></ha-automation-picker>
|
></ha-automation-picker>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template is='dom-if' if='[[automation]]' restamp>
|
<template is='dom-if' if='[[showEditor]]' restamp>
|
||||||
<ha-automation-editor
|
<ha-automation-editor
|
||||||
hass='[[hass]]'
|
hass='[[hass]]'
|
||||||
automation='[[automation]]'
|
automation='[[automation]]'
|
||||||
is-wide='[[isWide]]'
|
is-wide='[[isWide]]'
|
||||||
|
creating-new='[[creatingNew]]'
|
||||||
></ha-automation-editor>
|
></ha-automation-editor>
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
@ -64,7 +66,7 @@ Polymer({
|
|||||||
|
|
||||||
automation: {
|
automation: {
|
||||||
type: Object,
|
type: Object,
|
||||||
computed: 'computeAutomation(automations, automationId)',
|
computed: 'computeAutomation(automations, automationId, creatingNew)',
|
||||||
},
|
},
|
||||||
|
|
||||||
wide: {
|
wide: {
|
||||||
@ -79,17 +81,31 @@ Polymer({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
computed: 'computeIsWide(showMenu, wideSidebar, wide)'
|
computed: 'computeIsWide(showMenu, wideSidebar, wide)'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
creatingNew: {
|
||||||
|
type: Boolean,
|
||||||
|
value: false,
|
||||||
|
},
|
||||||
|
|
||||||
|
showEditor: {
|
||||||
|
type: Boolean,
|
||||||
|
computed: 'computeShowEditor(automation, creatingNew)',
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
listeners: {
|
listeners: {
|
||||||
'hass-automation-picked': 'automationPicked',
|
'hass-automation-picked': 'automationPicked',
|
||||||
|
'hass-create-automation': 'createAutomation',
|
||||||
},
|
},
|
||||||
|
|
||||||
computeIsWide: function (showMenu, wideSidebar, wide) {
|
computeIsWide: function (showMenu, wideSidebar, wide) {
|
||||||
return showMenu ? wideSidebar : wide;
|
return showMenu ? wideSidebar : wide;
|
||||||
},
|
},
|
||||||
|
|
||||||
computeAutomation: function (automations, automationId) {
|
computeAutomation: function (automations, automationId, creatingNew) {
|
||||||
|
if (creatingNew) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
for (var i = 0; i < automations.length; i++) {
|
for (var i = 0; i < automations.length; i++) {
|
||||||
if (automations[i].attributes.id === automationId) {
|
if (automations[i].attributes.id === automationId) {
|
||||||
return automations[i];
|
return automations[i];
|
||||||
@ -126,8 +142,19 @@ Polymer({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
computeShowEditor: function (automation, creatingNew) {
|
||||||
|
return creatingNew || automation;
|
||||||
|
},
|
||||||
|
|
||||||
automationPicked: function (ev) {
|
automationPicked: function (ev) {
|
||||||
this.automationId = ev.detail.id;
|
this.automationId = ev.detail.id;
|
||||||
|
if (this.creatingNew) {
|
||||||
|
this.creatingNew = false;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
createAutomation: function () {
|
||||||
|
this.creatingNew = true;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user