-
Notifications
You must be signed in to change notification settings - Fork 3
/
cwl.vue
122 lines (104 loc) · 3.49 KB
/
cwl.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<template>
<svg ref="svg" class="cwl-workflow"></svg>
</template>
<script>
import "cwl-svg/src/assets/styles/themes/rabix-dark/theme.scss";
import "cwl-svg/src/plugins/port-drag/theme.dark.scss";
import "cwl-svg/src/plugins/selection/theme.dark.scss";
import {WorkflowFactory} from "cwlts/models";
import {Workflow, SVGArrangePlugin, SelectionPlugin} from "cwl-svg";
export default {
data() {
return {
selectedNode: null,
workflow: null,
cwlState: null
};
},
computed: {
cwlModel() {
return WorkflowFactory.from(this.cwlState);
}
},
props: {
cwlUrl: {
type: String,
default: null,
note: `A URL to request for the initial CWL object from. Used as an alternative to
the "cwl" prop`
},
cwl: {
type: Object,
default: null,
note: `The JSON object representing the CWL workflow to render`
},
editingEnabled: {
type: Boolean,
default: false,
note: `True if the workflow is editable`
},
plugins: {
type: Array,
default: () => [],
note: `A list of CWL plugins to use in the CWL rendering`
}
},
/**
* If the cwlUrl prop was set, send a request for the CWL object, and set it to the internal
* state
*/
mounted(){
if (this.cwlUrl){
fetch(this.cwlUrl, {
headers: new Headers({
'Accept': 'application/json'
})
}).then(response => {
return response.json();
}).then(json => {
this.cwlState = json;
});
}
},
watch: {
/**
* If the cwl prop ever changes, update the internal workflow object to that
*/
cwl() {
this.cwlState = this.cwl;
},
workflow(){
this.$emit('workflow-changed', this.workflow)
},
cwlState(){
this.workflow = new Workflow({
editingEnabled: this.editingEnabled,
model: this.cwlModel,
svgRoot: this.$refs.svg,
plugins: this.plugins
});
// Hack to force ArrangePlugin to rearrange
const arranger = this.workflow.getPlugin(SVGArrangePlugin);
if (arranger)
arranger.arrange();
// Emit a selectionChanged event when selection changes
const selection = this.workflow.getPlugin(SelectionPlugin);
if (selection){
selection.registerOnSelectionChange(element => {
if (element) {
const id = element.getAttribute("data-connection-id");
const selected = this.workflow.model.findById(id);
this.$emit('selection-changed', selected);
}
});
}
}
}
}
</script>
<style lang="css">
.cwl-workflow {
height: 100%;
width: 100%;
}
</style>