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