+
+ //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="<style>#input-files-data-container a { color: #067ab4; font-size: 0.75em;} #input-files-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; } table#input-file-list-table { width:100%; } table#input-file-list-table th,table#input-file-list-table td { border: 1px solid black; border-collapse: collapse; } table#input-file-list-table th,table#input-file-list-table td { padding: 5px; text-align: left; } table#input-file-list-table tr:nth-child(even) { background-color: #eee; } table#input-file-list-table tr:nth-child(odd) { background-color:#fff; } table#input-file-list-table th { background-color: #65a9d7; color: white; } table#input-file-list-table a { color: #337ab7; } table#input-file-list-table a:link { color: #65a9d7; } table#input-file-list-table a:visited { color: #636; } table#input-file-list-table a:hover { color: #3366CC; cursor: pointer } table#input-file-list-table a:active { color: #65a9d7 }</style>";
+
+ var header="<div class='header'>List of Input Files </div>";
+ var html= divStyle + header + "<div id='input-files-data-container'>";
+ html+="<table id='input-file-list-table' border=1>";
+ html+="<tr>";
+ html+="<th>File</th>";
+ html+="<th>Delete</th>";
+ html+="</tr>";
+ files.sort(function (a,b){
+ if(a > b){
+ return -1;
+ }else if(a < b){
+ return 1;
+ }else{
+ return 0;
+ }
+ });
+ for(var i=0;files != null && i<files.length;i++){
+ html+="<tr><td><a href=\"#\" onclick=\"loadInputFile('" + files[i] + "')\">" + files[i] + "</a></td><td>" + "<input type='button' onclick='deleteInputFile(\"" + files[i] + "\")' value='Delete'></td></td></td></tr>";
+ }
+ html+="</table>";
+ html+="</div>";
+ $( "#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="<div id='request-template-div' style='width:875px;height:575px'><textarea style='width:875px;height:575px'>" + inputValStr + "</textarea></div>"
+ //var htmlStr="<div id='request-template-div' style='width:750px;height:550px;font-weight:bold;font-size:1em'><pre>" + inputValStr + "</pre></div>"
+ //var htmlStr = "<div id='test-dg-div' style='width:750px;height:50px'>";
+ var htmlStr = "<label style='font-weight:bold;font-size:1em'>URL</label><input id='test-dg-url' type='textbox' style='width:743px;height:30px;font-weight:bold;font-size:1em' value='" + data.restConfUrl + "'><br><br><label style='font-weight:bold;font-size:1em'>Method</label><input type='radio' name='methodType' value='GET'> GET <input type='radio' name='methodType' value='POST' checked> POST <input type='radio' name='methodType' value='PUT' > PUT <input type='radio' name='methodType' value='DELETE' > DELETE <br><br><label style='font-weight:bold;font-size:1em'>Input</label>";
+ htmlStr +="<textarea id='test-dg-request' style='width:750px;height:350px;font-size:1em' >" + sliApiInputStr + "</textarea><br><br><label style='font-weight:bold;font-size:1em'>Response</label><textarea id='test-dg-response' style='width:750px;height:150px;font-weight:bold;font-size:1em'></textarea>"
+ //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
+
+