diff --git a/xCAT-UI/js/monitor/xcatmon.js b/xCAT-UI/js/monitor/xcatmon.js index bd8b6a1ea..61bff5438 100644 --- a/xCAT-UI/js/monitor/xcatmon.js +++ b/xCAT-UI/js/monitor/xcatmon.js @@ -1,162 +1,507 @@ +/* +* Globle variable +* +*/ +var XcatmonTableId="XcatMonsettingTable"; +var dataTables=new Object(); + +/* +* set datatable +* +*/ +function setDatatable(id,obj){ + dataTables[id]=obj; +} +/* +* get datatable from the given id +* +* +*/ +function getDatatable(id){ + return dataTables[id]; +} +/* +* +* +*/ + function loadXcatMon(){ //find the xcat mon tab var xcatMonTab = $('#xcatmon'); - //add the stauts bar first. id = 'xcatMonStatus' - var StatusBar = createStatusBar('xcatMonStatus'); - StatusBar.append(createLoader()); - xcatMonTab.append(StatusBar); - - //add the configure button. - var configButton = createButton('Configure'); - configButton.click(function(){ - if ($('#xcatMonConfig').is(':hidden')){ - $('#xcatMonConfig').show(); - } - else{ - $('#xcatMonConfig').hide(); - } - }); - xcatMonTab.append(configButton); - - //add the configure div, id = 'xcatMonConfig' - xcatMonTab.append("
"); - $('#xcatMonConfig').hide(); - - //add button start, stop, cancel to the monconfig div - loadXcatMonConfigure(); - - //add the content of the xcat mon, id = 'xcatMonShow' - xcatMonTab.append("
"); - - //show the content of the page. - $.ajax( { - url : 'lib/cmd.php', - dataType : 'json', - data : { - cmd : 'monls', - tgt : '', - args : 'xcatmon', - msg : '' - }, - - success : loadXcatMonWorkStatus - }); -} - -function loadXcatMonWorkStatus(data){ - var xcatWorkStatus = data.rsp[0]; - - //the xcat mon did not run - if (-1 != xcatWorkStatus.indexOf('not-monitored')){ - $('#xcatMonStatus').empty().append('The xCAT Monitor is not working. Please start it first.'); - return; - } - - //the xcatmon is running, show the result - loadXcatMonShow(); -} - -function loadXcatMonConfigure(){ - //get the xcat mon configure div - var xcatMonConfigDiv = $('#xcatMonConfig'); - xcatMonConfigDiv.empty(); - - //add start button - var startButton = createButton('Start'); - xcatMonConfigDiv.append(startButton); - startButton.click(function(){ - $('#xcatMonStatus').empty().append(createLoader()); - $.ajax({ - url : 'lib/cmd.php', - dataType : 'json', - data : { - cmd : 'monstart', - tgt : '', - args : 'xcatmon', - msg : '' - }, - - success : function(data){ - //update the status bar, update the xcatmon show - $('#xcatMonStatus').empty().append(data.rsp[0]); - loadXcatMonShow(); - } - }); - }); - - //add stop buttons - var stopButton = createButton('Stop'); - xcatMonConfigDiv.append(stopButton); - stopButton.click(function(){ - $('#xcatMonStatus').empty().append(createLoader()); - $.ajax({ - url : 'lib/cmd.php', - dataType : 'json', - data : { - cmd : 'monstop', - tgt : '', - args : 'xcatmon', - msg : '' - }, - - success : function(data){ - $('#xcatMonStatus').empty().append(data.rsp[0]); - $('#xcatMonShow').empty(); - } - }); - }); - - //add cancel button - var cancelButton = createButton('Cancel'); - xcatMonConfigDiv.append(cancelButton); - cancelButton.click(function(){ - $('#xcatMonConfig').hide(); - }); -} - -function loadXcatMonShow(){ - //update the status bar into waiting - $('#xcatMonStatus').empty().append(createLoader()); - - //get the latest xcatmon information + xcatMonTab.append("
"); + // show the content of the table monsetting $.ajax({ - url : 'lib/cmd.php', - dataType : 'json', - data : { - cmd : 'nodestat', - tgt : 'lpar', - args : '', + url:'lib/cmd.php', + dataType: 'json', + data:{ + cmd : 'tabdump', + tgt :'', + args : 'monsetting', msg : '' }, - - success : updateXcatMonShow + success: loadXcatMonSetting }); } +function loadXcatMonSetting(data){ + + var apps;// contain the xcatmon apps config + var rsp=data.rsp; + var apps_flag=0;// Is the apps is stored? + var ping; // contain the xcatmon ping-interval setting + var ping_flag=0; -function updateXcatMonShow(data){ - var temp = 0; - var nodeStatus = data.rsp; - var show = ""; - var tempArray; - //update the status bar - $('#xcatMonStatus').empty().append("Get nodes' status finished."); + + //create a infoBar + var infoBar=createInfoBar('Click on a cell to edit,Click outside the table to write to the cell.
Once you finish the xCATmon config.click on Apply.'); + $('#xcatmonTable').append(infoBar); - $('#xcatMonShow').empty(); - $('#xcatMonShow').append("
Node Status
"); + //create xcatmonTable + var XcatmonTable= new DataTable(XcatmonTableId); - //get the nodestat from return data - //the data.rsp is an array, it look like this: - //['node1:ssh', 'node2:noping', 'node3:ssh'] - for (temp = 0; temp < nodeStatus.length; temp++){ - tempArray = nodeStatus[temp].split(':'); - show += '

' + tempArray[0] + ':' + tempArray[1] + '

'; + //create Datatable + var dTable; + + // create the xcatmonTable header + var header=rsp[0].split(","); + header.splice(3,2); + header.splice(0,1); + header[0]="apps name"; + header[1]="configure"; + header.push(''); + + header.unshift(''); + XcatmonTable.init(header);//create the table header + + + // create container of original table contents + var origCont= new Array(); + origCont[0]=header;// table header + + //create contariner for new contents use for update the monsetting table + var newCont =new Object(); + newCont[0]=rsp[0].split(",");// table header + // create container for other monsetting lines not xcatmon + var otherCont =new Array(); + + + + + + $('#xcatmonTable').append(XcatmonTable.object());// add table object + var m=1;// the count for origCont + var n=0; + for( var i=1;i'); + cols.unshift(''); + //add teh column tho the table. + XcatmonTable.add(cols); + + origCont[m++]=cols; + }else{ + + if(!apps_flag){//check the apps setting + if(rsp[i].indexOf("apps") > -1){// check for is apps or not + apps=rsp[i].split(',');// + + for(var j=0;j -1){ + ping=rsp[i].split(','); + // pair the semicolon + for(var j=0;j'); + } + } + + } + $(":checkbox").tooltip(); +/* + $(':checkbox').hover( + function(){ + $(this).append($("***")); + }, + function(){ + $(this).find("span:last").remove(); + } + ); + +*/ + + //make the table editable + + $('#'+XcatmonTableId+' td:not(td:nth-child(1),td:last-child)').editable( + + function(value,settings){ + + var colPos=this.cellIndex; + var rowPos=dTable.fnGetPosition(this.parentNode); + + dTable.fnUpdate(value,rowPos,colPos); + + return (value); + },{ + onblur : 'submit', + type : 'textarea', + placeholder: ' ', + height : '30px' + } + + ); + //save the datatable + dTable=$('#'+XcatmonTableId).dataTable(); + // set the datatable to the global variables datatables + setDatatable(XcatmonTableId,dTable); + + + //create button bar + var addBar = $('
'); + $('#xcatmon').append(addBar); + // create the button add row + var addRowBtn=createButton('Add row'); + // add the button to the page + addBar.append(addRowBtn); + // create the button apply + var ApplyBtn=createButton('Apply'); + // add the apply button to the page + addBar.append(ApplyBtn); + // create the button Cancel + var CancelBtn=createButton('Cancel'); + // add the cancel to the page + addBar.append(CancelBtn); + + // button click function + + //create a empty row + addRowBtn.bind('click',function(event){ + // create the container of the new row + var row = new Array(); + + // add the delete button to the row + row.push(''); + // add the xcatmon + // add the contain of the setting + for(var i =0;i'); + // get the datatable of the table + var dTable=getDatatable(XcatmonTableId); + // add the new row to the datatable + dTable.fnAddData(row); + + // make the datatable editable + $(":checkbox[title]").tooltip(); + $('#'+XcatmonTableId+' td:not(td:nth-child(1),td:last-child)').editable( + function(value,settings){ + var colPos=this.cellIndex; + var rowPos=dTable.fnGetPosition(this.parentNode); + + dTable.fnUpdate(value,rowPos,colPos); + + return (value); + },{ + onblur : 'submit', + type : 'textarea', + placeholder: ' ', + height : '30px' + } + + ); + }); + + +/* +* apply button +* +* +* +* The Apply button is used to store the contain of the table in the page to the monsetting table +* on the MN. +* +*/ + ApplyBtn.bind('click',function(event){ + // get the datatable of the page + var dTable=getDatatable(XcatmonTableId); + // get the rows of the datatable + var dRows=dTable.fnGetNodes(); + var count=0; + // create the new container of the apps' value. + var appValue=""; + var tableName="monsetting"; + var tmp; + var tmp1; + // get the contain of the rows + for (var i =0; i< dRows.length;i++){ + + if(dRows[i]){ + // get the columns fo the row + var cols=dRows[i].childNodes; + // create the container of the new column + var vals = new Array(); + + for(var j=1;j'); + }else{ + vals_orig.push(''); + } + // push the delete button to the row + vals_orig.unshift(''); + // add the row to the orignCont + + origCont[i+1]=vals_orig; + //tmp1=origCont; + //tmp=newCont; + count=i+1; + + // check the checkbox fo everyrow for merging the appName to the apps values + if(cols.item(cols.length-1).firstChild.checked){ + // the new value for the apps.get the name fo every app. + appValue=appValue.concat(cols.item(2).firstChild.nodeValue+","); + } + } + } + count++; + // delete the last "," of the apps value + appValue=appValue.substring(0,(appValue.length-1)); + apps[2]=appValue; + +// tmp =apps; + + // newCont add the apps row + newCont[count++]=apps; + // newCont add the ping-interval row + newCont[count++]=ping; + //tmp=otherCont; + // add the other monitor setting of the mosetting + for(var j=0;j