[CCSDK-28] populated the seed code for dgbuilder
[ccsdk/distribution.git] / dgbuilder / public / util / js / sliValues.js
1 var global_editor ; 
2 function addParam(idVal){
3         //console.log(val);
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");
8         }else{
9                 global_added_obj["a" + idVal]= 1;
10                 $("#addCnt" +  + idVal).text("added " + global_added_obj["a" + idVal] + " time");
11         }
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);
18
19
20         var paramElement = "<parameter name='" + nameVal + "' value='" + valueBoxVal + "'/>\n";
21         global_editor.setText(global_editor.getText() + paramElement);
22 }
23
24 var g_currValuesObj={};
25
26 function filterValues(filterVal){
27         global_added_obj={};
28         var matchedCnt =0;
29         var valuesObj = g_currValuesObj;
30         var newValuesObj ={};
31         var searchValues =[];
32         if(filterVal != null && filterVal != undefined){
33                 filterVal=filterVal.trim();
34         }       
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)) {
40                                 var newArrObj = [];
41                                 if(Array.isArray(valuesObj[key])){
42                                         var arrObj=valuesObj[key];
43                                         var cnt=1;
44                                         for(var i=0;i<arrObj.length;i++){
45                                                 var foundCount = 0;
46                                                 for(var k=0;k<searchValues.length;k++){
47                                                         if(arrObj[i].indexOf(searchValues[k]) != -1){
48                                                                 foundCount++;
49                                                         }
50                                                 }
51                                                 if(foundCount == searchValues.length){
52                                                         matchedCnt++;
53                                                         newArrObj.push(arrObj[i]);
54                                                 }
55                                         }       
56                                         newValuesObj[key] =  newArrObj;
57                                 }               
58                         }
59                 }
60                 $("#matchedCntId").html(matchedCnt);
61         }else{
62                 newValuesObj = valuesObj;
63         }
64         var valuesHtml=buildValuesHtml(newValuesObj);   
65         valuesHtml+="</div>";
66         $("#sli-values-div").html(valuesHtml);
67 }
68
69 function buildValuesHtml(valuesObj){
70         var idCounter=0;
71         var htmlVal = "";
72         
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];
78                         var cnt=1;
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>";
82                         var variableBox = "";
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] + "`'>";
88                         }else{
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>";
91                         }
92                           v += "<div id='valAddDiv" +  idVal + "' style='display:none;'>" +  valBox + "&nbsp;&nbsp;" + addBtn + "</div>" +
93                            "<div id='variableBoxDiv" + idVal + "' style='display:none;color:rgb(32, 45, 87);'>Display as a variable<br>" + variableBox + "</div>" + "</div>";
94                         cnt++;
95                       }
96                       htmlVal+= v + "</div>";
97                                 }
98                    }
99              }
100         return htmlVal;
101 }
102
103 function getModuleName(){
104         var activeWorkspace=RED.view.getWorkspace();
105         var moduleName="";
106         RED.nodes.eachNode(function(n) {
107                 if (n.z == activeWorkspace) {
108                         if(n.type == 'service-logic'){
109                                 //console.log("getModuleName():<" + n.module + ">");
110                                 moduleName=n.module;
111                         }
112                 }
113         });
114         return moduleName;
115 }
116 var global_added_obj={};
117 var displayingRpcs = false;
118 function showRpcsValuesBox(editor,valuesObj){
119         displayingRpcs = true;
120         showValuesBox(editor,valuesObj);
121 }
122
123 function showValuesBox(editor,valuesObj){
124         var moduleName = getModuleName();       
125         var obj = valuesObj[moduleName];
126         //console.dir(valuesObj);
127         //console.dir(obj);
128         var moduleObj ={};
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."];      
131         }else{
132                 moduleObj[moduleName] = obj;
133         }
134         showValuesBoxForModule(editor,moduleObj,moduleName);    
135 }
136
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>";
145         global_added_obj={};
146
147         
148  var title = "SLI Values for Module " + moduleName;     
149         if(displayingRpcs){
150                 title = "RPCs for Module " + moduleName;
151         }
152         $('#sli-values-dialog').dialog({
153                        modal: false,
154                        title: title,
155                        width: 1200,
156                        height: 500,
157                        dialogClass: 'color-dialog',
158                        open: function () {
159                                 $("#sli-values-dialog").dialog("widget").find(".ui-dialog-buttonpane").css({'background': 'aliceblue'});
160                                 $(this).html(valuesHtml);
161                        },
162                        buttons: {
163                            Close: function () {
164                                 displayingRpcs = false;
165                               //$(this).dialog("close");
166                               $(this).dialog("destroy");
167                            }
168                        },
169                         close: function(ev,ui){
170                                 displayingRpcs = false;
171                                 $(this).dialog("destroy");
172                         }
173         }); // end dialog div
174 }
175
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>" ;
179
180         var nodeName=$("#node-input-name").val();
181         $('#comments-dialog').dialog({
182                        modal: true,
183                        title: "Add comments for Node " + nodeName,
184                        width: 450,
185                        height: 300,     
186                         /*      
187                        open: function () {
188                                 $(this).html(commentsBoxHtml);
189                        },
190                         */
191                        buttons: {
192                            "Save Comments": function () {
193                                 var v=$("#taCommentId").val();
194                                 if(v != null){
195                                         v = v.trim();
196                                         if(v != ''){
197                                                 $("#node-input-btnComments").html("<span style='color:blue;'><b>View Comments</b></span>");
198                                         }else{
199                                                 $("#node-input-btnComments").html("<b>Add Comments</b>");
200                                         }
201                                 }
202                                 //console.log("value from text area" + v);
203                                 $("#node-input-comments").val(v);
204                                 $(this).dialog("close");
205                               //$(this).dialog("destroy");
206                            },
207                            Cancel: function () {
208                                 var v=$("#taCommentId").val();
209                                 if(v != null){
210                                         v = v.trim();
211                                         if(v != ''){
212                                                 $("#node-input-btnComments").html("<span style='color:blue;'><b>View Comments</b></span>");
213                                         }else{
214                                                 $("#node-input-btnComments").html("<b>Add Comments</b>");
215                                         }
216                                 }
217                                 $(this).dialog("close");
218                               //$(this).dialog("destroy");
219                            }
220                        },
221                         close: function(ev,ui){
222                                 //console.log("closing..");
223                                 $(this).dialog("destroy");
224                         }
225         }).html(commentsBoxHtml);
226
227         //console.log("done");
228 /*      
229         function functionDialogResize(ev,ui) {
230                 console.log("ui.size.height:" + ui.size.height);
231                 $(this).css("height",(ui.size.height-275)+"px");
232         };
233
234         $( this ).on("dialogresize", functionDialogResize);
235
236
237         $( this ).one("dialogopen", function(ev) {
238                 var size = $( "#sliValDiv" ).dialog('option','sizeCache-function');
239                 if (size) {
240                     functionDialogResize(null,{size:size});
241                 }
242          });
243 */
244
245 }
246
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");
266                 } else{
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)"});
274                         */
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)"});
282                         */
283                         $("#a" +  objId ).css({"background": "aliceblue",
284                                                 "color": "rgb(75, 111, 147)"});
285                 }
286                 $("#a" +  objId).select();
287         });
288         //console.log("group-heading" + objId);
289 //      var obj= document.getElementById("group-heading" +  objId);
290 //      obj.innerText = groupVal;
291 //      obj.style.color = "blue";
292 //      console.dir(obj);
293 }
294
295 function hidePrevGroup(objId){
296 //      console.log("mouseout" );
297 //      var obj= document.getElementById("group-heading" +  objId);
298 //      obj.innerText = "";
299 }
300 /*
301 function fixDiv() {
302     var $cache = $('#getFixed');
303     if ($(window).scrollTop() > 100)
304       $cache.css({
305         'position': 'fixed',
306         'top': '10px'
307       });
308     else
309       $cache.css({
310         'position': 'relative',
311         'top': 'auto'
312       });
313  }
314
315 $(window).scroll(fixDiv);
316
317 function isScrolledIntoView(elem)
318 {
319     var $elem = $(elem);
320     var $window = $(window);
321
322     var docViewTop = $window.scrollTop();
323     var docViewBottom = docViewTop + $window.height();
324
325     var elemTop = $elem.offset().top;
326     var elemBottom = elemTop + $elem.height();
327
328     return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
329 }
330 */
331
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);
342                         /*
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);   
348                         }
349                         */
350                 }
351         })
352         .fail(function(err) {
353         })
354         .always(function() {
355         });
356 }
357
358
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" + 
373                                 "</style>";
374                         var htmlStr="";
375                         //console.dir(rows);    
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>";
381                                 htmlStr += "<tr>";
382                                 htmlStr += "<th>Commit ID</th>" ;
383                                 htmlStr += "<th>Date</th>" ;
384                                 htmlStr += "<th>Author</th>" ;
385                                 htmlStr += "<th>Comment</th>" ;
386                                 htmlStr += "</tr>";
387                                 if(rows != null && rows.length == 0){
388                                         htmlStr += "<tr>";
389                                         htmlStr += "<td><b>No rows found</b></td>";
390                                         htmlStr += "</tr></table></div>";
391                                         return htmlStr;
392                                 }
393                                 for(var i=0;i<rows.length;i++){
394                                         var row = rows[i];
395                                         var _commitId = row.commit;
396                                         var dt = row.date;
397                                         var author = row.author;
398                                         var comment = row.comment;
399                                         htmlStr += "<tr>";
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>"; 
404                                         htmlStr += "</tr>";
405                                 }
406                                 htmlStr += "</table>";
407                                 htmlStr += "</div>";
408                         }
409         //console.log(htmlStr);
410         return htmlStr;
411 }
412
413
414 var gitLocalFlowFiles=[];
415 function filterGitLocalFlows(filterVal){
416         
417         var matchedCnt =0;
418         var valuesObj = gitLocalFlowFiles;
419         //console.dir(codeCloudFlowFiles);
420         var updatedValuesObj =[];
421         var searchValues =[];
422         if(filterVal != null && filterVal != undefined){
423                 filterVal=filterVal.trim();
424         }       
425         searchValues = filterVal.split(/ /);
426         //console.log("filterVal:" + filterVal);
427         //console.dir(searchValues);
428         if(searchValues != null && searchValues != undefined){  
429                 var foundCount = 0;
430                 for(var k=0;k<searchValues.length;k++){
431                         if(foundCount >0){
432                                 valuesObj=updatedValuesObj;
433                         }
434                         updatedValuesObj=[];
435                         for(var i=0;i<valuesObj.length;i++){
436                                 var patt = new RegExp(searchValues[k],"gi");
437                                 if(patt.test(valuesObj[i])){
438                                         foundCount++;
439                                         updatedValuesObj.push(valuesObj[i]);
440                                 }
441                         }
442                 }
443         }else{
444                 updatedValuesObj = valuesObj;
445         }
446         //console.dir(updatedValuesObj);
447         var html="<ul>";
448         if(updatedValuesObj != null){
449                 var files=updatedValuesObj;
450                 //console.dir(files);
451                 files.sort(function (a,b){
452                         if(a > b){
453                                 return 1;
454                         }else if(a <  b){
455                                 return -1;
456                         }else{  
457                                 return 0;
458                         }
459                 });
460                 for(var i=0;files != null && i<files.length;i++){
461                         html+="<li><a href=\"#\" onclick=\"importGitLocalFlow('" + files[i] + "')\">" + files[i] + "</a></li>";
462                 }
463         }
464                                         html+="</ul>";
465                                         html+="</div>";
466         $( "#gitlocal-data-container" ).html(html);
467 }
468
469 var codeCloudFlowFiles=[];
470 function filterFlows(filterVal){
471         
472         var matchedCnt =0;
473         var valuesObj = codeCloudFlowFiles;
474         //console.dir(codeCloudFlowFiles);
475         var updatedValuesObj =[];
476         var searchValues =[];
477         if(filterVal != null && filterVal != undefined){
478                 filterVal=filterVal.trim();
479         }       
480         searchValues = filterVal.split(/ /);
481         //console.log("filterVal:" + filterVal);
482         //console.dir(searchValues);
483         if(searchValues != null && searchValues != undefined){  
484                 var foundCount = 0;
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])){
489                                         foundCount++;
490                                         updatedValuesObj.push(valuesObj[i]);
491                                 }
492                         }
493                 }
494         }else{
495                 updatedValuesObj = valuesObj;
496         }
497         //console.dir(updatedValuesObj);
498         var html="<ul>";
499         if(updatedValuesObj != null){
500                 var files=updatedValuesObj;
501                 //console.dir(files);
502                 files.sort(function (a,b){
503                         if(a > b){
504                                 return 1;
505                         }else if(a <  b){
506                                 return -1;
507                         }else{  
508                                 return 0;
509                         }
510                 });
511                 for(var i=0;files != null && i<files.length;i++){
512                         html+="<li><a href=\"#\" onclick=\"getCommits('" + files[i] + "')\">" + files[i] + "</a></li>";
513                 }
514         }
515                                         html+="</ul>";
516                                         html+="</div>";
517         $( "#codecloud-data-container" ).html(html);
518 }
519
520 var yangFilesList=[];
521 /*
522 function filterYangFiles(filterVal){
523         
524         var matchedCnt =0;
525         var valuesObj = yangFilesList;
526         var updatedValuesObj =[];
527         var searchValues =[];
528         if(filterVal != null && filterVal != undefined){
529                 filterVal=filterVal.trim();
530         }       
531         searchValues = filterVal.split(/ /);
532         if(searchValues != null && searchValues != undefined){  
533                 var foundCount = 0;
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])){
538                                         foundCount++;
539                                         updatedValuesObj.push(valuesObj[i]);
540                                 }
541                         }
542                 }
543         }else{
544                 updatedValuesObj = valuesObj;
545         }
546         //console.dir(updatedValuesObj);
547         var html="<ul>";
548         if(updatedValuesObj != null){
549                 var files=updatedValuesObj;
550                 //console.dir(files);
551                 files.sort(function (a,b){
552                         if(a > b){
553                                 return 1;
554                         }else if(a <  b){
555                                 return -1;
556                         }else{  
557                                 return 0;
558                         }
559                 });
560                 for(var i=0;files != null && i<files.length;i++){
561                         html+="<li><a href=\"#\" onclick=\"getYangFile('" + files[i] + "')\">" + files[i] + "</a></li>";
562                 }
563         }
564                                         html+="</ul>";
565                                         html+="</div>";
566         $( "#list-yang-data-container" ).html(html);
567 }
568 */
569
570 function filterYangFiles(filterVal){
571         var matchedCnt =0;
572         var valuesObj = yangFilesList;
573         var updatedValuesObj =[];
574         var searchValues =[];
575         if(filterVal != null && filterVal != undefined){
576                 filterVal=filterVal.trim();
577         }       
578         searchValues = filterVal.split(/ /);
579         if(searchValues != null && searchValues != undefined){  
580                 var foundCount = 0;
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])){
585                                         foundCount++;
586                                         updatedValuesObj.push(valuesObj[i]);
587                                 }
588                         }
589                 }
590         }else{
591                 updatedValuesObj = valuesObj;
592         }
593         //console.dir(updatedValuesObj);
594         var html="<table id='yang-file-list-table'  border=1>";
595             html+="<tr>";
596             html+="<th>File</th>";
597             html+="<th>Delete</th>";
598             html+="</tr>";
599         
600         if(updatedValuesObj != null){
601                 var files=updatedValuesObj;
602                 //console.dir(files);
603                 files.sort(function (a,b){
604                         if(a > b){
605                                 return 1;
606                         }else if(a <  b){
607                                 return -1;
608                         }else{  
609                                 return 0;
610                         }
611                 });
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>";
614                 }
615         }
616         html+="</table>";
617         html+="</div>";
618
619         $( "#yang-files-data-container" ).html(html);
620 }
621
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();
629
630 }
631 function deleteYangFile(fileName){
632         var reqData= {"fileName":fileName};
633          $.post( "/deleteYangFile",reqData )
634                       .done(function( data ) {
635                       })
636                       .fail(function(err) {
637                           console.log( "error" + err );
638                        })
639                        .always(function() {
640                               $("#list-yang-browser-dialog").dialog("close");
641                                 $("#btn-list-yang-files").trigger("click");
642                        });
643 }
644
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));
654                 }
655         })
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.");
660         })
661         .always(function() {
662         });
663 }
664
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);
671                         var jsonObj;
672                         try{
673                                 jsonObj = JSON.parse(data.stdout);
674                                 $( "#gitlocal-browser-dialog" ).dialog("close");
675                                 RED.view.importNodes(JSON.stringify(jsonObj));
676                         }catch(err){
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);
680                         }
681                 }else{
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);
685                 }
686         })
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.");
691         })
692         .always(function() {
693         });
694 }
695
696 var availableYangModules=[];
697 function filterYangModules(filterVal){
698         
699         var matchedCnt =0;
700         var valuesObj = availableYangModules ;
701         //console.dir(codeCloudFlowFiles);
702         var updatedValuesObj =[];
703         var searchValues =[];
704         if(filterVal != null && filterVal != undefined){
705                 filterVal=filterVal.trim();
706         }       
707         searchValues = filterVal.split(/ /);
708         //console.log("filterVal:" + filterVal);
709         //console.dir(searchValues);
710         if(searchValues != null && searchValues != undefined){  
711                 var foundCount = 0;
712                 for(var k=0;k<searchValues.length;k++){
713                         if(foundCount >0){
714                                 valuesObj=updatedValuesObj;
715                         }
716                         updatedValuesObj=[];
717                         for(var i=0;i<valuesObj.length;i++){
718                                 var patt = new RegExp(searchValues[k],"gi");
719                                 if(patt.test(valuesObj[i])){
720                                         foundCount++;
721                                         updatedValuesObj.push(valuesObj[i]);
722                                 }
723                         }
724                 }
725         }else{
726                 updatedValuesObj = valuesObj;
727         }
728         //console.dir(updatedValuesObj);
729         var html="";
730         html+="<table border=1>";
731         html+="<tr>";
732         html+="<th>#</th>";
733         html+="<th>Load</th>";
734         html+="<th>Module</th>";
735         html+="</tr>";
736
737         if(updatedValuesObj != null){
738                 var files=updatedValuesObj;
739                 //console.dir(files);
740                 files.sort(function (a,b){
741                         if(a > b){
742                                 return 1;
743                         }else if(a <  b){
744                                 return -1;
745                         }else{  
746                                 return 0;
747                         }
748                 });
749                 var count=1;
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>";
754                         }else{
755                                 html+="<tr><td>" + count +   "</td><td><input type='checkbox' value='" + val + "'></td><td>" + val + "</td></tr>";
756                         }
757                         count++;
758                 }
759         }
760         html+="</table>";
761         html+="</div>";
762         $( "#yang-modules-data-container" ).html(html);
763 }