forked from ehwest/Advanced-Service-Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvertToYaml.js
54 lines (52 loc) · 2.15 KB
/
convertToYaml.js
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
function convertToYaml (data) {
for (var i=0; i<nodeArr.length; i++){
if (document.getElementById(nodeArr[i][1]).getAttribute('taska_id')==null || document.getElementById(nodeArr[i][1]).getAttribute('taska_id')==''){
return false;
}
}
//decode??
data = decodeJSON(data,null)
data = JSON.parse(data);
var elementList = data.diagram.elements; //stores all elements
var allNodes = data.diagram.elements.nodes;
var allArrows = data.diagram.elements.arrows;
var allNotes = data.diagram.elements.notes;
var loadedRows = data.diagram.rows;
var loadedCols = data.diagram.cols;
var separators = data.diagram.elements.separators
var description = data.diagram.description
startArrowAtIndex = 0;
var yamlText = '';
yamlText += 'callFlowName: "'+description+'"\n';
yamlText += 'callSequenceSteps:\n';
for (var s = 0; s<separators.length; s++){
yamlText += ' -\n';
yamlText += ' name:"'+separators[s].text+'"\n';
yamlText += ' subSteps:\n';
for (var i=startArrowAtIndex; i<allArrows.length; i++){
var index = recallArray(arrowArr,allArrows[i].id)
try{
if (parseInt(arrowArr[index][4])>=parseInt(separators[s+1].lineNumber)*42+60){
startArrowAtIndex = index;
break;
}
}
catch (err){}
yamlText += ' -\n';
yamlText += ' destination_tosca_id: '+document.getElementById(arrowArr[index][9]).getAttribute('taska_id')+'\n';
yamlText += ' link_description: "'+arrowArr[index][10]+'"\n';
yamlText += ' link_message: "'+arrowArr[index][2]+'"\n';
yamlText += ' link_title: ""\n';
yamlText += ' link_type: standard\n';
yamlText += ' message_type: '+separators[s].messageType+'\n';
yamlText += ' source_tosca_id: '+document.getElementById(arrowArr[index][8]).getAttribute('taska_id')+'\n';
}
}
yamlText += 'networkElementSequenceDefinition:\n';
for (var i=0; i<nodeArr.length;i++){
yamlText += '- id: "'+document.getElementById(nodeArr[i][1]).getAttribute('taska_id')+'"\n';
yamlText += ' role_name: ""\n';
}
yamlText += 'overviewDescription: description';
return yamlText;
}