/** * Copyright 2013 IBM Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. **/ var RED = (function() { function hideDropTarget() { $("#dropTarget").hide(); RED.keyboard.remove(/* ESCAPE */ 27); } $('#chart').on("dragenter",function(event) { if ($.inArray("text/plain",event.originalEvent.dataTransfer.types) != -1) { $("#dropTarget").css({display:'table'}); RED.keyboard.add(/* ESCAPE */ 27,hideDropTarget); } }); $('#dropTarget').on("dragover",function(event) { if ($.inArray("text/plain",event.originalEvent.dataTransfer.types) != -1) { event.preventDefault(); } }) .on("dragleave",function(event) { hideDropTarget(); }) .on("drop",function(event) { var data = event.originalEvent.dataTransfer.getData("text/plain"); hideDropTarget(); RED.view.importNodes(data); event.preventDefault(); }); function save(force) { if (RED.view.dirty()) { //$("#debug-tab-clear").click(); // uncomment this to auto clear debug on deploy if (!force) { var invalid = false; var unknownNodes = []; RED.nodes.eachNode(function(node) { invalid = invalid || !node.valid; if (node.type === "unknown") { if (unknownNodes.indexOf(node.name) == -1) { unknownNodes.push(node.name); } invalid = true; } }); if (invalid) { if (unknownNodes.length > 0) { $( "#node-dialog-confirm-deploy-config" ).hide(); $( "#node-dialog-confirm-deploy-unknown" ).show(); var list = "
  • "+unknownNodes.join("
  • ")+"
  • "; $( "#node-dialog-confirm-deploy-unknown-list" ).html(list); } else { $( "#node-dialog-confirm-deploy-config" ).show(); $( "#node-dialog-confirm-deploy-unknown" ).hide(); } $( "#node-dialog-confirm-deploy" ).dialog( "open" ); return; } } var nns = RED.nodes.createCompleteNodeSet(); /****************************************/ /*added new code to save the Tabs order */ /****************************************/ //console.log("nns before changes."); //console.dir(nns); var allTabsObj={}; var allTabsList=[]; var nnsTabIdsArr = []; var guiTabIdsArr = []; nns.forEach(function(n) { if(n.type == 'tab'){ allTabsObj[n.id] = n; allTabsList.push(n); nnsTabIdsArr.push(n.id); } }); var idx =0; $("#workspace-tabs li a").each(function(){ var href = $(this).prop("href"); var indexOfHash = href.indexOf("#"); var idVal = href.slice(indexOfHash+1); guiTabIdsArr.push(idVal); nns.splice(idx,1,allTabsObj[idVal]);; idx++; }); //console.log(nnsTabIdsArr.join(",")); //console.log(guiTabIdsArr.join(",")); //console.log("nns after changes."); //console.dir(nns); /****************************/ $("#btn-icn-deploy").removeClass('fa-download'); $("#btn-icn-deploy").addClass('spinner'); RED.view.dirty(false); $.ajax({ url:"flows", type: "POST", data: JSON.stringify(nns), contentType: "application/json; charset=utf-8" }).done(function(data,textStatus,xhr) { RED.notify("Successfully saved","success"); RED.nodes.eachNode(function(node) { if (node.changed) { node.dirty = true; node.changed = false; } if(node.credentials) { delete node.credentials; } }); RED.nodes.eachConfig(function (confNode) { if (confNode.credentials) { delete confNode.credentials; } }); // Once deployed, cannot undo back to a clean state RED.history.markAllDirty(); RED.view.redraw(); }).fail(function(xhr,textStatus,err) { RED.view.dirty(true); if (xhr.responseText) { RED.notify("Error: "+xhr.responseText,"error"); } else { RED.notify("Error: no response from server","error"); } }).always(function() { $("#btn-icn-deploy").removeClass('spinner'); $("#btn-icn-deploy").addClass('fa-download'); }); } } $('#btn-deploy').click(function() { save(); }); $( "#node-dialog-confirm-deploy" ).dialog({ title: "Confirm deploy", modal: true, autoOpen: false, width: 530, height: 230, buttons: [ { text: "Confirm deploy", click: function() { save(true); $( this ).dialog( "close" ); } }, { text: "Cancel", click: function() { $( this ).dialog( "close" ); } } ] }); function loadSettings() { $.get('settings', function(data) { RED.settings = data; console.log("Node-RED: "+data.version); loadNodeList(); }); } function loadNodeList() { $.ajax({ headers: { "Accept":"application/json" }, cache: false, url: 'nodes', success: function(data) { RED.nodes.setNodeList(data); loadNodes(); } }); } function loadNodes() { $.ajax({ headers: { "Accept":"text/html" }, cache: false, url: 'nodes', success: function(data) { $("body").append(data); $(".palette-spinner").hide(); $(".palette-scroll").show(); $("#palette-search").show(); loadFlows(); } }); } function loadFlows() { $.ajax({ headers: { "Accept":"application/json" }, cache: false, url: 'flows', success: function(nodes) { RED.nodes.import(nodes); RED.view.dirty(false); RED.view.redraw(); RED.comms.subscribe("status/#",function(topic,msg) { var parts = topic.split("/"); var node = RED.nodes.node(parts[1]); if (node) { node.status = msg; if (statusEnabled) { node.dirty = true; RED.view.redraw(); } } }); RED.comms.subscribe("node/#",function(topic,msg) { var i,m; var typeList; var info; if (topic == "node/added") { var addedTypes = []; for (i=0;i
  • ")+"
  • "; RED.notify("Node"+(addedTypes.length!=1 ? "s":"")+" added to palette:"+typeList,"success"); } } else if (topic == "node/removed") { for (i=0;i
  • ")+"
  • "; RED.notify("Node"+(m.types.length!=1 ? "s":"")+" removed from palette:"+typeList,"success"); } } } else if (topic == "node/enabled") { if (msg.types) { info = RED.nodes.getNodeSet(msg.id); if (info.added) { RED.nodes.enableNodeSet(msg.id); typeList = ""; RED.notify("Node"+(msg.types.length!=1 ? "s":"")+" enabled:"+typeList,"success"); } else { $.get('nodes/'+msg.id, function(data) { $("body").append(data); typeList = ""; RED.notify("Node"+(msg.types.length!=1 ? "s":"")+" added to palette:"+typeList,"success"); }); } } } else if (topic == "node/disabled") { if (msg.types) { RED.nodes.disableNodeSet(msg.id); typeList = ""; RED.notify("Node"+(msg.types.length!=1 ? "s":"")+" disabled:"+typeList,"success"); } } }); } }); } var statusEnabled = false; function toggleStatus(state) { statusEnabled = state; RED.view.status(statusEnabled); } function performLoopDetection(state) { loopDetectionEnabled = state; console.log("loopDetectionEnabled:" + loopDetectionEnabled); } var dgNumberEnabled = false; function toggleDgNumberDisplay(state) { dgNumberEnabled = state; RED.view.showNumbers(dgNumberEnabled); } var nodePaletteDisplay = false; function toggleNodePaletteDisplay(state) { nodePaletteDisplay = state; RED.view.showNodePalette(nodePaletteDisplay); } function displayAllDGs(state) { //defined showSLa() in dgstart.html showSLA(); } function showHelp() { var dialog = $('#node-help'); //$("#node-help").draggable({ // handle: ".modal-header" //}); dialog.on('show',function() { RED.keyboard.disable(); }); dialog.on('hidden',function() { RED.keyboard.enable(); }); dialog.modal(); } //Custom Functions Added here function showCodeCloudFlows(){ codeCloudFlowFiles=[]; var divStyle=""; $.get( "/getCodeCloudFlows") .done(function( data ) { var header="
    List of DG Flows in Code Cloud
    "; var html= divStyle + header + "
    "; html+="
      "; if(data != null){ var files=data.files; codeCloudFlowFiles=files; //console.dir(files); files.sort(function (a,b){ if(a > b){ return 1; }else if(a < b){ return -1; }else{ return 0; } }); for(var i=0;files != null && i" + files[i] + ""; } } html+="
    "; html+="
    "; $( "#codecloud-browser-dialog" ).dialog({ title: "Code Cloud DG Flow Browser", modal: true, autoOpen: true, width: 830, height: 630, buttons: [ { text: "Close", click: function() { $( this ).dialog( "close" ); } } ], close: function(ev,ui){ $(this).dialog("destroy"); } }).html(html); $("#codecloud-browser-dialog").show(); }) .fail(function(err) { RED.notify("Failed to get users."); }) .always(function() { }); } /* function listYangFiles(){ yangFilesList=[]; var divStyle=""; $.get( "/getYangFiles") .done(function( data ) { var header="
    List of Yang Files
    "; var html= divStyle + header + "
    "; html+="
      "; if(data != null){ var files=data.files; yangFilesList=files; //console.dir(files); files.sort(function (a,b){ if(a > b){ return 1; }else if(a < b){ return -1; }else{ return 0; } }); for(var i=0;files != null && i" + files[i] + ""; } } html+="
    "; html+="
    "; $( "#list-yang-browser-dialog" ).dialog({ title: "List Yang Files", modal: true, autoOpen: true, width: 830, height: 630, buttons: [ { text: "Close", click: function() { $( this ).dialog( "close" ); } } ], close: function(ev,ui){ $(this).dialog("destroy"); } }).html(html); $("#list-yang-browser-dialog").show(); }) .fail(function(err) { RED.notify("Failed to get yang files."); }) .always(function() { }); } */ function listYangFiles(){ yangFilesList=[]; var divStyle=""; $.get( "/getYangFiles") .done(function( data ) { var header="
    List of Yang Files
    "; var html= divStyle + header + "
    "; html+=""; html+=""; html+=""; html+=""; html+=""; if(data != null){ var files=data.files; yangFilesList=files; //console.dir(files); files.sort(function (a,b){ if(a > b){ return 1; }else if(a < b){ return -1; }else{ return 0; } }); for(var i=0;files != null && i" + files[i] + ""; } } html+="
    FileDelete
    " + "
    "; html+="
    "; $( "#list-yang-browser-dialog" ).dialog({ title: "List Yang Files", modal: true, autoOpen: true, width: 830, height: 630, buttons: [ { text: "Close", click: function() { $( this ).dialog( "close" ); } } ], close: function(ev,ui){ $(this).dialog("destroy"); } }).html(html); $("#list-yang-browser-dialog").show(); }) .fail(function(err) { RED.notify("Failed to get yang files."); }) .always(function() { }); } function showGitPullDialog(){ $.get( "/getCurrentGitBranch") .done(function( data ) { if(data != null){ if(data.output == "GIT_LOCAL_REPOSITORY_NOT_SET" ){ RED.notify("Git Local Repository path is not set. Please set it by choosing Configuration from the menu."); return; } var html= "
    "; html+=""; html+=""; html+=""; html+=""; html+=""; html+=""; html+=""; html+="" html+=""; html+=""; //html+=""; html+=""; html+="
    Branch" + data.output + "
      
    "; html+="
    "; html+="
    "; $( "#gitcommands-dialog" ).dialog({ title: "Git Pull", modal: true, autoOpen: true, width: 630, height: 500, buttons: [ { text: "Close", click: function() { $( this ).dialog( "close" ); } } ], close: function(ev,ui){ $(this).dialog("destroy"); } }).html(html); $("#responseId").css({width:'550',height:'275px', border: '2px solid lightgrey',overflow:'scroll', padding: '20px' }); $("#responseId").hide(); $("#gitcommands-dialog").show(); } }) .fail(function(err) { RED.notify("Failed to get gitBranch."); }) .always(function() { }); } function showGitStatusDialog(){ $.get( "/getCurrentGitBranch") .done(function( data ) { if(data != null){ if(data.output == "GIT_LOCAL_REPOSITORY_NOT_SET" ){ RED.notify("Git Local Repository path is not set. Please set it by choosing Configuration from the menu."); return; } var html= "
    "; html+=""; html+=""; html+=""; html+=""; html+=""; html+=""; html+=""; html+="" html+=""; html+=""; //html+=""; html+=""; html+="
    Branch" + data.output + "
      
    "; html+="
    "; html+="
    "; $( "#gitcommands-dialog" ).dialog({ title: "Git Status", modal: true, autoOpen: true, width: 630, height: 500, buttons: [ { text: "Close", click: function() { $( this ).dialog( "close" ); } } ], close: function(ev,ui){ $(this).dialog("destroy"); } }).html(html); //$("#responseId").css({width:'600px',height:'100px','border-radius' : '25px', border: '2px solid lightgrey', padding: '20px' }); $("#responseId").css({width:'550px',height:'100px', border: '2px solid lightgrey',overflow:'scroll', padding: '20px' }); $("#responseId").hide(); $("#gitcommands-dialog").show(); } }) .fail(function(err) { RED.notify("Failed to get gitBranch."); }) .always(function() { }); } function showGitCheckoutDialog(){ $.get( "/getCurrentGitBranch") .done(function( data ) { if(data != null){ if(data.output == "GIT_LOCAL_REPOSITORY_NOT_SET" ){ RED.notify("Git Local Repository path is not set. Please set it by choosing Configuration from the menu."); return; } var html= "
    "; html+=""; html+=""; html+=""; html+=""; html+=""; html+=""; html+=""; html+="" html+=""; html+=""; //html+=""; html+=""; html+="
    Branch
      
    "; html+="
    "; html+="
    "; $( "#gitcommands-dialog" ).dialog({ title: "Git Checkout", modal: true, autoOpen: true, width: 430, height: 350, buttons: [ { text: "Close", click: function() { $( this ).dialog( "close" ); } } ], close: function(ev,ui){ $(this).dialog("destroy"); } }).html(html); $("#responseId").css({width:'300',height:'100px', border: '2px solid lightgrey',overflow:'scroll', padding: '20px' }); $("#responseId").hide(); $("#gitcommands-dialog").show(); } }) .fail(function(err) { RED.notify("Failed to get gitBranch."); }) .always(function() { }); } function showGitLocalFlows(){ giLocalFlowFiles=[]; var divStyle=""; $.get( "/getGitLocalFlows") .done(function( data ) { if(data != null && data.files != null && data.files.length == 1){ if(data.files[0] == "GIT_LOCAL_REPOSITORY_NOT_SET" ){ RED.notify("Git Local Repository path is not set. Please set it by choosing Configuration from the menu."); return; } } //console.log("got response from server."); var header="
    List of DG Flows from Git Local Repository
    "; var html= divStyle + header + "
    "; html+="
      "; if(data != null){ var files=data.files; gitLocalFlowFiles=files; //console.dir(files); files.sort(function (a,b){ if(a > b){ return 1; }else if(a < b){ return -1; }else{ return 0; } }); for(var i=0;files != null && i" + files[i] + ""; } } html+="
    "; html+="
    "; $( "#gitlocal-browser-dialog" ).dialog({ title: "Git Local Repository DG Flow Browser", modal: true, autoOpen: true, width: 830, height: 630, buttons: [ { text: "Close", click: function() { $(this).dialog("close"); } } ] }).html(html); $("#gitlocal-browser-dialog").show(); /* if ($("#gitlocal-browser-dialog").dialog( "isOpen" )===true) { console.log("gitlocal dialog box is open"); //true } else { console.log("gitlocal dialog box is not open"); // $( "#gitlocal-browser-dialog" ).dialog("destroy").remove(); console.log($("#gitlocal-browser-dialog").dialog( "widget" )); $("#gitlocal-browser-dialog").dialog( "open" ); if ($("#gitlocal-browser-dialog").dialog( "isOpen" )===true) { console.log("gitlocal dialog box is now open"); } $("#gitlocal-browser-dialog").show(); //false } */ }) .fail(function(err) { RED.notify("Failed to get flows."); }) .always(function() { console.log("Done displaying"); }); } function showFlowShareUsers(){ 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: "Downloaded DG Flows Browser", modal: true, autoOpen: true, width: 530, height: 530, buttons: [ { text: "Close", click: function() { $( this ).dialog( "close" ); //$(this).dialog('destroy').remove(); } } ] }).html(html); $("#dgflow-browser-dialog").show(); /* if ($("#dgflow-browser-dialog").dialog( "isOpen" )===true) { console.log("dgflow dialog box is open"); //true } else { console.log("dgflow dialog box is not open"); $("#dgflow-browser-dialog").dialog( "open" ); $("#dgflow-browser-dialog").show(); //false } */ }) .fail(function(err) { RED.notify("Failed to get users."); }) .always(function() { }); } /* function showFlowShareUsers(){ 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: "Downloaded DG Flows Browser", modal: true, autoOpen: true, width: 530, height: 530, buttons: [ { text: "Close", click: function() { //$( this ).dialog( "close" ); $(this).dialog('destroy').remove(); } } ] }).html(html); //$("#dgflow-browser-dialog").show(); $( "#dgflow-browser-dialog" ).dialog( "open" ); }) .fail(function(err) { RED.notify("Failed to get users."); }) .always(function() { }); } */ function detectLoopInFlow(){ var errList = []; var activeWorkspace=RED.view.getWorkspace(); var nSet=[]; RED.nodes.eachNode(function(n) { if (n.z == activeWorkspace) { nSet.push({n:n}); } }); var nodeSet = RED.nodes.createExportableNodeSet(nSet); var isLoopDetected = false; var dgStartNode = getDgStartNode(nodeSet); if(dgStartNode == null || dgStartNode == undefined) { console.log("dgstart node not linked."); return null; } var wires = dgStartNode.wires; var nodesInPath = {}; var dgStartNodeId = dgStartNode.id; if(wires != null && wires != undefined && wires[0] != undefined){ for(var k=0;k" + val] = ""; } }else{ nodesInPath[dgStartNodeId + "->" + ""] = ""; } var loopDetectedObj = {}; /* the nodes will not be in 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); errList.push("Loop detected between " + n1.name + " and " + n2.name); isLoopDetected = true; } } } } } for(var l=0;delKeys != null && l
    "; } } if(msg != ""){ isLoopDetected = true; //RED.notify(msg); } } */ //images/page-loading.gif return errList; } function showLoopDetectionBox(){ $(function() { var htmlStr="

    Loop detection in Progress ...

    " $("#loop-detection-dialog").dialog({ modal:true, autoOpen :true, title: "DG Flow Loop Detection", width: 400, height: 250, minWidth : 400, minHeight :200, }).html(htmlStr); if($("#loop-detection-dialog").dialog("isOpen") == true){ var errList = detectLoopInFlow(); var errList=[]; if(errList == null){ $("#loop-detection-dialog").dialog("close"); } var msgHtml = ""; for(var i=0;errList != null && i"; } if(msgHtml == ""){ $("loop-box-div").html("

    SUCCESS. No Loop detected.

    "); }else{ $("loop-box-div").html(msgHtml); } } }); } function showSelectedTabs(){ var tabSheets = []; var beforeTabsOrder=[]; $(".red-ui-tabs li a").each(function(i){ var id=$(this).attr("href").replace('#',''); var title=$(this).attr("title"); var isVisible = $(this).parent().is(":visible"); if(title != 'info'){ tabSheets.push({"id" : id ,"title":title,"module":"NOT_SET","version" : "NOT_SET","rpc":"NOT_SET","isVisible":isVisible}); beforeTabsOrder.push(id); } }); RED.nodes.eachNode(function(n) { if(n.type == 'service-logic'){ var id = n.z; var module = n.module; tabSheets.forEach(function(tab){ if(tab.id == id){ tab.module=module; tab.version=n.version; } }); }else if(n.type == 'method'){ var id = n.z; tabSheets.forEach(function(tab){ if(tab.id == id){ var rpc=getAttributeValue(n.xml,"rpc"); tab.rpc=rpc; } }); } }); //console.dir(tabSheets); var htmlStr = getHtmlStr(tabSheets); $("#filter-tabs-dialog").dialog({ modal:true, title: "DG Builder Tabs", width: 1200, height: 750, minWidth : 600, minHeight :450, }).html(htmlStr); /* This code allows for the drag-drop of the rows in the table */ var fixHelperModified = function(e, tr) { var $originals = tr.children(); var $helper = tr.clone(); $helper.children().each(function(index) { $(this).width($originals.eq(index).width()) }); return $helper; }, updateIndex = function(e, ui) { var afterTabsOrder=[]; $('td.index', ui.item.parent()).each(function (i) { $(this).html(i + 1); }); //RE-ARRANGE the tabs var ul = $("#workspace-tabs"); $("#ftab02 tr td:nth-child(1)").each(function(i){ var idStr = $(this).prop("id").replace("tab-td_",""); afterTabsOrder.push(idStr); link = ul.find("a[href='#"+ idStr+"']"); li = link.parent(); //li.remove(); firstTab = $("#workspace-tabs li:first-child"); lastTab = $("#workspace-tabs li:last-child"); li.insertAfter(lastTab); //console.log( idStr); }); var beforeTabsStr = beforeTabsOrder.join(","); var afterTabsStr = afterTabsOrder.join(","); //console.log("beforeTabsStr:" +beforeTabsStr); //console.log("afterTabsStr:" +afterTabsStr); if(beforeTabsStr !== afterTabsStr){ //activate only when order has changed //activate the deploy button RED.view.dirty(true); $("#btn-deploy").removeClass("disabled"); } }; $("#ftab02 tbody").sortable({ helper: fixHelperModified, stop: updateIndex }).disableSelection(); } function getHtmlStr(rows){ var styleStr = ""; if(rows != null && rows != undefined){ //var alertDialog = '
    '; //htmlStr= alertDialog + "
    " + styleStr; var alertDialog = '
    '; htmlStr= alertDialog + "
    " + styleStr; htmlStr += ""; htmlStr += ""; htmlStr += "" ; htmlStr += "" ; htmlStr += "" ; htmlStr += "" ; htmlStr += "" ; htmlStr += "" ; htmlStr += "" ; htmlStr += ""; htmlStr += ""; if(rows != null && rows.length == 0){ htmlStr += ""; htmlStr += ""; htmlStr += "
    No.Tab TitleModuleRPCVersionRenameDelete
    No rows found
    "; return htmlStr; } for(var i=0;i"; //htmlStr += "" + (i+1) + ""; htmlStr += "" + (i+1) + ""; htmlStr += "" + title + ""; htmlStr += "" + _module + ""; htmlStr += "" + rpc + ""; htmlStr += "" + version + ""; //htmlStr += "Delete/Rename"; htmlStr += ""; if(rows.length == 1){ htmlStr += ""; }else{ htmlStr += ""; } /* if(isVisible){ htmlStr += ""; }else{ htmlStr += ""; } */ htmlStr += ""; } htmlStr += ""; htmlStr += ""; htmlStr += "
    "; } return htmlStr; } /* Added this logic because , when the configuration item is choosen in the menu the other dialog boxes were not poping up */ (function(){ //var msecs1= Date.now(); $( "#gitlocal-browser-dialog" ).dialog(); $( "#gitlocal-browser-dialog" ).dialog("close"); $( "#dgflow-browser-dialog" ).dialog(); $( "#dgflow-browser-dialog" ).dialog("close"); $( "#update-password-dialog" ).dialog(); $( "#update-password-dialog" ).dialog("close"); $( "#codecloud-browser-dialog" ).dialog(); $( "#codecloud-browser-dialog" ).dialog("close"); $( "#update-configuration-dialog" ).dialog(); $( "#update-configuration-dialog" ).dialog("close"); $( "#gitcommands-dialog" ).dialog(); $( "#gitcommands-dialog" ).dialog("close"); $("#filter-tabs-dialog").dialog(); $("#filter-tabs-dialog").dialog("close"); $("#loop-detection-dialog").dialog(); $("#loop-detection-dialog").dialog("close"); $("#dgstart-generate-xml-dialog").dialog(); $("#dgstart-generate-xml-dialog").dialog("close"); $("#xmldialog").dialog(); $("#xmldialog").dialog("close"); $("#upload-xml-status-dialog").dialog(); $("#upload-xml-status-dialog").dialog("close"); $("#flow-design-err-dialog").dialog(); $("#flow-design-err-dialog").dialog("close"); $("#sli-values-dialog").dialog(); $("#sli-values-dialog").dialog("close"); $("#comments-dialog").dialog(); $("#comments-dialog").dialog("close"); $("#show-errors-dialog").dialog(); $("#show-errors-dialog").dialog("close"); $("#dgnumber-find-dialog").dialog(); $("#dgnumber-find-dialog").dialog("close"); $("#search-text-dialog").dialog(); $("#search-text-dialog").dialog("close"); $("#yang-upload-dialog").dialog(); $("#yang-upload-dialog").dialog("close"); $("#yang-modules-browser-dialog").dialog(); $("#yang-modules-browser-dialog").dialog("close"); $("#list-yang-browser-dialog").dialog(); $("#list-yang-browser-dialog").dialog("close"); $("#request-input-dialog").dialog(); $("#request-input-dialog").dialog("close"); $("#test-dg-dialog").dialog(); $("#test-dg-dialog").dialog("close"); $("#ctx-values-dialog").dialog(); $("#ctx-values-dialog").dialog("close"); $("#list-input-browser-dialog").dialog(); $("#list-input-browser-dialog").dialog("close"); $("#diff-browser-dialog").dialog(); $("#diff-browser-dialog").dialog("close"); //var msecs2= Date.now(); //console.log("Time taken for dialog boxes:" + (msecs2 - msecs1)); })(); //start functions to support Test DG function testDG(){ getSliParametersFromDG(); /* for (var property in callNodes) { if (callNodes.hasOwnProperty(property)) { console.log(property); var moduleRpc = property.split("_"); var mName = moduleRpc[0]; var rName = moduleRpc[1]; } } */ showTestDGDialog(); } function showInputFiles(files){ var divStyle=""; var header="
    List of Input Files
    "; var html= divStyle + header + "
    "; html+=""; html+=""; html+=""; html+=""; html+=""; files.sort(function (a,b){ if(a > b){ return -1; }else if(a < b){ return 1; }else{ return 0; } }); for(var i=0;files != null && i" + files[i] + ""; } html+="
    FileDelete
    " + "
    "; html+="
    "; $( "#list-input-browser-dialog" ).dialog({ title: "List Input Files", modal: true, autoOpen: true, width: 830, height: 630, buttons: [ { text: "Close", click: function() { $( this ).dialog( "close" ); } } ], close: function(ev,ui){ $(this).dialog("destroy"); } }).html(html); $("#list-input-browser-dialog").show(); } function showTestDGDialog(){ $.get("/getCurrentSettings",function (data){ var activeWorkspace=RED.view.getWorkspace(); var currNodes = RED.nodes.nodes.filter(function(d) { return d.z == activeWorkspace }) var moduleName = ""; var rpcName = ""; if(currNodes != null && currNodes.length > 1){ currNodes.forEach(function(n){ if(n.type == 'service-logic'){ moduleName = getAttributeValue(n.xml,"module"); }else if(n.type == 'method'){ rpcName = getAttributeValue(n.xml,"rpc"); } }); } var sliApiInputObj = { "input" : { "module-name" : moduleName, "rpc-name" : rpcName, "mode" : "sync", "sli-parameter" : []}}; var intParameterObj = { "parameter-name" : "", "int-value": 0}; var booleanParameterObj = { "parameter-name" : "", "boolean-value": true}; /* //Use this logic to add all the Ctx variables that have -input. Object.keys(dgParsedParameters).forEach(function(key,index) { //console.log("key:" + key + " index" +index ); if(key.indexOf("-input.") != -1){ key = key.replace(/\$/g,""); var strParameterObj = { "parameter-name" : key, "string-value": ""}; sliApiInputObj["input"]["sli-parameter"].push(strParameterObj); } }); */ var sliApiInputStr = JSON.stringify(sliApiInputObj,null,4); //var htmlStr="
    " //var htmlStr="
    " + inputValStr + "
    " //var htmlStr = "
    "; var htmlStr = "

    GET POST PUT DELETE

    "; htmlStr +="

    " //background: "#c3e8d1", $("#test-dg-dialog").dialog({ dialogClass :"no-close", modal:true, autoOpen :false, title: "Test DG Module:" + moduleName + " RPC:" + rpcName, width: 800, height: "auto", buttons :[ { text: "$Variables", click: function() { $("#test-dg-response").val(""); showCtxVariables(moduleName,rpcName); //console.dir(dgParsedParameters); } }, { text: "Load", click: function() { var inputData = { "moduleName" : moduleName, "rpcName" : rpcName }; $.post( "/getInputFiles",inputData ) .done(function( data ) { //console.dir(data); if(data != undefined && data != null){ showInputFiles(data.files); } }) .fail(function(err) { console.log( "failed to save input. " + err ); }) .always(function() { }); } }, { text: "Send", click: function() { $("#test-dg-response").val(""); var methodType =$("input[name=methodType]:checked").val(); var urlValue = $("#test-dg-url").val(); var reqData = {}; try{ reqData = JSON.parse($("#test-dg-request").val()); }catch(er){ $("#test-dg-response").val(er); return false; } //console.log("urlValue:" + urlValue); //console.dir(reqData); var inputStr = $("#test-dg-request").val(); //headers: { 'Authorization': 'Basic ' + btoa(data.restConfUser + ":" + data.restConfPassword)}, var inputData = { "moduleName" : moduleName, "rpcName" : rpcName, "inputStr" : inputStr }; $.post( "/saveTestDGInput",inputData ) .done(function( data ) { }) .fail(function(err) { console.log( "failed to save input. " + err ); }) .always(function() { $.ajax({ xhrFields: { withCredentials: true }, type: methodType, url: urlValue, data: JSON.stringify(reqData), contentType: "application/json; charset=utf-8", username : data.restConfUser, password : data.restConfPassword, success: function(data) { if(data != null){ $("#test-dg-response").val(JSON.stringify(data,null,4)); }else{ $("#test-dg-response").val("No Content returned"); } }, error: function(err) { if(err != null){ $("#test-dg-response").val(JSON.stringify(err,null,4)); }else{ $("#test-dg-response").val("error Occured"); } } }); }); } }, { text: "Reset", click: function() { $("#test-dg-request").val(sliApiInputStr); $("#test-dg-response").val(""); } }, { text: "Close", click: function() { $("#test-dg-dialog").dialog("close"); } } ], open:function(){ $('#test-dg-dialog').css('overflow', 'hidden'); } }).dialog("open").html(htmlStr).css("background","aliceblue"); }); } //end functions to support Test DG function updateConfiguration(){ //console.log("in updateConfiguration"); $.get("/getCurrentSettings",function (data){ var dbHost = data.dbHost; var dbPort = data.dbPort; var dbName = data.dbName; var dbUser = data.dbUser; var dbPassword = data.dbPassword; var formatXML = data.formatXML; var formatJSON = data.formatJSON; var gitLocalRepository = data.gitLocalRepository; var performGitPull = data.performGitPull; var restConfUrl = data.restConfUrl; var restConfUser = data.restConfUser; var restConfPassword = data.restConfPassword; var emailAddress = data.emailAddress; if(dbHost == undefined) dbHost=""; if(dbPort == undefined) dbPort=""; if(dbName == undefined) dbName=""; if(dbUser == undefined) dbUser=""; if(dbPassword == undefined) dbPassword=""; if(gitLocalRepository == undefined) gitLocalRepository=""; if(performGitPull == undefined || performGitPull == null) performGitPull="N"; if(restConfUrl == undefined) restConfUrl=""; if(restConfUser == undefined) restConfUser=""; if(restConfPassword == undefined) restConfPassword=""; if(emailAddress == undefined) emailAddress=""; if(formatXML == undefined) formatXML="Y"; if(formatJSON == undefined) formatJSON="Y"; var divStyle="border: 1px solid #a1a1a1; padding: 10px 40px; background: #dddddd; width: 600px; border-radius: 25px;"; //var divStyle="border: 2px solid #a1a1a1; padding: 10px 40px; background: #99CCFF; width: 400px; border-radius: 25px;"; var html = "
    "; html += ""; html += "
    "; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += "
    DB Host IP
    DB Port
    DB Name
    DB UserNameHide
    DB PasswordHide
    "; html += "
    "; html += "

    "; html += "
    "; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; html += "
    RestConf URL
    RestConf UserName"; html += "  Hide
    RestConf Password"; html += "  Hide
    "; html += "
    "; html += "

    "; html += "
    "; html += ""; html += ""; html += ""; html += ""; html += ""; html += "
    Git Local Repository Path
    "; html += ""; html += ""; if(performGitPull == "N"){ html += ""; }else{ html += ""; } html += ""; html += "
    Perform Git Pull in Local Git Repository prior to importPerform Git Pull in Local Git Repository prior to import
    "; html += "
    "; html += "

    "; html += "
    "; html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; if(formatXML == "Y"){ html += ""; }else{ html += ""; } if(formatJSON == "Y"){ html += ""; }else{ html += ""; } html += ""; html += "
    Email
    Format XMLFormat XMLFormat JSONFormat JSON
    "; html += "
    "; html += "
    "; //console.log("html:" + html); $( "#update-configuration-dialog" ).dialog({ title: "Configuration", modal: true, autoOpen: true, width: 730, height: 930, buttons: [ { text: "Save", click: function() { var newDBHost = $("#dbhost").val().trim(); var newDBPort = $("#dbport").val().trim(); var newDBName = $("#dbname").val().trim(); var newDBUser = $("#dbuser").val().trim(); var newDBPassword = $("#dbpassword").val().trim(); var newGitLocalRepository = $("#gitLocalRepository").val().trim(); var isFormatXML = $('#formatXML').is(':checked'); var isFormatJSON = $('#formatJSON').is(':checked'); var isPerformGitPullChecked = $('#performGitPull').is(':checked'); var newRestConfUrl = $("#restconfurl").val().trim(); var newRestConfUser = $("#restconfuser").val().trim(); var newRestConfPassword = $("#restconfpassword").val().trim(); var newPerformGitPull = "N"; var newEmailAddress = $("#emailaddress").val().trim(); //console.log("newEmailAddress:" + newEmailAddress); if(isPerformGitPullChecked){ newPerformGitPull = "Y"; } if(isFormatXML){ newFormatXML = "Y"; }else{ newFormatXML = "N"; } if(isFormatJSON){ newFormatJSON = "Y"; }else{ newFormatJSON = "N"; } if(newDBHost == ""){ RED.notify("Error: DB Host is required."); $("#dbhost").focus(); return; }else if(newDBPort == ""){ RED.notify("Error: DB Port is required."); $("#dbport").focus(); return; }else if(newDBName == ""){ RED.notify("Error: DB Name is required."); $("#dbname").focus(); return; }else if(newDBUser == ""){ RED.notify("Error: DB User is required."); $("#dbuser").focus(); return; }else if(newDBPassword == ""){ RED.notify("Error: DB Password is required."); $("#dbpassword").focus(); return; }else if(newEmailAddress == ""){ RED.notify("Error: Email Address is required."); $("#emailaddress").focus(); return; }else{ //console.log("newGitLocalRepository:" + newGitLocalRepository); var reqData= {"dbHost":newDBHost, "dbPort" : newDBPort, "dbName" : newDBName, "dbUser" : newDBUser, "dbPassword" : newDBPassword, "gitLocalRepository" : newGitLocalRepository, "performGitPull" : newPerformGitPull , "formatXML": newFormatXML, "formatJSON": newFormatJSON, "restConfUrl" : newRestConfUrl, "restConfUser" : newRestConfUser, "restConfPassword" : newRestConfPassword, "emailAddress" : newEmailAddress }; $.post( "/updateConfiguration",reqData ) .done(function( data ) { RED.settings.emailAddress = newEmailAddress; format_xml = newFormatXML; format_json = newFormatJSON; RED.notify("Configuration updated successfully"); //loadSettings(); //RED.comms.connect(); //$( "#update-configuration-dialog" ).dialog('close'); $("#update-configuration-dialog").dialog("close"); //location.reload(); }) .fail(function(err) { console.log( "error" + err ); RED.notify("Failed to update the Configuration."); }) .always(function() { }); } } }, { text: "Cancel", click: function() { $( this ).dialog( "close" ); } } ] }).html(html); //$("#update-configuration-dialog").show(); $("#gitLocalRepository").css({"width" : 300}); }); } function updatePassword(){ var html="
    "; html += "
    New Password
    "; html += ""; html += "
    "; html += "
    Confirm Password
    "; html += ""; html += "
    "; $( "#update-password-dialog" ).dialog({ title: "Update Password", modal: true, autoOpen: true, width: 530, height: 230, buttons: [ { text: "Update Password", click: function() { var passwd1 = $("#passwd1").val().trim(); var passwd2 = $("#passwd2").val().trim(); if((passwd1 != passwd2) || (passwd1 == "" || passwd2 == "")){ RED.notify("Error:Passwords entered must be same and must be populated."); return; }else{ var reqData= {"password":passwd1}; $.post( "/updatePassword",reqData ) .done(function( data ) { RED.notify("Password updated successfully"); //loadSettings(); $( "#update-password-dialog" ).dialog('close'); }) .fail(function(err) { console.log( "error" + err ); RED.notify("Failed to update the password."); }) .always(function() { }); } } }, { text: "Cancel", click: function() { $( this ).dialog( "close" ); } } ] }).html(html); $("#update-password-dialog").show(); } function showAvailableYangModules(){ availableYangModules=[]; var divStyle=""; $.get( "/listAvailableModules") .done(function( data ) { var header="
    List of Available Yang Modules
    "; header += "

    Check the modules that you want to load and click on the Load button.

    "; //header += "
    "; var html= divStyle + header + "
    "; html+=""; html+=""; html+=""; html+=""; html+=""; html+=""; if(data != null){ var files=data.files; availableYangModules=files; //console.dir(files); files.sort(function (a,b){ if(a > b){ return 1; }else if(a < b){ return -1; }else{ return 0; } }); var count=1; for(var i=0;files != null && i"; }else{ html+=""; } count++; } } html+="
    #LoadModule
    " + val + "
    " + count + "" + val + "
    "; html+="
    "; $( "#yang-modules-browser-dialog" ).dialog({ title: "Available Yang Modules", modal: true, autoOpen: true, width: 830, height: 630, buttons: [ { text: "Load", click: function() { var allVals = []; function getValuesForSelected() { $('#yang-modules-data-container :checked').each(function() { allVals.push($(this).val()); }); return allVals; } var selectedModules = getValuesForSelected().toString(); console.log(selectedModules); $.ajax({ type: 'GET', /*contentType: "application/x-www-form-urlencoded",*/ url: '/loadSelectedModules?selectedModules=' + selectedModules, success: function(data) { RED.notify("Modules Loaded successfully"); //emptying existing g;obal variables sliValuesObj = {}; rpcValues = {}; reqInputValues = {}; if(data != undefined && data != null){ for(var i=0;i