diff options
author | Timoney, Daniel (dt5972) <dtimoney@att.com> | 2017-02-15 10:37:53 -0500 |
---|---|---|
committer | Timoney, Daniel (dt5972) <dtimoney@att.com> | 2017-02-15 10:40:37 -0500 |
commit | 324ee36fe31763e507b422ab0a88e4230045e205 (patch) | |
tree | d0b04520f6657601c918ce63fd27575977624187 /dgbuilder/public/util/js/dgeToXml.js.imp | |
parent | f0c97e8db427481e28c0a16b789bc73801b35e47 (diff) |
Initial commit for OpenECOMP SDN-C OA&M
Change-Id: I7ab579fd0d206bf356f36d52dcdf4f71f1fa2680
Signed-off-by: Timoney, Daniel (dt5972) <dtimoney@att.com>
Former-commit-id: 2a9f0edd09581f907e62ec4689b5ac94dd5382ba
Diffstat (limited to 'dgbuilder/public/util/js/dgeToXml.js.imp')
-rw-r--r-- | dgbuilder/public/util/js/dgeToXml.js.imp | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/dgbuilder/public/util/js/dgeToXml.js.imp b/dgbuilder/public/util/js/dgeToXml.js.imp new file mode 100644 index 00000000..199b1c6c --- /dev/null +++ b/dgbuilder/public/util/js/dgeToXml.js.imp @@ -0,0 +1,147 @@ +function getNodeToXml(){ + var nodeSet=[]; + var activeWorkspace=RED.view.getWorkspace(); + RED.nodes.eachNode(function(n) { + if (n.z == activeWorkspace) { + nodeSet.push({n:n}); + } + }); + + var exportableNodeSet = RED.nodes.createExportableNodeSet(nodeSet); + console.dir(exportableNodeSet); + console.log(JSON.stringify(exportableNodeSet)); + + function getDgStartNode(nodeList){ + for(var i=0;i<nodeList.length;i++){ + if(nodeList[i].type == 'dgstart'){ + return nodeList[i]; + } + } + return null; + } + function getNode(id){ + for(var i=0;i<exportableNodeSet.length;i++){ + if(exportableNodeSet[i].id == id){ + return exportableNodeSet[i]; + } + } + return null; + } + + function getStartTag(node){ + var startTag=""; + var xmlStr=""; + if(node != null && node.type != 'dgstart'){ + xmlStr=node.xml; + var regex = /(<)([\w-]+)(.*)?/; + var match = regex.exec(xmlStr); + if(match != null){ + if(match[1] != undefined && match[2] != undefined){ + startTag = match[2]; + } + }else{ + console.log("startTag not found."); + } + } + return startTag; + } + + var dgstartNode = getDgStartNode(exportableNodeSet); + + var level=0; + var fullXmlStr=""; + + printXml(dgstartNode); + + + function printXml(node){ + var xmlStr=""; + var startTag = ""; + if(node != null && node.type != 'dgstart'){ + xmlStr=node.xml; + startTag = getStartTag(node); + if(level > 0){ + var spacing = Array(level).join(" "); + xmlStr=xmlStr.replace(/\n/g,spacing); + fullXmlStr +=xmlStr; + + console.log(xmlStr); + }else{ + fullXmlStr +=xmlStr; + console.log(xmlStr); + } + } + + //console.log("startTag:" + startTag); + + var wiredNodes = []; + if(node != null && node.wires != null && node.wires[0] != null && node.wires[0] != undefined && node.wires[0].length >0 ){ + wiredNodes=node.wires[0]; + //sort based on y position + wiredNodes.sort(function(a, b){ + return a.y-b.y; + }); + } + + for(var k=0;wiredNodes != null && k<wiredNodes.length;k++){ + level++; + var nd = getNode(wiredNodes[k]); + printXml(nd); + } + + //append end tag + if(startTag != ""){ + if(level >0){ + var spacing = Array(level).join(" "); + fullXmlStr += spacing + "</" + startTag + ">"; + console.log(spacing + "</" + startTag + ">"); + }else{ + fullXmlStr += "</" + startTag + ">"; + console.log("</" + startTag + ">"); + } + } + + if(level>0){ + level=level-1; + } + console.log("endTag:" + startTag); + //console.log("xml:" + fullXmlStr); + } + console.log("fullXmlStr:" + fullXmlStr); + + /* + for (var link in allLinks){ + var nd = RED.nodes.node(link); + console.dir(nd); + var obj = RED.nodes.getNodeSet(RED.view.getWorkspace()); + console.dir(obj); + } + */ + + + //console.dir(RED.nodes.getAllFlowNodes()); + //console.dir(RED.nodes.getType()); + /* + console.dir(RED.nodes.nodes); + RED.nodes.nodes.forEach(function (node){ + console.dir(node); + }); + */ + + /*var map = {68: false, 69: false, 86: false}; + $("#node-input-validate").keydown(function(e) { + if (e.keyCode in map) { + map[e.keyCode] = true; + if (map[68] && map[69] && map[86]) { + // FIRE EVENT + return "abcd"; + } + } + }).keyup(function(e) { + if (e.keyCode in map) { + map[e.keyCode] = false; + } + }); + */ + return fullXmlStr; +} |