blob: 273bb19bf2e62824f4b25f124df368239eb684d4 [file] [log] [blame]
Iftekharul Islam99d199f2017-03-24 15:28:25 -05001/**
2 * Controller for power-operations
3 *
Iftekharul Islamcd789502017-04-19 14:37:55 -05004 * @module app/serverControl
Iftekharul Islam99d199f2017-03-24 15:28:25 -05005 * @exports powerOperationsController
6 * @name powerOperationsController
7 * @version 0.1.0
8 */
9
10window.angular && (function (angular) {
11 'use strict';
12
13 angular
Iftekharul Islamcd789502017-04-19 14:37:55 -050014 .module('app.serverControl')
Iftekharul Islam99d199f2017-03-24 15:28:25 -050015 .controller('powerOperationsController', [
16 '$scope',
17 'APIUtils',
18 'dataService',
19 '$timeout',
20 function($scope, APIUtils, dataService, $timeout){
21 $scope.dataService = dataService;
22 $scope.confirm = false;
23 $scope.power_confirm = false;
24 $scope.warmboot_confirm = false;
25 $scope.coldboot_confirm = false;
26 $scope.orderly_confirm = false;
27 $scope.immediately_confirm = false;
28
29 //@TODO: call api and get proper state
30 $scope.toggleState = function(){
31 dataService.server_state = (dataService.server_state == 'Running') ? 'Off': 'Running';
32 }
33
34 $scope.togglePower = function(){
35 var method = (dataService.server_state == 'Running') ? 'hostPowerOff' : 'hostPowerOn';
36 //@TODO: show progress or set class orange
37 APIUtils[method](function(response){
38 //update state based on response
39 //error case?
40 if(response == null){
41 console.log("Failed request.");
42 }else{
43 //@TODO::need to get the server status
44 if(dataService.server_state == 'Running'){
45 dataService.setPowerOffState();
46 }else{
47 dataService.setPowerOnState();
48 }
49 }
50 });
51 }
52 $scope.powerOnConfirm = function(){
53 if($scope.confirm) {
54 return;
55 }
56 $scope.confirm = true;
57 $scope.power_confirm = true;
58 };
59 $scope.warmReboot = function(){
60 //@TODO:show progress
61 dataService.setBootingState();
Gunnar Millscacfa6d2018-02-07 12:09:02 -060062 APIUtils.hostReboot(function(response){
Iftekharul Islam99d199f2017-03-24 15:28:25 -050063 if(response){
Gunnar Millscacfa6d2018-02-07 12:09:02 -060064 dataService.setPowerOnState();
65 }else{
66 //@TODO:hide progress & show error message
Iftekharul Islam99d199f2017-03-24 15:28:25 -050067 }
68 });
69 };
70 $scope.testState = function(){
71 $timeout(function(){
72 dataService.setPowerOffState();
73 $timeout(function(){
74 dataService.setPowerOnState();
75 }, 2000);
76 }, 1000);
77 };
78 $scope.warmRebootConfirm = function(){
79 if($scope.confirm) {
80 return;
81 }
82 $scope.confirm = true;
83 $scope.warmboot_confirm = true;
84 };
85
86 $scope.coldReboot = function(){
87 $scope.warmReboot();
88 };
89 $scope.coldRebootConfirm = function(){
90 if($scope.confirm) {
91 return;
92 }
93 $scope.confirm = true;
94 $scope.coldboot_confirm = true;
95 };
96
97 $scope.orderlyShutdown = function(){
98 //@TODO:show progress
99 APIUtils.hostPowerOff(function(response){
100 if(response){
101 dataService.setPowerOffState();
102 }else{
103 //@TODO:hide progress & show error message
104 }
105 });
106 };
107 $scope.orderlyShutdownConfirm = function(){
108 if($scope.confirm) {
109 return;
110 }
111 $scope.confirm = true;
112 $scope.orderly_confirm = true;
113 };
114
115 $scope.immediateShutdown = function(){
Gunnar Mills3aa8b532018-02-06 15:42:29 -0600116 //@TODO:show progress
117 APIUtils.chassisPowerOff(function(response){
118 if(response){
119 dataService.setPowerOffState();
120 }else{
121 //@TODO:hide progress & show error message
122 }
123 });
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500124 };
125 $scope.immediateShutdownConfirm = function(){
126 if($scope.confirm) {
127 return;
128 }
129 $scope.confirm = true;
130 $scope.immediately_confirm = true;
131 };
132 }
133 ]
134 );
135
136})(angular);