blob: d38076ff70318e6a8462c3516a305a741fd47622 [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();
62 APIUtils.hostPowerOff(function(response){
63 if(response){
64 APIUtils.hostPowerOn(function(response){
65 if(response){
66 dataService.setPowerOnState();
67 }else{
68 //@TODO:show error message
69 }
70 });
Iftekharul Islam99d199f2017-03-24 15:28:25 -050071 }
72 });
73 };
74 $scope.testState = function(){
75 $timeout(function(){
76 dataService.setPowerOffState();
77 $timeout(function(){
78 dataService.setPowerOnState();
79 }, 2000);
80 }, 1000);
81 };
82 $scope.warmRebootConfirm = function(){
83 if($scope.confirm) {
84 return;
85 }
86 $scope.confirm = true;
87 $scope.warmboot_confirm = true;
88 };
89
90 $scope.coldReboot = function(){
91 $scope.warmReboot();
92 };
93 $scope.coldRebootConfirm = function(){
94 if($scope.confirm) {
95 return;
96 }
97 $scope.confirm = true;
98 $scope.coldboot_confirm = true;
99 };
100
101 $scope.orderlyShutdown = function(){
102 //@TODO:show progress
103 APIUtils.hostPowerOff(function(response){
104 if(response){
105 dataService.setPowerOffState();
106 }else{
107 //@TODO:hide progress & show error message
108 }
109 });
110 };
111 $scope.orderlyShutdownConfirm = function(){
112 if($scope.confirm) {
113 return;
114 }
115 $scope.confirm = true;
116 $scope.orderly_confirm = true;
117 };
118
119 $scope.immediateShutdown = function(){
Gunnar Mills3aa8b532018-02-06 15:42:29 -0600120 //@TODO:show progress
121 APIUtils.chassisPowerOff(function(response){
122 if(response){
123 dataService.setPowerOffState();
124 }else{
125 //@TODO:hide progress & show error message
126 }
127 });
Iftekharul Islam99d199f2017-03-24 15:28:25 -0500128 };
129 $scope.immediateShutdownConfirm = function(){
130 if($scope.confirm) {
131 return;
132 }
133 $scope.confirm = true;
134 $scope.immediately_confirm = true;
135 };
136 }
137 ]
138 );
139
140})(angular);