From e7e76087c0081d0d42a00deeb7c1e842af41789b Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 16 Sep 2024 03:08:46 +0200 Subject: [PATCH] [#341] Added support for setting variables in procedure editor. --- .../src/components/Action/ActionsList.vue | 45 ++- .../src/components/Action/LoopEditor.vue | 4 +- .../webapp/src/components/Action/LoopTile.vue | 3 +- .../webapp/src/components/Action/Mixin.vue | 4 + .../components/Action/SetVariablesTile.vue | 361 ++++++++++++++++++ 5 files changed, 408 insertions(+), 9 deletions(-) create mode 100644 platypush/backend/http/webapp/src/components/Action/SetVariablesTile.vue diff --git a/platypush/backend/http/webapp/src/components/Action/ActionsList.vue b/platypush/backend/http/webapp/src/components/Action/ActionsList.vue index faa20209b2..46ee92081a 100644 --- a/platypush/backend/http/webapp/src/components/Action/ActionsList.vue +++ b/platypush/backend/http/webapp/src/components/Action/ActionsList.vue @@ -31,6 +31,12 @@ :dragging="isDragging" v-else-if="loops[index]" /> + + + +
+ +
@@ -117,6 +127,7 @@ import ListItem from "./ListItem" import LoopBlock from "./LoopBlock" import Mixin from "./Mixin" import ReturnTile from "./ReturnTile" +import SetVariablesTile from "./SetVariablesTile" import Utils from "@/Utils" export default { @@ -146,6 +157,7 @@ export default { ListItem, LoopBlock, ReturnTile, + SetVariablesTile, }, props: { @@ -280,6 +292,10 @@ export default { data.props.type = 'while' } + if (this.isSet(action)) { + data.props.value = action.set + } + return data }) }, @@ -365,6 +381,16 @@ export default { }, {}) }, + sets() { + return this.newValue?.reduce?.((acc, action, index) => { + if (this.isSet(action)) { + acc[index] = action + } + + return acc + }, {}) || {} + }, + hasChanges() { return this.newStringValue !== this.stringValue }, @@ -463,9 +489,10 @@ export default { this.fors[index] || this.whiles[index] || this.isAction(action) || - this.isReturn(action) || this.isBreak(action) || - this.isContinue(action) + this.isContinue(action) || + this.isReturn(action) || + this.isSet(action) ) { acc[index] = action } @@ -481,6 +508,7 @@ export default { condition: this.allowAddButtons, for: this.allowAddButtons, while: this.allowAddButtons, + set: this.allowAddButtons, else: ( this.allowAddButtons && this.parent && @@ -562,7 +590,7 @@ export default { return } - event.stopPropagation() + event.stopPropagation?.() this.$emit('dragenter', index) }, @@ -571,7 +599,7 @@ export default { return } - event.stopPropagation() + event.stopPropagation?.() this.$emit('dragleave', index) }, @@ -584,7 +612,7 @@ export default { return } - event.stopPropagation() + event.stopPropagation?.() let dropIndices = [] if (!event.detail?.length) { @@ -673,7 +701,7 @@ export default { // otherwise the event will be caught by the parent element. If the parent // is a modal, then the modal will be closed, making it impossible to edit // text fields in the action tiles. - event.stopPropagation() + event.stopPropagation?.() return } @@ -713,6 +741,11 @@ export default { this.newValue.push('continue') }, + addSet() { + this.newValue.push({ 'set': {} }) + this.selectLastExprEditor() + }, + addReturn() { this.newValue.push({ 'return': null }) this.selectLastExprEditor() diff --git a/platypush/backend/http/webapp/src/components/Action/LoopEditor.vue b/platypush/backend/http/webapp/src/components/Action/LoopEditor.vue index d54803a7de..6eb60b7f0c 100644 --- a/platypush/backend/http/webapp/src/components/Action/LoopEditor.vue +++ b/platypush/backend/http/webapp/src/components/Action/LoopEditor.vue @@ -29,6 +29,7 @@   Run in parallel @@ -76,11 +77,12 @@ export default { onSubmit() { const iterator = this.$refs.iterator.value.trim() const iterable = this.$refs.iterable.value.trim() + const async_ = this.$refs.async.checked if (!iterator.length || !iterable.length) { return } - this.$emit('change', { iterator, iterable }) + this.$emit('change', { iterator, iterable, async: async_ }) }, onInput(target, event) { diff --git a/platypush/backend/http/webapp/src/components/Action/LoopTile.vue b/platypush/backend/http/webapp/src/components/Action/LoopTile.vue index a2799f798d..81a2b2416a 100644 --- a/platypush/backend/http/webapp/src/components/Action/LoopTile.vue +++ b/platypush/backend/http/webapp/src/components/Action/LoopTile.vue @@ -18,8 +18,7 @@ - fork  - + fork in [ ] diff --git a/platypush/backend/http/webapp/src/components/Action/Mixin.vue b/platypush/backend/http/webapp/src/components/Action/Mixin.vue index 5bf4230b4f..2bba46f167 100644 --- a/platypush/backend/http/webapp/src/components/Action/Mixin.vue +++ b/platypush/backend/http/webapp/src/components/Action/Mixin.vue @@ -67,6 +67,10 @@ export default { return this.getKey(value) === 'return' }, + + isSet(value) { + return this.getKey(value) === 'set' + }, }, } diff --git a/platypush/backend/http/webapp/src/components/Action/SetVariablesTile.vue b/platypush/backend/http/webapp/src/components/Action/SetVariablesTile.vue new file mode 100644 index 0000000000..f8d8a15416 --- /dev/null +++ b/platypush/backend/http/webapp/src/components/Action/SetVariablesTile.vue @@ -0,0 +1,361 @@ + + + + +