Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// import "./assets/styles/theme";
// import "./plugins/port-drag/theme.scss";
// import "./plugins/selection/theme.scss";
import {WorkflowFactory} from "cwlts/models";
import {Workflow} from "./graph/workflow";
import {SVGArrangePlugin} from "./plugins/arrange/arrange";
import {SVGNodeMovePlugin} from "./plugins/node-move/node-move";
import {SVGPortDragPlugin} from "./plugins/port-drag/port-drag";
import {SelectionPlugin} from "./plugins/selection/selection";
import {SVGEdgeHoverPlugin} from "./plugins/edge-hover/edge-hover";
import {ZoomPlugin} from "./plugins/zoom/zoom";
const sample = require(__dirname + "/../cwl-samples/rna-seq-alignment.json");
const wf = WorkflowFactory.from(sample);
const svgRoot = document.getElementById("svg") as any;
const workflow = new Workflow({
model: wf,
svgRoot: svgRoot,
plugins: [
new SVGArrangePlugin(),
new SVGEdgeHoverPlugin(),
new SVGNodeMovePlugin({
movementSpeed: 10
}),
new SVGPortDragPlugin(),
new SelectionPlugin(),
new ZoomPlugin(),
]
).subscribeTracked(this, () => {
this.modelChangedFromHistory = WorkflowFactory.from(this.workflowEditorService.historyRedo(this.model));
// Resets the reference of inspected node (reference is lost after model serialization)
this.resetInspectedNodeReference();
this.modelChange.next(this.modelChangedFromHistory);
});
).subscribeTracked(this, () => {
this.modelChangedFromHistory = WorkflowFactory.from(this.workflowEditorService.historyUndo(this.model));
// Resets the reference of inspected node (reference is lost after model serialization)
this.resetInspectedNodeReference();
this.modelChange.next(this.modelChangedFromHistory);
});
switchTab(tabName): void {
super.switchTab(tabName);
if (this.jobSubscription) {
this.jobSubscription.unsubscribe();
this.jobSubscription = null;
}
if (!this.dataModel) return;
if (tabName === "test") {
// create the workflow model that will be displayed on the test tab
this.workflowWrapper = WorkflowFactory.from({cwlVersion: this.dataModel.cwlVersion} as any);
// add this tool as its only step
const step = this.workflowWrapper.addStepFromProcess(this.dataModel.serialize());
/**
* Adding a step sometimes generates a different id for that step than that of an app that it was made from.
* On graph job representation, step progress plugin knows about tool id, and will try to update execution state on it.
* If this representation has a different id, they will not match and step will not be found on the SVG.
* This is a place to fix that since this workflow is not a source of truth for the data, but just a utility
* to help us render a graph, so just patch the ID to ensure that it's exactly what we expect to find.
*
* However, ID is not required by CWL, so this applies only if dataModel has one.
*/
if (this.dataModel.id) {
this.workflowWrapper.changeStepId(step, this.dataModel.id);
}
// iterate through all inputs of the tool
protected recreateModel(json: Object): void {
this.dataModel = WorkflowFactory.from(json as any, "document");
if (!this.dataModel.namespaces.has("sbg")) {
this.dataModel.namespaces.set("sbg", "https://www.sevenbridges.com/");
}
this.dataModel.setValidationCallback(this.afterModelValidation.bind(this));
this.dataModel.validate().then(this.afterModelValidation.bind(this));
}