UNPKG

@seqera/node-red-seqera

Version:

Node-RED nodes for interacting with the Seqera Platform API

207 lines (178 loc) 8.22 kB
<script type="text/html" data-template-name="seqera-workflow-launch"> <div class="form-row"> <label for="node-input-seqera"><i class="icon-globe"></i> Seqera config</label> <input type="text" id="node-input-seqera" data-type="seqera-config" /> </div> <div class="form-row"> <label for="node-input-launchpadName"><i class="fa fa-rocket"></i> Launchpad</label> <input type="text" id="node-input-launchpadName" /> </div> <div class="form-row"> <label for="node-input-paramsKey"><i class="fa fa-code"></i> Params</label> <input type="text" id="node-input-paramsKey" /> </div> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name" /> </div> <div class="form-row"> <label for="node-input-workspaceId"><i class="icon-tasks"></i> Workspace ID</label> <input type="text" id="node-input-workspaceId" /> </div> <div class="form-row"> <label for="node-input-sourceWorkspaceId"><i class="icon-tasks"></i> Source WS ID</label> <input type="text" id="node-input-sourceWorkspaceId" /> </div> </script> <!-- prettier-ignore --> <script type="text/markdown" data-help-name="seqera-workflow-launch"> Launches a workflow using the Seqera Platform API. ### Inputs : launchpadName (string) : The human-readable name of a pipeline in the launchpad to use. : params (object) : JSON object containing parameters to merge with the launchpad's default parameters. : workspaceId (string) : Override the workspace ID from the config node. : sourceWorkspaceId (string) : The source workspace ID (if a shared workflow and different to workspaceId). : body (object) : A full launch request body (alternative to using launchpadName). ### Outputs 1. Standard output : payload (object) : The launch response from the API. : workflowId (string) : The ID of the launched workflow. ### Details This node launches a workflow using either: 1. A launchpad name - the node will automatically look up the launchpad configuration 2. A full launch request body provided in `msg.body` Workflow parameters can be provided as a JSON object and will be merged with the default parameters from the launchpad. ### References - [Seqera Platform API docs](https://docs.seqera.io/platform/latest/api) - information about launching workflows </script> <script type="text/javascript"> RED.nodes.registerType("seqera-workflow-launch", { category: "seqera", color: "#A9A1C6", inputs: 1, outputs: 1, icon: "icons/pipeline.svg", align: "left", paletteLabel: "Launch wf", label: function () { return this.name || "Launch workflow"; }, defaults: { name: { value: "" }, seqera: { value: "", type: "seqera-config" }, launchpadName: { value: "", required: true }, launchpadNameType: { value: "str" }, paramsKey: { value: "{}" }, paramsKeyType: { value: "json" }, workspaceId: { value: "" }, workspaceIdType: { value: "str" }, sourceWorkspaceId: { value: "" }, sourceWorkspaceIdType: { value: "str" }, }, oneditprepare: function () { function ti(id, val, type) { $(id).typedInput({ default: "str", types: ["str", "msg", "flow", "global", "env", "jsonata"] }); $(id).typedInput("value", val); $(id).typedInput("type", type); } // Special case for params - default to json type $("#node-input-paramsKey").typedInput({ default: "json", types: ["json", "msg", "flow", "global", "str", "env", "jsonata"], }); $("#node-input-paramsKey").typedInput("value", this.paramsKey || "{}"); $("#node-input-paramsKey").typedInput("type", this.paramsKeyType || "json"); ti("#node-input-launchpadName", this.launchpadName || "", this.launchpadNameType || "str"); ti("#node-input-workspaceId", this.workspaceId || "", this.workspaceIdType || "str"); ti("#node-input-sourceWorkspaceId", this.sourceWorkspaceId || "", this.sourceWorkspaceIdType || "str"); // Add auto-complete for launchpad name when type is "str" const setupAutoComplete = () => { const launchpadInput = $("#node-input-launchpadName"); const currentType = launchpadInput.typedInput("type"); // Ensure our custom CSS is added only once if (!document.getElementById("seqera-autocomplete-style")) { const style = document.createElement("style"); style.id = "seqera-autocomplete-style"; style.innerHTML = `.red-ui-autoComplete li a { display:block; padding:4px 8px; width:100%; box-sizing:border-box; }`; document.head.appendChild(style); } // Get the actual visible input element from the typedInput widget const actualInput = launchpadInput.parent().find(".red-ui-typedInput-input"); // Remove existing auto-complete if any if (actualInput.data("autoCompleteEnabled")) { actualInput.autoComplete("destroy"); actualInput.data("autoCompleteEnabled", false); } if (currentType === "str" && actualInput.length > 0) { // Add a small delay to ensure typedInput is fully initialized setTimeout(() => { actualInput.autoComplete({ search: function (value, done) { // Only search if we have some input if (!value || value.length < 1) { done([]); return; } // Make API call to get pipeline names const nodeId = (RED.editor.edit_node && RED.editor.edit_node.id) || (RED.editor.edit_stack && RED.editor.edit_stack.length > 0 && RED.editor.edit_stack[0].id) || "temp-" + Date.now(); const seqeraConfigId = $("#node-input-seqera").val(); if (!seqeraConfigId) { done([]); return; } const params = new URLSearchParams({ search: value, seqeraConfig: seqeraConfigId, }); // Add workspace ID override if configured const workspaceIdOverride = $("#node-input-workspaceId").typedInput("value"); const workspaceIdType = $("#node-input-workspaceId").typedInput("type"); if (workspaceIdType === "str" && workspaceIdOverride && workspaceIdOverride.trim()) { params.append("workspaceId", workspaceIdOverride); } $.ajax({ url: `admin/seqera/pipelines/${nodeId}?${params.toString()}`, method: "GET", success: function (data) { // data is already in the correct format: [{value, label}] done(data || []); }, error: function () { done([]); }, }); }, }); actualInput.data("autoCompleteEnabled", true); }, 100); } }; // Set up auto-complete initially setupAutoComplete(); // Re-setup auto-complete when type changes $("#node-input-launchpadName").on("change", function (event, type) { if (type) { // Add delay to avoid conflicts with ongoing autocomplete operations setTimeout(setupAutoComplete, 200); } }); // Re-setup auto-complete when Seqera config changes $("#node-input-seqera").on("change", function () { setupAutoComplete(); }); }, oneditsave: function () { function save(id, prop, propType) { this[prop] = $(id).typedInput("value"); this[propType] = $(id).typedInput("type"); } save.call(this, "#node-input-launchpadName", "launchpadName", "launchpadNameType"); save.call(this, "#node-input-paramsKey", "paramsKey", "paramsKeyType"); save.call(this, "#node-input-workspaceId", "workspaceId", "workspaceIdType"); save.call(this, "#node-input-sourceWorkspaceId", "sourceWorkspaceId", "sourceWorkspaceIdType"); }, }); </script>