From 77098f54d80885efc6d89ae67afe5994d91a2fca Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Mon, 4 Nov 2019 16:25:25 +0000 Subject: [PATCH] Updated JsonForm to use new taskSubmitter component --- .../genericComponents/taskProgress.vue | 10 +- .../genericComponents/taskSubmitter.vue | 282 ++++++++++++++++++ src/components/pluginComponents/JsonForm.vue | 78 ++--- 3 files changed, 315 insertions(+), 55 deletions(-) create mode 100644 src/components/genericComponents/taskSubmitter.vue diff --git a/src/components/genericComponents/taskProgress.vue b/src/components/genericComponents/taskProgress.vue index 3586d3c8..9d2b67ea 100644 --- a/src/components/genericComponents/taskProgress.vue +++ b/src/components/genericComponents/taskProgress.vue @@ -22,6 +22,11 @@ export default { type: String, required: true }, + pollInterval: { + type: Number, + required: false, + default: 500 + }, }, data: function () { @@ -34,7 +39,7 @@ export default { created() { this.polling = setInterval(() => { this.pollProgress() - }, 500) + }, this.pollInterval) }, beforeDestroy () { @@ -44,14 +49,11 @@ export default { methods: { pollProgress: function() { console.log("Starting progress polling") - var interval = 500; - axios.get(`${this.$store.getters.uri}/task/${this.taskId}`) .then(response => { console.log("PROGRESS RESPONSE: ", response.data.progress) this.progress = response.data.progress }) - }, terminateTask: function() { diff --git a/src/components/genericComponents/taskSubmitter.vue b/src/components/genericComponents/taskSubmitter.vue new file mode 100644 index 00000000..1a2c9315 --- /dev/null +++ b/src/components/genericComponents/taskSubmitter.vue @@ -0,0 +1,282 @@ + + + + + \ No newline at end of file diff --git a/src/components/pluginComponents/JsonForm.vue b/src/components/pluginComponents/JsonForm.vue index be99e39e..2648b809 100644 --- a/src/components/pluginComponents/JsonForm.vue +++ b/src/components/pluginComponents/JsonForm.vue @@ -6,7 +6,7 @@ cached -
+
@@ -26,11 +26,16 @@
-
- -
+ + - + @@ -50,8 +55,7 @@ import checkList from "../fieldComponents/checkList" import tagList from "../fieldComponents/tagList" import keyvalList from "../fieldComponents/keyvalList" -import progressBar from "../genericComponents/progressBar" -import taskProgress from "../genericComponents/taskProgress" +import taskSubmitter from "../genericComponents/taskSubmitter" export default { name: 'JsonForm', @@ -65,8 +69,7 @@ export default { checkList, tagList, keyvalList, - progressBar, - taskProgress + taskSubmitter }, props: { @@ -102,9 +105,7 @@ export default { data: function () { return { - formData: {}, - taskRunning: false, - taskId: null + formData: {} } }, @@ -145,15 +146,6 @@ export default { this.$emit('input', this.formData) }, - submitForm() { - if (this.isTask == true) { - this.newLongRequest(this.formData) - } - else { - this.newQuickRequest(this.formData) - } - }, - getFormData: function() { // Send a quick request axios.get(this.submitApiUri) @@ -184,38 +176,22 @@ export default { }) }, - newLongRequest: function(params) { - axios.post(this.submitApiUri, params) - .then(response => { - // Fetch the task ID - console.log("Task ID: " + response.data.id) - this.taskId = response.data.id - // Start the store polling TaskId for success - this.taskRunning = true - return this.$store.dispatch('pollTask', [this.taskId, null, null]) - }) - .then(response => { - // Do something with the response - console.log(response) - }) - .catch(error => { - console.log("Task eneded with error: ", error) - if (error) { - this.modalError(error) // Display the error, if one exists - } - }) - .finally(() => { - console.log("Cleaning up after task.") - // Reset taskRunning and taskId - this.taskRunning = false - this.taskId = null - // Update the form data if we're self-updating - if (this.selfUpdate) { - this.getFormData() - } - }) + onTaskSubmit: function(submitData) { + // We don't need to do anything on this event yet + console.log("onTaskSubmit event triggered") }, + onTaskResponse: function(responseData) { + console.log("Task finished with response data: ", responseData) + if (this.selfUpdate) { + this.getFormData() + } + }, + + onTaskError: function(error) { + this.modalError(error) + } + }, computed: {