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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/**
* Controller for power-usage
*
* @module app/serverControl
* @exports powerUsageController
* @name powerUsageController
*/
window.angular && (function(angular) {
'use strict';
angular.module('app.serverControl').controller('powerUsageController', [
'$scope', '$window', 'APIUtils', '$route', '$q', 'toastService',
function($scope, $window, APIUtils, $route, $q, toastService) {
$scope.power_consumption = '';
$scope.power_cap = {};
$scope.loading = false;
loadPowerData();
function loadPowerData() {
$scope.loading = true;
var getPowerCapPromise = APIUtils.getPowerCap().then(
function(data) {
$scope.power_cap = data.data;
},
function(error) {
console.log(JSON.stringify(error));
});
var getPowerConsumptionPromise = APIUtils.getPowerConsumption().then(
function(data) {
$scope.power_consumption = data;
},
function(error) {
console.log(JSON.stringify(error));
});
var promises = [
getPowerConsumptionPromise,
getPowerCapPromise,
];
$q.all(promises).finally(function() {
$scope.loading = false;
});
}
$scope.setPowerCap = function() {
// The power cap value will be undefined if outside range
if (!$scope.power_cap.PowerCap) {
toastService.error(
'Power cap value between 100 and 10,000 is required');
return;
}
$scope.loading = true;
var promises = [
setPowerCapValue(),
setPowerCapEnable(),
];
$q.all(promises)
.then(
function() {
toastService.success('Power cap settings saved');
},
function(errors) {
toastService.error('Power cap settings could not be saved');
})
.finally(function() {
$scope.loading = false;
});
};
$scope.refresh = function() {
$route.reload();
};
function setPowerCapValue() {
return APIUtils.setPowerCap($scope.power_cap.PowerCap)
.then(
function(data) {},
function(error) {
console.log(JSON.stringify(error));
return $q.reject();
});
}
function setPowerCapEnable() {
return APIUtils.setPowerCapEnable($scope.power_cap.PowerCapEnable)
.then(
function(data) {},
function(error) {
console.log(JSON.stringify(error));
return $q.reject();
});
}
}
]);
})(angular);
|