blob: 1b5df0fc52222e0d5bb5ac62682d4e4f8ee53f0e [file] [log] [blame]
Michael Davis29825e42017-07-12 16:13:22 -05001angular
2 .module('app.controllers', [])
3 .controller('loginController', ['$scope', '$window', 'APIUtils', 'dataService', 'userModel', function ($scope, $window, APIUtils, dataService, userModel) {
4 $scope.dataService = dataService;
Iftekharul Islam115984a2017-03-09 09:47:35 -06005
Michael Davis29825e42017-07-12 16:13:22 -05006 $scope.tryLogin = function (username, password, event) {
7 if (event.keyCode === 13) {
8 $scope.login(username, password);
9 }
10 };
11 $scope.login = function (username, password) {
12 $scope.error = false;
13 if (!username || username == "" || !password || password == "") {
14 return false;
15 } else {
16 if (userModel.login(username, password)) {
17 $window.location.hash = '#/system-overview';
18 } else {
19 $scope.error = true;
20 }
Iftekharul Islamf157d372017-03-08 11:11:27 -060021 }
22 }
Michael Davis29825e42017-07-12 16:13:22 -050023 }])
24 .controller('dashboardController', ['$scope', 'dataService', function ($scope, dataService) {
25 $scope.dataService = dataService;
26 }])
27 .controller('systemOverviewController', ['$scope', 'dataService', function ($scope, dataService) {
28 $scope.dataService = dataService;
29 }])
30 .controller('unitIDController', ['$scope', 'dataService', function ($scope, dataService) {
31 $scope.dataService = dataService;
32 }])
33 .controller('bmcRebootController', ['$scope', 'dataService', function ($scope, dataService) {
34 $scope.dataService = dataService;
35 $scope.bmcReboot_confirm = false;
Iftekharul Islamf157d372017-03-08 11:11:27 -060036
Michael Davis29825e42017-07-12 16:13:22 -050037 // BMC reboot
38 $scope.bmcReboot = function () {
39 //@TODO:show progress
40 APIUtils.bmcReboot(function (response) {
41 if (response) {
42 //@TODO: set proper server state
43 } else {
44 //@TODO:show error message
45 }
46 //@TODO:hide progress
47 });
48 };
49 $scope.bmcRebootConfirm = function () {
50 if ($scope.confirm) {
51 return;
Iftekharul Islamf157d372017-03-08 11:11:27 -060052 }
Michael Davis29825e42017-07-12 16:13:22 -050053 $scope.confirm = true;
54 $scope.bmcReboot_confirm = true;
55 };
56 }])
57 .controller('powerOperationsController', ['$scope', 'APIUtils', 'dataService', function ($scope, APIUtils, dataService) {
58 $scope.dataService = dataService;
59 $scope.confirm = false;
60 $scope.power_confirm = false;
61 $scope.warmboot_confirm = false;
62 $scope.coldboot_confirm = false;
63 $scope.orderly_confirm = false;
64 $scope.immediately_confirm = false;
Iftekharul Islamf157d372017-03-08 11:11:27 -060065
Michael Davis29825e42017-07-12 16:13:22 -050066 //@TODO: call api and get proper state
67 $scope.toggleState = function () {
68 dataService.server_state = (dataService.server_state == 'On') ? 'Off' : 'On';
69 };
70
71 $scope.togglePower = function () {
72 var method = (dataService.server_state == 'On') ? 'chassisPowerOff' : 'chassisPowerOn';
73 //@TODO: show progress or set class orange
74 APIUtils[method](function (response) {
75 //update state based on response
76 //error case?
77 if (response == null) {
78 console.log("Failed request.");
79 } else {
80 dataService.server_state = response;
81 }
82 });
83 }
84 $scope.powerOnConfirm = function () {
85 if ($scope.confirm) {
86 return;
Iftekharul Islamf157d372017-03-08 11:11:27 -060087 }
Michael Davis29825e42017-07-12 16:13:22 -050088 $scope.confirm = true;
89 $scope.power_confirm = true;
90 };
91 $scope.warmReboot = function () {
92 //@TODO:show progress
93 APIUtils.hostPowerOff(function (response) {
94 if (response) {
95 APIUtils.hostPowerOn(function (response) {
96 if (response) {
Iftekharul Islamf157d372017-03-08 11:11:27 -060097
Michael Davis29825e42017-07-12 16:13:22 -050098 } else {
99 //@TODO:show error message
100 }
101 //@TODO:hide progress, set proper server state
102 });
103 } else {
104 //@TODO:hide progress & show error message
105 }
106 });
107 };
108 $scope.warmRebootConfirm = function () {
109 if ($scope.confirm) {
110 return;
Iftekharul Islamf157d372017-03-08 11:11:27 -0600111 }
Michael Davis29825e42017-07-12 16:13:22 -0500112 $scope.confirm = true;
113 $scope.warmboot_confirm = true;
114 };
Iftekharul Islamf157d372017-03-08 11:11:27 -0600115
Michael Davis29825e42017-07-12 16:13:22 -0500116 $scope.coldReboot = function () {
117 //@TODO:show progress
118 APIUtils.chassisPowerOff(function (response) {
119 if (response) {
120 APIUtils.chassisPowerOn(function (response) {
121 if (response) {
Iftekharul Islamf157d372017-03-08 11:11:27 -0600122
Michael Davis29825e42017-07-12 16:13:22 -0500123 } else {
124 //@TODO:show error message
125 }
126 //@TODO:hide progress, set proper server state
127 });
128 } else {
129 //@TODO:hide progress & show error message
130 }
131 });
132 };
133 $scope.coldRebootConfirm = function () {
134 if ($scope.confirm) {
135 return;
Iftekharul Islamf157d372017-03-08 11:11:27 -0600136 }
Michael Davis29825e42017-07-12 16:13:22 -0500137 $scope.confirm = true;
138 $scope.coldboot_confirm = true;
139 };
Iftekharul Islamf157d372017-03-08 11:11:27 -0600140
Michael Davis29825e42017-07-12 16:13:22 -0500141 $scope.orderlyShutdown = function () {
142 //@TODO:show progress
143 APIUtils.hostPowerOff(function (response) {
144 if (response) {
145 APIUtils.chassisPowerOff(function (response) {
146 if (response) {
147
148 } else {
149 //@TODO:show error message
150 }
151 //@TODO:hide progress, set proper server state
152 });
153 } else {
154 //@TODO:hide progress & show error message
155 }
156 });
157 };
158 $scope.orderlyShutdownConfirm = function () {
159 if ($scope.confirm) {
160 return;
Iftekharul Islamf157d372017-03-08 11:11:27 -0600161 }
Michael Davis29825e42017-07-12 16:13:22 -0500162 $scope.confirm = true;
163 $scope.orderly_confirm = true;
164 };
165
166 $scope.immediateShutdown = function () {
167 //@TODO:show progress
168 APIUtils.chassisPowerOff(function (response) {
169 if (response) {
170 //@TODO: set proper server state
171 } else {
172 //@TODO:show error message
173 }
174 //@TODO:hide progress
175 });
176 };
177 $scope.immediateShutdownConfirm = function () {
178 if ($scope.confirm) {
179 return;
180 }
181 $scope.confirm = true;
182 $scope.immediately_confirm = true;
183 };
184
185 }]);