machine.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. var app = angular.module('sentinelDashboardApp');
  2. app.controller('MachineCtl', ['$scope', '$stateParams', 'MachineService',
  3. function ($scope, $stateParams, MachineService) {
  4. $scope.app = $stateParams.app;
  5. $scope.propertyName = '';
  6. $scope.reverse = false;
  7. $scope.currentPage = 1;
  8. $scope.machines = [];
  9. $scope.machinesPageConfig = {
  10. pageSize: 10,
  11. currentPageIndex: 1,
  12. totalPage: 1,
  13. totalCount: 0,
  14. };
  15. $scope.sortBy = function (propertyName) {
  16. // console.log('machine sortBy ' + propertyName);
  17. $scope.reverse = ($scope.propertyName === propertyName) ? !$scope.reverse : false;
  18. $scope.propertyName = propertyName;
  19. };
  20. $scope.reloadMachines = function() {
  21. MachineService.getAppMachines($scope.app).success(
  22. function (data) {
  23. // console.log('get machines: ' + data.data[0].hostname)
  24. if (data.code == 0 && data.data) {
  25. $scope.machines = data.data;
  26. var healthy = 0;
  27. $scope.machines.forEach(function (item) {
  28. if (item.healthy) {
  29. healthy++;
  30. }
  31. if (!item.hostname) {
  32. item.hostname = '未知'
  33. }
  34. })
  35. $scope.healthyCount = healthy;
  36. $scope.machinesPageConfig.totalCount = $scope.machines.length;
  37. } else {
  38. $scope.machines = [];
  39. $scope.healthyCount = 0;
  40. }
  41. }
  42. );
  43. };
  44. $scope.removeMachine = function(ip, port) {
  45. if (!confirm("confirm to remove machine [" + ip + ":" + port + "]?")) {
  46. return;
  47. }
  48. MachineService.removeAppMachine($scope.app, ip, port).success(
  49. function(data) {
  50. if (data.code == 0) {
  51. $scope.reloadMachines();
  52. } else {
  53. alert("remove failed");
  54. }
  55. }
  56. );
  57. };
  58. $scope.reloadMachines();
  59. }]);