@@ -129,7 +143,7 @@
{{ error != null ? 'Error' : 'Output' }}
-
@@ -159,7 +173,7 @@
-
+
@@ -207,13 +221,14 @@
import Argdoc from "./Argdoc"
import Autocomplete from "@/components/elements/Autocomplete"
import Loading from "@/components/Loading"
+import Modal from "@/components/Modal";
import Tab from "@/components/elements/Tab"
import Tabs from "@/components/elements/Tabs"
import Utils from "@/Utils"
export default {
name: "Execute",
- components: {Argdoc, Autocomplete, Loading, Tab, Tabs},
+ components: {Argdoc, Autocomplete, Loading, Modal, Tab, Tabs},
mixins: [Utils],
data() {
@@ -264,6 +279,64 @@ export default {
actionInput() {
return this.$refs.autocomplete.$el.parentElement.querySelector('input[type=text]')
},
+
+ requestArgs() {
+ if (!this.action.name)
+ return {}
+
+ return {
+ ...Object.entries(this.action.args).reduce((args, arg) => {
+ if (arg[1].value != null) {
+ let value = arg[1].value
+ try {
+ value = JSON.parse(value)
+ } catch (e) {
+ console.debug('Not a valid JSON value')
+ console.debug(value)
+ }
+
+ args[arg[0]] = value
+ }
+ return args
+ }, {}),
+
+ ...this.action.extraArgs.reduce((args, arg) => {
+ let value = args[arg.value]
+ try {
+ value = JSON.parse(value)
+ } catch (e) {
+ console.debug('Not a valid JSON value')
+ console.debug(value)
+ }
+
+ args[arg.name] = value
+ return args
+ }, {})
+ }
+ },
+
+ curlURL() {
+ return `${window.location.protocol}//${window.location.host}/execute`
+ },
+
+ curlSnippet() {
+ if (!this.action.name)
+ return ''
+
+ const request = {
+ type: 'request',
+ action: this.action.name,
+ args: this.requestArgs,
+ }
+
+ return (
+ 'curl -XPOST -H "Content-Type: application/json" \\\n\t' +
+ `-H "Cookie: session_token=${this.getCookies()['session_token']}"`+
+ " \\\n\t -d '" +
+ this.indent(JSON.stringify(request, null, 2), 2).trim() + "' \\\n\t" +
+ `'${this.curlURL}'`
+ )
+ },
},
methods: {
@@ -421,14 +494,6 @@ export default {
this.running = false
},
- async copyToClipboard() {
- const output = (
- this.error != null ? this.error : this.response
- )
-
- await navigator.clipboard.writeText(output)
- },
-
getPluginName(actionName) {
if (!actionName?.length)
return ''
@@ -442,37 +507,7 @@ export default {
this.running = true
if (this.structuredInput) {
- const args = {
- ...Object.entries(this.action.args).reduce((args, arg) => {
- if (arg[1].value != null) {
- let value = arg[1].value
- try {
- value = JSON.parse(value)
- } catch (e) {
- console.debug('Not a valid JSON value')
- console.debug(value)
- }
-
- args[arg[0]] = value
- }
- return args
- }, {}),
-
- ...this.action.extraArgs.reduce((args, arg) => {
- let value = args[arg.value]
- try {
- value = JSON.parse(value)
- } catch (e) {
- console.debug('Not a valid JSON value')
- console.debug(value)
- }
-
- args[arg.name] = value
- return args
- }, {})
- }
-
- this.request(this.action.name, args).then(this.onResponse).catch(this.onError).finally(this.onDone)
+ this.request(this.action.name, this.requestArgs).then(this.onResponse).catch(this.onError).finally(this.onDone)
} else {
try {
const request = JSON.parse(this.rawRequest)
diff --git a/platypush/backend/http/webapp/src/components/panels/Execute/common.scss b/platypush/backend/http/webapp/src/components/panels/Execute/common.scss
index b82082ec2..e075822f0 100644
--- a/platypush/backend/http/webapp/src/components/panels/Execute/common.scss
+++ b/platypush/backend/http/webapp/src/components/panels/Execute/common.scss
@@ -207,7 +207,7 @@ form {
}
}
-.response {
+.response, .doc-container {
flex-grow: 1;
h2 {
@@ -225,22 +225,28 @@ form {
}
}
}
+}
- .output {
- background: $output-bg;
- padding: 0 0.75em;
- overflow: auto;
- margin-top: 0.1em;
- border-radius: 1em;
- box-shadow: $output-shadow;
+.output {
+ background: $output-bg;
+ padding: 0 0.75em;
+ overflow: auto;
+ margin-top: 0.1em;
+ border-radius: 1em;
+ box-shadow: $output-shadow;
+ color: $response-fg;
- &.response {
- color: $response-fg;
- }
-
- &.error {
- color: $error-fg;
- }
+ &.error {
+ color: $error-fg;
}
}
+textarea.curl-snippet {
+ width: calc(100vw - 5em);
+ height: 100vh;
+ max-width: 40em;
+ max-height: 25em;
+ line-break: anywhere;
+ overflow: auto;
+ padding: 0.5em;
+}
diff --git a/platypush/backend/http/webapp/src/utils/Clipboard.vue b/platypush/backend/http/webapp/src/utils/Clipboard.vue
new file mode 100644
index 000000000..0245fef6c
--- /dev/null
+++ b/platypush/backend/http/webapp/src/utils/Clipboard.vue
@@ -0,0 +1,17 @@
+
+
diff --git a/platypush/backend/http/webapp/src/utils/Text.vue b/platypush/backend/http/webapp/src/utils/Text.vue
index 26aee37a7..425e448d6 100644
--- a/platypush/backend/http/webapp/src/utils/Text.vue
+++ b/platypush/backend/http/webapp/src/utils/Text.vue
@@ -12,6 +12,10 @@ export default {
prettify(text) {
return text.split('_').map((t) => this.capitalize(t)).join(' ')
},
+
+ indent(text, tabs = 1) {
+ return text.split('\n').map((t) => `${'\t'.repeat(tabs)}${t}`).join('\n')
+ },
},
}