From 324ee36fe31763e507b422ab0a88e4230045e205 Mon Sep 17 00:00:00 2001 From: "Timoney, Daniel (dt5972)" Date: Wed, 15 Feb 2017 10:37:53 -0500 Subject: Initial commit for OpenECOMP SDN-C OA&M Change-Id: I7ab579fd0d206bf356f36d52dcdf4f71f1fa2680 Signed-off-by: Timoney, Daniel (dt5972) Former-commit-id: 2a9f0edd09581f907e62ec4689b5ac94dd5382ba --- dgbuilder/public/util/css/validateNodeXml.css | 86 ++ dgbuilder/public/util/js/dgeToXml.js | 1328 ++++++++++++++++++++ dgbuilder/public/util/js/dgeToXml.js.imp | 147 +++ dgbuilder/public/util/js/jsonTool.js | 67 + dgbuilder/public/util/js/migrateFlow.js | 184 +++ dgbuilder/public/util/js/sliValues.js | 763 +++++++++++ dgbuilder/public/util/js/validateNodeXml.js | 325 +++++ .../public/util/js/vkbeautify.0.99.00.beta.js | 358 ++++++ 8 files changed, 3258 insertions(+) create mode 100644 dgbuilder/public/util/css/validateNodeXml.css create mode 100644 dgbuilder/public/util/js/dgeToXml.js create mode 100644 dgbuilder/public/util/js/dgeToXml.js.imp create mode 100644 dgbuilder/public/util/js/jsonTool.js create mode 100644 dgbuilder/public/util/js/migrateFlow.js create mode 100644 dgbuilder/public/util/js/sliValues.js create mode 100644 dgbuilder/public/util/js/validateNodeXml.js create mode 100644 dgbuilder/public/util/js/vkbeautify.0.99.00.beta.js (limited to 'dgbuilder/public/util') 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" + 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" + 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" + n2.name] ="looped"; + //console.dir(loopDetectedObj); + isLoopDetected = true; + } + } + } + } + } + for(var l=0;delKeys != null && l
"; + } + } + if(msg != ""){ + isLoopDetected = true; + RED.notify(msg); + } + } +/* + for(var i=0;nodeSet != null && i1){ + console.log("Loop detected for node " + nodeName + "with node:" + node.name); + RED.notify("Flow error detected for node '" + nodeName + "' with node '" + node.name + "'"); + //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") != -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="
"; + for(var j=0;errList != null && j"; + } + htmlStr += "
Error List
"; + + $("#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 && k0){ + 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 + ""; + } + 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;i0){ + var wiredNodes=node.wires[0]; + var wiredNodesArr=[]; + for(var k=0;wiredNodes != undefined && wiredNodes != null && k 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;k0){ + 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 && i0){ + var wiredNodes=node.wires[0]; + var wiredNodesArr=[]; + for(var k=0;wiredNodes != undefined && wiredNodes != null && k -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.
Node Name:" + node.name + "
DG Number:" + node.dgnumber[0] ); + }else{ + flowDesignErrors.push("Warning:May need a block Node after Node
Node name:" + 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="
"; + for(var j=0;flowDesignErrors != null && j"; + } + htmlStr += "
Error List
"; + + //$('
').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 remove them + comments=comments.replace("",""); + xmlStr=""; + } + 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"; + /* + if(level >0){ + var spacing = Array(level).join(" "); + fullXmlStr += spacing + ""; + console.log(spacing + ""); + }else{ + fullXmlStr += ""; + console.log(""); + } + */ + } + + /*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=""; + var divStyle=""; + + var htmlStr=divStyle + "
List of Flow files of User " + userName + "
    " ; + $.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[k].name + ""; + /* + //Use this code to display the View Xml Link + htmlStr += "
  • " + data[k].name + "[View Xml]
  • "; + */ + } + htmlStr+="
"; + } + $( "#dgflow-browser-dialog").html(htmlStr); + }else{ + //console.log("no flow files found for user " + userName); + var noFlowFilesHtml = divStyle + "

No downloaded Flow files found in " + userName + " directory

Back to List.
"; + $( "#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=""; + $.get( "/flowShareUsers") + .done(function( data ) { + + var header="
List of downloaded DG Flows
"; + var html= divStyle + header + "
"; + html+="
    "; + 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[i].name + ""; + } + } + html+="
"; + html+="
"; + $( "#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,"
"); + 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,"
"); + 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 = "
Tab TitleModuleRPCVersion
" + title + "" + _module +"" + rpc + "" +version + "

"; + var alertMsg = dgInfo + "

Are you sure you want to Delete this Tab ?

"; + +$( "#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 = "
Tab TitleModuleRPCVersion
" + _module +"" + rpc + "" +version + "

"; + var alertMsg = dgInfo + "

Change the title and click Rename.

"; + +$( "#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,"
"); + 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("", "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(" 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 && k0){ + var spacing = Array(level).join(" "); + fullXmlStr += spacing + ""; + console.log(spacing + ""); + }else{ + fullXmlStr += ""; + console.log(""); + } + } + + 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]+)"); + 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("", "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("\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"; + if(Array.isArray(valuesObj[key])){ + var arrObj=valuesObj[key]; + var cnt=1; + for(var i=0;i
"; + var variableBox = ""; + var valBox = ""; + if(arrObj[i] != undefined && arrObj[i].length <150){ + //v += "
" + "" ; + v += "
" + "" ; + variableBox = ""; + }else{ + v+= "
" + ""; + variableBox = ""; + } + v += "" + + "" + "
"; + cnt++; + } + htmlVal+= v + "
"; + } + } + } + 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="
" ; + valuesHtml+=buildValuesHtml(valuesObj); + valuesHtml+="
"; + 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="
" ; + + 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("View Comments"); + }else{ + $("#node-input-btnComments").html("Add Comments"); + } + } + //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("View Comments"); + }else{ + $("#node-input-btnComments").html("Add Comments"); + } + } + $(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"; + var htmlStr=""; + //console.dir(rows); + if(rows != null && rows.length >0){ + var alertDialog = '
'; + htmlStr= alertDialog + "
" + styleStr; + htmlStr += ""; + htmlStr += ""; + htmlStr += ""; + htmlStr += "" ; + htmlStr += "" ; + htmlStr += "" ; + htmlStr += "" ; + htmlStr += ""; + if(rows != null && rows.length == 0){ + htmlStr += ""; + htmlStr += ""; + htmlStr += "
" + filePath + "
Commit IDDateAuthorComment
No rows found
"; + return htmlStr; + } + for(var i=0;i" + _commitId + ""; + htmlStr += "" + dt + ""; + htmlStr += "" + author + ""; + htmlStr += "" + comment + ""; + htmlStr += ""; + } + htmlStr += ""; + htmlStr += "
"; + } + //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;k0){ + valuesObj=updatedValuesObj; + } + updatedValuesObj=[]; + for(var i=0;i b){ + return 1; + }else if(a < b){ + return -1; + }else{ + return 0; + } + }); + for(var i=0;files != null && i" + files[i] + ""; + } + } + html+=""; + html+=""; + $( "#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 b){ + return 1; + }else if(a < b){ + return -1; + }else{ + return 0; + } + }); + for(var i=0;files != null && i" + files[i] + ""; + } + } + html+=""; + html+=""; + $( "#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 b){ + return 1; + }else if(a < b){ + return -1; + }else{ + return 0; + } + }); + for(var i=0;files != null && i" + files[i] + ""; + } + } + html+=""; + html+=""; + $( "#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 b){ + return 1; + }else if(a < b){ + return -1; + }else{ + return 0; + } + }); + for(var i=0;files != null && i" + files[i] + "" + ""; + } + } + html+=""; + html+=""; + + $( "#yang-files-data-container" ).html(html); +} + +function getYangFile(fileName){ + $("#dwnldYangFormId").remove(); + //using form to submit + var form = $('
'); + form.append(''); + 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;k0){ + valuesObj=updatedValuesObj; + } + updatedValuesObj=[]; + for(var i=0;i b){ + return 1; + }else if(a < b){ + return -1; + }else{ + return 0; + } + }); + var count=1; + for(var i=0;files != null && i" + val + ""; + }else{ + html+="" + count + "" + val + ""; + } + count++; + } + } + html+=""; + html+=""; + $( "#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 <" + processedNode + "> Element#" + elementCount; + errList.push(msg); + resp = false; + return; + } + processedNode = xmlNode.nodeName; + var attrs = xmlNode.attributes; + for(var i=0;i attribute '" + attrs[i].nodeName + "' is not set.Element#" + elementCount); + resp = false; + } + } + var childNodes = xmlNode.childNodes; + for(var k=0;kXML validation: SUCCESS","success"); + }else{ + console.log("Errors found. "); + RED.notify("XML validation: FAILED","error"); + } + }catch(e){ + console.log("error:" +e); + RED.notify("XML validation: 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 = ""; + + if(xmlStr.indexOf(endTag) != -1){ + resp=false; + showMsg("Error: End tag </" + startTag + "> must not be included.","red"); + console.log("End tag " + endTag + " must not be included."); + return resp; + } + try{ + //var xmlTopStr = "\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. show errors","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="
"; + for(var i=0;errList != null && i"; + } + htmlStr += "
Error List
"; + //var prevHtml = $("#tab-info").html(); + //htmlStr += ""; + //$('#show-errors-div').html(htmlStr); + //$("#tab-info").html(prevHtml + htmlStr); + + //$('
').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,}<") + .replace(/ or -1) { + str += shift[deep]+ar[ix]; + inComment = true; + // end comment or // + if(ar[ix].search(/-->/) > -1 || ar[ix].search(/\]>/) > -1 || ar[ix].search(/!DOCTYPE/) > -1 ) { + inComment = false; + } + } else + // end comment or // + if(ar[ix].search(/-->/) > -1 || ar[ix].search(/\]>/) > -1) { + str += ar[ix]; + inComment = false; + } else + // // + 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 + // // + 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 + // ... // + if(ar[ix].search(/<\w/) > -1 && ar[ix].search(/<\//) > -1) { + str = !inComment ? str += shift[deep]+ar[ix] : str += ar[ix]; + } else + // // + if(ar[ix].search(/<\//) > -1) { + str = !inComment ? str += shift[--deep]+ar[ix] : str += ar[ix]; + } else + // // + if(ar[ix].search(/\/>/) > -1 ) { + str = !inComment ? str += shift[deep]+ar[ix] : str += ar[ix]; + } else + // // + 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/g,"") + .replace(/[ \r\n\t]{1,}xmlns/g, ' xmlns'); + return str.replace(/>\s{0,}<"); +} + +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(); + +})(); + -- cgit 1.2.3-korg