summaryrefslogtreecommitdiffstats
path: root/dgbuilder/public/util
diff options
context:
space:
mode:
Diffstat (limited to 'dgbuilder/public/util')
-rw-r--r--dgbuilder/public/util/css/validateNodeXml.css86
-rw-r--r--dgbuilder/public/util/js/dgeToXml.js1328
-rw-r--r--dgbuilder/public/util/js/dgeToXml.js.imp147
-rw-r--r--dgbuilder/public/util/js/jsonTool.js67
-rw-r--r--dgbuilder/public/util/js/migrateFlow.js184
-rw-r--r--dgbuilder/public/util/js/sliValues.js763
-rw-r--r--dgbuilder/public/util/js/validateNodeXml.js325
-rw-r--r--dgbuilder/public/util/js/vkbeautify.0.99.00.beta.js358
8 files changed, 3258 insertions, 0 deletions
diff --git a/dgbuilder/public/util/css/validateNodeXml.css b/dgbuilder/public/util/css/validateNodeXml.css
new file mode 100644
index 00000000..895ad7fd
--- /dev/null
+++ b/dgbuilder/public/util/css/validateNodeXml.css
@@ -0,0 +1,86 @@
+#error-list-div{
+overflow:scroll;
+color:brown;
+width:480px;
+height:300px;
+}
+
+#node-validate-result a{
+ text-decoration: underline;
+ color:blue;
+ cursor:pointer;
+}
+
+table#errTable tr td:first-child {
+ border-left: 0px solid #e5e5e5;
+ text-align: center;
+}
+
+table#errTable tr td:last-child {
+ border-right: 0px solid #e5e5e5;
+}
+table#errTable tr:nth-of-type(odd) {
+ background-color: #FFF0F0;
+}
+
+table#errTable tr td {
+ border-width: 0px 0px 0px 0px;
+ border-style: solid;
+ border-color: #fff;
+ text-align: center;
+ font-size: 1.0em;
+}
+
+#sli-values-div{
+overflow:auto;
+color:blue;
+width:850px;
+height:600px;
+}
+
+#sli-values-div input[type="text"] {
+ padding: 1px;
+ border: solid 1px grey;
+ /*border: solid 1px #dcdcdc;*/
+ width:800px;
+ transition: box-shadow 0.3s, border 0.3s;
+ box-shadow: 0 0 5px 1px #969696;
+ cursor:pointer;
+}
+
+.valueBoxDiv {
+ border-width: 1px 2px 1px 1px;
+ border-style: solid;
+ /*border-color: #9999FF;*/
+ border-color: grey;
+ /*border-color: #fff;*/
+ font-size: 1.0em;
+ border-left: 1px solid #fff;
+ border-right: 1px solid #fff;
+ border-top: 1px solid #fff;
+ border-bottom: 1px solid #fff;
+ padding-left: 5px;
+ padding-right: 5px;
+ padding-top: 5px;
+ padding-bottom: 5px;
+ /*background-color:#FFE6E6;*/
+ background-color:#fff;
+}
+
+/*#sli-values-div input[type="text"]:focus,
+
+#sli-values-div input[type="text"].focus {
+ border: solid 1px #707070;
+ box-shadow: 0 0 5px 1px #969696;
+}
+*/
+/*
+#getFixed {
+ color: #c00;
+ font: bold 15px arial;
+ padding: 10px;
+ margin: 10px;
+ border: 1px solid #c00;
+ width: 200px;
+}
+*/
diff --git a/dgbuilder/public/util/js/dgeToXml.js b/dgbuilder/public/util/js/dgeToXml.js
new file mode 100644
index 00000000..2bbb0c15
--- /dev/null
+++ b/dgbuilder/public/util/js/dgeToXml.js
@@ -0,0 +1,1328 @@
+function getDgStartNode(nodeList){
+ for(var i=0;i<nodeList.length;i++){
+ if(nodeList[i].type == 'dgstart' && nodeList[i].wires != null && nodeList[i].wires != undefined){
+ return nodeList[i];
+ }
+ }
+ RED.notify("DGSTART node not found.");
+ return null;
+}
+
+
+var loopDetectionEnabled = true;
+
+function detectLoopPrev(){
+ var activeWorkspace=RED.view.getWorkspace();
+ /*
+ RED.nodes.links.filter(function(d) {
+ if(d.source.z == activeWorkspace && d.target.z == activeWorkspace){
+ console.log(d.source.id+":"+d.sourcePort+":"+d.target.id);
+ }
+ });
+ */
+ //console.dir(RED.nodes.links);
+ var nSet=[];
+
+ RED.nodes.eachNode(function(n) {
+ if (n.z == activeWorkspace) {
+ nSet.push({'n':n});
+ }
+ });
+
+ var nodeSet = RED.nodes.createExportableNodeSet(nSet);
+ //console.dir(nodeSet);
+
+ //console.log("nodeSet length:" + nodeSet.length);
+
+ var isLoopDetected = false;
+ var dgStartNode = getDgStartNode(nodeSet);
+ if(dgStartNode == null || dgStartNode == undefined) {
+ console.log("dgstart node not linked.");
+ return true;
+ }
+
+ var wires = dgStartNode.wires;
+ var nodesInPath = {};
+ var dgStartNodeId = dgStartNode.id;
+ if(wires != null && wires != undefined && wires[0] != undefined){
+ for(var k=0;k<wires[0].length;k++){
+ var val = wires[0][k];
+ nodesInPath[dgStartNodeId + "->" + val] = "";
+ }
+ }else{
+ nodesInPath[dgStartNodeId + "->" + ""] = "";
+ }
+
+ //console.dir(nodesInPath);
+ var loopDetectedObj = {};
+ /* the nodes will not be order so will need to loop thru again */
+ for(var m=0;nodeSet != null && m<nodeSet.length;m++){
+ for(var i=0;nodeSet != null && i<nodeSet.length;i++){
+ var link=nodeSet[i].id;
+ //console.log("NAME:" + nodeSet[i].name + ":" + link);
+ if(link == dgStartNodeId) continue;
+ var wires = nodeSet[i].wires;
+ //console.log("link:" + link);
+ var delKeys = [];
+ if(wires != null && wires != undefined && wires[0] != undefined){
+ for(var k=0;k<wires[0].length;k++){
+ var val = (wires[0])[k];
+ var keys = Object.keys(nodesInPath);
+ //console.log("keys:" + keys);
+ for (var j=0;j<keys.length;j++){
+ //console.log("key:" + keys[j]);
+ //console.log("val:" + val);
+ var index = -1;
+ if(keys[j] != null){
+ index = keys[j].indexOf("->" + link);
+ }
+ var lastIndex = keys[j].lastIndexOf("->");
+ if(index != -1 && index == lastIndex){
+ //delete nodesInPath[key];
+ var previousNodeId = keys[j].substr(lastIndex +2);
+ var indexOfArrow = -1;
+ if(previousNodeId != ""){
+ indexOfArrow = previousNodeId.indexOf("->");
+ }
+ if(previousNodeId != null && indexOfArrow != -1){
+ previousNodeId = previousNodeId.substr(0,indexOfArrow);
+ }
+ nodesInPath[keys[j] + "->" + val] = "";
+ //console.log("keys[j]:" + keys[j]);
+ delKeys.push(keys[j]);
+ var prevNodeIdIndex = keys[j].indexOf("->" + previousNodeId);
+ var priorOccurence = keys[j].indexOf(val + "->");
+ if(priorOccurence != -1 && priorOccurence<prevNodeIdIndex){
+ //console.log("previousNodeId:" + previousNodeId);
+ //console.log("val:" + val);
+ var n1 = getNode(nodeSet,previousNodeId);
+ var n2 = getNode(nodeSet,val);
+ //console.log("loop detected for node " + n1.name + " and " + n2.name);
+ loopDetectedObj[n1.name + "->" + n2.name] ="looped";
+ //console.dir(loopDetectedObj);
+ isLoopDetected = true;
+ }
+ }
+ }
+ }
+ }
+ for(var l=0;delKeys != null && l<delKeys.length;l++){
+ delete nodesInPath[delKeys[l]];
+ }
+ }
+
+
+ }
+ if(loopDetectedObj != null ){
+ var msg = "";
+ for(var key in loopDetectedObj){
+ if(loopDetectedObj.hasOwnProperty(key)) {
+ console.log("Loop detected " + key);
+ msg += "<strong>Loop detected for:" + key + "</strong><br>";
+ }
+ }
+ if(msg != ""){
+ isLoopDetected = true;
+ RED.notify(msg);
+ }
+ }
+/*
+ for(var i=0;nodeSet != null && i<nodeSet.length;i++){
+ var foundCount=0;
+ var nodeId = nodeSet[i].id;
+ var nodeName = nodeSet[i].name;
+ for(var j=0;nodeSet != null && j<nodeSet.length;j++){
+ var node = nodeSet[j];
+ if(node.id == nodeId){
+ continue;
+ }
+ var wires = node.wires;
+ console.log(node.type + ":wires:" + wires);
+ for(var k=0;wires != null && wires != undefined && wires[0] != undefined && k<wires[0].length;k++){
+ var id = (wires[0])[k];
+ console.log(nodeName + ":" + nodeId + ":" + id);
+ if(id == nodeId ){
+ foundCount++;
+ if(foundCount>1){
+ console.log("Loop detected for node " + nodeName + "with node:" + node.name);
+ RED.notify("<strong>Flow error detected for node '" + nodeName + "' with node '" + node.name + "'</strong>");
+ //RED.nodes.eachLink(function(d){
+ // if(d.source.id == nodeSet[i] || d.target.id == nodeSet[j]){
+ // d.selected = true;
+ // }else if(d.source.id == nodeSet[j] || d.target.id == nodeSet[i]){
+ // d.selected = true;
+ // }
+ //});
+ //RED.view.redraw();
+ isLoopDetected = true;
+ return true;
+ }
+ }
+ }
+
+ }
+ }
+*/
+ //console.log("isLoopDetected:" + isLoopDetected);
+ return isLoopDetected;
+}
+
+function generateNodePath(nodeIdToNodeObj,nodeId,pathStr,nodesInPath,errList){
+ var node = nodeIdToNodeObj[nodeId];
+ var wires = node.wires;
+ if(wires != null && wires != undefined && wires[0] != undefined){
+ for(var k=0;k<wires[0].length;k++){
+ var val = wires[0][k];
+ if(pathStr.indexOf(val + "->") != -1){
+ //console.log("pathStr:" + pathStr);
+ var n1= nodeIdToNodeObj[nodeId].name;
+ var n2= nodeIdToNodeObj[val].name;
+ errList.push("Loop detected between nodes '" + n1 + "' and " + "'" + n2 + "'");
+ }else{
+ pathStr += "->" + val ;
+ generateNodePath(nodeIdToNodeObj,val,pathStr,nodesInPath,errList);
+ }
+ }
+ }else{
+ //pathStr += nodeId + "->" + "";
+ nodesInPath.push(pathStr);
+ }
+}
+
+function detectLoop(){
+ var activeWorkspace=RED.view.getWorkspace();
+ var nSet=[];
+ var nodeIdToNodeObj = {};
+ RED.nodes.eachNode(function(n) {
+ if (n.z == activeWorkspace) {
+ nSet.push({'n':n});
+ }
+ });
+
+ var nodeSet = RED.nodes.createExportableNodeSet(nSet);
+ nodeIdToNodeObj = getNodeIdToNodeMap(nodeSet);
+ var isLoopDetected = false;
+ //var dgStartNode = getDgStartNode(nodeSet);
+ var dgStartNode = nodeIdToNodeObj["dgstart"];
+ var errList = [];
+ var dgStartNodeId = dgStartNode.id;
+ var nodesInPathArr = [];
+ generateNodePath(nodeIdToNodeObj,dgStartNodeId,dgStartNodeId,nodesInPathArr,errList);
+ if(errList != null && errList != undefined && errList.length > 0){
+ isLoopDetected = true;
+ var htmlStr="<div id='loop-detect-err-list-div'><table id='loopErrListTable' border='1'><tr><th>Error List</th></tr>";
+ for(var j=0;errList != null && j<errList.length;j++){
+ var errSeq = j+1;
+ htmlStr += "<tr><td>" + errSeq + ")" + errList[j] + "</td></tr>";
+ }
+ htmlStr += "</table></div>";
+
+ $("#loop-detection-dialog").dialog({
+ autoOpen : false,
+ modal: true,
+ title: "DG Flow validation Error List ",
+ width: 500,
+ buttons: {
+ Close: function () {
+ $("#loop-detection-dialog").dialog("close");
+ }
+ }
+ }).dialog("open").html(htmlStr); // end dialog div
+ }
+ nodesInPathArr=null;
+ nodeSet ={};
+ nodeIdToNodeObj={};
+ return isLoopDetected;
+}
+
+
+var xmlNumberCnt = 0;
+function processForXmlNumbers(nodeSet,node){
+ if( node != null && node.type != 'dgstart'){
+ if(node.xmlnumber != null && node.xmlnumber){
+ node.xmlnumber.push(++xmlNumberCnt);
+ }else{
+ node.xmlnumber = [++xmlNumberCnt];
+ }
+ }
+
+ if(node != null && node.wires != null && node.wires.length>0){
+ var wiredNodes=node.wires[0];
+ var wiredNodesArr=[];
+ for(var k=0;wiredNodes != undefined && wiredNodes != null && k<wiredNodes.length;k++){
+ wiredNodesArr.push(getNode(nodeSet,wiredNodes[k]));
+ }
+
+ //use this sort to sort by y position
+ wiredNodesArr.sort(function(a, b){
+ return a.y-b.y;
+ });
+
+ for(var k=0;k<wiredNodesArr.length;k++){
+ var n = wiredNodesArr[k];
+ processForXmlNumbers(nodeSet,n);
+ }
+ }
+}
+
+function updateXmlNumbers(){
+ xmlNumberCnt = 0;
+ var nodeSet = getCurrentFlowNodeSet();
+ if(nodeSet == null && nodeSet.length >0){
+ nodeSet.forEach(function(n){
+ if(n.xmlnumber){
+ delete n.xmlnumber;
+ }
+ });
+ }
+ var dgStartNode = getDgStartNode(nodeSet);
+ processForXmlNumbers(nodeSet,dgStartNode);
+ var activeWorkspace=RED.view.getWorkspace();
+ RED.nodes.eachNode(function(n) {
+ //console.log("Node processed in eachNode");
+ if (n.z == activeWorkspace) {
+ if(n != null){
+ var updatedNode = getNode(nodeSet,n.id);
+ //console.log("updated Node processed in eachNode");
+ //console.dir(updatedNode);
+
+ if (n.id == updatedNode.id) {
+ n.xmlnumber = updatedNode.xmlnumber;
+ n.dirty = true;
+ }
+ }
+ }
+ });
+}
+
+function getOutcomeValue(node){
+ var xmlStr = "";
+ if(node != null && node.xml != undefined && node.xml !=""){
+ xmlStr = node.xml + "</outcome>";
+ }
+ var xmlDoc;
+ if (window.DOMParser){
+ try{
+ var parser=new DOMParser();
+ xmlDoc=parser.parseFromString(xmlStr,'text/xml');
+ //console.log("Not IE");
+ var n = xmlDoc.documentElement.nodeName;
+ if(n == "html"){
+ resp=false;
+ console.log("Error parsing");
+ return resp;
+ }
+ }catch(e){
+ console.log("xmlStr:" + xmlStr);
+ console.log("Error parsing" +e);
+ return null;
+ }
+ }else{
+ try{
+ //console.log("IE");
+ // code for IE
+ xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
+ xmlDoc.async=false;
+ xmlDoc.loadXMLString(xmlStr);
+ }catch(e){
+ console.log("xmlStr:" + xmlStr);
+ console.log("Error parsing" +e);
+ return null;
+ }
+ }
+ if(xmlDoc != null){
+ var xmlNode = xmlDoc.documentElement;
+ //console.dir(xmlNode);
+ var processedNode = xmlNode.nodeName;
+ //console.log("processedNode:" + processedNode);
+ var attrs = xmlNode.attributes;
+ for(var i=0;i<attrs.length;i++){
+ if(attrs[i].nodeName == "value"){
+ return attrs[i].value;
+ }
+ }
+ }
+ return null;
+}
+
+var dgNumberCnt = 0;
+function processForDgNumbers(nodeSet,node){
+ var outcomeTypes = [ "already-active", "failure", "not-found", "other", "outcomeFalse", "outcome", "outcomeTrue", "success" ];
+ if( node != null && node.type != 'dgstart' && node.type != 'service-logic' && node.type != 'method' ){
+ //console.log("child of " + parentNodeType + " :" + nodeType);
+ //check if NOT outcome node
+ if(outcomeTypes.indexOf(node.type) == -1){
+ if(node.type == "GenericXML"){
+ if(node.xml != undefined && node.xml != null && node.xml.indexOf("<outcome ") != -1){
+ //this GenericXML node is used for outcome , so need to skip
+ }else{
+ if(node.dgnumber != undefined && node.dgnumber != null && node.dgnumber){
+ node.dgnumber.push(++dgNumberCnt);
+ }else{
+ node.dgnumber = [++dgNumberCnt];
+ }
+ }
+
+ }else{
+ if(node.dgnumber != undefined && node.dgnumber != null && node.dgnumber){
+ node.dgnumber.push(++dgNumberCnt);
+ }else{
+ node.dgnumber = [++dgNumberCnt];
+ }
+ }
+ }
+ }
+
+ var hasOutcomeNodes = false;
+ if(node != null && node.wires != null && node.wires.length>0){
+ var wiredNodes=node.wires[0];
+ var wiredNodesArr=[];
+ for(var k=0;wiredNodes != undefined && wiredNodes != null && k<wiredNodes.length;k++){
+ var wiredNode = getNode(nodeSet,wiredNodes[k]);
+ //check if outcome node
+ if(outcomeTypes.indexOf(wiredNode.type) != -1){
+ hasOutcomeNodes = true;
+ }
+ if(wiredNode.type == "GenericXML"){
+ if( node.xml != undefined && node.xml != null && node.xml.indexOf("<outcome ") != -1){
+ //this GenericXML node is used for outcome
+ hasOutcomeNodes = true;
+ }
+ }
+ wiredNodesArr.push(wiredNode);
+
+ }
+
+ //use this sort to sort by y position
+ wiredNodesArr.sort(function(a, b){
+ return a.y-b.y;
+ });
+
+ /*
+ //USE THIS LOGIC TO SORT BY OUTCOME VALUE FOR SPECIFIC NODES
+ var parentNodeType = node.type;
+ if(hasOutcomeNodes && parentNodeType != 'switchNode' && parentNodeType != 'block' && parentNodeType != 'configure' ){
+ //use the value of outcome to sort the wired nodes
+ wiredNodesArr.sort(function(a, b){
+ var val1 = getOutcomeValue(a);
+ var val2 = getOutcomeValue(b);
+ //console.log("val1:" + val1);
+ //console.log("val2:" + val2);
+ if ( val1 < val2 ){
+ return -1;
+ }else if ( val1 > val2 ){
+ return 1;
+ }else{
+ return 0;
+ }
+ });
+ }else{
+ //use this sort to sort by y position
+ wiredNodesArr.sort(function(a, b){
+ return a.y-b.y;
+ });
+ }
+
+ */
+
+ for(var k=0;k<wiredNodesArr.length;k++){
+ var n = wiredNodesArr[k];
+ processForDgNumbers(nodeSet,n);
+ }
+ }
+}
+
+function updateDgNumbers(){
+ dgNumberCnt = 0;
+ var nodeSet = getCurrentFlowNodeSet();
+ if(nodeSet == null && nodeSet.length >0){
+ nodeSet.forEach(function(n){
+ if(n.dgnumber){
+ delete n.dgnumber;
+ }
+ });
+ }
+ var dgStartNode = getDgStartNode(nodeSet);
+ processForDgNumbers(nodeSet,dgStartNode);
+ var activeWorkspace=RED.view.getWorkspace();
+ RED.nodes.eachNode(function(n) {
+ //console.log("Node processed in eachNode");
+ if (n.z == activeWorkspace) {
+ if(n != null){
+ var updatedNode = getNode(nodeSet,n.id);
+ //console.log("updated Node processed in eachNode");
+ //console.dir(updatedNode);
+
+ if (n.id == updatedNode.id) {
+ //console.log(n.type + ":" + updatedNode.dgnumber);
+ n.dgnumber = updatedNode.dgnumber;
+ n.dirty = true;
+ }
+ }
+ }
+ });
+ return nodeSet;
+}
+
+function customValidation(currNodeSet){
+ //validation to make sure there a block node infront of mutiple dgelogic nodes
+ flowDesignErrors=[];
+ var dgStartCnt=0;
+ var serviceLogicCnt=0;
+ var methodCnt=0;
+ for(var i=0;currNodeSet != null && i<currNodeSet.length;i++){
+ var node = currNodeSet[i];
+ var parentNodeName = node.name;
+ var parentNodeType = node.type;
+ var dgNumber = node.dgnumber;
+ if(parentNodeType == 'dgstart'){
+ dgStartCnt++;
+ }
+ if(parentNodeType == 'service-logic'){
+ serviceLogicCnt++;
+ }
+ if(parentNodeType == 'method'){
+ methodCnt++;
+ }
+ if(parentNodeType == "GenericXML"){
+ if( node.xml != undefined && node.xml != null && node.xml.indexOf("<service-logic ") != -1 ){
+ //this GenericXML node is used for service-logic
+ serviceLogicCnt++;
+ }else if( node.xml != undefined && node.xml != null && node.xml.indexOf("<method ") != -1 ){
+ //this GenericXML node is used for method
+ methodCnt++;
+ }else if( node.xml != undefined && node.xml != null && node.xml.indexOf("<block") != -1 ){
+ //this GenericXML node is used for block
+ parentNodeType = "block";
+ }
+ }
+ if(node != null && node.wires != null && node.wires.length>0){
+ var wiredNodes=node.wires[0];
+ var wiredNodesArr=[];
+ for(var k=0;wiredNodes != undefined && wiredNodes != null && k<wiredNodes.length;k++){
+ wiredNodesArr.push(getNode(currNodeSet,wiredNodes[k]));
+ }
+ var countChildLogicNodes =0;
+ for(var k=0;k<wiredNodesArr.length;k++){
+ var n = wiredNodesArr[k];
+ var nodeType = n.type;
+ var outcomeTypes = [ "already-active", "failure", "not-found", "other", "outcomeFalse", "outcome", "outcomeTrue", "success" ];
+ var isOutcomeOrSetNode = false;
+ if(nodeType == "GenericXML"){
+ if( n.xml != undefined && n.xml != null && (n.xml.indexOf("<outcome ") != -1 || n.xml.indexOf("<set ") != -1)){
+ //this GenericXML node is used for outcome
+ isOutcomeOrSetNode = true;
+ }
+ }
+ //console.log("child of " + parentNodeType + " :" + nodeType);
+ if(outcomeTypes.indexOf(nodeType) > -1 ||nodeType == 'set' || isOutcomeOrSetNode){
+ //its a outcome or set node
+ }else{
+ countChildLogicNodes++;
+ }
+
+ //console.log("parentNodeType:" + parentNodeType);
+ if(countChildLogicNodes >1 && parentNodeType != 'block' ){
+ if(node.dgnumber != undefined && node.dgnumber){
+ flowDesignErrors.push("Warning:May need a block Node after Node. <br><span style='color:red'>Node Name:</span>" + node.name + "<br><span style='color:red'>DG Number:</span>" + node.dgnumber[0] );
+ }else{
+ flowDesignErrors.push("Warning:May need a block Node after Node <br><span style='color:red'>Node name:</span>" + parentNodeName);
+ }
+ break;
+ }
+ }
+ }
+ }
+ if(dgStartCnt > 1){
+ flowDesignErrors.push("Error:There should only be 1 dgstart Node in the current workspace.");
+ }
+
+ if(serviceLogicCnt > 1){
+ flowDesignErrors.push("Error:There should only be 1 service-logic Node in the current workspace.");
+ }
+
+ if(methodCnt > 1){
+ flowDesignErrors.push("Error:There should only be 1 method Node in the current workspace.");
+ }
+
+ if(flowDesignErrors != null && flowDesignErrors.length >0){
+ return false;
+ }
+ return true;
+}
+
+var flowDesignErrors = [];
+function showFlowDesignErrorBox(){
+ if(flowDesignErrors != null && flowDesignErrors.length >0){
+ var htmlStr="<div id='flowpath-err-list-div'><table id='fpeTable' border='1'><tr><th>Error List</th></tr>";
+ for(var j=0;flowDesignErrors != null && j<flowDesignErrors.length;j++){
+ var errSeq = j+1;
+ htmlStr += "<tr><td>" + errSeq + ")" + flowDesignErrors[j] + "</td></tr>";
+ }
+ htmlStr += "</table></div>";
+
+ //$('<div></div>').dialog({
+
+ $('#flow-design-err-dialog').dialog({
+ modal: true,
+ title: "Flow design Error List ",
+ width: 500,
+ /*open: function () {
+ $(this).html(htmlStr);
+ },*/
+ buttons: {
+ Close: function () {
+ $(this).dialog("close");
+ }
+ }
+ }).html(htmlStr); // end dialog div
+ }
+}
+
+
+function getCurrentFlowNodeSet(){
+ var nodeSet=[];
+ //console.dir(RED);
+ //RED.view.dirty();
+ //RED.view.redraw();
+ 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));
+ return exportableNodeSet;
+}
+
+function getNode(nodeSet,id){
+ for(var i=0;i<nodeSet.length;i++){
+ if(nodeSet[i].id == id){
+ return nodeSet[i];
+ }
+ }
+ return null;
+}
+function getNodeIdToNodeMap(nodeSet){
+ var nodeIdToNodeMap ={};
+ for(var i=0;i<nodeSet.length;i++){
+ nodeIdToNodeMap[nodeSet[i].id] = nodeSet[i];
+ if(nodeSet[i].type == "dgstart"){
+ nodeIdToNodeMap["dgstart"] = nodeSet[i];
+ }
+ }
+ return nodeIdToNodeMap;
+}
+
+function validateEachNodeXml(){
+ var activeWorkspace=RED.view.getWorkspace();
+ RED.nodes.eachNode(function(n) {
+ if (n.z == activeWorkspace) {
+ var xml = n.xml;
+ if( xml != null && xml != ''){
+ var validationSuccess = validateXML(n.xml);
+ if(validationSuccess){
+ n.status = {fill:"green",shape:"dot",text:"OK"};
+ }else{
+ n.status = {fill:"red",shape:"dot",text:"ERROR"};
+ }
+ }
+ }
+ });
+}
+
+
+function getNodeToXml(inputNodeSet){
+ var exportableNodeSet;
+ //uses inputNodeSet if passed otherwise build the latest nodeSet
+
+ //$("#btn-deploy").removeClass("disabled");
+
+
+ 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;
+ }
+
+ if(inputNodeSet == null || inputNodeSet == undefined){
+ exportableNodeSet = getCurrentFlowNodeSet();
+ }else{
+ exportableNodeSet = JSON.parse(inputNodeSet);
+ }
+ var dgstartNode = getDgStartNode(exportableNodeSet);
+
+ var level=0;
+ var fullXmlStr="";
+
+ printXml(dgstartNode);
+
+
+ function printXml(node){
+ var xmlStr="";
+ var startTag = "";
+ if(node != null && node.type != 'dgstart'){
+ var comments=node.comments;
+ if(comments != null && comments != ""){
+ //if xml comments field already has the <!-- and --> remove them
+ comments=comments.replace("<!--","");
+ comments=comments.replace("-->","");
+ xmlStr="<!--" + comments + "-->";
+ }
+ xmlStr+=node.xml;
+ startTag = getStartTag(node);
+ fullXmlStr +=xmlStr;
+ /*
+ 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 = [];
+ var wiredNodesArr = [];
+ if(node != null && node.wires != null && node.wires[0] != null && node.wires[0] != undefined && node.wires[0].length >0 ){
+ wiredNodes=node.wires[0];
+ //console.log("Before sort");
+ for(var k=0;wiredNodes != undefined && wiredNodes != null && k<wiredNodes.length;k++){
+ wiredNodesArr.push(getNode(wiredNodes[k]));
+ }
+ //console.dir(wiredNodesArr);
+ //sort based on y position
+ wiredNodesArr.sort(function(a, b){
+ return a.y-b.y;
+ });
+ //console.log("After sort");
+ //console.dir(wiredNodesArr);
+ }
+
+ for(var k=0;wiredNodesArr != null && k<wiredNodesArr.length;k++){
+ level++;
+ var nd = wiredNodesArr[k];
+ printXml(nd);
+ }
+
+ //append end tag
+ if(startTag != ""){
+ fullXmlStr += "</" + 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);
+ return fullXmlStr;
+}
+
+function showFlow(filePath){
+var jqxhr = $.post( "/getSharedFlow",{"filePath":filePath})
+ .done(function(data) {
+ $( "#dgflow-browser-dialog").dialog("close");
+ var migratedNodes = migrateNodes(data);
+ //RED.view.importNodes(data)
+ RED.view.importNodes(JSON.stringify(migratedNodes));
+ //console.log( "import done");
+ })
+ .fail(function() {
+ RED.notify("Could not import user flow .");
+ $( "#dgflow-browser-dialog").dialog("close");
+ console.log( "error occured importing flow.");
+ })
+ .always(function() {
+ //console.log( "complete" );
+ });
+}
+
+function showFlowXml(filePath){
+var jqxhr = $.post( "/getSharedFlow",{"filePath":filePath})
+ .done(function(data) {
+ //console.dir(data);
+ var xmlStr=getNodeToXml(data);
+ showImportedXml(xmlStr,this);
+ })
+ .fail(function() {
+ RED.notify("Could not convert to XML.");
+ $( "#dgflow-browser-dialog").dialog("close");
+ console.log( "error occured importing flow.");
+ })
+ .always(function() {
+ //console.log( "complete" );
+ });
+}
+
+function showFlowFiles(userName){
+ //var divStyle="color:#07c; margin-bottom: 1.2em; font-size: 16px;";
+ //var divStyle="<style>#data-container a { color: #067ab4; font-size: 0.75em;} #data-container a:hover { text-decoration: underline; padding: -15px -15px -15px 15px; } </style>";
+ var divStyle="<style>#data-container a { color: #067ab4; font-size: 0.75em;} #data-container a:hover { text-decoration: underline; padding: -15px -15px -15px 15px; } .header { height: 40px; border-bottom: 1px solid #EEE; background-color: #ffffff; height: 40px; -webkit-border-top-left-radius: 5px; -webkit-border-top-right-radius: 5px; -moz-border-radius-topleft: 5px; -moz-border-radius-topright: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; } .footer { height: 40px; background-color: whiteSmoke; border-top: 1px solid #DDD; -webkit-border-bottom-left-radius: 5px; -webkit-border-bottom-right-radius: 5px; -moz-border-radius-bottomleft: 5px; -moz-border-radius-bottomright: 5px; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; }</style>";
+
+ var htmlStr=divStyle + "<div class='header'>List of Flow files of User " + userName + "</div><div id='data-container'><ul>" ;
+ $.post( "/getFiles/" + userName)
+ .done(function( data ) {
+ //console.dir(data);
+ //console.log("found " + data.length + " files");
+ if(data != null && data.length != undefined && data.length != 0){
+ if(data != null && data.length>0){
+ for(var k=0;k<data.length;k++){
+ htmlStr += "<li><a href=\"#\" onclick=\"showFlow('" +data[k].filePath + "')\">" + data[k].name + "</a></li>";
+ /*
+ //Use this code to display the View Xml Link
+ htmlStr += "<li><a href=\"#\" onclick=\"showFlow('" +data[k].filePath + "')\">" + data[k].name + "</a><span style=\"margin-left:15px;color:blue\"><a href=\#\" onclick=\"showFlowXml('" +data[k].filePath + "')\">[View Xml]</a></span></li>";
+ */
+ }
+ htmlStr+="</ul></div>";
+ }
+ $( "#dgflow-browser-dialog").html(htmlStr);
+ }else{
+ //console.log("no flow files found for user " + userName);
+ var noFlowFilesHtml = divStyle + "<div id='data-container'><p>No downloaded Flow files found in " + userName + " directory</p><a href='#' onclick='javascript:closeAndShowFlowShareUsers()'>Back to List.</a></div>";
+ $( "#dgflow-browser-dialog").html(noFlowFilesHtml);
+ }
+ })
+ .fail(function(err) {
+ console.log( "error" + err );
+ })
+ .always(function() {
+ //console.log("done");
+ });
+
+}
+
+ function closeAndShowFlowShareUsers(){
+ $("#dgflow-browser-dialog").dialog( "close" );
+ var divStyle="<style>#data-container a { color: #067ab4; font-size: 0.75em;} #data-container a:hover { text-decoration: underline; padding: -15px -15px -15px 15px; } .header { height: 40px; border-bottom: 1px solid #EEE; background-color: #ffffff; height: 40px; -webkit-border-top-left-radius: 5px; -webkit-border-top-right-radius: 5px; -moz-border-radius-topleft: 5px; -moz-border-radius-topright: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; } .footer { height: 40px; background-color: whiteSmoke; border-top: 1px solid #DDD; -webkit-border-bottom-left-radius: 5px; -webkit-border-bottom-right-radius: 5px; -moz-border-radius-bottomleft: 5px; -moz-border-radius-bottomright: 5px; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; }</style>";
+ $.get( "/flowShareUsers")
+ .done(function( data ) {
+
+ var header="<div class='header'>List of downloaded DG Flows </div>";
+ var html= divStyle + header + "<div id='data-container'>";
+ html+="<ul>";
+ if(data != null){
+ var users=data.flowShareUsers;
+ users.sort(function (a,b){
+ if(a.name > b.name){
+ return 1;
+ }else if(a.name < b.name){
+ return -1;
+ }else{
+ return 0;
+ }
+ });
+ for(var i=0;users != null && i<users.length;i++){
+ html+="<li><a href=\"#\" onclick=\"showFlowFiles('" + users[i].rootDir + "')\">" + users[i].name + "</a></li>";
+ }
+ }
+ html+="</ul>";
+ html+="</div>";
+ $( "#dgflow-browser-dialog" ).dialog({
+ title: "Dowloaded DG Flow Browser",
+ modal: true,
+ autoOpen: true,
+ width: 530,
+ height: 530,
+ buttons: [
+ {
+ text: "Close",
+ click: function() {
+ $( this ).dialog( "close" );
+ }
+ }
+ ]
+ }).html(html);
+ $("#dgflow-browser-dialog").show();
+ })
+ .fail(function(err) {
+ RED.notify("Failed to get users.");
+ })
+ .always(function() {
+ });
+ }
+
+function showImportedXml(xmlStr,dialogBox){
+ var formattedXml=vkbeautify.xml(xmlStr);
+ var that = dialogBox;
+ require(["orion/editor/edit"], function(edit) {
+ that.editor = edit({
+ parent:document.getElementById('dgflow-browser-dialog'),
+ lang:"html",
+ readonly:true,
+ contents: formattedXml
+ });
+ RED.library.create({
+ url:"functions", // where to get the data from
+ type:"function", // the type of object the library is for
+ editor:that.editor, // the field name the main text body goes to
+ fields:['name','outputs']
+ });
+ });
+}
+
+function getTag(xmlStr){
+ var tag= null ;
+ if(xmlStr != null){
+ xmlStr = xmlStr.trim();
+ }
+ try{
+ var regex = new RegExp("(<)([^ >]+)");
+ var match = regex.exec(xmlStr);
+ if(match != null){
+ if(match[1] != undefined && match[2] != undefined){
+ tag = match[2];
+ }
+ }
+ }catch(e){
+ console.log(e);
+ }
+ return tag;
+
+}
+
+function getAttributeValue(xmlStr,attribute){
+
+ var attrVal=null;
+ try{
+ var myRe = new RegExp(attribute + "[\s+]?=[\s+]?['\"]([^'\"]+)['\"]","m");
+ var myArray = myRe.exec(xmlStr);
+ if(myArray != null && myArray[1] != null){
+ attrVal=myArray[1];
+ }
+ }catch(err){
+ console.log(err);
+ }
+ return attrVal;
+}
+
+function showOrHideTab(checkbox,idVal){
+
+ var activeWorkspace=RED.view.getWorkspace();
+ var table = $("#ftab02");
+ $('td input:checkbox',table).each(function(i){
+ console.log(this.checked);
+ });
+ //console.dir($('td input:checkbox',table).prop('checked',this.checked));
+
+ $(".red-ui-tabs li a").each(function(i){
+ var id=$(this).attr("href").replace('#','');
+ if(id == idVal){
+ $(this).parent().toggle();
+ var isVisible = $(this).parent().is(":visible");
+ if(isVisible){
+ checkbox.checked = true;
+ }else{
+ checkbox.checked = false;
+ }
+ if(activeWorkspace == id){
+ //$("#chart").hide();
+ //var li = ul.find("a[href='#"+id+"']").parent();
+ var li = $(this).parent();
+ if (li.hasClass("active")) {
+ li.removeClass("active");
+ if(li.parent().children().size() != 0){
+ }
+ console.log("has Class active");
+ var tab = li.prev();
+ if (tab.size() === 0) {
+ console.log("li prev size 0");
+ tab = li.next();
+ }
+ if(tab.is(":visible")){
+ console.log("added active");
+ tab.addClass("active");
+ tab.click();
+ //tab.trigger("click");
+ }
+ //console.dir(tab);
+ //tab.parent().addClass("active");
+ //tab.click();
+ }
+ }else{
+ console.log("added active id" +id);
+ if(isVisible){
+ var li = $(this).parent();
+ li.addClass("active");
+ li.click();
+ //console.dir(li);
+ }else{
+ var li = $(this).parent();
+ li.removeClass("active");
+ }
+ }
+ }
+ });
+/*
+ $(".red-ui-tabs li a").each(function(i){
+ var id=$(this).attr("href").replace('#','');
+ if(id != idVal){
+ $(this).trigger("click");
+ if(activeWorkspace == idVal){
+ $("#chart").show();
+ }
+ return false;
+ }
+ });
+*/
+}
+
+function performGitCheckout(){
+ $("#responseId").text("");
+ if(!event) event = window.event;
+ var target = $(event.target);
+ target.val("Processing");
+ target.css({ "background-image": "url('images/page-loading.gif')" });
+ target.css({ "background-repeat": "no-repeat" });
+ target.css({ "background-size": "25px 25px" });
+
+ var branch = document.getElementById("branchId").value.trim();
+ var statusObj = document.getElementById("responseId");
+ if(branch == null || branch == ''){
+ statusObj.innerText = "Branch is required.";
+ return;
+ }
+ var urlVal = "/gitcheckout?branch=" + branch;
+ $.get(urlVal)
+ .done(function( data ) {
+ var output = data.output;
+ if(output != null){
+ output=output.replace(/\n/g,"<br>");
+ statusObj.innerHTML = output;
+ }
+ })
+ .fail(function(err) {
+ statusObj.innerText = "Failed to do git checkout.";
+ })
+ .always(function() {
+ $("#responseId").show();
+ target.val("Checkout");
+ target.css({ "background-image": "none" });
+ });
+}
+
+function performGitPull(){
+ $("#responseId").text("");
+ if(!event) event = window.event;
+ var target = $(event.target);
+ target.val("Processing");
+ target.css({ "background-image": "url('images/page-loading.gif')" });
+ target.css({ "background-repeat": "no-repeat" });
+ target.css({ "background-size": "25px 25px" });
+
+ var statusObj = document.getElementById("responseId");
+ var urlVal = "/gitpull";
+ $.get(urlVal)
+ .done(function( data ) {
+ var output = data.output;
+ if(output != null){
+ output=output.replace(/\n/g,"<br>");
+ statusObj.innerHTML = output;
+ }
+ })
+ .fail(function(err) {
+ statusObj.innerText = "Failed to do git pull.";
+ })
+ .always(function() {
+ $("#responseId").show();
+ target.val("Pull");
+ target.css({ "background-image": "none" });
+ });
+}
+
+
+function activateClickedTab(idVal) {
+
+ $("#filter-tabs-dialog").dialog( "close" );
+ var ul = $("#workspace-tabs");
+ ul.children().each(function(){
+ var li = $(this);
+ var link =li.find("a");
+ var href = link.prop("href");
+ var hrefId = href.split("#");
+ if(hrefId[1] == idVal){
+ link.trigger("click");
+ }
+ });
+}
+
+function deleteOrRenameTab(idVal) {
+ $("#filter-tabs-dialog").dialog( "close" );
+ var ul = $("#workspace-tabs");
+ ul.children().each(function(){
+ var li = $(this);
+ var link =li.find("a");
+ var href = link.prop("href");
+ var hrefId = href.split("#");
+ if(hrefId[1] == idVal){
+ link.trigger("click");
+ link.trigger("dblclick");
+ }
+ });
+}
+
+function deleteSelectedTab(idVal,title,_module,rpc,version){
+ var dgInfo = "<div><table width='100%' border='1'><tr style='background-color:#65a9d7;color:white;' ><th>Tab Title</th><th>Module</th><th>RPC</th><th>Version</th></tr><tr style='background-color:white'><td>" + title + "</td><td>" + _module +"</td><td>" + rpc + "</td><td>" +version + "</td></tr></table></div><br>";
+ var alertMsg = dgInfo + "<p>Are you sure you want to Delete this Tab ?</p>";
+
+$( "#tabAlertDialog" ).dialog({
+ dialogClass: "no-close",
+ modal:true,
+ draggable : true,
+ /*dialogClass: "alert",*/
+ title: "Confirm Tab sheet Delete",
+ width: 600,
+ buttons: [
+ {
+ text: "Delete",
+ class:"alertDialogButton",
+ click: function() {
+ var ws = RED.nodes.workspace(idVal);
+ RED.view.removeWorkspace(ws);
+ var historyEvent = RED.nodes.removeWorkspace(idVal);
+ historyEvent.t = 'delete';
+ historyEvent.dirty = true;
+ historyEvent.workspaces = [ws];
+ RED.history.push(historyEvent);
+ RED.view.dirty(true);
+ $( this ).dialog( "close" );
+ $("#filter-tabs-dialog").dialog( "close" );
+ $("#btn-manage-tabs").trigger("click");
+ }
+ },
+ {
+ text: "Cancel",
+ class:"alertDialogButton",
+ click: function() {
+ $( this ).dialog( "close" );
+ }
+ }
+ ]
+}).html(alertMsg);
+}
+
+function renameSelectedTab(idVal,title,_module,rpc,version){
+ var dgInfo = "<div><table width='100%' border='1'><tr style='background-color:#65a9d7;color:white;' ><th>Tab Title</th><th>Module</th><th>RPC</th><th>Version</th></tr><tr style='background-color:white'><td><input id='tab-name-" + idVal + "' type='text' value='" + title + "'></td><td>" + _module +"</td><td>" + rpc + "</td><td>" +version + "</td></tr></table></div><br>";
+ var alertMsg = dgInfo + "<p>Change the title and click Rename.</p>";
+
+$( "#tabAlertDialog" ).dialog({
+ dialogClass: "no-close",
+ modal:true,
+ draggable : true,
+ /*dialogClass: "alert",*/
+ title: "Rename Tab sheet",
+ width: 600,
+ buttons: [
+ {
+ text: "Rename",
+ class:"alertDialogButton",
+ click: function() {
+ var ws = RED.nodes.workspace(idVal);
+ var label = document.getElementById("tab-name-" + idVal).value;
+ //console.log("label:" +label);
+ //console.log("ws.label:" + ws.label);
+ if (ws.label != label) {
+ ws.label = label;
+ var link = $("#workspace-tabs a[href='#"+idVal+"']");
+ link.attr("title",label);
+ link.text(label);
+ RED.view.dirty(true);
+ }
+ $("#tabAlertDialog").dialog('destroy').remove();
+ //$(this).dialog( "close" );
+ $("#filter-tabs-dialog").dialog( "close" );
+ $("#btn-manage-tabs").trigger("click");
+ }
+ },
+ {
+ text: "Cancel",
+ class:"alertDialogButton",
+ click: function() {
+ $( this ).dialog( "close" );
+ }
+ }
+ ]
+}).html(alertMsg);
+}
+
+function performGitStatus(){
+ $("#responseId").text("");
+ if(!event) event = window.event;
+ var target = $(event.target);
+ target.val("Processing");
+ target.css({ "background-image": "url('images/page-loading.gif')" });
+ target.css({ "background-repeat": "no-repeat" });
+ target.css({ "background-size": "25px 25px" });
+
+ var statusObj = document.getElementById("responseId");
+ var urlVal = "/gitstatus";
+ $.get(urlVal)
+ .done(function( data ) {
+ var output = data.output;
+ if(output != null){
+ output=output.replace(/\n/g,"<br>");
+ statusObj.innerHTML = output;
+ }
+ //statusObj.innerText = data.output;
+ })
+ .fail(function(err) {
+ statusObj.innerText = "Failed to do git status.";
+ })
+ .always(function() {
+ $("#responseId").show();
+ target.val("Status");
+ target.css({ "background-image": "none" });
+ });
+}
+
+function migrateNodes(jsonStr){
+ var nodes = JSON.parse(jsonStr);
+ nodes.forEach( function(node) {
+ if( node.xml != undefined && node.xml != null && node.xml.indexOf("<service-logic") != -1){
+ //console.log(node.xml);
+ var module="";
+ var version="";
+ module=getAttributeValue(node.xml,"module");
+ /*
+ var myRe = new RegExp("module=\"(.*)\" ", "m");
+ var myArray = myRe.exec(node.xml);
+ if(myArray != null && myArray[1] != null){
+ module=myArray[1];
+ }
+ myRe = new RegExp("version=\"(.*)\">", "m");
+ myArray = myRe.exec(node.xml);
+ if(myArray != null && myArray[1] != null){
+ version=myArray[1];
+ //console.dir(myArray);
+ }
+ */
+ version=getAttributeValue(node.xml,"version");
+ node.type="service-logic";
+ //node.category="DGEmain";
+ node.module=module;
+ node.version=version;
+ if(module != null && version != null){
+ node.name=module+ " " + version;
+ }
+ console.log("module=" + module);
+ console.log("version=" + version);
+ }else if( node.xml != undefined && node.xml != null && node.xml.indexOf("<method") != -1){
+ var rpc=getAttributeValue(node.xml,"rpc");
+ node.type="method";
+ if(rpc != null){
+ node.name=rpc;
+ }
+ }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<outcome") != -1){
+ var uxml = node.xml.toUpperCase();
+ if(uxml.indexOf("FAILURE") != -1){
+ node.type="failure";
+ }else if(uxml.indexOf("SUCCESS") != -1){
+ node.type="success";
+ }else if(uxml.indexOf("TRUE") != -1){
+ node.type="outcomeTrue";
+ }else if(uxml.indexOf("FALSE") != -1){
+ node.type="outcomeFalse";
+ }else if(uxml.indexOf("ALREADY-ACTIVE") != -1){
+ node.type="already-active";
+ }else if(uxml.indexOf("NOT-FOUND") != -1){
+ node.type="not-found";
+ }else{
+ node.type="other";
+ }
+ }else if( node.xml != undefined &&node.xml != null && node.xml.indexOf("<return") != -1){
+ var uxml = node.xml.toUpperCase();
+ if(uxml.indexOf("FAILURE") != -1){
+ node.type="returnFailure";
+ }else if(uxml.indexOf("SUCCESS") != -1){
+ node.type="returnSuccess";
+ }
+ }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<exists") != -1){
+ node.type="exists";
+ }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<block") != -1){
+ node.type="block";
+ var atomic=getAttributeValue(node.xml,"atomic");
+
+ if(atomic=='true'){
+ node.atomic="true";
+ node.name="block : atomic";
+ }else{
+ node.atomic="false";
+ node.name="block";
+ }
+ }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<save") != -1){
+ node.type="save";
+ }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<switch") != -1){
+ node.type="switchNode";
+ }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<record") != -1){
+ node.type="record";
+ }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<call") != -1){
+ node.type="call";
+ }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<release") != -1){
+ node.type="release";
+ }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<set") != -1){
+ node.type="set";
+ }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<for") != -1){
+ node.type="for";
+ }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<is-available") != -1){
+ node.type="is-available";
+ }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<reserve") != -1){
+ node.type="reserve";
+ }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<get-resource") != -1){
+ node.type="get-resource";
+ }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<configure") != -1){
+ node.type="configure";
+ }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<delete") != -1){
+ node.type="delete";
+ }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<execute") != -1){
+ node.type="execute";
+ }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<notify") != -1){
+ node.type="notify";
+ }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<update") != -1){
+ node.type="update";
+ }
+ //console.dir(node);
+ });
+ return nodes;
+}
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;
+}
diff --git a/dgbuilder/public/util/js/jsonTool.js b/dgbuilder/public/util/js/jsonTool.js
new file mode 100644
index 00000000..f4d0de36
--- /dev/null
+++ b/dgbuilder/public/util/js/jsonTool.js
@@ -0,0 +1,67 @@
+var obj={};
+function dotToJson(str,value,obj){
+ //var objArr = path.split("."), part;
+ var objArr = str.split(".");
+ var prevStr;
+ var currObj;
+ var prevObj;
+ console.log(str);
+ for(var i=0;i<objArr.length -1;i++){
+ var subStr= objArr[i] ;
+ //console.log("subStr:" + subStr);
+ if(i==0 && obj[subStr] == undefined ){
+ obj[subStr] = {};
+ currObj= obj[subStr];
+ }else if(i==0 && obj[subStr] != undefined ){
+ currObj=obj[subStr];
+ //console.log("in gkjgjkg");
+ }else{
+ if(i == 1){
+ prevObj=obj[prevStr];
+ if(prevObj[subStr] == undefined){
+ prevObj[subStr] = {};
+ currObj = prevObj[subStr];
+ }else{
+ currObj = prevObj[subStr];
+ }
+ }else{
+ if(prevObj[subStr] == undefined){
+ prevObj[subStr] = {};
+ currObj = prevObj[subStr];
+ }else{
+ currObj = prevObj[subStr];
+ }
+ }
+ //console.dir(currObj);
+ }
+ prevStr=subStr;
+ if(i <objArr.length-2){
+ prevObj=currObj;
+ }
+ }
+ var lastStr = objArr[objArr.length-1];
+ currObj[lastStr] = value;
+ //prevObj[lastStr] = value;
+ //console.dir(currObj);
+ return obj;
+}
+n=dotToJson('abcfdfghdghdghdghdhdhd.efhfjhfjhfjhfjhfjhfjhfbg.hfjhfjhfjhfjhfjhfjh.l',"1234",obj);
+//console.dir(n);
+JSON.stringify(n,undefined,2);
+m=dotToJson('abc.ebg.h.n',"5678",n);
+console.dir(m);
+function printObj(obj){
+for( j in obj){
+ console.log(j + ":" + obj[j]);
+ if(typeof obj[j] == "object" ){
+ printObj(obj[j]);
+ }
+
+}
+}
+printObj(m);
+a=JSON.parse(JSON.stringify(m,null,2));
+console.dir(a);
+
+
+//console.log (stringToObj('abc.ebg.h',"",{}));
diff --git a/dgbuilder/public/util/js/migrateFlow.js b/dgbuilder/public/util/js/migrateFlow.js
new file mode 100644
index 00000000..399db606
--- /dev/null
+++ b/dgbuilder/public/util/js/migrateFlow.js
@@ -0,0 +1,184 @@
+fs=require('fs');
+_=require('lodash');
+//extras=require("/home/users/schinthakayala/nodered/sheshi/dgxml/extras");
+//puts=extras.puts;
+var path = require('path');
+var appDir = path.dirname(require.main.filename);
+
+var dgjson = [];
+var level = 0;
+
+function getJSON() {
+var filename = process.argv[2];
+ console.log("reading json from flows file" + filename);
+ //flowsJson=fs.readFileSync(appDir + "/flows_ss4nj01dev01.localdomain.json").toString();
+ flowsJson=fs.readFileSync(filename).toString();
+ // Let's make a backup while we're here...
+ ts=Date.now().toString();
+ flows=JSON.parse(flowsJson);
+ //console.log("returning flows");
+ return(flows);
+}
+
+function getStartTag(xmlStr){
+ var startTag= null ;
+ if(xmlStr != null){
+ xmlStr = xmlStr.trim();
+ }
+ try{
+ var regex = new RegExp("(<)([^ >]+)");
+ var match = regex.exec(xmlStr);
+ if(match != null){
+ if(match[1] != undefined && match[2] != undefined){
+ startTag = match[2];
+ }
+ }
+ }catch(e){
+ console.log(e);
+ }
+ return startTag;
+
+}
+
+function getAttributeValue(xmlStr,attribute){
+ var attrVal=null;
+ try{
+ var myRe = new RegExp(attribute + "=['\"](.*)['\"] ","m");
+ var myArray = myRe.exec(xmlStr);
+ if(myArray != null && myArray[1] != null){
+ attrVal=myArray[1];
+ }
+ }catch(err){
+ console.log(err);
+ }
+ return attrVal;
+}
+
+function processNodes(){
+ var nodes = getJSON();
+ //console.dir(nodes);
+
+ nodes.forEach( function(node) {
+ if( node.xml != null && node.xml.indexOf("<service-logic") != -1){
+ //console.log(node.xml);
+ var module="";
+ var version="";
+ module=getAttributeValue(node.xml,"module");
+ /*
+ var myRe = new RegExp("module=\"(.*)\" ", "m");
+ var myArray = myRe.exec(node.xml);
+ if(myArray != null && myArray[1] != null){
+ module=myArray[1];
+ }
+ myRe = new RegExp("version=\"(.*)\">", "m");
+ myArray = myRe.exec(node.xml);
+ if(myArray != null && myArray[1] != null){
+ version=myArray[1];
+ //console.dir(myArray);
+ }
+ */
+ version=getAttributeValue(node.xml,"version");
+ node.type="service-logic";
+ //node.category="DGEmain";
+ node.module=module;
+ node.version=version;
+ if(module != null && version != null){
+ node.name=module+ "_" + version;
+ }
+ console.log("module=" + module);
+ console.log("version=" + version);
+ }else if( node.xml != null && node.xml.indexOf("<method") != -1){
+ var rpc=getAttributeValue(node.xml,"rpc");
+ node.type="method";
+ if(rpc != null){
+ node.name=rpc;
+ }
+ }else if( node.xml != null && node.xml.indexOf("<outcome") != -1){
+ var uxml = node.xml.toUpperCase();
+ if(uxml.indexOf("FAILURE") != -1){
+ node.type="failure";
+ }else if(uxml.indexOf("SUCCESS") != -1){
+ node.type="success";
+ }else if(uxml.indexOf("TRUE") != -1){
+ node.type="outcomeTrue";
+ }else if(uxml.indexOf("FALSE") != -1){
+ node.type="outcomeFalse";
+ }else if(uxml.indexOf("ALREADY-ACTIVE") != -1){
+ node.type="already-active";
+ }else if(uxml.indexOf("NOT-FOUND") != -1){
+ node.type="not-found";
+ }else{
+ node.type="other";
+ }
+ }else if( node.xml != null && node.xml.indexOf("<return") != -1){
+ var uxml = node.xml.toUpperCase();
+ if(uxml.indexOf("FAILURE") != -1){
+ node.type="returnFailure";
+ }else if(uxml.indexOf("SUCCESS") != -1){
+ node.type="returnSuccess";
+ }
+ }else if( node.xml != null && node.xml.indexOf("<exists") != -1){
+ node.type="exists";
+ }else if( node.xml != null && node.xml.indexOf("<block") != -1){
+ node.type="block";
+ var atomic=getAttributeValue(node.xml,"atomic");
+
+ if(atomic=='true'){
+ node.atomic="true";
+ node.name="block : atomic";
+ }else{
+ node.atomic="false";
+ node.name="block";
+ }
+ }else if( node.xml != null && node.xml.indexOf("<save") != -1){
+ node.type="save";
+ }else if( node.xml != null && node.xml.indexOf("<switch") != -1){
+ node.type="switchNode";
+ }else if( node.xml != null && node.xml.indexOf("<record") != -1){
+ node.type="record";
+ }else if( node.xml != null && node.xml.indexOf("<call") != -1){
+ node.type="call";
+ }else if( node.xml != null && node.xml.indexOf("<release") != -1){
+ node.type="release";
+ }else if( node.xml != null && node.xml.indexOf("<set") != -1){
+ node.type="set";
+ }else if( node.xml != null && node.xml.indexOf("<for") != -1){
+ node.type="for";
+ }else if( node.xml != null && node.xml.indexOf("<is-available") != -1){
+ node.type="is-available";
+ }else if( node.xml != null && node.xml.indexOf("<reserve") != -1){
+ node.type="reserve";
+ }else if( node.xml != null && node.xml.indexOf("<get-resource") != -1){
+ node.type="get-resource";
+ }else if( node.xml != null && node.xml.indexOf("<configure") != -1){
+ node.type="configure";
+ }else if( node.xml != null && node.xml.indexOf("<delete") != -1){
+ node.type="delete";
+ }else if( node.xml != null && node.xml.indexOf("<execute") != -1){
+ node.type="execute";
+ }
+ //console.dir(node);
+ });
+/*
+ var moduleName = "service-logic";
+ var methodName = "method";
+ for(var i=0;nodes != null && i<nodes.length;i++){
+ if(nodes[i].type == "service-logic"){
+ moduleName = nodes[i].name;
+ }
+ if(nodes[i].type == "method"){
+ methodName = nodes[i].name;
+ }
+ }
+ var fName = moduleName + "_" + methodName + ".json";
+ fName = fName.replace(/\s/g, "_");
+
+ var newFilename = process.argv[3];
+ var filename = newFilename + "/" + fName;
+ console.log("filename" + filename);
+ fs.writeFileSync(filename, JSON.stringify(nodes,null,4));
+ */
+}
+
+
+processNodes();
diff --git a/dgbuilder/public/util/js/sliValues.js b/dgbuilder/public/util/js/sliValues.js
new file mode 100644
index 00000000..eae10601
--- /dev/null
+++ b/dgbuilder/public/util/js/sliValues.js
@@ -0,0 +1,763 @@
+var global_editor ;
+function addParam(idVal){
+ //console.log(val);
+ //console.log(global_editor.getText());
+ if(global_added_obj["a" + idVal] != undefined && global_added_obj["a" + idVal] != null){
+ global_added_obj["a" + idVal]= global_added_obj["a" + idVal]+1;
+ $("#addCnt" + + idVal).text("added " + global_added_obj["a" + idVal] + " times");
+ }else{
+ global_added_obj["a" + idVal]= 1;
+ $("#addCnt" + + idVal).text("added " + global_added_obj["a" + idVal] + " time");
+ }
+ var nameVal = document.getElementById("a" + idVal).value;
+ var valueBoxVal = document.getElementById("valbox" + idVal).value;
+ //$("#btn" + idVal).val('Added');
+ //$("#btn" + idVal).attr('disabled','disabled');
+ //console.dir(nameVal);
+ //console.dir(valueBoxVal);
+
+
+ var paramElement = "<parameter name='" + nameVal + "' value='" + valueBoxVal + "'/>\n";
+ global_editor.setText(global_editor.getText() + paramElement);
+}
+
+var g_currValuesObj={};
+
+function filterValues(filterVal){
+ global_added_obj={};
+ var matchedCnt =0;
+ var valuesObj = g_currValuesObj;
+ var newValuesObj ={};
+ var searchValues =[];
+ if(filterVal != null && filterVal != undefined){
+ filterVal=filterVal.trim();
+ }
+ searchValues = filterVal.split(/ /);
+ //console.log("filterVal:" + filterVal);
+ if(searchValues != null && searchValues != undefined){
+ for (var key in valuesObj) {
+ if (valuesObj.hasOwnProperty(key)) {
+ var newArrObj = [];
+ if(Array.isArray(valuesObj[key])){
+ var arrObj=valuesObj[key];
+ var cnt=1;
+ for(var i=0;i<arrObj.length;i++){
+ var foundCount = 0;
+ for(var k=0;k<searchValues.length;k++){
+ if(arrObj[i].indexOf(searchValues[k]) != -1){
+ foundCount++;
+ }
+ }
+ if(foundCount == searchValues.length){
+ matchedCnt++;
+ newArrObj.push(arrObj[i]);
+ }
+ }
+ newValuesObj[key] = newArrObj;
+ }
+ }
+ }
+ $("#matchedCntId").html(matchedCnt);
+ }else{
+ newValuesObj = valuesObj;
+ }
+ var valuesHtml=buildValuesHtml(newValuesObj);
+ valuesHtml+="</div>";
+ $("#sli-values-div").html(valuesHtml);
+}
+
+function buildValuesHtml(valuesObj){
+ var idCounter=0;
+ var htmlVal = "";
+
+ for (var key in valuesObj) {
+ if (valuesObj.hasOwnProperty(key)) {
+ var v = "<div style='font-weight:bold;font-size:1.0em;'><label>" + key + "<b/label>";
+ if(Array.isArray(valuesObj[key])){
+ var arrObj=valuesObj[key];
+ var cnt=1;
+ for(var i=0;i<arrObj.length;i++){
+ var idVal = idCounter++;
+ var addBtn = "<input id='btn" + idVal + "' type='button' style='background-color:#D6EBFF;' value='Add as Parameter'" + "onclick='addParam(\"" + idVal + "\")'><div style='float:right' id='addCnt" + idVal + "'></div>";
+ var variableBox = "";
+ var valBox = "<input id='valbox" + idVal + "' type='text' style='width:500px;height:30px;' value=''>";
+ if(arrObj[i] != undefined && arrObj[i].length <150){
+ //v += "<div style='width:1150px;background:aliceblue;border-color:aliceblue' class='valueBoxDiv' id='valueBoxDiv" + idVal + "'>" + "<input style='width:1125px;background:rgb(223, 191, 191);color:rgb(32, 45, 87);' type='text' readonly='1' id='a" + idVal + "' onclick='selectText(\"" + idVal+"\",\"" + key + "\")' value='" +arrObj[i] + "' title='" + arrObj[i] + "' >" ;
+ v += "<div style='width:1150px;background:aliceblue;border-color:aliceblue' class='valueBoxDiv' id='valueBoxDiv" + idVal + "'>" + "<input style='width:1125px;background:aliceblue;color:rgb(32, 45, 87);' type='text' readonly='1' id='a" + idVal + "' onclick='selectText(\"" + idVal+"\",\"" + key + "\")' value='" +arrObj[i] + "' title='" + arrObj[i] + "' >" ;
+ variableBox = "<input style='width:1125px' id='variableBox" + idVal + "' type='text' value='`$" + arrObj[i] + "`'>";
+ }else{
+ v+= "<div style='width:1150px;background:aliceblue;border-color:aliceblue' class='valueBoxDiv' id='valueBoxDiv" + idVal + "'>" + "<textarea style='width:1125px;background:aliceblue;color:rgb(32, 45, 87);' readonly='1' id='a" + idVal + "' onclick='selectText(\"" + idVal+"\",\"" + key + "\")' title='" + arrObj[i] + "' >" + arrObj[i] + "</textarea>";
+ variableBox = "<textarea style='width:1125px' id='variableBox" + idVal + "' >`$" + arrObj[i] + "`'</textarea>";
+ }
+ v += "<div id='valAddDiv" + idVal + "' style='display:none;'>" + valBox + "&nbsp;&nbsp;" + addBtn + "</div>" +
+ "<div id='variableBoxDiv" + idVal + "' style='display:none;color:rgb(32, 45, 87);'>Display as a variable<br>" + variableBox + "</div>" + "</div>";
+ cnt++;
+ }
+ htmlVal+= v + "</div>";
+ }
+ }
+ }
+ return htmlVal;
+}
+
+function getModuleName(){
+ var activeWorkspace=RED.view.getWorkspace();
+ var moduleName="";
+ RED.nodes.eachNode(function(n) {
+ if (n.z == activeWorkspace) {
+ if(n.type == 'service-logic'){
+ //console.log("getModuleName():<" + n.module + ">");
+ moduleName=n.module;
+ }
+ }
+ });
+ return moduleName;
+}
+var global_added_obj={};
+var displayingRpcs = false;
+function showRpcsValuesBox(editor,valuesObj){
+ displayingRpcs = true;
+ showValuesBox(editor,valuesObj);
+}
+
+function showValuesBox(editor,valuesObj){
+ var moduleName = getModuleName();
+ var obj = valuesObj[moduleName];
+ //console.dir(valuesObj);
+ //console.dir(obj);
+ var moduleObj ={};
+ if(obj == undefined){
+ moduleObj[moduleName] = ["No SLI values setup for this module " + moduleName + ".Upload the yang file for this module or if already uploaded ,load it from the Available Modules from the Menu."];
+ }else{
+ moduleObj[moduleName] = obj;
+ }
+ showValuesBoxForModule(editor,moduleObj,moduleName);
+}
+
+function showValuesBoxForModule(editor,valuesObj,moduleName){
+ global_editor=editor;
+ g_currValuesObj = valuesObj;
+ //console.log(editor.getText());
+ //populate the valid SLI values
+ var valuesHtml="<style>.color-dialog {background:aliceblue;border-color:lightgrey;border-width:3px;border-style:solid; }</style><div style='float:left;width:1200px;background:aliceblue'><input style='width:1125px' id='filter-id' type='text' value='' placeholder='To filter the values type words seperated by space in this box' onkeyup='filterValues(this.value)'></div><div style='float:left;color:green;font-size:0.8em' id='matchedCntId'></div><div style='clear:both'></div><div id='sli-values-div' style='width:1200px;'>" ;
+ valuesHtml+=buildValuesHtml(valuesObj);
+ valuesHtml+="</div>";
+ global_added_obj={};
+
+
+ var title = "SLI Values for Module " + moduleName;
+ if(displayingRpcs){
+ title = "RPCs for Module " + moduleName;
+ }
+ $('#sli-values-dialog').dialog({
+ modal: false,
+ title: title,
+ width: 1200,
+ height: 500,
+ dialogClass: 'color-dialog',
+ open: function () {
+ $("#sli-values-dialog").dialog("widget").find(".ui-dialog-buttonpane").css({'background': 'aliceblue'});
+ $(this).html(valuesHtml);
+ },
+ buttons: {
+ Close: function () {
+ displayingRpcs = false;
+ //$(this).dialog("close");
+ $(this).dialog("destroy");
+ }
+ },
+ close: function(ev,ui){
+ displayingRpcs = false;
+ $(this).dialog("destroy");
+ }
+ }); // end dialog div
+}
+
+function showCommentsBox(){
+ var comments = $("#node-input-comments").val();
+ var commentsBoxHtml="<div><textarea style='font-size:18px;height:150px;width:390px;' id='taCommentId'>" + comments + "</textarea></div>" ;
+
+ var nodeName=$("#node-input-name").val();
+ $('#comments-dialog').dialog({
+ modal: true,
+ title: "Add comments for Node " + nodeName,
+ width: 450,
+ height: 300,
+ /*
+ open: function () {
+ $(this).html(commentsBoxHtml);
+ },
+ */
+ buttons: {
+ "Save Comments": function () {
+ var v=$("#taCommentId").val();
+ if(v != null){
+ v = v.trim();
+ if(v != ''){
+ $("#node-input-btnComments").html("<span style='color:blue;'><b>View Comments</b></span>");
+ }else{
+ $("#node-input-btnComments").html("<b>Add Comments</b>");
+ }
+ }
+ //console.log("value from text area" + v);
+ $("#node-input-comments").val(v);
+ $(this).dialog("close");
+ //$(this).dialog("destroy");
+ },
+ Cancel: function () {
+ var v=$("#taCommentId").val();
+ if(v != null){
+ v = v.trim();
+ if(v != ''){
+ $("#node-input-btnComments").html("<span style='color:blue;'><b>View Comments</b></span>");
+ }else{
+ $("#node-input-btnComments").html("<b>Add Comments</b>");
+ }
+ }
+ $(this).dialog("close");
+ //$(this).dialog("destroy");
+ }
+ },
+ close: function(ev,ui){
+ //console.log("closing..");
+ $(this).dialog("destroy");
+ }
+ }).html(commentsBoxHtml);
+
+ //console.log("done");
+/*
+ function functionDialogResize(ev,ui) {
+ console.log("ui.size.height:" + ui.size.height);
+ $(this).css("height",(ui.size.height-275)+"px");
+ };
+
+ $( this ).on("dialogresize", functionDialogResize);
+
+
+ $( this ).one("dialogopen", function(ev) {
+ var size = $( "#sliValDiv" ).dialog('option','sizeCache-function');
+ if (size) {
+ functionDialogResize(null,{size:size});
+ }
+ });
+*/
+
+}
+
+function selectText(objId,groupVal){
+ //console.log(objId + groupVal);
+ //console.log(objId + groupVal);
+ $(document).ready(function(){
+ //console.log("doc ready");
+ //console.dir($('#valAddDiv' + objId));
+ if ($('#valAddDiv' + objId).is(":visible")) {
+ $("#variableBoxDiv" + objId ).hide("slow");
+ //$("#a" + objId ).css({"background": "rgb(223, 191, 191)",
+ // "color": "rgb(32, 45, 87)"});
+ $("#a" + objId ).css({"background": "aliceblue",
+ "color": "rgb(32, 45, 87)"});
+ /*"color": "rgb(32, 45, 87)"});*/
+ $("#valAddDiv" + objId ).hide("slow");
+ $("#valueBoxDiv" +objId).css({"border-color": "aliceblue",
+ "border-width":"1px",
+ "background-color":"aliceblue",
+ "border-style":"solid"});
+ //$("#valAddDiv" + objId ).fadeOut("slow");
+ } else{
+ $("#variableBoxDiv" + objId ).show("slow");
+ $("#valAddDiv" + objId).show("slow");
+ /*$("#valueBoxDiv" +objId).css({"border-color": "rgb(75, 111, 147)",
+ "border-width":"5px",
+ "background-color": "rgb(223, 191, 191)",
+ "border-style":"solid",
+ "border-bottom": "5px solid rgb(75, 111, 147)"});
+ */
+ $("#valueBoxDiv" +objId).css({"border-color": "rgb(75, 111, 147)",
+ "border-width":"3px",
+ "background-color": "aliceblue",
+ "border-style":"solid",
+ "border-bottom": "3px solid rgb(75, 111, 147)"});
+ /*$("#a" + objId ).css({"background": "rgb(223, 191, 191)",
+ "color": "rgb(75, 111, 147)"});
+ */
+ $("#a" + objId ).css({"background": "aliceblue",
+ "color": "rgb(75, 111, 147)"});
+ }
+ $("#a" + objId).select();
+ });
+ //console.log("group-heading" + objId);
+// var obj= document.getElementById("group-heading" + objId);
+// obj.innerText = groupVal;
+// obj.style.color = "blue";
+// console.dir(obj);
+}
+
+function hidePrevGroup(objId){
+// console.log("mouseout" );
+// var obj= document.getElementById("group-heading" + objId);
+// obj.innerText = "";
+}
+/*
+function fixDiv() {
+ var $cache = $('#getFixed');
+ if ($(window).scrollTop() > 100)
+ $cache.css({
+ 'position': 'fixed',
+ 'top': '10px'
+ });
+ else
+ $cache.css({
+ 'position': 'relative',
+ 'top': 'auto'
+ });
+ }
+
+$(window).scroll(fixDiv);
+
+function isScrolledIntoView(elem)
+{
+ var $elem = $(elem);
+ var $window = $(window);
+
+ var docViewTop = $window.scrollTop();
+ var docViewBottom = docViewTop + $window.height();
+
+ var elemTop = $elem.offset().top;
+ var elemBottom = elemTop + $elem.height();
+
+ return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
+}
+*/
+
+function getCommits(filePath){
+var urlPath="/getCommitsInfo";
+$.get(urlPath,{"filePath" : filePath })
+ .done(function( data ) {
+ if(data != undefined && data != null){
+ //console.log(data.stdout);
+ var jsonObj = JSON.parse(data.stdout);
+ var codeCloudFilesHtmlStr = $( "#codecloud-browser-dialog" ).html();
+ var htmlStr = getCCFileHtmlStr(filePath,jsonObj,codeCloudFilesHtmlStr);
+ $( "#codecloud-browser-dialog" ).html(htmlStr);
+ /*
+ for(var i=0;i<jsonObj.length;i++){
+ console.log("commit:" + jsonObj[i].commit);
+ console.log("date:" + jsonObj[i].date);
+ console.log("author:" + jsonObj[i].author);
+ console.log("comment:" + jsonObj[i].comment);
+ }
+ */
+ }
+ })
+ .fail(function(err) {
+ })
+ .always(function() {
+ });
+}
+
+
+function getCCFileHtmlStr(filePath,rows,codeCloudFilesHtmlStr){
+ var styleStr = "<style> " +
+ "table#cct01 { width:100%; } \n" +
+ "table#cct01 th,table#cct01 td { border: 1px solid black; border-collapse: collapse; } \n" +
+ "table#cct01 th,table#cct01 td { padding: 5px; text-align: left; } \n" +
+ "table#cct01 tr:nth-child(even) { background-color: #eee; }\n" +
+ "table#cct01 tr:nth-child(odd) { background-color:#fff; }\n" +
+ "table#cct01 th { background-color: #65a9d7; color: white; }\n" +
+ "table#cct01 a { color: #337ab7; }\n" +
+ "table#cct01 a:link { color: #65a9d7; }\n" +
+ "table#cct01 a:visited { color: #636; }\n" +
+ "table#cct01 a:hover { color: #3366CC; cursor: pointer }\n" +
+ "table#cct01 a:active { color: #65a9d7 }\n" +
+ "table#cct01 caption { display: table-caption; text-align: center; background: #eee; font-weight: bold; font-size: 1.1em; border: 1px solid black; }\n" +
+ "</style>";
+ var htmlStr="";
+ //console.dir(rows);
+ if(rows != null && rows.length >0){
+ var alertDialog = '<div id="ccAlertdialog"></div>';
+ htmlStr= alertDialog + "<div style='width:1050;height:650'>" + styleStr;
+ htmlStr += "<table id='cct01' >";
+ htmlStr += "<caption id='ccCaptionId'>" + filePath + "</caption>";
+ htmlStr += "<tr>";
+ htmlStr += "<th>Commit ID</th>" ;
+ htmlStr += "<th>Date</th>" ;
+ htmlStr += "<th>Author</th>" ;
+ htmlStr += "<th>Comment</th>" ;
+ htmlStr += "</tr>";
+ if(rows != null && rows.length == 0){
+ htmlStr += "<tr>";
+ htmlStr += "<td><b>No rows found</b></td>";
+ htmlStr += "</tr></table></div>";
+ return htmlStr;
+ }
+ for(var i=0;i<rows.length;i++){
+ var row = rows[i];
+ var _commitId = row.commit;
+ var dt = row.date;
+ var author = row.author;
+ var comment = row.comment;
+ htmlStr += "<tr>";
+ htmlStr += "<td><a onclick=\"javascript:importCCFlow('" + _commitId + "','" + filePath + "')\">" + _commitId + "</a></td>";
+ htmlStr += "<td>" + dt + "</td>";
+ htmlStr += "<td>" + author + "</td>";
+ htmlStr += "<td>" + comment + "</td>";
+ htmlStr += "</tr>";
+ }
+ htmlStr += "</table>";
+ htmlStr += "</div>";
+ }
+ //console.log(htmlStr);
+ return htmlStr;
+}
+
+
+var gitLocalFlowFiles=[];
+function filterGitLocalFlows(filterVal){
+
+ var matchedCnt =0;
+ var valuesObj = gitLocalFlowFiles;
+ //console.dir(codeCloudFlowFiles);
+ var updatedValuesObj =[];
+ var searchValues =[];
+ if(filterVal != null && filterVal != undefined){
+ filterVal=filterVal.trim();
+ }
+ searchValues = filterVal.split(/ /);
+ //console.log("filterVal:" + filterVal);
+ //console.dir(searchValues);
+ if(searchValues != null && searchValues != undefined){
+ var foundCount = 0;
+ for(var k=0;k<searchValues.length;k++){
+ if(foundCount >0){
+ valuesObj=updatedValuesObj;
+ }
+ updatedValuesObj=[];
+ for(var i=0;i<valuesObj.length;i++){
+ var patt = new RegExp(searchValues[k],"gi");
+ if(patt.test(valuesObj[i])){
+ foundCount++;
+ updatedValuesObj.push(valuesObj[i]);
+ }
+ }
+ }
+ }else{
+ updatedValuesObj = valuesObj;
+ }
+ //console.dir(updatedValuesObj);
+ var html="<ul>";
+ if(updatedValuesObj != null){
+ var files=updatedValuesObj;
+ //console.dir(files);
+ files.sort(function (a,b){
+ if(a > b){
+ return 1;
+ }else if(a < b){
+ return -1;
+ }else{
+ return 0;
+ }
+ });
+ for(var i=0;files != null && i<files.length;i++){
+ html+="<li><a href=\"#\" onclick=\"importGitLocalFlow('" + files[i] + "')\">" + files[i] + "</a></li>";
+ }
+ }
+ html+="</ul>";
+ html+="</div>";
+ $( "#gitlocal-data-container" ).html(html);
+}
+
+var codeCloudFlowFiles=[];
+function filterFlows(filterVal){
+
+ var matchedCnt =0;
+ var valuesObj = codeCloudFlowFiles;
+ //console.dir(codeCloudFlowFiles);
+ var updatedValuesObj =[];
+ var searchValues =[];
+ if(filterVal != null && filterVal != undefined){
+ filterVal=filterVal.trim();
+ }
+ searchValues = filterVal.split(/ /);
+ //console.log("filterVal:" + filterVal);
+ //console.dir(searchValues);
+ if(searchValues != null && searchValues != undefined){
+ var foundCount = 0;
+ for(var k=0;k<searchValues.length;k++){
+ for(var i=0;i<valuesObj.length;i++){
+ var patt = new RegExp(searchValues[k],"gi");
+ if(patt.test(valuesObj[i])){
+ foundCount++;
+ updatedValuesObj.push(valuesObj[i]);
+ }
+ }
+ }
+ }else{
+ updatedValuesObj = valuesObj;
+ }
+ //console.dir(updatedValuesObj);
+ var html="<ul>";
+ if(updatedValuesObj != null){
+ var files=updatedValuesObj;
+ //console.dir(files);
+ files.sort(function (a,b){
+ if(a > b){
+ return 1;
+ }else if(a < b){
+ return -1;
+ }else{
+ return 0;
+ }
+ });
+ for(var i=0;files != null && i<files.length;i++){
+ html+="<li><a href=\"#\" onclick=\"getCommits('" + files[i] + "')\">" + files[i] + "</a></li>";
+ }
+ }
+ html+="</ul>";
+ html+="</div>";
+ $( "#codecloud-data-container" ).html(html);
+}
+
+var yangFilesList=[];
+/*
+function filterYangFiles(filterVal){
+
+ var matchedCnt =0;
+ var valuesObj = yangFilesList;
+ var updatedValuesObj =[];
+ var searchValues =[];
+ if(filterVal != null && filterVal != undefined){
+ filterVal=filterVal.trim();
+ }
+ searchValues = filterVal.split(/ /);
+ if(searchValues != null && searchValues != undefined){
+ var foundCount = 0;
+ for(var k=0;k<searchValues.length;k++){
+ for(var i=0;i<valuesObj.length;i++){
+ var patt = new RegExp(searchValues[k],"gi");
+ if(patt.test(valuesObj[i])){
+ foundCount++;
+ updatedValuesObj.push(valuesObj[i]);
+ }
+ }
+ }
+ }else{
+ updatedValuesObj = valuesObj;
+ }
+ //console.dir(updatedValuesObj);
+ var html="<ul>";
+ if(updatedValuesObj != null){
+ var files=updatedValuesObj;
+ //console.dir(files);
+ files.sort(function (a,b){
+ if(a > b){
+ return 1;
+ }else if(a < b){
+ return -1;
+ }else{
+ return 0;
+ }
+ });
+ for(var i=0;files != null && i<files.length;i++){
+ html+="<li><a href=\"#\" onclick=\"getYangFile('" + files[i] + "')\">" + files[i] + "</a></li>";
+ }
+ }
+ html+="</ul>";
+ html+="</div>";
+ $( "#list-yang-data-container" ).html(html);
+}
+*/
+
+function filterYangFiles(filterVal){
+ var matchedCnt =0;
+ var valuesObj = yangFilesList;
+ var updatedValuesObj =[];
+ var searchValues =[];
+ if(filterVal != null && filterVal != undefined){
+ filterVal=filterVal.trim();
+ }
+ searchValues = filterVal.split(/ /);
+ if(searchValues != null && searchValues != undefined){
+ var foundCount = 0;
+ for(var k=0;k<searchValues.length;k++){
+ for(var i=0;i<valuesObj.length;i++){
+ var patt = new RegExp(searchValues[k],"gi");
+ if(patt.test(valuesObj[i])){
+ foundCount++;
+ updatedValuesObj.push(valuesObj[i]);
+ }
+ }
+ }
+ }else{
+ updatedValuesObj = valuesObj;
+ }
+ //console.dir(updatedValuesObj);
+ var html="<table id='yang-file-list-table' border=1>";
+ html+="<tr>";
+ html+="<th>File</th>";
+ html+="<th>Delete</th>";
+ html+="</tr>";
+
+ if(updatedValuesObj != null){
+ var files=updatedValuesObj;
+ //console.dir(files);
+ files.sort(function (a,b){
+ if(a > b){
+ return 1;
+ }else if(a < b){
+ return -1;
+ }else{
+ return 0;
+ }
+ });
+ for(var i=0;files != null && i<files.length;i++){
+ html+="<tr><td><a href=\"#\" onclick=\"getYangFile('" + files[i] + "')\">" + files[i] + "</a></td><td>" + "<input type='button' onclick='deleteYangFile(\"" + files[i] + "\")' value='Delete'></td></td></td></tr>";
+ }
+ }
+ html+="</table>";
+ html+="</div>";
+
+ $( "#yang-files-data-container" ).html(html);
+}
+
+function getYangFile(fileName){
+ $("#dwnldYangFormId").remove();
+ //using form to submit
+ var form = $('<form id="dwnldYangFormId" method="POST" action="/downloadYang"></form>');
+ form.append('<input type="hidden" name="fileName" value="' + fileName + '"/>');
+ form.appendTo('body');
+ $("#dwnldYangFormId").submit();
+
+}
+function deleteYangFile(fileName){
+ var reqData= {"fileName":fileName};
+ $.post( "/deleteYangFile",reqData )
+ .done(function( data ) {
+ })
+ .fail(function(err) {
+ console.log( "error" + err );
+ })
+ .always(function() {
+ $("#list-yang-browser-dialog").dialog("close");
+ $("#btn-list-yang-files").trigger("click");
+ });
+}
+
+function importCCFlow(commitId,filePath){
+var urlPath="/importCodeCloudFlow";
+$.get(urlPath,{"commitId" : commitId,"filePath" : filePath })
+ .done(function( data ) {
+ if(data != undefined && data != null){
+ //console.log(data.stdout);
+ var jsonObj = JSON.parse(data.stdout);
+ $( "#codecloud-browser-dialog" ).dialog("close");
+ RED.view.importNodes(JSON.stringify(jsonObj));
+ }
+ })
+ .fail(function(err) {
+ RED.notify("Could not import flow from code cloud.");
+ $( "#codecloud-browser-dialog").dialog("close");
+ console.log( "error occured importing flow.");
+ })
+ .always(function() {
+ });
+}
+
+function importGitLocalFlow(filePath){
+var urlPath="/importGitLocalFlow";
+$.get(urlPath,{"filePath" : filePath })
+ .done(function( data ) {
+ if(data != undefined && data != null){
+ //console.log(data.stdout);
+ var jsonObj;
+ try{
+ jsonObj = JSON.parse(data.stdout);
+ $( "#gitlocal-browser-dialog" ).dialog("close");
+ RED.view.importNodes(JSON.stringify(jsonObj));
+ }catch(err){
+ RED.notify("Could not import flow from Local Git Repository.");
+ $( "#gitlocal-browser-dialog").dialog("close");
+ console.log( "error occured importing flow." + err);
+ }
+ }else{
+ RED.notify("Could not import flow from Local Git Repository.");
+ $( "#gitlocal-browser-dialog").dialog("close");
+ console.log( "error occured importing flow." + err);
+ }
+ })
+ .fail(function(err) {
+ RED.notify("Could not import flow from Local Git Repository.");
+ $( "#gitlocal-browser-dialog").dialog("close");
+ console.log( "error occured importing flow.");
+ })
+ .always(function() {
+ });
+}
+
+var availableYangModules=[];
+function filterYangModules(filterVal){
+
+ var matchedCnt =0;
+ var valuesObj = availableYangModules ;
+ //console.dir(codeCloudFlowFiles);
+ var updatedValuesObj =[];
+ var searchValues =[];
+ if(filterVal != null && filterVal != undefined){
+ filterVal=filterVal.trim();
+ }
+ searchValues = filterVal.split(/ /);
+ //console.log("filterVal:" + filterVal);
+ //console.dir(searchValues);
+ if(searchValues != null && searchValues != undefined){
+ var foundCount = 0;
+ for(var k=0;k<searchValues.length;k++){
+ if(foundCount >0){
+ valuesObj=updatedValuesObj;
+ }
+ updatedValuesObj=[];
+ for(var i=0;i<valuesObj.length;i++){
+ var patt = new RegExp(searchValues[k],"gi");
+ if(patt.test(valuesObj[i])){
+ foundCount++;
+ updatedValuesObj.push(valuesObj[i]);
+ }
+ }
+ }
+ }else{
+ updatedValuesObj = valuesObj;
+ }
+ //console.dir(updatedValuesObj);
+ var html="";
+ html+="<table border=1>";
+ html+="<tr>";
+ html+="<th>#</th>";
+ html+="<th>Load</th>";
+ html+="<th>Module</th>";
+ html+="</tr>";
+
+ if(updatedValuesObj != null){
+ var files=updatedValuesObj;
+ //console.dir(files);
+ files.sort(function (a,b){
+ if(a > b){
+ return 1;
+ }else if(a < b){
+ return -1;
+ }else{
+ return 0;
+ }
+ });
+ var count=1;
+ for(var i=0;files != null && i<files.length;i++){
+ var val = files[i].replace(/:.*/,"");
+ if(files[i].indexOf(":checked") != -1){
+ html+="<tr><td>" + count + "</td><td><input type='checkbox' checked value='" + val + "'></td><td>" + val + "</td></tr>";
+ }else{
+ html+="<tr><td>" + count + "</td><td><input type='checkbox' value='" + val + "'></td><td>" + val + "</td></tr>";
+ }
+ count++;
+ }
+ }
+ html+="</table>";
+ html+="</div>";
+ $( "#yang-modules-data-container" ).html(html);
+}
diff --git a/dgbuilder/public/util/js/validateNodeXml.js b/dgbuilder/public/util/js/validateNodeXml.js
new file mode 100644
index 00000000..2291d865
--- /dev/null
+++ b/dgbuilder/public/util/js/validateNodeXml.js
@@ -0,0 +1,325 @@
+function resetStatus(){
+ showMsg("","green");
+}
+
+function showMsg(msg,color){
+ $("#node-validate-result").html(msg);
+ $("#node-validate-result")
+ .css('color', '')
+ .css('color', color);
+}
+
+function getAttributeValue(xmlStr,attribute){
+
+ var attrVal=null;
+ try{
+ if(xmlStr != null){
+ var myRe = new RegExp(attribute + "[\s+]?=[\s+]?['\"]([^'\"]+)['\"]","m");
+ var myArray = myRe.exec(xmlStr);
+ if(myArray != null && myArray[1] != null){
+ attrVal=myArray[1];
+ }
+ }
+ }catch(err){
+ console.log(err);
+ }
+ return attrVal;
+}
+
+
+var resp = true;
+var processedNode = "";
+var errList=[];
+var elementCount=0;
+function processNode(xmlNode){
+ if(xmlNode == null) return;
+ if(xmlNode.nodeName != "parsererror" && xmlNode.nodeName != "#text"){
+ processedNode = xmlNode.nodeName;
+ }
+ //console.log("processedNode:" + processedNode);
+ switch(xmlNode.nodeType){
+ case 1:
+ elementCount++;
+ //ELEMENT_NODE
+ //console.log(xmlNode.nodeName);
+ //console.dir(xmlNode.nodeName);
+ if(xmlNode.nodeName == "parsererror"){
+ //var nearNode = xmlNode.previousSibling != null ?xmlNode.previousSibling.nodeName : xmlNode.parentNode.nodeName;
+ console.log("Error parsing xml after node " + processedNode);
+ var msg = "error parsing XML after element &lt;" + processedNode + "&gt; Element#" + elementCount;
+ errList.push(msg);
+ resp = false;
+ return;
+ }
+ processedNode = xmlNode.nodeName;
+ var attrs = xmlNode.attributes;
+ for(var i=0;i<attrs.length;i++){
+ //console.log("Attribute:" + attrs[i].nodeName);
+ //console.log("Value:" + attrs[i].value);
+ if(attrs[i].nodeName != "value" && attrs[i].value == ""){
+ var msg="";
+ /*
+ var prevSibling = xmlNode.previousSibling;
+ if(prevSibling != null && prevSibling != undefined){
+ msg = "element &lt;" + xmlNode.nodeName + "&gt; attribute '" + attrs[i].nodeName + "' is not set. Element#" + elementCount;
+ }else{
+ msg = "element &lt;" + xmlNode.nodeName + "&gt; attribute '" + attrs[i].nodeName + "' is not set. Element#" + elementCount;
+ }
+ */
+ msg = "element &lt;" + xmlNode.nodeName + "&gt; attribute '" + attrs[i].nodeName + "' is not set. Element#" + elementCount;
+ errList.push(msg);
+ //console.log("element <" + xmlNode.nodeName + "> attribute '" + attrs[i].nodeName + "' is not set.Element#" + elementCount);
+ resp = false;
+ }
+ }
+ var childNodes = xmlNode.childNodes;
+ for(var k=0;k<childNodes.length;k++){
+ processNode(childNodes[k]);
+ }
+ break;
+ case 2:
+ //ATTRIBUTE_NODE
+ //console.log(xmlNode.nodeName);
+ break;
+ case 3:
+ //TEXT_NODE
+ //console.log(xmlNode.nodeValue);
+ break;
+ case 4:
+ //CDATA_SECTION_NODE
+ console.log("CDATA_SECTION_NODE");
+ break;
+ case 5:
+ //ENTITY_REFERENCE_NODE
+ console.log("ENTITY_REFERENCE_NODE");
+ break;
+ case 6:
+ //ENTITY_NODE
+ console.log("ENTITY_NODE");
+ break;
+ case 7:
+ //PROCESSING_INSTRUCTION_NODE
+ console.log("PROCESSING_INSTRUCTION_NODE");
+ break;
+ case 8:
+ //COMMENT_NODE
+ console.log("COMMENT_NODE");
+ break;
+ case 9:
+ //DOCUMENT_NODE
+ console.log("DOCUMENT_NODE");
+ break;
+ case 10:
+ //DOCUMENT_TYPE_NODE
+ console.log("DOCUMENT_TYPE_NODE");
+ break;
+ case 11:
+ //DOCUMENT_TYPE_NODE
+ console.log("DOCUMENT_FRAGMENT_NODE");
+ break;
+ case 12:
+ //NOTATION_NODE
+ console.log("DOCUMENT_FRAGMENT_NODE");
+ break;
+ }
+}
+
+function validateFinalXML(xmlStr){
+
+ //console.dir(RED);
+ processedNode="";
+ resp=true;
+ errList=[];
+ elementCount=0;
+ //console.log("In validateXML xmlStr:" + xmlStr);
+ if(xmlStr == null || xmlStr == "") return true;
+ xmlStr = xmlStr.trim();
+ try{
+ var xmlDoc;
+ if (window.DOMParser){
+ try{
+ var parser=new DOMParser();
+ xmlDoc=parser.parseFromString(xmlStr,'text/xml');
+ //console.log("Not IE");
+ var n = xmlDoc.documentElement.nodeName;
+ if(n == "html"){
+ resp=false;
+ console.log("Error parsing");
+ return resp;
+ }
+ }catch(e){
+ console.log("Error parsing" +e);
+ return false;
+ }
+ }else{
+ try{
+ //console.log("IE");
+ // code for IE
+ xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
+ xmlDoc.async=false;
+ xmlDoc.loadXMLString(xmlStr);
+ }catch(e){
+ console.log("Error parsing" +e);
+ return false;
+ }
+ }
+
+ //console.dir(xmlDoc);
+ processNode(xmlDoc.documentElement);
+
+ if(resp){
+ console.log("Validation Successful");
+ RED.notify("<strong>XML validation</strong>: SUCCESS","success");
+ }else{
+ console.log("Errors found. ");
+ RED.notify("<strong>XML validation</strong>: FAILED","error");
+ }
+ }catch(e){
+ console.log("error:" +e);
+ RED.notify("<strong>XML validation</strong>: FAILED","error");
+ resp=false;
+ return resp;
+ }
+ return resp;
+}
+
+function validateXML(xmlStr){
+
+ //console.dir(RED);
+ processedNode="";
+ resp=true;
+ errList=[];
+ elementCount=0;
+ //console.log("In validateXML xmlStr:" + xmlStr);
+ //var xmlStr = $("#node-input-xml-editor").text();
+ if(xmlStr == null || xmlStr == undefined){
+ xmlStr = $("#node-input-xml-editor").text();
+ }
+ if(xmlStr == undefined) return false;
+ //console.dir($("#node-input-xml-editor"));
+ //console.log("xmlStr:" + xmlStr);
+ xmlStr = xmlStr.trim();
+ var startTag ;
+ var endTag ;
+ try{
+ var re = /^[0-9]+/;
+ xmlStr = xmlStr.replace(re,'');
+ var regex = /(<)([\w-]+)(.*)?/;
+ var match = regex.exec(xmlStr);
+ if(match != null){
+ if(match[1] != undefined && match[2] != undefined){
+ startTag = match[2];
+ }
+ }else{
+ resp=false;
+ showMsg("startTag not found.","red");
+ return resp;
+ }
+ }catch(e){
+ console.log(e);
+ return false;
+ }
+ //console.log(xmlStr);
+ if(xmlStr == ""){
+ resp=false;
+ showMsg("XML not found","red");
+ return resp;
+ }
+ endTag = "</" + startTag + ">";
+
+ if(xmlStr.indexOf(endTag) != -1){
+ resp=false;
+ showMsg("Error: End tag &lt;/" + startTag + "&gt; must not be included.","red");
+ console.log("End tag " + endTag + " must not be included.");
+ return resp;
+ }
+ try{
+ //var xmlTopStr = "<?xml version='1.0' encoding='UTF-8'?>\n" ;
+ //xmlStr = xmlTopStr + xmlStr;
+ //xmlStr = xmlStr.replace(/'/g,"\"");
+ xmlStr+= "\n" + endTag;
+ xmlStr = xmlStr.trim();
+ //console.log("xmlStr:" + xmlStr);
+ var xmlDoc;
+ if (window.DOMParser){
+ try{
+ var parser=new DOMParser();
+ xmlDoc=parser.parseFromString(xmlStr,'text/xml');
+ //console.log("Not IE");
+ var n = xmlDoc.documentElement.nodeName;
+ if(n == "html"){
+ resp=false;
+ showMsg("Error parsing","red");
+ console.log("Error parsing");
+ return resp;
+ }
+ }catch(e){
+ console.log("Error parsing" +e);
+ return false;
+ }
+ }else{
+ try{
+ //console.log("IE");
+ // code for IE
+ xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
+ xmlDoc.async=false;
+ xmlDoc.loadXMLString(xmlStr);
+ }catch(e){
+ console.log("Error parsing" +e);
+ return false;
+ }
+ }
+
+ //console.dir(xmlDoc);
+ processNode(xmlDoc.documentElement);
+ if(resp){
+ showMsg("Validation Successful","green");
+ }else{
+ showMsg("Errors found. <a onclick='javascript:showErrors()'>show errors</a>","red");
+ console.log("Errors found. ");
+ }
+ }catch(e){
+ console.log("error:" +e);
+ showMsg(e,"red");
+ resp=false;
+ return resp;
+ }
+ return resp;
+}
+
+function showErrors() {
+ //var sourceField = event != null ?event.srcElement:event.target;
+ //console.dir(sourceField);
+ //sourceField.style.backgroundColor="skyblue";
+ //var leftVal = event.target.offsetLeft ;
+ //alert(topVal + ":" + leftVal);
+ /*left:leftVal,*/
+ //var pos = event.target;
+ //var topVal = event.target.offsetTop + topPosition ;
+ //var topVal = event.target.offsetTop +75;
+ var htmlStr="<div id='error-list-div'><table id='errTable' border='1'><tr><th>Error List</th></tr>";
+ for(var i=0;errList != null && i<errList.length;i++){
+ var errSeq = i+1;
+ htmlStr += "<tr><td>" + errSeq + ")" + errList[i] + "</td></tr>";
+ }
+ htmlStr += "</table></div>";
+ //var prevHtml = $("#tab-info").html();
+ //htmlStr += "<input type='button' value='Hide Errors' onclick=\"closeShowErrors('" + prevHtml + "')\" >";
+ //$('#show-errors-div').html(htmlStr);
+ //$("#tab-info").html(prevHtml + htmlStr);
+
+ //$('<div></div>').dialog({
+ $('#show-errors-dialog').dialog({
+ modal: true,
+ title: "XML Error List ",
+ width: 500,
+ open: function () {
+ $(this).html(htmlStr);
+ },
+ buttons: {
+ Close: function () {
+ $(this).dialog("close");
+ }
+ }
+ }); // end dialog div
+}
diff --git a/dgbuilder/public/util/js/vkbeautify.0.99.00.beta.js b/dgbuilder/public/util/js/vkbeautify.0.99.00.beta.js
new file mode 100644
index 00000000..13cee3a5
--- /dev/null
+++ b/dgbuilder/public/util/js/vkbeautify.0.99.00.beta.js
@@ -0,0 +1,358 @@
+/**
+* vkBeautify - javascript plugin to pretty-print or minify text in XML, JSON, CSS and SQL formats.
+*
+* Version - 0.99.00.beta
+* Copyright (c) 2012 Vadim Kiryukhin
+* vkiryukhin @ gmail.com
+* http://www.eslinstructor.net/vkbeautify/
+*
+* Dual licensed under the MIT and GPL licenses:
+* http://www.opensource.org/licenses/mit-license.php
+* http://www.gnu.org/licenses/gpl.html
+*
+* Pretty print
+*
+* vkbeautify.xml(text [,indent_pattern]);
+* vkbeautify.json(text [,indent_pattern]);
+* vkbeautify.css(text [,indent_pattern]);
+* vkbeautify.sql(text [,indent_pattern]);
+*
+* @text - String; text to beatufy;
+* @indent_pattern - Integer | String;
+* Integer: number of white spaces;
+* String: character string to visualize indentation ( can also be a set of white spaces )
+* Minify
+*
+* vkbeautify.xmlmin(text [,preserve_comments]);
+* vkbeautify.jsonmin(text);
+* vkbeautify.cssmin(text [,preserve_comments]);
+* vkbeautify.sqlmin(text);
+*
+* @text - String; text to minify;
+* @preserve_comments - Bool; [optional];
+* Set this flag to true to prevent removing comments from @text ( minxml and mincss functions only. )
+*
+* Examples:
+* vkbeautify.xml(text); // pretty print XML
+* vkbeautify.json(text, 4 ); // pretty print JSON
+* vkbeautify.css(text, '. . . .'); // pretty print CSS
+* vkbeautify.sql(text, '----'); // pretty print SQL
+*
+* vkbeautify.xmlmin(text, true);// minify XML, preserve comments
+* vkbeautify.jsonmin(text);// minify JSON
+* vkbeautify.cssmin(text);// minify CSS, remove comments ( default )
+* vkbeautify.sqlmin(text);// minify SQL
+*
+*/
+
+(function() {
+
+function createShiftArr(step) {
+
+ var space = ' ';
+
+ if ( isNaN(parseInt(step)) ) { // argument is string
+ space = step;
+ } else { // argument is integer
+ switch(step) {
+ case 1: space = ' '; break;
+ case 2: space = ' '; break;
+ case 3: space = ' '; break;
+ case 4: space = ' '; break;
+ case 5: space = ' '; break;
+ case 6: space = ' '; break;
+ case 7: space = ' '; break;
+ case 8: space = ' '; break;
+ case 9: space = ' '; break;
+ case 10: space = ' '; break;
+ case 11: space = ' '; break;
+ case 12: space = ' '; break;
+ }
+ }
+
+ var shift = ['\n']; // array of shifts
+ for(ix=0;ix<100;ix++){
+ shift.push(shift[ix]+space);
+ }
+ return shift;
+}
+
+function vkbeautify(){
+ this.step = ' '; // 4 spaces
+ this.shift = createShiftArr(this.step);
+};
+
+vkbeautify.prototype.xml = function(text,step) {
+
+ var ar = text.replace(/>\s{0,}</g,"><")
+ .replace(/</g,"~::~<")
+ .replace(/\s*xmlns\:/g,"~::~xmlns:")
+ .replace(/\s*xmlns\=/g,"~::~xmlns=")
+ .split('~::~'),
+ len = ar.length,
+ inComment = false,
+ deep = 0,
+ str = '',
+ ix = 0,
+ shift = step ? createShiftArr(step) : this.shift;
+
+ for(ix=0;ix<len;ix++) {
+ // start comment or <![CDATA[...]]> or <!DOCTYPE //
+ if(ar[ix].search(/<!/) > -1) {
+ str += shift[deep]+ar[ix];
+ inComment = true;
+ // end comment or <![CDATA[...]]> //
+ if(ar[ix].search(/-->/) > -1 || ar[ix].search(/\]>/) > -1 || ar[ix].search(/!DOCTYPE/) > -1 ) {
+ inComment = false;
+ }
+ } else
+ // end comment or <![CDATA[...]]> //
+ if(ar[ix].search(/-->/) > -1 || ar[ix].search(/\]>/) > -1) {
+ str += ar[ix];
+ inComment = false;
+ } else
+ // <elm></elm> //
+ if( /^<\w/.exec(ar[ix-1]) && /^<\/\w/.exec(ar[ix]) &&
+ /^<[\w:\-\.\,]+/.exec(ar[ix-1]) == /^<\/[\w:\-\.\,]+/.exec(ar[ix])[0].replace('/','')) {
+ str += ar[ix];
+ if(!inComment) deep--;
+ } else
+ // <elm> //
+ if(ar[ix].search(/<\w/) > -1 && ar[ix].search(/<\//) == -1 && ar[ix].search(/\/>/) == -1 ) {
+ str = !inComment ? str += shift[deep++]+ar[ix] : str += ar[ix];
+ } else
+ // <elm>...</elm> //
+ if(ar[ix].search(/<\w/) > -1 && ar[ix].search(/<\//) > -1) {
+ str = !inComment ? str += shift[deep]+ar[ix] : str += ar[ix];
+ } else
+ // </elm> //
+ if(ar[ix].search(/<\//) > -1) {
+ str = !inComment ? str += shift[--deep]+ar[ix] : str += ar[ix];
+ } else
+ // <elm/> //
+ if(ar[ix].search(/\/>/) > -1 ) {
+ str = !inComment ? str += shift[deep]+ar[ix] : str += ar[ix];
+ } else
+ // <? xml ... ?> //
+ if(ar[ix].search(/<\?/) > -1) {
+ str += shift[deep]+ar[ix];
+ } else
+ // xmlns //
+ if( ar[ix].search(/xmlns\:/) > -1 || ar[ix].search(/xmlns\=/) > -1) {
+ str += shift[deep]+ar[ix];
+ }
+
+ else {
+ str += ar[ix];
+ }
+ }
+
+ return (str[0] == '\n') ? str.slice(1) : str;
+}
+
+vkbeautify.prototype.json = function(text,step) {
+
+ var step = step ? step : this.step;
+
+ if (typeof JSON === 'undefined' ) return text;
+
+ if ( typeof text === "string" ) return JSON.stringify(JSON.parse(text), null, step);
+ if ( typeof text === "object" ) return JSON.stringify(text, null, step);
+
+ return text; // text is not string nor object
+}
+
+vkbeautify.prototype.css = function(text, step) {
+
+ var ar = text.replace(/\s{1,}/g,' ')
+ .replace(/\{/g,"{~::~")
+ .replace(/\}/g,"~::~}~::~")
+ .replace(/\;/g,";~::~")
+ .replace(/\/\*/g,"~::~/*")
+ .replace(/\*\//g,"*/~::~")
+ .replace(/~::~\s{0,}~::~/g,"~::~")
+ .split('~::~'),
+ len = ar.length,
+ deep = 0,
+ str = '',
+ ix = 0,
+ shift = step ? createShiftArr(step) : this.shift;
+
+ for(ix=0;ix<len;ix++) {
+
+ if( /\{/.exec(ar[ix])) {
+ str += shift[deep++]+ar[ix];
+ } else
+ if( /\}/.exec(ar[ix])) {
+ str += shift[--deep]+ar[ix];
+ } else
+ if( /\*\\/.exec(ar[ix])) {
+ str += shift[deep]+ar[ix];
+ }
+ else {
+ str += shift[deep]+ar[ix];
+ }
+ }
+ return str.replace(/^\n{1,}/,'');
+}
+
+//----------------------------------------------------------------------------
+
+function isSubquery(str, parenthesisLevel) {
+ return parenthesisLevel - (str.replace(/\(/g,'').length - str.replace(/\)/g,'').length )
+}
+
+function split_sql(str, tab) {
+
+ return str.replace(/\s{1,}/g," ")
+
+ .replace(/ AND /ig,"~::~"+tab+tab+"AND ")
+ .replace(/ BETWEEN /ig,"~::~"+tab+"BETWEEN ")
+ .replace(/ CASE /ig,"~::~"+tab+"CASE ")
+ .replace(/ ELSE /ig,"~::~"+tab+"ELSE ")
+ .replace(/ END /ig,"~::~"+tab+"END ")
+ .replace(/ FROM /ig,"~::~FROM ")
+ .replace(/ GROUP\s{1,}BY/ig,"~::~GROUP BY ")
+ .replace(/ HAVING /ig,"~::~HAVING ")
+ //.replace(/ SET /ig," SET~::~")
+ .replace(/ IN /ig," IN ")
+
+ .replace(/ JOIN /ig,"~::~JOIN ")
+ .replace(/ CROSS~::~{1,}JOIN /ig,"~::~CROSS JOIN ")
+ .replace(/ INNER~::~{1,}JOIN /ig,"~::~INNER JOIN ")
+ .replace(/ LEFT~::~{1,}JOIN /ig,"~::~LEFT JOIN ")
+ .replace(/ RIGHT~::~{1,}JOIN /ig,"~::~RIGHT JOIN ")
+
+ .replace(/ ON /ig,"~::~"+tab+"ON ")
+ .replace(/ OR /ig,"~::~"+tab+tab+"OR ")
+ .replace(/ ORDER\s{1,}BY/ig,"~::~ORDER BY ")
+ .replace(/ OVER /ig,"~::~"+tab+"OVER ")
+
+ .replace(/\(\s{0,}SELECT /ig,"~::~(SELECT ")
+ .replace(/\)\s{0,}SELECT /ig,")~::~SELECT ")
+
+ .replace(/ THEN /ig," THEN~::~"+tab+"")
+ .replace(/ UNION /ig,"~::~UNION~::~")
+ .replace(/ USING /ig,"~::~USING ")
+ .replace(/ WHEN /ig,"~::~"+tab+"WHEN ")
+ .replace(/ WHERE /ig,"~::~WHERE ")
+ .replace(/ WITH /ig,"~::~WITH ")
+
+ //.replace(/\,\s{0,}\(/ig,",~::~( ")
+ //.replace(/\,/ig,",~::~"+tab+tab+"")
+
+ .replace(/ ALL /ig," ALL ")
+ .replace(/ AS /ig," AS ")
+ .replace(/ ASC /ig," ASC ")
+ .replace(/ DESC /ig," DESC ")
+ .replace(/ DISTINCT /ig," DISTINCT ")
+ .replace(/ EXISTS /ig," EXISTS ")
+ .replace(/ NOT /ig," NOT ")
+ .replace(/ NULL /ig," NULL ")
+ .replace(/ LIKE /ig," LIKE ")
+ .replace(/\s{0,}SELECT /ig,"SELECT ")
+ .replace(/\s{0,}UPDATE /ig,"UPDATE ")
+ .replace(/ SET /ig," SET ")
+
+ .replace(/~::~{1,}/g,"~::~")
+ .split('~::~');
+}
+
+vkbeautify.prototype.sql = function(text,step) {
+
+ var ar_by_quote = text.replace(/\s{1,}/g," ")
+ .replace(/\'/ig,"~::~\'")
+ .split('~::~'),
+ len = ar_by_quote.length,
+ ar = [],
+ deep = 0,
+ tab = this.step,//+this.step,
+ inComment = true,
+ inQuote = false,
+ parenthesisLevel = 0,
+ str = '',
+ ix = 0,
+ shift = step ? createShiftArr(step) : this.shift;;
+
+ for(ix=0;ix<len;ix++) {
+ if(ix%2) {
+ ar = ar.concat(ar_by_quote[ix]);
+ } else {
+ ar = ar.concat(split_sql(ar_by_quote[ix], tab) );
+ }
+ }
+
+ len = ar.length;
+ for(ix=0;ix<len;ix++) {
+
+ parenthesisLevel = isSubquery(ar[ix], parenthesisLevel);
+
+ if( /\s{0,}\s{0,}SELECT\s{0,}/.exec(ar[ix])) {
+ ar[ix] = ar[ix].replace(/\,/g,",\n"+tab+tab+"")
+ }
+
+ if( /\s{0,}\s{0,}SET\s{0,}/.exec(ar[ix])) {
+ ar[ix] = ar[ix].replace(/\,/g,",\n"+tab+tab+"")
+ }
+
+ if( /\s{0,}\(\s{0,}SELECT\s{0,}/.exec(ar[ix])) {
+ deep++;
+ str += shift[deep]+ar[ix];
+ } else
+ if( /\'/.exec(ar[ix]) ) {
+ if(parenthesisLevel<1 && deep) {
+ deep--;
+ }
+ str += ar[ix];
+ }
+ else {
+ str += shift[deep]+ar[ix];
+ if(parenthesisLevel<1 && deep) {
+ deep--;
+ }
+ }
+ var junk = 0;
+ }
+
+ str = str.replace(/^\n{1,}/,'').replace(/\n{1,}/g,"\n");
+ return str;
+}
+
+
+vkbeautify.prototype.xmlmin = function(text, preserveComments) {
+
+ var str = preserveComments ? text
+ : text.replace(/\<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)\>/g,"")
+ .replace(/[ \r\n\t]{1,}xmlns/g, ' xmlns');
+ return str.replace(/>\s{0,}</g,"><");
+}
+
+vkbeautify.prototype.jsonmin = function(text) {
+
+ if (typeof JSON === 'undefined' ) return text;
+
+ return JSON.stringify(JSON.parse(text), null, 0);
+
+}
+
+vkbeautify.prototype.cssmin = function(text, preserveComments) {
+
+ var str = preserveComments ? text
+ : text.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"") ;
+
+ return str.replace(/\s{1,}/g,' ')
+ .replace(/\{\s{1,}/g,"{")
+ .replace(/\}\s{1,}/g,"}")
+ .replace(/\;\s{1,}/g,";")
+ .replace(/\/\*\s{1,}/g,"/*")
+ .replace(/\*\/\s{1,}/g,"*/");
+}
+
+vkbeautify.prototype.sqlmin = function(text) {
+ return text.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")");
+}
+
+window.vkbeautify = new vkbeautify();
+
+})();
+