Chinthakayala, Sheshashailavas (sc2914) | d156997 | 2017-08-28 05:25:46 -0900 | [diff] [blame] | 1 | function getDgStartNode(nodeList){ |
| 2 | for(var i=0;i<nodeList.length;i++){ |
| 3 | if(nodeList[i].type == 'dgstart' && nodeList[i].wires != null && nodeList[i].wires != undefined){ |
| 4 | return nodeList[i]; |
| 5 | } |
| 6 | } |
| 7 | RED.notify("DGSTART node not found."); |
| 8 | return null; |
| 9 | } |
| 10 | |
| 11 | |
| 12 | var loopDetectionEnabled = true; |
| 13 | |
| 14 | function detectLoopPrev(){ |
| 15 | var activeWorkspace=RED.view.getWorkspace(); |
| 16 | /* |
| 17 | RED.nodes.links.filter(function(d) { |
| 18 | if(d.source.z == activeWorkspace && d.target.z == activeWorkspace){ |
| 19 | console.log(d.source.id+":"+d.sourcePort+":"+d.target.id); |
| 20 | } |
| 21 | }); |
| 22 | */ |
| 23 | //console.dir(RED.nodes.links); |
| 24 | var nSet=[]; |
| 25 | |
| 26 | RED.nodes.eachNode(function(n) { |
| 27 | if (n.z == activeWorkspace) { |
| 28 | nSet.push({'n':n}); |
| 29 | } |
| 30 | }); |
| 31 | |
| 32 | var nodeSet = RED.nodes.createExportableNodeSet(nSet); |
| 33 | //console.dir(nodeSet); |
| 34 | |
| 35 | //console.log("nodeSet length:" + nodeSet.length); |
| 36 | |
| 37 | var isLoopDetected = false; |
| 38 | var dgStartNode = getDgStartNode(nodeSet); |
| 39 | if(dgStartNode == null || dgStartNode == undefined) { |
| 40 | console.log("dgstart node not linked."); |
| 41 | return true; |
| 42 | } |
| 43 | |
| 44 | var wires = dgStartNode.wires; |
| 45 | var nodesInPath = {}; |
| 46 | var dgStartNodeId = dgStartNode.id; |
| 47 | if(wires != null && wires != undefined && wires[0] != undefined){ |
| 48 | for(var k=0;k<wires[0].length;k++){ |
| 49 | var val = wires[0][k]; |
| 50 | nodesInPath[dgStartNodeId + "->" + val] = ""; |
| 51 | } |
| 52 | }else{ |
| 53 | nodesInPath[dgStartNodeId + "->" + ""] = ""; |
| 54 | } |
| 55 | |
| 56 | //console.dir(nodesInPath); |
| 57 | var loopDetectedObj = {}; |
| 58 | /* the nodes will not be order so will need to loop thru again */ |
| 59 | for(var m=0;nodeSet != null && m<nodeSet.length;m++){ |
| 60 | for(var i=0;nodeSet != null && i<nodeSet.length;i++){ |
| 61 | var link=nodeSet[i].id; |
| 62 | //console.log("NAME:" + nodeSet[i].name + ":" + link); |
| 63 | if(link == dgStartNodeId) continue; |
| 64 | var wires = nodeSet[i].wires; |
| 65 | //console.log("link:" + link); |
| 66 | var delKeys = []; |
| 67 | if(wires != null && wires != undefined && wires[0] != undefined){ |
| 68 | for(var k=0;k<wires[0].length;k++){ |
| 69 | var val = (wires[0])[k]; |
| 70 | var keys = Object.keys(nodesInPath); |
| 71 | //console.log("keys:" + keys); |
| 72 | for (var j=0;j<keys.length;j++){ |
| 73 | //console.log("key:" + keys[j]); |
| 74 | //console.log("val:" + val); |
| 75 | var index = -1; |
| 76 | if(keys[j] != null){ |
| 77 | index = keys[j].indexOf("->" + link); |
| 78 | } |
| 79 | var lastIndex = keys[j].lastIndexOf("->"); |
| 80 | if(index != -1 && index == lastIndex){ |
| 81 | //delete nodesInPath[key]; |
| 82 | var previousNodeId = keys[j].substr(lastIndex +2); |
| 83 | var indexOfArrow = -1; |
| 84 | if(previousNodeId != ""){ |
| 85 | indexOfArrow = previousNodeId.indexOf("->"); |
| 86 | } |
| 87 | if(previousNodeId != null && indexOfArrow != -1){ |
| 88 | previousNodeId = previousNodeId.substr(0,indexOfArrow); |
| 89 | } |
| 90 | nodesInPath[keys[j] + "->" + val] = ""; |
| 91 | //console.log("keys[j]:" + keys[j]); |
| 92 | delKeys.push(keys[j]); |
| 93 | var prevNodeIdIndex = keys[j].indexOf("->" + previousNodeId); |
| 94 | var priorOccurence = keys[j].indexOf(val + "->"); |
| 95 | if(priorOccurence != -1 && priorOccurence<prevNodeIdIndex){ |
| 96 | //console.log("previousNodeId:" + previousNodeId); |
| 97 | //console.log("val:" + val); |
| 98 | var n1 = getNode(nodeSet,previousNodeId); |
| 99 | var n2 = getNode(nodeSet,val); |
| 100 | //console.log("loop detected for node " + n1.name + " and " + n2.name); |
| 101 | loopDetectedObj[n1.name + "->" + n2.name] ="looped"; |
| 102 | //console.dir(loopDetectedObj); |
| 103 | isLoopDetected = true; |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | for(var l=0;delKeys != null && l<delKeys.length;l++){ |
| 110 | delete nodesInPath[delKeys[l]]; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | |
| 115 | } |
| 116 | if(loopDetectedObj != null ){ |
| 117 | var msg = ""; |
| 118 | for(var key in loopDetectedObj){ |
| 119 | if(loopDetectedObj.hasOwnProperty(key)) { |
| 120 | console.log("Loop detected " + key); |
| 121 | msg += "<strong>Loop detected for:" + key + "</strong><br>"; |
| 122 | } |
| 123 | } |
| 124 | if(msg != ""){ |
| 125 | isLoopDetected = true; |
| 126 | RED.notify(msg); |
| 127 | } |
| 128 | } |
| 129 | /* |
| 130 | for(var i=0;nodeSet != null && i<nodeSet.length;i++){ |
| 131 | var foundCount=0; |
| 132 | var nodeId = nodeSet[i].id; |
| 133 | var nodeName = nodeSet[i].name; |
| 134 | for(var j=0;nodeSet != null && j<nodeSet.length;j++){ |
| 135 | var node = nodeSet[j]; |
| 136 | if(node.id == nodeId){ |
| 137 | continue; |
| 138 | } |
| 139 | var wires = node.wires; |
| 140 | console.log(node.type + ":wires:" + wires); |
| 141 | for(var k=0;wires != null && wires != undefined && wires[0] != undefined && k<wires[0].length;k++){ |
| 142 | var id = (wires[0])[k]; |
| 143 | console.log(nodeName + ":" + nodeId + ":" + id); |
| 144 | if(id == nodeId ){ |
| 145 | foundCount++; |
| 146 | if(foundCount>1){ |
| 147 | console.log("Loop detected for node " + nodeName + "with node:" + node.name); |
| 148 | RED.notify("<strong>Flow error detected for node '" + nodeName + "' with node '" + node.name + "'</strong>"); |
| 149 | //RED.nodes.eachLink(function(d){ |
| 150 | // if(d.source.id == nodeSet[i] || d.target.id == nodeSet[j]){ |
| 151 | // d.selected = true; |
| 152 | // }else if(d.source.id == nodeSet[j] || d.target.id == nodeSet[i]){ |
| 153 | // d.selected = true; |
| 154 | // } |
| 155 | //}); |
| 156 | //RED.view.redraw(); |
| 157 | isLoopDetected = true; |
| 158 | return true; |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | } |
| 164 | } |
| 165 | */ |
| 166 | //console.log("isLoopDetected:" + isLoopDetected); |
| 167 | return isLoopDetected; |
| 168 | } |
| 169 | |
| 170 | function generateNodePath(nodeIdToNodeObj,nodeId,pathStr,nodesInPath,errList){ |
| 171 | var node = nodeIdToNodeObj[nodeId]; |
| 172 | var wires = node.wires; |
| 173 | if(wires != null && wires != undefined && wires[0] != undefined){ |
| 174 | for(var k=0;k<wires[0].length;k++){ |
| 175 | var val = wires[0][k]; |
| 176 | if(pathStr.indexOf(val + "->") != -1){ |
| 177 | //console.log("pathStr:" + pathStr); |
| 178 | var n1= nodeIdToNodeObj[nodeId].name; |
| 179 | var n2= nodeIdToNodeObj[val].name; |
| 180 | errList.push("Loop detected between nodes '" + n1 + "' and " + "'" + n2 + "'"); |
| 181 | }else{ |
| 182 | pathStr += "->" + val ; |
| 183 | generateNodePath(nodeIdToNodeObj,val,pathStr,nodesInPath,errList); |
| 184 | } |
| 185 | } |
| 186 | }else{ |
| 187 | //pathStr += nodeId + "->" + ""; |
| 188 | nodesInPath.push(pathStr); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | function detectLoop(){ |
| 193 | var activeWorkspace=RED.view.getWorkspace(); |
| 194 | var nSet=[]; |
| 195 | var nodeIdToNodeObj = {}; |
| 196 | RED.nodes.eachNode(function(n) { |
| 197 | if (n.z == activeWorkspace) { |
| 198 | nSet.push({'n':n}); |
| 199 | } |
| 200 | }); |
| 201 | |
| 202 | var nodeSet = RED.nodes.createExportableNodeSet(nSet); |
| 203 | nodeIdToNodeObj = getNodeIdToNodeMap(nodeSet); |
| 204 | var isLoopDetected = false; |
| 205 | //var dgStartNode = getDgStartNode(nodeSet); |
| 206 | var dgStartNode = nodeIdToNodeObj["dgstart"]; |
| 207 | var errList = []; |
| 208 | var dgStartNodeId = dgStartNode.id; |
| 209 | var nodesInPathArr = []; |
| 210 | generateNodePath(nodeIdToNodeObj,dgStartNodeId,dgStartNodeId,nodesInPathArr,errList); |
| 211 | if(errList != null && errList != undefined && errList.length > 0){ |
| 212 | isLoopDetected = true; |
| 213 | var htmlStr="<div id='loop-detect-err-list-div'><table id='loopErrListTable' border='1'><tr><th>Error List</th></tr>"; |
| 214 | for(var j=0;errList != null && j<errList.length;j++){ |
| 215 | var errSeq = j+1; |
| 216 | htmlStr += "<tr><td>" + errSeq + ")" + errList[j] + "</td></tr>"; |
| 217 | } |
| 218 | htmlStr += "</table></div>"; |
| 219 | |
| 220 | $("#loop-detection-dialog").dialog({ |
| 221 | autoOpen : false, |
| 222 | modal: true, |
| 223 | title: "DG Flow validation Error List ", |
| 224 | width: 500, |
| 225 | buttons: { |
| 226 | Close: function () { |
| 227 | $("#loop-detection-dialog").dialog("close"); |
| 228 | } |
| 229 | } |
| 230 | }).dialog("open").html(htmlStr); // end dialog div |
| 231 | } |
| 232 | nodesInPathArr=null; |
| 233 | nodeSet ={}; |
| 234 | nodeIdToNodeObj={}; |
| 235 | return isLoopDetected; |
| 236 | } |
| 237 | |
| 238 | |
| 239 | var xmlNumberCnt = 0; |
| 240 | function processForXmlNumbers(nodeSet,node){ |
| 241 | if( node != null && node.type != 'dgstart'){ |
| 242 | if(node.xmlnumber != null && node.xmlnumber){ |
| 243 | node.xmlnumber.push(++xmlNumberCnt); |
| 244 | }else{ |
| 245 | node.xmlnumber = [++xmlNumberCnt]; |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | if(node != null && node.wires != null && node.wires.length>0){ |
| 250 | var wiredNodes=node.wires[0]; |
| 251 | var wiredNodesArr=[]; |
| 252 | for(var k=0;wiredNodes != undefined && wiredNodes != null && k<wiredNodes.length;k++){ |
| 253 | wiredNodesArr.push(getNode(nodeSet,wiredNodes[k])); |
| 254 | } |
| 255 | |
| 256 | //use this sort to sort by y position |
| 257 | wiredNodesArr.sort(function(a, b){ |
| 258 | return a.y-b.y; |
| 259 | }); |
| 260 | |
| 261 | for(var k=0;k<wiredNodesArr.length;k++){ |
| 262 | var n = wiredNodesArr[k]; |
| 263 | processForXmlNumbers(nodeSet,n); |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | function updateXmlNumbers(){ |
| 269 | xmlNumberCnt = 0; |
| 270 | var nodeSet = getCurrentFlowNodeSet(); |
| 271 | if(nodeSet == null && nodeSet.length >0){ |
| 272 | nodeSet.forEach(function(n){ |
| 273 | if(n.xmlnumber){ |
| 274 | delete n.xmlnumber; |
| 275 | } |
| 276 | }); |
| 277 | } |
| 278 | var dgStartNode = getDgStartNode(nodeSet); |
| 279 | processForXmlNumbers(nodeSet,dgStartNode); |
| 280 | var activeWorkspace=RED.view.getWorkspace(); |
| 281 | RED.nodes.eachNode(function(n) { |
| 282 | //console.log("Node processed in eachNode"); |
| 283 | if (n.z == activeWorkspace) { |
| 284 | if(n != null){ |
| 285 | var updatedNode = getNode(nodeSet,n.id); |
| 286 | //console.log("updated Node processed in eachNode"); |
| 287 | //console.dir(updatedNode); |
| 288 | |
| 289 | if (n.id == updatedNode.id) { |
| 290 | n.xmlnumber = updatedNode.xmlnumber; |
| 291 | n.dirty = true; |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | }); |
| 296 | } |
| 297 | |
| 298 | function getOutcomeValue(node){ |
| 299 | var xmlStr = ""; |
| 300 | if(node != null && node.xml != undefined && node.xml !=""){ |
| 301 | xmlStr = node.xml + "</outcome>"; |
| 302 | } |
| 303 | var xmlDoc; |
| 304 | if (window.DOMParser){ |
| 305 | try{ |
| 306 | var parser=new DOMParser(); |
| 307 | xmlDoc=parser.parseFromString(xmlStr,'text/xml'); |
| 308 | //console.log("Not IE"); |
| 309 | var n = xmlDoc.documentElement.nodeName; |
| 310 | if(n == "html"){ |
| 311 | resp=false; |
| 312 | console.log("Error parsing"); |
| 313 | return resp; |
| 314 | } |
| 315 | }catch(e){ |
| 316 | console.log("xmlStr:" + xmlStr); |
| 317 | console.log("Error parsing" +e); |
| 318 | return null; |
| 319 | } |
| 320 | }else{ |
| 321 | try{ |
| 322 | //console.log("IE"); |
| 323 | // code for IE |
| 324 | xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); |
| 325 | xmlDoc.async=false; |
| 326 | xmlDoc.loadXMLString(xmlStr); |
| 327 | }catch(e){ |
| 328 | console.log("xmlStr:" + xmlStr); |
| 329 | console.log("Error parsing" +e); |
| 330 | return null; |
| 331 | } |
| 332 | } |
| 333 | if(xmlDoc != null){ |
| 334 | var xmlNode = xmlDoc.documentElement; |
| 335 | //console.dir(xmlNode); |
| 336 | var processedNode = xmlNode.nodeName; |
| 337 | //console.log("processedNode:" + processedNode); |
| 338 | var attrs = xmlNode.attributes; |
| 339 | for(var i=0;i<attrs.length;i++){ |
| 340 | if(attrs[i].nodeName == "value"){ |
| 341 | return attrs[i].value; |
| 342 | } |
| 343 | } |
| 344 | } |
| 345 | return null; |
| 346 | } |
| 347 | |
| 348 | var dgNumberCnt = 0; |
| 349 | function processForDgNumbers(nodeSet,node){ |
| 350 | var outcomeTypes = [ "already-active", "failure", "not-found", "other", "outcomeFalse", "outcome", "outcomeTrue", "success" ]; |
| 351 | if( node != null && node.type != 'dgstart' && node.type != 'service-logic' && node.type != 'method' ){ |
| 352 | //console.log("child of " + parentNodeType + " :" + nodeType); |
| 353 | //check if NOT outcome node |
| 354 | if(outcomeTypes.indexOf(node.type) == -1){ |
| 355 | if(node.type == "GenericXML"){ |
| 356 | if(node.xml != undefined && node.xml != null && node.xml.indexOf("<outcome ") != -1){ |
| 357 | //this GenericXML node is used for outcome , so need to skip |
| 358 | }else{ |
| 359 | if(node.dgnumber != undefined && node.dgnumber != null && node.dgnumber){ |
| 360 | node.dgnumber.push(++dgNumberCnt); |
| 361 | }else{ |
| 362 | node.dgnumber = [++dgNumberCnt]; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | }else{ |
| 367 | if(node.dgnumber != undefined && node.dgnumber != null && node.dgnumber){ |
| 368 | node.dgnumber.push(++dgNumberCnt); |
| 369 | }else{ |
| 370 | node.dgnumber = [++dgNumberCnt]; |
| 371 | } |
| 372 | } |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | var hasOutcomeNodes = false; |
| 377 | if(node != null && node.wires != null && node.wires.length>0){ |
| 378 | var wiredNodes=node.wires[0]; |
| 379 | var wiredNodesArr=[]; |
| 380 | for(var k=0;wiredNodes != undefined && wiredNodes != null && k<wiredNodes.length;k++){ |
| 381 | var wiredNode = getNode(nodeSet,wiredNodes[k]); |
| 382 | //check if outcome node |
| 383 | if(outcomeTypes.indexOf(wiredNode.type) != -1){ |
| 384 | hasOutcomeNodes = true; |
| 385 | } |
| 386 | if(wiredNode.type == "GenericXML"){ |
| 387 | if( node.xml != undefined && node.xml != null && node.xml.indexOf("<outcome ") != -1){ |
| 388 | //this GenericXML node is used for outcome |
| 389 | hasOutcomeNodes = true; |
| 390 | } |
| 391 | } |
| 392 | wiredNodesArr.push(wiredNode); |
| 393 | |
| 394 | } |
| 395 | |
| 396 | //use this sort to sort by y position |
| 397 | wiredNodesArr.sort(function(a, b){ |
| 398 | return a.y-b.y; |
| 399 | }); |
| 400 | |
| 401 | /* |
| 402 | //USE THIS LOGIC TO SORT BY OUTCOME VALUE FOR SPECIFIC NODES |
| 403 | var parentNodeType = node.type; |
| 404 | if(hasOutcomeNodes && parentNodeType != 'switchNode' && parentNodeType != 'block' && parentNodeType != 'configure' ){ |
| 405 | //use the value of outcome to sort the wired nodes |
| 406 | wiredNodesArr.sort(function(a, b){ |
| 407 | var val1 = getOutcomeValue(a); |
| 408 | var val2 = getOutcomeValue(b); |
| 409 | //console.log("val1:" + val1); |
| 410 | //console.log("val2:" + val2); |
| 411 | if ( val1 < val2 ){ |
| 412 | return -1; |
| 413 | }else if ( val1 > val2 ){ |
| 414 | return 1; |
| 415 | }else{ |
| 416 | return 0; |
| 417 | } |
| 418 | }); |
| 419 | }else{ |
| 420 | //use this sort to sort by y position |
| 421 | wiredNodesArr.sort(function(a, b){ |
| 422 | return a.y-b.y; |
| 423 | }); |
| 424 | } |
| 425 | |
| 426 | */ |
| 427 | |
| 428 | for(var k=0;k<wiredNodesArr.length;k++){ |
| 429 | var n = wiredNodesArr[k]; |
| 430 | processForDgNumbers(nodeSet,n); |
| 431 | } |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | function updateDgNumbers(){ |
| 436 | dgNumberCnt = 0; |
| 437 | var nodeSet = getCurrentFlowNodeSet(); |
| 438 | if(nodeSet == null && nodeSet.length >0){ |
| 439 | nodeSet.forEach(function(n){ |
| 440 | if(n.dgnumber){ |
| 441 | delete n.dgnumber; |
| 442 | } |
| 443 | }); |
| 444 | } |
| 445 | var dgStartNode = getDgStartNode(nodeSet); |
| 446 | processForDgNumbers(nodeSet,dgStartNode); |
| 447 | var activeWorkspace=RED.view.getWorkspace(); |
| 448 | RED.nodes.eachNode(function(n) { |
| 449 | //console.log("Node processed in eachNode"); |
| 450 | if (n.z == activeWorkspace) { |
| 451 | if(n != null){ |
| 452 | var updatedNode = getNode(nodeSet,n.id); |
| 453 | //console.log("updated Node processed in eachNode"); |
| 454 | //console.dir(updatedNode); |
| 455 | |
| 456 | if (n.id == updatedNode.id) { |
| 457 | //console.log(n.type + ":" + updatedNode.dgnumber); |
| 458 | n.dgnumber = updatedNode.dgnumber; |
| 459 | n.dirty = true; |
| 460 | } |
| 461 | } |
| 462 | } |
| 463 | }); |
| 464 | return nodeSet; |
| 465 | } |
| 466 | |
| 467 | function customValidation(currNodeSet){ |
| 468 | //validation to make sure there a block node infront of mutiple dgelogic nodes |
| 469 | flowDesignErrors=[]; |
| 470 | var dgStartCnt=0; |
| 471 | var serviceLogicCnt=0; |
| 472 | var methodCnt=0; |
| 473 | for(var i=0;currNodeSet != null && i<currNodeSet.length;i++){ |
| 474 | var node = currNodeSet[i]; |
| 475 | var parentNodeName = node.name; |
| 476 | var parentNodeType = node.type; |
| 477 | var dgNumber = node.dgnumber; |
| 478 | if(parentNodeType == 'dgstart'){ |
| 479 | dgStartCnt++; |
| 480 | } |
| 481 | if(parentNodeType == 'service-logic'){ |
| 482 | serviceLogicCnt++; |
| 483 | } |
| 484 | if(parentNodeType == 'method'){ |
| 485 | methodCnt++; |
| 486 | } |
| 487 | if(parentNodeType == "GenericXML"){ |
| 488 | if( node.xml != undefined && node.xml != null && node.xml.indexOf("<service-logic ") != -1 ){ |
| 489 | //this GenericXML node is used for service-logic |
| 490 | serviceLogicCnt++; |
| 491 | }else if( node.xml != undefined && node.xml != null && node.xml.indexOf("<method ") != -1 ){ |
| 492 | //this GenericXML node is used for method |
| 493 | methodCnt++; |
| 494 | }else if( node.xml != undefined && node.xml != null && node.xml.indexOf("<block") != -1 ){ |
| 495 | //this GenericXML node is used for block |
| 496 | parentNodeType = "block"; |
| 497 | } |
| 498 | } |
| 499 | if(node != null && node.wires != null && node.wires.length>0){ |
| 500 | var wiredNodes=node.wires[0]; |
| 501 | var wiredNodesArr=[]; |
| 502 | for(var k=0;wiredNodes != undefined && wiredNodes != null && k<wiredNodes.length;k++){ |
| 503 | wiredNodesArr.push(getNode(currNodeSet,wiredNodes[k])); |
| 504 | } |
| 505 | var countChildLogicNodes =0; |
| 506 | for(var k=0;k<wiredNodesArr.length;k++){ |
| 507 | var n = wiredNodesArr[k]; |
| 508 | var nodeType = n.type; |
| 509 | var outcomeTypes = [ "already-active", "failure", "not-found", "other", "outcomeFalse", "outcome", "outcomeTrue", "success" ]; |
| 510 | var isOutcomeOrSetNode = false; |
| 511 | if(nodeType == "GenericXML"){ |
| 512 | if( n.xml != undefined && n.xml != null && (n.xml.indexOf("<outcome ") != -1 || n.xml.indexOf("<set ") != -1)){ |
| 513 | //this GenericXML node is used for outcome |
| 514 | isOutcomeOrSetNode = true; |
| 515 | } |
| 516 | } |
| 517 | //console.log("child of " + parentNodeType + " :" + nodeType); |
| 518 | if(outcomeTypes.indexOf(nodeType) > -1 ||nodeType == 'set' || isOutcomeOrSetNode){ |
| 519 | //its a outcome or set node |
| 520 | }else{ |
| 521 | countChildLogicNodes++; |
| 522 | } |
| 523 | |
| 524 | //console.log("parentNodeType:" + parentNodeType); |
| 525 | if(countChildLogicNodes >1 && parentNodeType != 'block' && parentNodeType != 'for' ){ |
| 526 | if(node.dgnumber != undefined && node.dgnumber){ |
| 527 | 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] ); |
| 528 | }else{ |
| 529 | flowDesignErrors.push("Warning:May need a block Node after Node <br><span style='color:red'>Node name:</span>" + parentNodeName); |
| 530 | } |
| 531 | break; |
| 532 | } |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | if(dgStartCnt > 1){ |
| 537 | flowDesignErrors.push("Error:There should only be 1 dgstart Node in the current workspace."); |
| 538 | } |
| 539 | |
| 540 | if(serviceLogicCnt > 1){ |
| 541 | flowDesignErrors.push("Error:There should only be 1 service-logic Node in the current workspace."); |
| 542 | } |
| 543 | |
| 544 | if(methodCnt > 1){ |
| 545 | flowDesignErrors.push("Error:There should only be 1 method Node in the current workspace."); |
| 546 | } |
| 547 | |
| 548 | if(flowDesignErrors != null && flowDesignErrors.length >0){ |
| 549 | return false; |
| 550 | } |
| 551 | return true; |
| 552 | } |
| 553 | |
| 554 | var flowDesignErrors = []; |
| 555 | function showFlowDesignErrorBox(){ |
| 556 | if(flowDesignErrors != null && flowDesignErrors.length >0){ |
| 557 | var htmlStr="<div id='flowpath-err-list-div'><table id='fpeTable' border='1'><tr><th>Error List</th></tr>"; |
| 558 | for(var j=0;flowDesignErrors != null && j<flowDesignErrors.length;j++){ |
| 559 | var errSeq = j+1; |
| 560 | htmlStr += "<tr><td>" + errSeq + ")" + flowDesignErrors[j] + "</td></tr>"; |
| 561 | } |
| 562 | htmlStr += "</table></div>"; |
| 563 | |
| 564 | //$('<div></div>').dialog({ |
| 565 | |
| 566 | $('#flow-design-err-dialog').dialog({ |
| 567 | modal: true, |
| 568 | title: "Flow design Error List ", |
| 569 | width: 500, |
| 570 | /*open: function () { |
| 571 | $(this).html(htmlStr); |
| 572 | },*/ |
| 573 | buttons: { |
| 574 | Close: function () { |
| 575 | $(this).dialog("close"); |
| 576 | } |
| 577 | } |
| 578 | }).html(htmlStr); // end dialog div |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | |
| 583 | function getCurrentFlowNodeSet(){ |
| 584 | var nodeSet=[]; |
| 585 | //console.dir(RED); |
| 586 | //RED.view.dirty(); |
| 587 | //RED.view.redraw(); |
| 588 | var activeWorkspace=RED.view.getWorkspace(); |
| 589 | RED.nodes.eachNode(function(n) { |
| 590 | if (n.z == activeWorkspace) { |
| 591 | nodeSet.push({'n':n}); |
| 592 | } |
| 593 | }); |
| 594 | |
| 595 | var exportableNodeSet = RED.nodes.createExportableNodeSet(nodeSet); |
| 596 | //console.dir(exportableNodeSet); |
| 597 | //console.log(JSON.stringify(exportableNodeSet)); |
| 598 | return exportableNodeSet; |
| 599 | } |
| 600 | |
| 601 | function getNode(nodeSet,id){ |
| 602 | for(var i=0;i<nodeSet.length;i++){ |
| 603 | if(nodeSet[i].id == id){ |
| 604 | return nodeSet[i]; |
| 605 | } |
| 606 | } |
| 607 | return null; |
| 608 | } |
| 609 | function getNodeIdToNodeMap(nodeSet){ |
| 610 | var nodeIdToNodeMap ={}; |
| 611 | for(var i=0;i<nodeSet.length;i++){ |
| 612 | nodeIdToNodeMap[nodeSet[i].id] = nodeSet[i]; |
| 613 | if(nodeSet[i].type == "dgstart"){ |
| 614 | nodeIdToNodeMap["dgstart"] = nodeSet[i]; |
| 615 | } |
| 616 | } |
| 617 | return nodeIdToNodeMap; |
| 618 | } |
| 619 | |
| 620 | function validateEachNodeXml(){ |
| 621 | var activeWorkspace=RED.view.getWorkspace(); |
| 622 | RED.nodes.eachNode(function(n) { |
| 623 | if (n.z == activeWorkspace) { |
| 624 | var xml = n.xml; |
| 625 | if( xml != null && xml != ''){ |
| 626 | var validationSuccess = validateXML(n.xml); |
| 627 | if(validationSuccess){ |
| 628 | n.status = {fill:"green",shape:"dot",text:"OK"}; |
| 629 | }else{ |
| 630 | n.status = {fill:"red",shape:"dot",text:"ERROR"}; |
| 631 | } |
| 632 | } |
| 633 | } |
| 634 | }); |
| 635 | } |
| 636 | |
| 637 | |
| 638 | function getNodeToXml(inputNodeSet){ |
| 639 | var exportableNodeSet; |
| 640 | //uses inputNodeSet if passed otherwise build the latest nodeSet |
| 641 | |
| 642 | //$("#btn-deploy").removeClass("disabled"); |
| 643 | |
| 644 | |
| 645 | function getNode(id){ |
| 646 | for(var i=0;i<exportableNodeSet.length;i++){ |
| 647 | if(exportableNodeSet[i].id == id){ |
| 648 | return exportableNodeSet[i]; |
| 649 | } |
| 650 | } |
| 651 | return null; |
| 652 | } |
| 653 | |
| 654 | function getStartTag(node){ |
| 655 | var startTag=""; |
| 656 | var xmlStr=""; |
| 657 | if(node != null && node.type != 'dgstart'){ |
| 658 | xmlStr=node.xml; |
| 659 | var regex = /(<)([\w-]+)(.*)?/; |
| 660 | var match = regex.exec(xmlStr); |
| 661 | if(match != null){ |
| 662 | if(match[1] != undefined && match[2] != undefined){ |
| 663 | startTag = match[2]; |
| 664 | } |
| 665 | }else{ |
| 666 | console.log("startTag not found."); |
| 667 | } |
| 668 | } |
| 669 | return startTag; |
| 670 | } |
| 671 | |
| 672 | if(inputNodeSet == null || inputNodeSet == undefined){ |
| 673 | exportableNodeSet = getCurrentFlowNodeSet(); |
| 674 | }else{ |
| 675 | exportableNodeSet = JSON.parse(inputNodeSet); |
| 676 | } |
| 677 | var dgstartNode = getDgStartNode(exportableNodeSet); |
| 678 | |
| 679 | var level=0; |
| 680 | var fullXmlStr=""; |
| 681 | |
| 682 | printXml(dgstartNode); |
| 683 | |
| 684 | |
| 685 | function printXml(node){ |
| 686 | var xmlStr=""; |
| 687 | var startTag = ""; |
| 688 | if(node != null && node.type != 'dgstart'){ |
| 689 | var comments=node.comments; |
| 690 | if(comments != null && comments != ""){ |
| 691 | //if xml comments field already has the <!-- and --> remove them |
| 692 | comments=comments.replace("<!--",""); |
| 693 | comments=comments.replace("-->",""); |
| 694 | xmlStr="<!--" + comments + "-->"; |
| 695 | } |
| 696 | xmlStr+=node.xml; |
| 697 | startTag = getStartTag(node); |
Chinthakayala,Sheshashailavas(sc2914) | 8f6a6c4 | 2018-06-27 16:11:44 +0000 | [diff] [blame] | 698 | //special handling for break node |
| 699 | if(xmlStr != undefined && xmlStr != null && xmlStr.trim() == "<break>"){ |
| 700 | fullXmlStr += "<break/>"; |
| 701 | }else{ |
| 702 | fullXmlStr +=xmlStr; |
| 703 | } |
Chinthakayala, Sheshashailavas (sc2914) | d156997 | 2017-08-28 05:25:46 -0900 | [diff] [blame] | 704 | /* |
| 705 | if(level > 0){ |
| 706 | var spacing = Array(level).join(" "); |
| 707 | xmlStr=xmlStr.replace(/\n/g,spacing); |
| 708 | fullXmlStr +=xmlStr; |
| 709 | |
| 710 | console.log(xmlStr); |
| 711 | }else{ |
| 712 | fullXmlStr +=xmlStr; |
| 713 | console.log(xmlStr); |
| 714 | } |
| 715 | */ |
| 716 | } |
| 717 | |
| 718 | //console.log("startTag:" + startTag); |
| 719 | |
| 720 | var wiredNodes = []; |
| 721 | var wiredNodesArr = []; |
| 722 | if(node != null && node.wires != null && node.wires[0] != null && node.wires[0] != undefined && node.wires[0].length >0 ){ |
| 723 | wiredNodes=node.wires[0]; |
| 724 | //console.log("Before sort"); |
| 725 | for(var k=0;wiredNodes != undefined && wiredNodes != null && k<wiredNodes.length;k++){ |
| 726 | wiredNodesArr.push(getNode(wiredNodes[k])); |
| 727 | } |
| 728 | //console.dir(wiredNodesArr); |
| 729 | //sort based on y position |
| 730 | wiredNodesArr.sort(function(a, b){ |
| 731 | return a.y-b.y; |
| 732 | }); |
| 733 | //console.log("After sort"); |
| 734 | //console.dir(wiredNodesArr); |
| 735 | } |
| 736 | |
| 737 | for(var k=0;wiredNodesArr != null && k<wiredNodesArr.length;k++){ |
| 738 | level++; |
| 739 | var nd = wiredNodesArr[k]; |
| 740 | printXml(nd); |
| 741 | } |
| 742 | |
| 743 | //append end tag |
| 744 | if(startTag != ""){ |
Chinthakayala,Sheshashailavas(sc2914) | 8f6a6c4 | 2018-06-27 16:11:44 +0000 | [diff] [blame] | 745 | if(startTag != "break"){ |
| 746 | fullXmlStr += "</" + startTag + ">"; |
| 747 | } |
Chinthakayala, Sheshashailavas (sc2914) | d156997 | 2017-08-28 05:25:46 -0900 | [diff] [blame] | 748 | /* |
| 749 | if(level >0){ |
| 750 | var spacing = Array(level).join(" "); |
| 751 | fullXmlStr += spacing + "</" + startTag + ">"; |
| 752 | console.log(spacing + "</" + startTag + ">"); |
| 753 | }else{ |
| 754 | fullXmlStr += "</" + startTag + ">"; |
| 755 | console.log("</" + startTag + ">"); |
| 756 | } |
| 757 | */ |
| 758 | } |
| 759 | |
| 760 | /*if(level>0){ |
| 761 | level=level-1; |
| 762 | } |
| 763 | */ |
| 764 | //console.log("endTag:" + startTag); |
| 765 | //console.log("xml:" + fullXmlStr); |
| 766 | } |
| 767 | //console.log("fullXmlStr:" + fullXmlStr); |
| 768 | return fullXmlStr; |
| 769 | } |
| 770 | |
| 771 | function showFlow(filePath){ |
| 772 | var jqxhr = $.post( "/getSharedFlow",{"filePath":filePath}) |
| 773 | .done(function(data) { |
| 774 | $( "#dgflow-browser-dialog").dialog("close"); |
| 775 | var migratedNodes = migrateNodes(data); |
Sheshashailavas Chinthakayala | 8797a45 | 2018-11-12 22:28:37 +0000 | [diff] [blame] | 776 | var nodeSet = getCurrentFlowNodeSet(); |
| 777 | //console.dir(nodeSet); |
| 778 | if(nodeSet != null && nodeSet.length == 0){ |
| 779 | RED.view.setIsImportAction(true); |
| 780 | } |
Chinthakayala, Sheshashailavas (sc2914) | d156997 | 2017-08-28 05:25:46 -0900 | [diff] [blame] | 781 | //RED.view.importNodes(data) |
| 782 | RED.view.importNodes(JSON.stringify(migratedNodes)); |
| 783 | //console.log( "import done"); |
| 784 | }) |
| 785 | .fail(function() { |
| 786 | RED.notify("Could not import user flow ."); |
| 787 | $( "#dgflow-browser-dialog").dialog("close"); |
| 788 | console.log( "error occured importing flow."); |
| 789 | }) |
| 790 | .always(function() { |
| 791 | //console.log( "complete" ); |
| 792 | }); |
| 793 | } |
| 794 | |
| 795 | function showFlowXml(filePath){ |
| 796 | var jqxhr = $.post( "/getSharedFlow",{"filePath":filePath}) |
| 797 | .done(function(data) { |
| 798 | //console.dir(data); |
| 799 | var xmlStr=getNodeToXml(data); |
| 800 | showImportedXml(xmlStr,this); |
| 801 | }) |
| 802 | .fail(function() { |
| 803 | RED.notify("Could not convert to XML."); |
| 804 | $( "#dgflow-browser-dialog").dialog("close"); |
| 805 | console.log( "error occured importing flow."); |
| 806 | }) |
| 807 | .always(function() { |
| 808 | //console.log( "complete" ); |
| 809 | }); |
| 810 | } |
| 811 | |
| 812 | function showFlowFiles(userName){ |
| 813 | //var divStyle="color:#07c; margin-bottom: 1.2em; font-size: 16px;"; |
| 814 | //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>"; |
| 815 | 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>"; |
| 816 | |
| 817 | var htmlStr=divStyle + "<div class='header'>List of Flow files of User " + userName + "</div><div id='data-container'><ul>" ; |
| 818 | $.post( "/getFiles/" + userName) |
| 819 | .done(function( data ) { |
| 820 | //console.dir(data); |
| 821 | //console.log("found " + data.length + " files"); |
| 822 | if(data != null && data.length != undefined && data.length != 0){ |
| 823 | if(data != null && data.length>0){ |
| 824 | for(var k=0;k<data.length;k++){ |
| 825 | htmlStr += "<li><a href=\"#\" onclick=\"showFlow('" +data[k].filePath + "')\">" + data[k].name + "</a></li>"; |
| 826 | /* |
| 827 | //Use this code to display the View Xml Link |
| 828 | 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>"; |
| 829 | */ |
| 830 | } |
| 831 | htmlStr+="</ul></div>"; |
| 832 | } |
| 833 | $( "#dgflow-browser-dialog").html(htmlStr); |
| 834 | }else{ |
| 835 | //console.log("no flow files found for user " + userName); |
| 836 | 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>"; |
| 837 | $( "#dgflow-browser-dialog").html(noFlowFilesHtml); |
| 838 | } |
| 839 | }) |
| 840 | .fail(function(err) { |
| 841 | console.log( "error" + err ); |
| 842 | }) |
| 843 | .always(function() { |
| 844 | //console.log("done"); |
| 845 | }); |
| 846 | |
| 847 | } |
| 848 | |
| 849 | function closeAndShowFlowShareUsers(){ |
| 850 | $("#dgflow-browser-dialog").dialog( "close" ); |
| 851 | 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>"; |
| 852 | $.get( "/flowShareUsers") |
| 853 | .done(function( data ) { |
| 854 | |
| 855 | var header="<div class='header'>List of downloaded DG Flows </div>"; |
| 856 | var html= divStyle + header + "<div id='data-container'>"; |
| 857 | html+="<ul>"; |
| 858 | if(data != null){ |
| 859 | var users=data.flowShareUsers; |
| 860 | users.sort(function (a,b){ |
| 861 | if(a.name > b.name){ |
| 862 | return 1; |
| 863 | }else if(a.name < b.name){ |
| 864 | return -1; |
| 865 | }else{ |
| 866 | return 0; |
| 867 | } |
| 868 | }); |
| 869 | for(var i=0;users != null && i<users.length;i++){ |
| 870 | html+="<li><a href=\"#\" onclick=\"showFlowFiles('" + users[i].rootDir + "')\">" + users[i].name + "</a></li>"; |
| 871 | } |
| 872 | } |
| 873 | html+="</ul>"; |
| 874 | html+="</div>"; |
| 875 | $( "#dgflow-browser-dialog" ).dialog({ |
| 876 | title: "Dowloaded DG Flow Browser", |
| 877 | modal: true, |
| 878 | autoOpen: true, |
| 879 | width: 530, |
| 880 | height: 530, |
| 881 | buttons: [ |
| 882 | { |
| 883 | text: "Close", |
| 884 | click: function() { |
| 885 | $( this ).dialog( "close" ); |
| 886 | } |
| 887 | } |
| 888 | ] |
| 889 | }).html(html); |
| 890 | $("#dgflow-browser-dialog").show(); |
| 891 | }) |
| 892 | .fail(function(err) { |
| 893 | RED.notify("Failed to get users."); |
| 894 | }) |
| 895 | .always(function() { |
| 896 | }); |
| 897 | } |
| 898 | |
| 899 | function showImportedXml(xmlStr,dialogBox){ |
| 900 | var formattedXml=vkbeautify.xml(xmlStr); |
| 901 | var that = dialogBox; |
| 902 | require(["orion/editor/edit"], function(edit) { |
| 903 | that.editor = edit({ |
| 904 | parent:document.getElementById('dgflow-browser-dialog'), |
| 905 | lang:"html", |
| 906 | readonly:true, |
| 907 | contents: formattedXml |
| 908 | }); |
| 909 | RED.library.create({ |
| 910 | url:"functions", // where to get the data from |
| 911 | type:"function", // the type of object the library is for |
| 912 | editor:that.editor, // the field name the main text body goes to |
| 913 | fields:['name','outputs'] |
| 914 | }); |
| 915 | }); |
| 916 | } |
| 917 | |
| 918 | function getTag(xmlStr){ |
| 919 | var tag= null ; |
| 920 | if(xmlStr != null){ |
| 921 | xmlStr = xmlStr.trim(); |
| 922 | } |
| 923 | try{ |
| 924 | var regex = new RegExp("(<)([^ >]+)"); |
| 925 | var match = regex.exec(xmlStr); |
| 926 | if(match != null){ |
| 927 | if(match[1] != undefined && match[2] != undefined){ |
| 928 | tag = match[2]; |
| 929 | } |
| 930 | } |
| 931 | }catch(e){ |
| 932 | console.log(e); |
| 933 | } |
| 934 | return tag; |
| 935 | |
| 936 | } |
| 937 | |
| 938 | function getAttributeValue(xmlStr,attribute){ |
| 939 | |
| 940 | var attrVal=null; |
| 941 | try{ |
| 942 | var myRe = new RegExp(attribute + "[\s+]?=[\s+]?['\"]([^'\"]+)['\"]","m"); |
| 943 | var myArray = myRe.exec(xmlStr); |
| 944 | if(myArray != null && myArray[1] != null){ |
| 945 | attrVal=myArray[1]; |
| 946 | } |
| 947 | }catch(err){ |
| 948 | console.log(err); |
| 949 | } |
| 950 | return attrVal; |
| 951 | } |
| 952 | |
| 953 | function showOrHideTab(checkbox,idVal){ |
| 954 | |
| 955 | var activeWorkspace=RED.view.getWorkspace(); |
| 956 | var table = $("#ftab02"); |
| 957 | $('td input:checkbox',table).each(function(i){ |
| 958 | console.log(this.checked); |
| 959 | }); |
| 960 | //console.dir($('td input:checkbox',table).prop('checked',this.checked)); |
| 961 | |
| 962 | $(".red-ui-tabs li a").each(function(i){ |
| 963 | var id=$(this).attr("href").replace('#',''); |
| 964 | if(id == idVal){ |
| 965 | $(this).parent().toggle(); |
| 966 | var isVisible = $(this).parent().is(":visible"); |
| 967 | if(isVisible){ |
| 968 | checkbox.checked = true; |
| 969 | }else{ |
| 970 | checkbox.checked = false; |
| 971 | } |
| 972 | if(activeWorkspace == id){ |
| 973 | //$("#chart").hide(); |
| 974 | //var li = ul.find("a[href='#"+id+"']").parent(); |
| 975 | var li = $(this).parent(); |
| 976 | if (li.hasClass("active")) { |
| 977 | li.removeClass("active"); |
| 978 | if(li.parent().children().size() != 0){ |
| 979 | } |
| 980 | console.log("has Class active"); |
| 981 | var tab = li.prev(); |
| 982 | if (tab.size() === 0) { |
| 983 | console.log("li prev size 0"); |
| 984 | tab = li.next(); |
| 985 | } |
| 986 | if(tab.is(":visible")){ |
| 987 | console.log("added active"); |
| 988 | tab.addClass("active"); |
| 989 | tab.click(); |
| 990 | //tab.trigger("click"); |
| 991 | } |
| 992 | //console.dir(tab); |
| 993 | //tab.parent().addClass("active"); |
| 994 | //tab.click(); |
| 995 | } |
| 996 | }else{ |
| 997 | console.log("added active id" +id); |
| 998 | if(isVisible){ |
| 999 | var li = $(this).parent(); |
| 1000 | li.addClass("active"); |
| 1001 | li.click(); |
| 1002 | //console.dir(li); |
| 1003 | }else{ |
| 1004 | var li = $(this).parent(); |
| 1005 | li.removeClass("active"); |
| 1006 | } |
| 1007 | } |
| 1008 | } |
| 1009 | }); |
| 1010 | /* |
| 1011 | $(".red-ui-tabs li a").each(function(i){ |
| 1012 | var id=$(this).attr("href").replace('#',''); |
| 1013 | if(id != idVal){ |
| 1014 | $(this).trigger("click"); |
| 1015 | if(activeWorkspace == idVal){ |
| 1016 | $("#chart").show(); |
| 1017 | } |
| 1018 | return false; |
| 1019 | } |
| 1020 | }); |
| 1021 | */ |
| 1022 | } |
| 1023 | |
| 1024 | function performGitCheckout(){ |
| 1025 | $("#responseId").text(""); |
| 1026 | if(!event) event = window.event; |
| 1027 | var target = $(event.target); |
| 1028 | target.val("Processing"); |
| 1029 | target.css({ "background-image": "url('images/page-loading.gif')" }); |
| 1030 | target.css({ "background-repeat": "no-repeat" }); |
| 1031 | target.css({ "background-size": "25px 25px" }); |
| 1032 | |
| 1033 | var branch = document.getElementById("branchId").value.trim(); |
| 1034 | var statusObj = document.getElementById("responseId"); |
| 1035 | if(branch == null || branch == ''){ |
| 1036 | statusObj.innerText = "Branch is required."; |
| 1037 | return; |
| 1038 | } |
| 1039 | var urlVal = "/gitcheckout?branch=" + branch; |
| 1040 | $.get(urlVal) |
| 1041 | .done(function( data ) { |
| 1042 | var output = data.output; |
| 1043 | if(output != null){ |
| 1044 | output=output.replace(/\n/g,"<br>"); |
| 1045 | statusObj.innerHTML = output; |
| 1046 | } |
| 1047 | }) |
| 1048 | .fail(function(err) { |
| 1049 | statusObj.innerText = "Failed to do git checkout."; |
| 1050 | }) |
| 1051 | .always(function() { |
| 1052 | $("#responseId").show(); |
| 1053 | target.val("Checkout"); |
| 1054 | target.css({ "background-image": "none" }); |
| 1055 | }); |
| 1056 | } |
| 1057 | |
| 1058 | function performGitPull(){ |
| 1059 | $("#responseId").text(""); |
| 1060 | if(!event) event = window.event; |
| 1061 | var target = $(event.target); |
| 1062 | target.val("Processing"); |
| 1063 | target.css({ "background-image": "url('images/page-loading.gif')" }); |
| 1064 | target.css({ "background-repeat": "no-repeat" }); |
| 1065 | target.css({ "background-size": "25px 25px" }); |
| 1066 | |
| 1067 | var statusObj = document.getElementById("responseId"); |
| 1068 | var urlVal = "/gitpull"; |
| 1069 | $.get(urlVal) |
| 1070 | .done(function( data ) { |
| 1071 | var output = data.output; |
| 1072 | if(output != null){ |
| 1073 | output=output.replace(/\n/g,"<br>"); |
| 1074 | statusObj.innerHTML = output; |
| 1075 | } |
| 1076 | }) |
| 1077 | .fail(function(err) { |
| 1078 | statusObj.innerText = "Failed to do git pull."; |
| 1079 | }) |
| 1080 | .always(function() { |
| 1081 | $("#responseId").show(); |
| 1082 | target.val("Pull"); |
| 1083 | target.css({ "background-image": "none" }); |
| 1084 | }); |
| 1085 | } |
| 1086 | |
| 1087 | |
| 1088 | function activateClickedTab(idVal) { |
| 1089 | |
| 1090 | $("#filter-tabs-dialog").dialog( "close" ); |
| 1091 | var ul = $("#workspace-tabs"); |
| 1092 | ul.children().each(function(){ |
| 1093 | var li = $(this); |
| 1094 | var link =li.find("a"); |
| 1095 | var href = link.prop("href"); |
| 1096 | var hrefId = href.split("#"); |
| 1097 | if(hrefId[1] == idVal){ |
| 1098 | link.trigger("click"); |
| 1099 | } |
| 1100 | }); |
| 1101 | } |
| 1102 | |
| 1103 | function deleteOrRenameTab(idVal) { |
| 1104 | $("#filter-tabs-dialog").dialog( "close" ); |
| 1105 | var ul = $("#workspace-tabs"); |
| 1106 | ul.children().each(function(){ |
| 1107 | var li = $(this); |
| 1108 | var link =li.find("a"); |
| 1109 | var href = link.prop("href"); |
| 1110 | var hrefId = href.split("#"); |
| 1111 | if(hrefId[1] == idVal){ |
| 1112 | link.trigger("click"); |
| 1113 | link.trigger("dblclick"); |
| 1114 | } |
| 1115 | }); |
| 1116 | } |
| 1117 | |
| 1118 | function deleteSelectedTab(idVal,title,_module,rpc,version){ |
| 1119 | 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>"; |
| 1120 | var alertMsg = dgInfo + "<p>Are you sure you want to Delete this Tab ?</p>"; |
| 1121 | |
| 1122 | $( "#tabAlertDialog" ).dialog({ |
| 1123 | dialogClass: "no-close", |
| 1124 | modal:true, |
| 1125 | draggable : true, |
| 1126 | /*dialogClass: "alert",*/ |
| 1127 | title: "Confirm Tab sheet Delete", |
| 1128 | width: 600, |
| 1129 | buttons: [ |
| 1130 | { |
| 1131 | text: "Delete", |
| 1132 | class:"alertDialogButton", |
| 1133 | click: function() { |
| 1134 | var ws = RED.nodes.workspace(idVal); |
| 1135 | RED.view.removeWorkspace(ws); |
| 1136 | var historyEvent = RED.nodes.removeWorkspace(idVal); |
| 1137 | historyEvent.t = 'delete'; |
| 1138 | historyEvent.dirty = true; |
| 1139 | historyEvent.workspaces = [ws]; |
| 1140 | RED.history.push(historyEvent); |
| 1141 | RED.view.dirty(true); |
| 1142 | $( this ).dialog( "close" ); |
| 1143 | $("#filter-tabs-dialog").dialog( "close" ); |
| 1144 | $("#btn-manage-tabs").trigger("click"); |
| 1145 | } |
| 1146 | }, |
| 1147 | { |
| 1148 | text: "Cancel", |
| 1149 | class:"alertDialogButton", |
| 1150 | click: function() { |
| 1151 | $( this ).dialog( "close" ); |
| 1152 | } |
| 1153 | } |
| 1154 | ] |
| 1155 | }).html(alertMsg); |
| 1156 | } |
| 1157 | |
| 1158 | function renameSelectedTab(idVal,title,_module,rpc,version){ |
| 1159 | 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>"; |
| 1160 | var alertMsg = dgInfo + "<p>Change the title and click Rename.</p>"; |
| 1161 | |
| 1162 | $( "#tabAlertDialog" ).dialog({ |
| 1163 | dialogClass: "no-close", |
| 1164 | modal:true, |
| 1165 | draggable : true, |
| 1166 | /*dialogClass: "alert",*/ |
| 1167 | title: "Rename Tab sheet", |
| 1168 | width: 600, |
| 1169 | buttons: [ |
| 1170 | { |
| 1171 | text: "Rename", |
| 1172 | class:"alertDialogButton", |
| 1173 | click: function() { |
| 1174 | var ws = RED.nodes.workspace(idVal); |
| 1175 | var label = document.getElementById("tab-name-" + idVal).value; |
| 1176 | //console.log("label:" +label); |
| 1177 | //console.log("ws.label:" + ws.label); |
| 1178 | if (ws.label != label) { |
| 1179 | ws.label = label; |
| 1180 | var link = $("#workspace-tabs a[href='#"+idVal+"']"); |
| 1181 | link.attr("title",label); |
| 1182 | link.text(label); |
| 1183 | RED.view.dirty(true); |
| 1184 | } |
| 1185 | $("#tabAlertDialog").dialog('destroy').remove(); |
| 1186 | //$(this).dialog( "close" ); |
| 1187 | $("#filter-tabs-dialog").dialog( "close" ); |
| 1188 | $("#btn-manage-tabs").trigger("click"); |
| 1189 | } |
| 1190 | }, |
| 1191 | { |
| 1192 | text: "Cancel", |
| 1193 | class:"alertDialogButton", |
| 1194 | click: function() { |
| 1195 | $( this ).dialog( "close" ); |
| 1196 | } |
| 1197 | } |
| 1198 | ] |
| 1199 | }).html(alertMsg); |
| 1200 | } |
| 1201 | |
| 1202 | function performGitStatus(){ |
| 1203 | $("#responseId").text(""); |
| 1204 | if(!event) event = window.event; |
| 1205 | var target = $(event.target); |
| 1206 | target.val("Processing"); |
| 1207 | target.css({ "background-image": "url('images/page-loading.gif')" }); |
| 1208 | target.css({ "background-repeat": "no-repeat" }); |
| 1209 | target.css({ "background-size": "25px 25px" }); |
| 1210 | |
| 1211 | var statusObj = document.getElementById("responseId"); |
| 1212 | var urlVal = "/gitstatus"; |
| 1213 | $.get(urlVal) |
| 1214 | .done(function( data ) { |
| 1215 | var output = data.output; |
| 1216 | if(output != null){ |
| 1217 | output=output.replace(/\n/g,"<br>"); |
| 1218 | statusObj.innerHTML = output; |
| 1219 | } |
| 1220 | //statusObj.innerText = data.output; |
| 1221 | }) |
| 1222 | .fail(function(err) { |
| 1223 | statusObj.innerText = "Failed to do git status."; |
| 1224 | }) |
| 1225 | .always(function() { |
| 1226 | $("#responseId").show(); |
| 1227 | target.val("Status"); |
| 1228 | target.css({ "background-image": "none" }); |
| 1229 | }); |
| 1230 | } |
| 1231 | |
| 1232 | function migrateNodes(jsonStr){ |
| 1233 | var nodes = JSON.parse(jsonStr); |
| 1234 | nodes.forEach( function(node) { |
| 1235 | if( node.xml != undefined && node.xml != null && node.xml.indexOf("<service-logic") != -1){ |
| 1236 | //console.log(node.xml); |
| 1237 | var module=""; |
| 1238 | var version=""; |
| 1239 | module=getAttributeValue(node.xml,"module"); |
| 1240 | /* |
| 1241 | var myRe = new RegExp("module=\"(.*)\" ", "m"); |
| 1242 | var myArray = myRe.exec(node.xml); |
| 1243 | if(myArray != null && myArray[1] != null){ |
| 1244 | module=myArray[1]; |
| 1245 | } |
| 1246 | myRe = new RegExp("version=\"(.*)\">", "m"); |
| 1247 | myArray = myRe.exec(node.xml); |
| 1248 | if(myArray != null && myArray[1] != null){ |
| 1249 | version=myArray[1]; |
| 1250 | //console.dir(myArray); |
| 1251 | } |
| 1252 | */ |
| 1253 | version=getAttributeValue(node.xml,"version"); |
| 1254 | node.type="service-logic"; |
| 1255 | //node.category="DGEmain"; |
| 1256 | node.module=module; |
| 1257 | node.version=version; |
| 1258 | if(module != null && version != null){ |
| 1259 | node.name=module+ " " + version; |
| 1260 | } |
| 1261 | console.log("module=" + module); |
| 1262 | console.log("version=" + version); |
| 1263 | }else if( node.xml != undefined && node.xml != null && node.xml.indexOf("<method") != -1){ |
| 1264 | var rpc=getAttributeValue(node.xml,"rpc"); |
| 1265 | node.type="method"; |
| 1266 | if(rpc != null){ |
| 1267 | node.name=rpc; |
| 1268 | } |
| 1269 | }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<outcome") != -1){ |
| 1270 | var uxml = node.xml.toUpperCase(); |
| 1271 | if(uxml.indexOf("FAILURE") != -1){ |
| 1272 | node.type="failure"; |
| 1273 | }else if(uxml.indexOf("SUCCESS") != -1){ |
| 1274 | node.type="success"; |
| 1275 | }else if(uxml.indexOf("TRUE") != -1){ |
| 1276 | node.type="outcomeTrue"; |
| 1277 | }else if(uxml.indexOf("FALSE") != -1){ |
| 1278 | node.type="outcomeFalse"; |
| 1279 | }else if(uxml.indexOf("ALREADY-ACTIVE") != -1){ |
| 1280 | node.type="already-active"; |
| 1281 | }else if(uxml.indexOf("NOT-FOUND") != -1){ |
| 1282 | node.type="not-found"; |
| 1283 | }else{ |
| 1284 | node.type="other"; |
| 1285 | } |
| 1286 | }else if( node.xml != undefined &&node.xml != null && node.xml.indexOf("<return") != -1){ |
| 1287 | var uxml = node.xml.toUpperCase(); |
| 1288 | if(uxml.indexOf("FAILURE") != -1){ |
| 1289 | node.type="returnFailure"; |
| 1290 | }else if(uxml.indexOf("SUCCESS") != -1){ |
| 1291 | node.type="returnSuccess"; |
| 1292 | } |
| 1293 | }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<exists") != -1){ |
| 1294 | node.type="exists"; |
Chinthakayala,Sheshashailavas(sc2914) | 8f6a6c4 | 2018-06-27 16:11:44 +0000 | [diff] [blame] | 1295 | }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<break") != -1){ |
| 1296 | node.type="break"; |
Chinthakayala, Sheshashailavas (sc2914) | d156997 | 2017-08-28 05:25:46 -0900 | [diff] [blame] | 1297 | }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<block") != -1){ |
| 1298 | node.type="block"; |
| 1299 | var atomic=getAttributeValue(node.xml,"atomic"); |
| 1300 | |
| 1301 | if(atomic=='true'){ |
| 1302 | node.atomic="true"; |
| 1303 | node.name="block : atomic"; |
| 1304 | }else{ |
| 1305 | node.atomic="false"; |
| 1306 | node.name="block"; |
| 1307 | } |
| 1308 | }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<save") != -1){ |
| 1309 | node.type="save"; |
Chinthakayala,Sheshashailavas(sc2914) | 8f6a6c4 | 2018-06-27 16:11:44 +0000 | [diff] [blame] | 1310 | }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<while") != -1){ |
| 1311 | node.type="while"; |
Chinthakayala, Sheshashailavas (sc2914) | d156997 | 2017-08-28 05:25:46 -0900 | [diff] [blame] | 1312 | }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<switch") != -1){ |
| 1313 | node.type="switchNode"; |
| 1314 | }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<record") != -1){ |
| 1315 | node.type="record"; |
| 1316 | }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<call") != -1){ |
| 1317 | node.type="call"; |
| 1318 | }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<release") != -1){ |
| 1319 | node.type="release"; |
| 1320 | }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<set") != -1){ |
| 1321 | node.type="set"; |
| 1322 | }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<for") != -1){ |
| 1323 | node.type="for"; |
| 1324 | }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<is-available") != -1){ |
| 1325 | node.type="is-available"; |
| 1326 | }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<reserve") != -1){ |
| 1327 | node.type="reserve"; |
| 1328 | }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<get-resource") != -1){ |
| 1329 | node.type="get-resource"; |
| 1330 | }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<configure") != -1){ |
| 1331 | node.type="configure"; |
| 1332 | }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<delete") != -1){ |
| 1333 | node.type="delete"; |
| 1334 | }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<execute") != -1){ |
| 1335 | node.type="execute"; |
| 1336 | }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<notify") != -1){ |
| 1337 | node.type="notify"; |
| 1338 | }else if(node.xml != undefined && node.xml != null && node.xml.indexOf("<update") != -1){ |
| 1339 | node.type="update"; |
| 1340 | } |
| 1341 | //console.dir(node); |
| 1342 | }); |
| 1343 | return nodes; |
| 1344 | } |