From d8243dbfdaa79e08ceeb5a944dc886e459091bf9 Mon Sep 17 00:00:00 2001 From: Florian Hotze Date: Thu, 22 Dec 2022 18:32:22 +0100 Subject: [PATCH 1/7] [MainUI] Extend script settings for tags & language Signed-off-by: Florian Hotze --- .../settings/rules/script/script-edit.vue | 42 ++++++++++++------- .../rules/script/script-general-settings.vue | 21 +++++++++- 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/bundles/org.openhab.ui/web/src/pages/settings/rules/script/script-edit.vue b/bundles/org.openhab.ui/web/src/pages/settings/rules/script/script-edit.vue index 416a1e4455..7a3386013d 100644 --- a/bundles/org.openhab.ui/web/src/pages/settings/rules/script/script-edit.vue +++ b/bundles/org.openhab.ui/web/src/pages/settings/rules/script/script-edit.vue @@ -85,7 +85,7 @@ - + @@ -189,20 +189,8 @@ export default { tags: ['Script'] } this.mode = 'application/javascript+blockly' - this.$oh.api.get('/rest/module-types/script.ScriptAction').then((data) => { - this.$set(this, 'scriptModuleType', data) - this.$set(this, 'languages', - this.scriptModuleType.configDescriptions - .find((c) => c.name === 'type').options - .map((l) => { - return { - contentType: l.value, - name: l.label.split(' (')[0], - version: l.label.split(' (')[1].replace(')', '') - } - })) - this.ready = true - }) + this.loadScriptModules() + this.ready = true }, createScript () { if (!this.rule.uid) { @@ -243,6 +231,22 @@ export default { this.load() }) }, + loadScriptModules () { + this.$oh.api.get('/rest/module-types/script.ScriptAction').then((data) => { + this.$set(this, 'scriptModuleType', data) + let languages = this.scriptModuleType.configDescriptions + .find((c) => c.name === 'type').options + .map((l) => { + return { + contentType: l.value, + name: l.label.split(' (')[0], + version: l.label.split(' (')[1].replace(')', '') + } + }) + if (this.isBlockly) languages = languages.filter((l) => l.contentType.startsWith('application/javascript')) + this.$set(this, 'languages', languages) + }) + }, load () { if (this.loading) return this.loading = true @@ -277,6 +281,8 @@ export default { this.script = triggerDescriptionComments + '\n' + this.script } + this.loadScriptModules() + this.ready = true if (!this.eventSource) this.startEventSource() }) @@ -300,6 +306,8 @@ export default { } } this.currentModule.configuration.script = this.script + this.currentModule.configuration.type = this.mode + if (this.isScriptRule && !this.rule.tags.includes('Script')) this.rule.tags.push('Script') return this.$oh.api.put('/rest/rules/' + this.rule.uid, this.rule).then((data) => { this.dirty = false if (!noToast) { @@ -317,6 +325,10 @@ export default { }).open() }) }, + changeLanguage (contentType) { + if (this.createMode) return + this.mode = contentType + }, toggleDisabled () { if (this.createMode) return const enable = (this.rule.status.statusDetail === 'DISABLED') 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 a4af69ada4..204883ca2e 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 @@ -12,11 +12,30 @@ @input="rule.description = $event.target.value" clear-button /> + + Tags + + + + Scripting Language + + + + From c0fc1a79d51c208a46cac85258bf999b5d38d004 Mon Sep 17 00:00:00 2001 From: Florian Hotze Date: Thu, 22 Dec 2022 18:50:39 +0100 Subject: [PATCH 2/7] [MainUI] Enable script language setting for rules Signed-off-by: Florian Hotze --- .../web/src/pages/settings/rules/script/script-edit.vue | 6 +++--- .../pages/settings/rules/script/script-general-settings.vue | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bundles/org.openhab.ui/web/src/pages/settings/rules/script/script-edit.vue b/bundles/org.openhab.ui/web/src/pages/settings/rules/script/script-edit.vue index 7a3386013d..f886a2aba6 100644 --- a/bundles/org.openhab.ui/web/src/pages/settings/rules/script/script-edit.vue +++ b/bundles/org.openhab.ui/web/src/pages/settings/rules/script/script-edit.vue @@ -29,14 +29,14 @@ - + - + @@ -85,7 +85,7 @@ - + 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 204883ca2e..a18cca0e88 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,6 +1,6 @@