Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display conditions in script-edit.vue #3042

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,10 @@ export default {
if (this.loading) return
this.loading = true

Promise.all([this.$oh.api.get('/rest/module-types?type=trigger'), this.$oh.api.get('/rest/rules/' + this.ruleId)]).then((data) => {
Promise.all([this.$oh.api.get('/rest/module-types?type=trigger'), this.$oh.api.get('/rest/module-types?type=condition'), this.$oh.api.get('/rest/rules/' + this.ruleId)]).then((data) => {
this.$set(this.moduleTypes, 'triggers', data[0])
this.$set(this, 'rule', data[1])
this.$set(this.moduleTypes, 'conditions', data[1])
this.$set(this, 'rule', data[2])

if (this.moduleId) {
this.$set(this, 'currentModule', this.rule.actions.concat(this.rule.conditions).find((m) => m.id === this.moduleId))
Expand All @@ -438,7 +439,7 @@ export default {

if (!this.rule.editable) {
const commentChar = (this.mode === 'application/x-ruby' ? '#' : '//')
let triggerDescriptionComments = `${commentChar} Triggers:\n`
let preamble = `${commentChar} Triggers:\n`
for (const trigger of this.rule.triggers) {
const triggerModuleType = this.moduleTypes.triggers.find((t) => t.uid === trigger.type)
let description = trigger.label || this.suggestedModuleTitle(trigger, triggerModuleType, 'trigger')
Expand All @@ -447,9 +448,20 @@ export default {
} else {
description = 'When ' + description
}
triggerDescriptionComments += `${commentChar} - ${description}\n`
preamble += `${commentChar} - ${description}\n`
}
this.script = triggerDescriptionComments + '\n' + this.script

if (this.rule.conditions.length > 0) {
preamble += `\n${commentChar} Conditions:\n`
for (const condition of this.rule.conditions) {
const conditionModuleType = this.moduleTypes.conditions.find((t) => t.uid === condition.type)
let description = condition.label || this.suggestedModuleTitle(condition, conditionModuleType, 'condition')
description = 'Only If ' + description
preamble += `${commentChar} - ${description}\n`
}
}

this.script = preamble + '\n' + this.script
}

this.loadScriptModuleTypes().then(() => {
Expand Down