diff --git a/bundles/org.openhab.ui/web/src/components/pagedesigner/page-settings.vue b/bundles/org.openhab.ui/web/src/components/pagedesigner/page-settings.vue index e28e360d48..4aa9d3bb49 100644 --- a/bundles/org.openhab.ui/web/src/components/pagedesigner/page-settings.vue +++ b/bundles/org.openhab.ui/web/src/components/pagedesigner/page-settings.vue @@ -27,7 +27,7 @@ - + diff --git a/bundles/org.openhab.ui/web/src/components/rule/rule-general-settings.vue b/bundles/org.openhab.ui/web/src/components/rule/rule-general-settings.vue new file mode 100644 index 0000000000..f4cd0d7ebb --- /dev/null +++ b/bundles/org.openhab.ui/web/src/components/rule/rule-general-settings.vue @@ -0,0 +1,70 @@ + + + diff --git a/bundles/org.openhab.ui/web/src/components/tags/tag-input.vue b/bundles/org.openhab.ui/web/src/components/tags/tag-input.vue index b8935e35b9..f43974d7df 100644 --- a/bundles/org.openhab.ui/web/src/components/tags/tag-input.vue +++ b/bundles/org.openhab.ui/web/src/components/tags/tag-input.vue @@ -3,7 +3,7 @@
- +
@@ -29,7 +29,7 @@ import TagMixin from '@/components/tags/tag-mixin' export default { mixins: [TagMixin], - props: ['item', 'disabled', 'inScriptEditor'], + props: ['item', 'disabled', 'inScriptEditor', 'inSceneEditor', 'showSemanticTags'], data () { return { pendingTag: '' @@ -40,6 +40,10 @@ export default { if (this.inScriptEditor !== true) return false if (tag === 'Script') return true }, + isSceneTag (tag) { + if (this.inSceneEditor !== true) return false + if (tag === 'Scene') return true + }, addTag () { if (this.pendingTag && this.item.tags.indexOf(this.pendingTag) === -1) { this.item.tags.push(this.pendingTag) diff --git a/bundles/org.openhab.ui/web/src/pages/settings/rules/rule-edit-mixin.js b/bundles/org.openhab.ui/web/src/pages/settings/rules/rule-edit-mixin.js new file mode 100644 index 0000000000..469d34b808 --- /dev/null +++ b/bundles/org.openhab.ui/web/src/pages/settings/rules/rule-edit-mixin.js @@ -0,0 +1,111 @@ +import YAML from 'yaml' + +export default { + data () { + return { + showModuleControls: false, + eventSource: null, + keyHandler: null + } + }, + computed: { + isEditable () { + return this.rule && this.rule.editable !== false + }, + yamlError () { + if (this.currentTab !== 'code') return null + try { + YAML.parse(this.ruleYaml, { prettyErrors: true }) + return 'OK' + } catch (e) { + return e + } + } + }, + methods: { + onPageAfterIn () { + if (window) { + window.addEventListener('keydown', this.keyDown) + } + this.load() + }, + onPageAfterOut () { + this.stopEventSource() + if (window) { + window.removeEventListener('keydown', this.keyDown) + } + }, + onEditorInput (value) { + this.ruleYaml = value + this.dirty = true + }, + toggleDisabled () { + if (this.createMode) return + if (this.copyMode) return + const enable = (this.rule.status.statusDetail === 'DISABLED') + this.$oh.api.postPlain('/rest/rules/' + this.rule.uid + '/enable', enable.toString()).then((data) => { + this.$f7.toast.create({ + text: (enable) ? 'Enabled' : 'Disabled', + destroyOnClose: true, + closeTimeout: 2000 + }).open() + }).catch((err) => { + this.$f7.toast.create({ + text: 'Error while disabling or enabling: ' + err, + destroyOnClose: true, + closeTimeout: 2000 + }).open() + }) + }, + keyDown (ev) { + if ((ev.ctrlKey || ev.metaKey) && !(ev.altKey || ev.shiftKey)) { + if (this.currentModule) return + switch (ev.keyCode) { + case 68: + this.toggleDisabled() + ev.stopPropagation() + ev.preventDefault() + break + case 82: + this.runNow() + ev.stopPropagation() + ev.preventDefault() + break + case 83: + this.save() + ev.stopPropagation() + ev.preventDefault() + break + } + } + }, + toggleModuleControls () { + this.showModuleControls = !this.showModuleControls + }, + showSwipeout (ev) { + let swipeoutElement = ev.target + ev.cancelBubble = true + while (!swipeoutElement.classList.contains('swipeout')) { + swipeoutElement = swipeoutElement.parentElement + } + + if (swipeoutElement) { + this.$f7.swipeout.open(swipeoutElement) + } + }, + startEventSource () { + this.eventSource = this.$oh.sse.connect('/rest/events?topics=openhab/rules/' + this.ruleId + '/*', null, (event) => { + const topicParts = event.topic.split('/') + switch (topicParts[3]) { + case 'state': + this.$set(this.rule, 'status', JSON.parse(event.payload)) // e.g. {"status":"RUNNING","statusDetail":"NONE"} + break + } + }) + }, + stopEventSource () { + this.$oh.sse.close(this.eventSource) + this.eventSource = null + } + } +} diff --git a/bundles/org.openhab.ui/web/src/pages/settings/rules/rule-edit.vue b/bundles/org.openhab.ui/web/src/pages/settings/rules/rule-edit.vue index d5c76e581a..ab31ce4901 100644 --- a/bundles/org.openhab.ui/web/src/pages/settings/rules/rule-edit.vue +++ b/bundles/org.openhab.ui/web/src/pages/settings/rules/rule-edit.vue @@ -50,35 +50,9 @@ - - - - - - - - - - - - - - - - - - - + +  Note: this rule is not editable because it has been provisioned from a file. @@ -150,11 +124,6 @@
- - Tags - - - @@ -211,23 +180,21 @@ import YAML from 'yaml' import cloneDeep from 'lodash/cloneDeep' import fastDeepEqual from 'fast-deep-equal/es6' -import SemanticsPicker from '@/components/tags/semantics-picker.vue' -import TagInput from '@/components/tags/tag-input.vue' - import RuleModulePopup from './rule-module-popup.vue' +import RuleMixin from './rule-edit-mixin' import ModuleDescriptionSuggestions from './module-description-suggestions' import RuleStatus from '@/components/rule/rule-status-mixin' import DirtyMixin from '../dirty-mixin' import ConfigSheet from '@/components/config/config-sheet.vue' +import RuleGeneralSettings from '@/components/rule/rule-general-settings.vue' export default { - mixins: [ModuleDescriptionSuggestions, RuleStatus, DirtyMixin], + mixins: [RuleMixin, ModuleDescriptionSuggestions, RuleStatus, DirtyMixin], components: { + RuleGeneralSettings, ConfigSheet, - SemanticsPicker, - TagInput, 'editor': () => import(/* webpackChunkName: "script-editor" */ '@/components/config/controls/script-editor.vue') }, props: ['ruleId', 'createMode', 'copyMode', 'ruleCopy', 'schedule'], @@ -242,7 +209,6 @@ export default { conditions: [], triggers: [] }, - showModuleControls: false, currentSection: 'actions', currentTab: 'design', currentModuleType: null, @@ -253,8 +219,6 @@ export default { actions: ['Then', 'Add Action'], conditions: ['But only if', 'Add Condition'] }, - eventSource: null, - keyHandler: null, codeEditorOpened: false, cronPopupOpened: false, @@ -281,22 +245,6 @@ export default { } }, methods: { - onPageAfterIn () { - if (window) { - window.addEventListener('keydown', this.keyDown) - } - this.load() - }, - onPageAfterOut () { - this.stopEventSource() - if (window) { - window.removeEventListener('keydown', this.keyDown) - } - }, - onEditorInput (value) { - this.ruleYaml = value - this.dirty = true - }, load () { if (this.loading) return this.loading = true @@ -412,23 +360,6 @@ export default { }).open() }) }, - toggleDisabled () { - if (this.isNewRule) return - const enable = (this.rule.status.statusDetail === 'DISABLED') - this.$oh.api.postPlain('/rest/rules/' + this.rule.uid + '/enable', enable.toString()).then((data) => { - this.$f7.toast.create({ - text: (enable) ? 'Rule enabled' : 'Rule disabled', - destroyOnClose: true, - closeTimeout: 2000 - }).open() - }).catch((err) => { - this.$f7.toast.create({ - text: 'Error while disabling or enabling: ' + err, - destroyOnClose: true, - closeTimeout: 2000 - }).open() - }) - }, copyRule () { let ruleClone = cloneDeep(this.rule) this.$f7router.navigate({ @@ -477,20 +408,6 @@ export default { } ) }, - startEventSource () { - this.eventSource = this.$oh.sse.connect('/rest/events?topics=openhab/rules/' + this.ruleId + '/*', null, (event) => { - const topicParts = event.topic.split('/') - switch (topicParts[3]) { - case 'state': - this.$set(this.rule, 'status', JSON.parse(event.payload)) - break - } - }) - }, - stopEventSource () { - this.$oh.sse.close(this.eventSource) - this.eventSource = null - }, selectTemplate (uid) { this.$set(this.rule, 'configuration', {}) this.$set(this.rule, 'triggers', []) @@ -503,42 +420,6 @@ export default { this.$set(this, 'currentTemplate', this.templates.find((t) => t.uid === uid)) this.rule.templateUID = uid }, - keyDown (ev) { - if ((ev.ctrlKey || ev.metaKey) && !(ev.altKey || ev.shiftKey)) { - if (this.currentModule) return - switch (ev.keyCode) { - case 68: - this.toggleDisabled() - ev.stopPropagation() - ev.preventDefault() - break - case 82: - this.runNow() - ev.stopPropagation() - ev.preventDefault() - break - case 83: - this.save() - ev.stopPropagation() - ev.preventDefault() - break - } - } - }, - toggleModuleControls () { - this.showModuleControls = !this.showModuleControls - }, - showSwipeout (ev) { - let swipeoutElement = ev.target - ev.cancelBubble = true - while (!swipeoutElement.classList.contains('swipeout')) { - swipeoutElement = swipeoutElement.parentElement - } - - if (swipeoutElement) { - this.$f7.swipeout.open(swipeoutElement) - } - }, editModule (ev, section, mod, force) { if (this.showModuleControls) return if (!this.isEditable) return @@ -740,9 +621,6 @@ export default { } }, computed: { - isEditable () { - return this.rule && this.rule.editable !== false - }, hasTemplate () { return this.rule && this.currentTemplate !== null }, @@ -755,15 +633,6 @@ export default { const marketplaceTag = this.currentTemplate.tags.find((t) => t.indexOf('marketplace:') === 0) if (marketplaceTag) return 'https://community.openhab.org/t/' + marketplaceTag.replace('marketplace:', '') return null - }, - yamlError () { - if (this.currentTab !== 'code') return null - try { - YAML.parse(this.ruleYaml, { prettyErrors: true }) - return 'OK' - } catch (e) { - return e - } } } } diff --git a/bundles/org.openhab.ui/web/src/pages/settings/rules/scene/scene-edit.vue b/bundles/org.openhab.ui/web/src/pages/settings/rules/scene/scene-edit.vue index a2294280f7..3e81b11772 100644 --- a/bundles/org.openhab.ui/web/src/pages/settings/rules/scene/scene-edit.vue +++ b/bundles/org.openhab.ui/web/src/pages/settings/rules/scene/scene-edit.vue @@ -23,7 +23,7 @@
- +
Status: - - - - - - - - - - - - - - - - - - - + +  Note: this rule is not editable because it has been provisioned from a file. @@ -141,11 +113,6 @@
- - Tags - - - @@ -221,22 +188,21 @@ diff --git a/bundles/org.openhab.ui/web/src/pages/settings/rules/script/script-general-settings.vue b/bundles/org.openhab.ui/web/src/pages/settings/rules/script/script-general-settings.vue index 2bf26f4b04..8b5cd9a59a 100644 --- a/bundles/org.openhab.ui/web/src/pages/settings/rules/script/script-general-settings.vue +++ b/bundles/org.openhab.ui/web/src/pages/settings/rules/script/script-general-settings.vue @@ -1,41 +1,28 @@