Advertisement
Guest User

DevicesCtrl.js - devices

a guest
Apr 1st, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. $scope.format = function (d){
  2. $scope.data = d
  3. // `d` is the original data object for the row
  4. return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">'+
  5. '<tr>'+
  6. '<td>CPU Load:</td>'+
  7. '<td></td>' +
  8. '<td><span class="txt-color-yellow">'+d.cpuloads[0]+ '</span><span class="txt-color-green"> ' + d.cpuloads[1] + '</span> <span class="txt-color-red">' + d.cpuloads[2] + '</span></td>'+
  9. '</tr>'+
  10. '<tr>'+
  11. '<td>RAM usage:<td>'+
  12. '<td><div class="progress-xs"><div class="progress-bar progress-xs bg-color-red" style="width: ' + (100 - (d.ramdata[0] / (d.ramdata[2] / 100))) +'%"></div><div class="progress-bar progress-xs bg-color-greenLight" style="width: ' + (100 - (d.ramdata[1] / (d.ramdata[2] / 100))) + '%"></div></div>'+'</td>'+
  13. '</tr>' +
  14. '<tr>' +
  15. '<td>Actions:</td>'+
  16. '<td></td>' +
  17. '<td><button id="' + d.name + '" class="btn btn-xs bg-color-red txt-color-white deleteAction">Delete server</button> <a class="btn btn-xs btn-info" data-ui-sref="app">Testas</a></td>' +
  18. '</tr>' +
  19. '</table>';
  20. };
  21.  
  22.  
  23. $(document).ready(function()
  24. {
  25. require(['datatables', 'datatables-bootstrap', 'datatables-tools', 'datatables-colvis', 'datatables-responsive'], function( jq ) {
  26. var table = $('#example').DataTable( {
  27. "ajax": "http://127.0.0.1:5000/servers/info",
  28. "columns": [
  29. {
  30. "className": 'details-control',
  31. "orderable": false,
  32. "data": null,
  33. "defaultContent": ''
  34. },
  35. { "data": "name", "title": "Server's name" },
  36. { "data": "location", "title": "Server's location"},
  37. { "data": "type", "title": "Server's type"},
  38. { 'data': "ip", "title": "Server's IP"},
  39. { "data": "datacenter", "title": "Server's datacenter"},
  40. { "data": "privateip", "title": "Server's private IP"}
  41. ],
  42. "order": [[1, 'asc']]
  43. } );
  44. $('#example tbody').on('click', function (){
  45. clickedButton = $("button[clicked=true]");
  46. serverName = clickedButton.prevObject[0].activeElement.id;
  47. if (clickedButton.prevObject[0].activeElement.innerHTML === "Delete server") {
  48. $.SmartMessageBox({
  49. "title": "Server delete confirmation",
  50. "content": "Do you really really want to delete this server: " + serverName + "?",
  51. "buttons": "[YES][NO]"
  52. }, function(buttonPressed) {
  53. if (buttonPressed == "YES") {
  54. $scope.deleteServer(serverName)
  55. }
  56. })
  57. }
  58.  
  59.  
  60. });
  61. $('#example tbody').on('click', 'td.details-control', function () {
  62. var tr = $(this).closest('tr');
  63. var row = table.row( tr );
  64.  
  65. if ( row.child.isShown() ) {
  66. // This row is already open - close it
  67. row.child.hide();
  68. tr.removeClass('shown');
  69. }
  70. else {
  71. // Open this row
  72. row.child($scope.format(row.data()) ).show();
  73. tr.addClass('shown');
  74. }
  75. } );
  76. });
  77.  
  78.  
  79. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement