2 function addParam(idVal){
4 //console.log(global_editor.getText());
5 if(global_added_obj["a" + idVal] != undefined && global_added_obj["a" + idVal] != null){
6 global_added_obj["a" + idVal]= global_added_obj["a" + idVal]+1;
7 $("#addCnt" + + idVal).text("added " + global_added_obj["a" + idVal] + " times");
9 global_added_obj["a" + idVal]= 1;
10 $("#addCnt" + + idVal).text("added " + global_added_obj["a" + idVal] + " time");
12 var nameVal = document.getElementById("a" + idVal).value;
13 var valueBoxVal = document.getElementById("valbox" + idVal).value;
14 //$("#btn" + idVal).val('Added');
15 //$("#btn" + idVal).attr('disabled','disabled');
16 //console.dir(nameVal);
17 //console.dir(valueBoxVal);
20 var paramElement = "<parameter name='" + nameVal + "' value='" + valueBoxVal + "'/>\n";
21 global_editor.setText(global_editor.getText() + paramElement);
24 var g_currValuesObj={};
26 function filterValues(filterVal){
29 var valuesObj = g_currValuesObj;
32 if(filterVal != null && filterVal != undefined){
33 filterVal=filterVal.trim();
35 searchValues = filterVal.split(/ /);
36 //console.log("filterVal:" + filterVal);
37 if(searchValues != null && searchValues != undefined){
38 for (var key in valuesObj) {
39 if (valuesObj.hasOwnProperty(key)) {
41 if(Array.isArray(valuesObj[key])){
42 var arrObj=valuesObj[key];
44 for(var i=0;i<arrObj.length;i++){
46 for(var k=0;k<searchValues.length;k++){
47 if(arrObj[i].indexOf(searchValues[k]) != -1){
51 if(foundCount == searchValues.length){
53 newArrObj.push(arrObj[i]);
56 newValuesObj[key] = newArrObj;
60 $("#matchedCntId").html(matchedCnt);
62 newValuesObj = valuesObj;
64 var valuesHtml=buildValuesHtml(newValuesObj);
66 $("#sli-values-div").html(valuesHtml);
69 function buildValuesHtml(valuesObj){
73 for (var key in valuesObj) {
74 if (valuesObj.hasOwnProperty(key)) {
75 var v = "<div style='font-weight:bold;font-size:1.0em;'><label>" + key + "<b/label>";
76 if(Array.isArray(valuesObj[key])){
77 var arrObj=valuesObj[key];
79 for(var i=0;i<arrObj.length;i++){
80 var idVal = idCounter++;
81 var addBtn = "<input id='btn" + idVal + "' type='button' style='background-color:#D6EBFF;' value='Add as Parameter'" + "onclick='addParam(\"" + idVal + "\")'><div style='float:right' id='addCnt" + idVal + "'></div>";
83 var valBox = "<input id='valbox" + idVal + "' type='text' style='width:500px;height:30px;' value=''>";
84 if(arrObj[i] != undefined && arrObj[i].length <150){
85 //v += "<div style='width:1150px;background:aliceblue;border-color:aliceblue' class='valueBoxDiv' id='valueBoxDiv" + idVal + "'>" + "<input style='width:1125px;background:rgb(223, 191, 191);color:rgb(32, 45, 87);' type='text' readonly='1' id='a" + idVal + "' onclick='selectText(\"" + idVal+"\",\"" + key + "\")' value='" +arrObj[i] + "' title='" + arrObj[i] + "' >" ;
86 v += "<div style='width:1150px;background:aliceblue;border-color:aliceblue' class='valueBoxDiv' id='valueBoxDiv" + idVal + "'>" + "<input style='width:1125px;background:aliceblue;color:rgb(32, 45, 87);' type='text' readonly='1' id='a" + idVal + "' onclick='selectText(\"" + idVal+"\",\"" + key + "\")' value='" +arrObj[i] + "' title='" + arrObj[i] + "' >" ;
87 variableBox = "<input style='width:1125px' id='variableBox" + idVal + "' type='text' value='`$" + arrObj[i] + "`'>";
89 v+= "<div style='width:1150px;background:aliceblue;border-color:aliceblue' class='valueBoxDiv' id='valueBoxDiv" + idVal + "'>" + "<textarea style='width:1125px;background:aliceblue;color:rgb(32, 45, 87);' readonly='1' id='a" + idVal + "' onclick='selectText(\"" + idVal+"\",\"" + key + "\")' title='" + arrObj[i] + "' >" + arrObj[i] + "</textarea>";
90 variableBox = "<textarea style='width:1125px' id='variableBox" + idVal + "' >`$" + arrObj[i] + "`'</textarea>";
92 v += "<div id='valAddDiv" + idVal + "' style='display:none;'>" + valBox + " " + addBtn + "</div>" +
93 "<div id='variableBoxDiv" + idVal + "' style='display:none;color:rgb(32, 45, 87);'>Display as a variable<br>" + variableBox + "</div>" + "</div>";
96 htmlVal+= v + "</div>";
103 function getModuleName(){
104 var activeWorkspace=RED.view.getWorkspace();
106 RED.nodes.eachNode(function(n) {
107 if (n.z == activeWorkspace) {
108 if(n.type == 'service-logic'){
109 //console.log("getModuleName():<" + n.module + ">");
116 var global_added_obj={};
117 var displayingRpcs = false;
118 function showRpcsValuesBox(editor,valuesObj){
119 displayingRpcs = true;
120 showValuesBox(editor,valuesObj);
123 function showValuesBox(editor,valuesObj){
124 var moduleName = getModuleName();
125 var obj = valuesObj[moduleName];
126 //console.dir(valuesObj);
129 if(obj == undefined){
130 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."];
132 moduleObj[moduleName] = obj;
134 showValuesBoxForModule(editor,moduleObj,moduleName);
137 function showValuesBoxForModule(editor,valuesObj,moduleName){
138 global_editor=editor;
139 g_currValuesObj = valuesObj;
140 //console.log(editor.getText());
141 //populate the valid SLI values
142 var valuesHtml="<style>.color-dialog {background:aliceblue;border-color:lightgrey;border-width:3px;border-style:solid; }</style><div style='float:left;width:1200px;background:aliceblue'><input style='width:1125px' id='filter-id' type='text' value='' placeholder='To filter the values type words seperated by space in this box' onkeyup='filterValues(this.value)'></div><div style='float:left;color:green;font-size:0.8em' id='matchedCntId'></div><div style='clear:both'></div><div id='sli-values-div' style='width:1200px;'>" ;
143 valuesHtml+=buildValuesHtml(valuesObj);
144 valuesHtml+="</div>";
148 var title = "SLI Values for Module " + moduleName;
150 title = "RPCs for Module " + moduleName;
152 $('#sli-values-dialog').dialog({
157 dialogClass: 'color-dialog',
159 $("#sli-values-dialog").dialog("widget").find(".ui-dialog-buttonpane").css({'background': 'aliceblue'});
160 $(this).html(valuesHtml);
164 displayingRpcs = false;
165 //$(this).dialog("close");
166 $(this).dialog("destroy");
169 close: function(ev,ui){
170 displayingRpcs = false;
171 $(this).dialog("destroy");
173 }); // end dialog div
176 function showCommentsBox(){
177 var comments = $("#node-input-comments").val();
178 var commentsBoxHtml="<div><textarea style='font-size:18px;height:150px;width:390px;' id='taCommentId'>" + comments + "</textarea></div>" ;
180 var nodeName=$("#node-input-name").val();
181 $('#comments-dialog').dialog({
183 title: "Add comments for Node " + nodeName,
188 $(this).html(commentsBoxHtml);
192 "Save Comments": function () {
193 var v=$("#taCommentId").val();
197 $("#node-input-btnComments").html("<span style='color:blue;'><b>View Comments</b></span>");
199 $("#node-input-btnComments").html("<b>Add Comments</b>");
202 //console.log("value from text area" + v);
203 $("#node-input-comments").val(v);
204 $(this).dialog("close");
205 //$(this).dialog("destroy");
207 Cancel: function () {
208 var v=$("#taCommentId").val();
212 $("#node-input-btnComments").html("<span style='color:blue;'><b>View Comments</b></span>");
214 $("#node-input-btnComments").html("<b>Add Comments</b>");
217 $(this).dialog("close");
218 //$(this).dialog("destroy");
221 close: function(ev,ui){
222 //console.log("closing..");
223 $(this).dialog("destroy");
225 }).html(commentsBoxHtml);
227 //console.log("done");
229 function functionDialogResize(ev,ui) {
230 console.log("ui.size.height:" + ui.size.height);
231 $(this).css("height",(ui.size.height-275)+"px");
234 $( this ).on("dialogresize", functionDialogResize);
237 $( this ).one("dialogopen", function(ev) {
238 var size = $( "#sliValDiv" ).dialog('option','sizeCache-function');
240 functionDialogResize(null,{size:size});
247 function selectText(objId,groupVal){
248 //console.log(objId + groupVal);
249 //console.log(objId + groupVal);
250 $(document).ready(function(){
251 //console.log("doc ready");
252 //console.dir($('#valAddDiv' + objId));
253 if ($('#valAddDiv' + objId).is(":visible")) {
254 $("#variableBoxDiv" + objId ).hide("slow");
255 //$("#a" + objId ).css({"background": "rgb(223, 191, 191)",
256 // "color": "rgb(32, 45, 87)"});
257 $("#a" + objId ).css({"background": "aliceblue",
258 "color": "rgb(32, 45, 87)"});
259 /*"color": "rgb(32, 45, 87)"});*/
260 $("#valAddDiv" + objId ).hide("slow");
261 $("#valueBoxDiv" +objId).css({"border-color": "aliceblue",
262 "border-width":"1px",
263 "background-color":"aliceblue",
264 "border-style":"solid"});
265 //$("#valAddDiv" + objId ).fadeOut("slow");
267 $("#variableBoxDiv" + objId ).show("slow");
268 $("#valAddDiv" + objId).show("slow");
269 /*$("#valueBoxDiv" +objId).css({"border-color": "rgb(75, 111, 147)",
270 "border-width":"5px",
271 "background-color": "rgb(223, 191, 191)",
272 "border-style":"solid",
273 "border-bottom": "5px solid rgb(75, 111, 147)"});
275 $("#valueBoxDiv" +objId).css({"border-color": "rgb(75, 111, 147)",
276 "border-width":"3px",
277 "background-color": "aliceblue",
278 "border-style":"solid",
279 "border-bottom": "3px solid rgb(75, 111, 147)"});
280 /*$("#a" + objId ).css({"background": "rgb(223, 191, 191)",
281 "color": "rgb(75, 111, 147)"});
283 $("#a" + objId ).css({"background": "aliceblue",
284 "color": "rgb(75, 111, 147)"});
286 $("#a" + objId).select();
288 //console.log("group-heading" + objId);
289 // var obj= document.getElementById("group-heading" + objId);
290 // obj.innerText = groupVal;
291 // obj.style.color = "blue";
295 function hidePrevGroup(objId){
296 // console.log("mouseout" );
297 // var obj= document.getElementById("group-heading" + objId);
298 // obj.innerText = "";
302 var $cache = $('#getFixed');
303 if ($(window).scrollTop() > 100)
310 'position': 'relative',
315 $(window).scroll(fixDiv);
317 function isScrolledIntoView(elem)
320 var $window = $(window);
322 var docViewTop = $window.scrollTop();
323 var docViewBottom = docViewTop + $window.height();
325 var elemTop = $elem.offset().top;
326 var elemBottom = elemTop + $elem.height();
328 return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
332 function getCommits(filePath){
333 var urlPath="/getCommitsInfo";
334 $.get(urlPath,{"filePath" : filePath })
335 .done(function( data ) {
336 if(data != undefined && data != null){
337 //console.log(data.stdout);
338 var jsonObj = JSON.parse(data.stdout);
339 var codeCloudFilesHtmlStr = $( "#codecloud-browser-dialog" ).html();
340 var htmlStr = getCCFileHtmlStr(filePath,jsonObj,codeCloudFilesHtmlStr);
341 $( "#codecloud-browser-dialog" ).html(htmlStr);
343 for(var i=0;i<jsonObj.length;i++){
344 console.log("commit:" + jsonObj[i].commit);
345 console.log("date:" + jsonObj[i].date);
346 console.log("author:" + jsonObj[i].author);
347 console.log("comment:" + jsonObj[i].comment);
352 .fail(function(err) {
359 function getCCFileHtmlStr(filePath,rows,codeCloudFilesHtmlStr){
360 var styleStr = "<style> " +
361 "table#cct01 { width:100%; } \n" +
362 "table#cct01 th,table#cct01 td { border: 1px solid black; border-collapse: collapse; } \n" +
363 "table#cct01 th,table#cct01 td { padding: 5px; text-align: left; } \n" +
364 "table#cct01 tr:nth-child(even) { background-color: #eee; }\n" +
365 "table#cct01 tr:nth-child(odd) { background-color:#fff; }\n" +
366 "table#cct01 th { background-color: #65a9d7; color: white; }\n" +
367 "table#cct01 a { color: #337ab7; }\n" +
368 "table#cct01 a:link { color: #65a9d7; }\n" +
369 "table#cct01 a:visited { color: #636; }\n" +
370 "table#cct01 a:hover { color: #3366CC; cursor: pointer }\n" +
371 "table#cct01 a:active { color: #65a9d7 }\n" +
372 "table#cct01 caption { display: table-caption; text-align: center; background: #eee; font-weight: bold; font-size: 1.1em; border: 1px solid black; }\n" +
376 if(rows != null && rows.length >0){
377 var alertDialog = '<div id="ccAlertdialog"></div>';
378 htmlStr= alertDialog + "<div style='width:1050;height:650'>" + styleStr;
379 htmlStr += "<table id='cct01' >";
380 htmlStr += "<caption id='ccCaptionId'>" + filePath + "</caption>";
382 htmlStr += "<th>Commit ID</th>" ;
383 htmlStr += "<th>Date</th>" ;
384 htmlStr += "<th>Author</th>" ;
385 htmlStr += "<th>Comment</th>" ;
387 if(rows != null && rows.length == 0){
389 htmlStr += "<td><b>No rows found</b></td>";
390 htmlStr += "</tr></table></div>";
393 for(var i=0;i<rows.length;i++){
395 var _commitId = row.commit;
397 var author = row.author;
398 var comment = row.comment;
400 htmlStr += "<td><a onclick=\"javascript:importCCFlow('" + _commitId + "','" + filePath + "')\">" + _commitId + "</a></td>";
401 htmlStr += "<td>" + dt + "</td>";
402 htmlStr += "<td>" + author + "</td>";
403 htmlStr += "<td>" + comment + "</td>";
406 htmlStr += "</table>";
409 //console.log(htmlStr);
414 var gitLocalFlowFiles=[];
415 function filterGitLocalFlows(filterVal){
418 var valuesObj = gitLocalFlowFiles;
419 //console.dir(codeCloudFlowFiles);
420 var updatedValuesObj =[];
421 var searchValues =[];
422 if(filterVal != null && filterVal != undefined){
423 filterVal=filterVal.trim();
425 searchValues = filterVal.split(/ /);
426 //console.log("filterVal:" + filterVal);
427 //console.dir(searchValues);
428 if(searchValues != null && searchValues != undefined){
430 for(var k=0;k<searchValues.length;k++){
432 valuesObj=updatedValuesObj;
435 for(var i=0;i<valuesObj.length;i++){
436 var patt = new RegExp(searchValues[k],"gi");
437 if(patt.test(valuesObj[i])){
439 updatedValuesObj.push(valuesObj[i]);
444 updatedValuesObj = valuesObj;
446 //console.dir(updatedValuesObj);
448 if(updatedValuesObj != null){
449 var files=updatedValuesObj;
450 //console.dir(files);
451 files.sort(function (a,b){
460 for(var i=0;files != null && i<files.length;i++){
461 html+="<li><a href=\"#\" onclick=\"importGitLocalFlow('" + files[i] + "')\">" + files[i] + "</a></li>";
466 $( "#gitlocal-data-container" ).html(html);
469 var codeCloudFlowFiles=[];
470 function filterFlows(filterVal){
473 var valuesObj = codeCloudFlowFiles;
474 //console.dir(codeCloudFlowFiles);
475 var updatedValuesObj =[];
476 var searchValues =[];
477 if(filterVal != null && filterVal != undefined){
478 filterVal=filterVal.trim();
480 searchValues = filterVal.split(/ /);
481 //console.log("filterVal:" + filterVal);
482 //console.dir(searchValues);
483 if(searchValues != null && searchValues != undefined){
485 for(var k=0;k<searchValues.length;k++){
486 for(var i=0;i<valuesObj.length;i++){
487 var patt = new RegExp(searchValues[k],"gi");
488 if(patt.test(valuesObj[i])){
490 updatedValuesObj.push(valuesObj[i]);
495 updatedValuesObj = valuesObj;
497 //console.dir(updatedValuesObj);
499 if(updatedValuesObj != null){
500 var files=updatedValuesObj;
501 //console.dir(files);
502 files.sort(function (a,b){
511 for(var i=0;files != null && i<files.length;i++){
512 html+="<li><a href=\"#\" onclick=\"getCommits('" + files[i] + "')\">" + files[i] + "</a></li>";
517 $( "#codecloud-data-container" ).html(html);
520 var yangFilesList=[];
522 function filterYangFiles(filterVal){
525 var valuesObj = yangFilesList;
526 var updatedValuesObj =[];
527 var searchValues =[];
528 if(filterVal != null && filterVal != undefined){
529 filterVal=filterVal.trim();
531 searchValues = filterVal.split(/ /);
532 if(searchValues != null && searchValues != undefined){
534 for(var k=0;k<searchValues.length;k++){
535 for(var i=0;i<valuesObj.length;i++){
536 var patt = new RegExp(searchValues[k],"gi");
537 if(patt.test(valuesObj[i])){
539 updatedValuesObj.push(valuesObj[i]);
544 updatedValuesObj = valuesObj;
546 //console.dir(updatedValuesObj);
548 if(updatedValuesObj != null){
549 var files=updatedValuesObj;
550 //console.dir(files);
551 files.sort(function (a,b){
560 for(var i=0;files != null && i<files.length;i++){
561 html+="<li><a href=\"#\" onclick=\"getYangFile('" + files[i] + "')\">" + files[i] + "</a></li>";
566 $( "#list-yang-data-container" ).html(html);
570 function filterYangFiles(filterVal){
572 var valuesObj = yangFilesList;
573 var updatedValuesObj =[];
574 var searchValues =[];
575 if(filterVal != null && filterVal != undefined){
576 filterVal=filterVal.trim();
578 searchValues = filterVal.split(/ /);
579 if(searchValues != null && searchValues != undefined){
581 for(var k=0;k<searchValues.length;k++){
582 for(var i=0;i<valuesObj.length;i++){
583 var patt = new RegExp(searchValues[k],"gi");
584 if(patt.test(valuesObj[i])){
586 updatedValuesObj.push(valuesObj[i]);
591 updatedValuesObj = valuesObj;
593 //console.dir(updatedValuesObj);
594 var html="<table id='yang-file-list-table' border=1>";
596 html+="<th>File</th>";
597 html+="<th>Delete</th>";
600 if(updatedValuesObj != null){
601 var files=updatedValuesObj;
602 //console.dir(files);
603 files.sort(function (a,b){
612 for(var i=0;files != null && i<files.length;i++){
613 html+="<tr><td><a href=\"#\" onclick=\"getYangFile('" + files[i] + "')\">" + files[i] + "</a></td><td>" + "<input type='button' onclick='deleteYangFile(\"" + files[i] + "\")' value='Delete'></td></td></td></tr>";
619 $( "#yang-files-data-container" ).html(html);
622 function getYangFile(fileName){
623 $("#dwnldYangFormId").remove();
624 //using form to submit
625 var form = $('<form id="dwnldYangFormId" method="POST" action="/downloadYang"></form>');
626 form.append('<input type="hidden" name="fileName" value="' + fileName + '"/>');
627 form.appendTo('body');
628 $("#dwnldYangFormId").submit();
631 function deleteYangFile(fileName){
632 var reqData= {"fileName":fileName};
633 $.post( "/deleteYangFile",reqData )
634 .done(function( data ) {
636 .fail(function(err) {
637 console.log( "error" + err );
640 $("#list-yang-browser-dialog").dialog("close");
641 $("#btn-list-yang-files").trigger("click");
645 function importCCFlow(commitId,filePath){
646 var urlPath="/importCodeCloudFlow";
647 $.get(urlPath,{"commitId" : commitId,"filePath" : filePath })
648 .done(function( data ) {
649 if(data != undefined && data != null){
650 //console.log(data.stdout);
651 var jsonObj = JSON.parse(data.stdout);
652 $( "#codecloud-browser-dialog" ).dialog("close");
653 RED.view.importNodes(JSON.stringify(jsonObj));
656 .fail(function(err) {
657 RED.notify("Could not import flow from code cloud.");
658 $( "#codecloud-browser-dialog").dialog("close");
659 console.log( "error occured importing flow.");
665 function importGitLocalFlow(filePath){
666 var urlPath="/importGitLocalFlow";
667 $.get(urlPath,{"filePath" : filePath })
668 .done(function( data ) {
669 if(data != undefined && data != null){
670 //console.log(data.stdout);
673 jsonObj = JSON.parse(data.stdout);
674 $( "#gitlocal-browser-dialog" ).dialog("close");
675 RED.view.importNodes(JSON.stringify(jsonObj));
677 RED.notify("Could not import flow from Local Git Repository.");
678 $( "#gitlocal-browser-dialog").dialog("close");
679 console.log( "error occured importing flow." + err);
682 RED.notify("Could not import flow from Local Git Repository.");
683 $( "#gitlocal-browser-dialog").dialog("close");
684 console.log( "error occured importing flow." + err);
687 .fail(function(err) {
688 RED.notify("Could not import flow from Local Git Repository.");
689 $( "#gitlocal-browser-dialog").dialog("close");
690 console.log( "error occured importing flow.");
696 var availableYangModules=[];
697 function filterYangModules(filterVal){
700 var valuesObj = availableYangModules ;
701 //console.dir(codeCloudFlowFiles);
702 var updatedValuesObj =[];
703 var searchValues =[];
704 if(filterVal != null && filterVal != undefined){
705 filterVal=filterVal.trim();
707 searchValues = filterVal.split(/ /);
708 //console.log("filterVal:" + filterVal);
709 //console.dir(searchValues);
710 if(searchValues != null && searchValues != undefined){
712 for(var k=0;k<searchValues.length;k++){
714 valuesObj=updatedValuesObj;
717 for(var i=0;i<valuesObj.length;i++){
718 var patt = new RegExp(searchValues[k],"gi");
719 if(patt.test(valuesObj[i])){
721 updatedValuesObj.push(valuesObj[i]);
726 updatedValuesObj = valuesObj;
728 //console.dir(updatedValuesObj);
730 html+="<table border=1>";
733 html+="<th>Load</th>";
734 html+="<th>Module</th>";
737 if(updatedValuesObj != null){
738 var files=updatedValuesObj;
739 //console.dir(files);
740 files.sort(function (a,b){
750 for(var i=0;files != null && i<files.length;i++){
751 var val = files[i].replace(/:.*/,"");
752 if(files[i].indexOf(":checked") != -1){
753 html+="<tr><td>" + count + "</td><td><input type='checkbox' checked value='" + val + "'></td><td>" + val + "</td></tr>";
755 html+="<tr><td>" + count + "</td><td><input type='checkbox' value='" + val + "'></td><td>" + val + "</td></tr>";
762 $( "#yang-modules-data-container" ).html(html);