From 114e4bd4103194ce20fc14683e82b91c14cced4a Mon Sep 17 00:00:00 2001 From: John Chilton Date: Thu, 19 Dec 2019 18:06:36 -0500 Subject: [PATCH] wfrun2vue - add invoking workflows to service layer, cleanup imports --- .../scripts/components/Workflow/Run/index.js | 6 ++++ .../components/Workflow/Run/services.js | 11 +++++++ .../scripts/mvc/tool/tool-form-composite.js | 29 +++++++++---------- 3 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 client/galaxy/scripts/components/Workflow/Run/index.js diff --git a/client/galaxy/scripts/components/Workflow/Run/index.js b/client/galaxy/scripts/components/Workflow/Run/index.js new file mode 100644 index 000000000000..094943bc7cf5 --- /dev/null +++ b/client/galaxy/scripts/components/Workflow/Run/index.js @@ -0,0 +1,6 @@ +export { default as WorkflowRun } from "./WorkflowRun"; + +// Utilities used outside this component directory by tool-form-composite. +export { isDataStep } from "./model"; + +export { invokeWorkflow } from "./services"; diff --git a/client/galaxy/scripts/components/Workflow/Run/services.js b/client/galaxy/scripts/components/Workflow/Run/services.js index 3fd32cb05508..581228840026 100644 --- a/client/galaxy/scripts/components/Workflow/Run/services.js +++ b/client/galaxy/scripts/components/Workflow/Run/services.js @@ -20,3 +20,14 @@ export async function getRunData(workflowId) { rethrowSimple(e); } } + +/** + * Invoke the specified workflow using the supplied data. + * + * @param {String} workflowId - (Stored?) Workflow ID to fetch data for. + */ +export async function invokeWorkflow(workflowId, invocationData) { + const url = `${getAppRoot()}api/workflows/${workflowId}/invocations`; + const response = await axios.post(url, invocationData); + return response.data; +} diff --git a/client/galaxy/scripts/mvc/tool/tool-form-composite.js b/client/galaxy/scripts/mvc/tool/tool-form-composite.js index 1d08bc97d792..9f5debf480f1 100644 --- a/client/galaxy/scripts/mvc/tool/tool-form-composite.js +++ b/client/galaxy/scripts/mvc/tool/tool-form-composite.js @@ -8,7 +8,7 @@ import _l from "utils/localization"; import Utils from "utils/utils"; import Deferred from "utils/deferred"; import Form from "mvc/form/form-view"; -import { isDataStep } from "components/Workflow/Run/model"; +import { isDataStep, invokeWorkflow } from "components/Workflow/Run"; import ToolFormBase from "mvc/tool/tool-form-base"; import Modal from "mvc/ui/ui-modal"; @@ -377,19 +377,19 @@ var View = Backbone.View.extend({ Galaxy.emit.debug("tool-form-composite::submit()", "Validation failed.", job_def); } else { Galaxy.emit.debug("tool-form-composite::submit()", "Validation complete.", job_def); - Utils.request({ - type: "POST", - url: `${getAppRoot()}api/workflows/${this.runWorkflowModel.workflowId}/invocations`, - data: job_def, - success: response => { - Galaxy.emit.debug("tool-form-composite::submit", "Submission successful.", response); - if ($.isArray(response) && response.length > 0) { - this.handleInvocations(response); + invokeWorkflow(this.runWorkflowModel.workflowId, job_def) + .then(invocations => { + Galaxy.emit.debug("tool-form-composite::submit", "Submission successful.", invocations); + if ($.isArray(invocations) && invocations.length > 0) { + this.handleInvocations(invocations); } else { - this.submissionErrorModal(job_def, response); + this.submissionErrorModal(job_def, invocations); } - }, - error: response => { + this._enabled(true); + }) + .catch(response => { + // TODO: Is this the same response as the Utils post would + // have had? Galaxy.emit.debug("tool-form-composite::submit", "Submission failed.", response); var input_found = false; if (response && response.err_data) { @@ -409,11 +409,8 @@ var View = Backbone.View.extend({ if (!input_found) { this.submissionErrorModal(job_def, response); } - }, - complete: () => { this._enabled(true); - } - }); + }); } },