summaryrefslogtreecommitdiffstats
path: root/app/server-control/controllers/power-operations-controller.js
blob: 4ab765d90f8cf6e49a8a38cff871a54652036f71 (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
 * Controller for power-operations
 *
 * @module app/serverControl
 * @exports powerOperationsController
 * @name powerOperationsController
 * @version 0.1.0
 */

window.angular && (function (angular) {
    'use strict';

    angular
        .module('app.serverControl')
        .controller('powerOperationsController', [
            '$scope', 
            'APIUtils', 
            'dataService', 
            '$timeout', 
            function($scope, APIUtils, dataService, $timeout){
                $scope.dataService = dataService;
                $scope.confirm = false;
                $scope.power_confirm = false;
                $scope.warmboot_confirm = false;
                $scope.coldboot_confirm = false;
                $scope.orderly_confirm = false;
                $scope.immediately_confirm = false;

                //@TODO: call api and get proper state
                $scope.toggleState = function(){
                    dataService.server_state = (dataService.server_state == 'Running') ? 'Off': 'Running';
                }

                $scope.togglePower = function(){
                    var method = (dataService.server_state == 'Running') ? 'hostPowerOff' : 'hostPowerOn';
                     //@TODO: show progress or set class orange
                    APIUtils[method](function(response){
                        //update state based on response
                        //error case?
                        if(response == null){
                            console.log("Failed request.");
                        }else{
                            //@TODO::need to get the server status
                            if(dataService.server_state == 'Running'){
                                dataService.setPowerOffState();
                            }else{
                                dataService.setPowerOnState();
                            }
                        }
                    });
                }
                $scope.powerOnConfirm = function(){
                    if($scope.confirm) {
                        return;
                    }
                    $scope.confirm = true;
                    $scope.power_confirm = true;
                };
                $scope.warmReboot = function(){
                    //@TODO:show progress
                    dataService.setBootingState();
                    APIUtils.hostPowerOff(function(response){
                        if(response){
                            APIUtils.hostPowerOn(function(response){
                                if(response){
                                    dataService.setPowerOnState();
                                }else{
                                    //@TODO:show error message
                                }
                            });
                        }
                    });
                };
                $scope.testState = function(){
                    $timeout(function(){
                        dataService.setPowerOffState();
                        $timeout(function(){
                            dataService.setPowerOnState();
                        }, 2000);
                    }, 1000);
                };
                $scope.warmRebootConfirm = function(){
                    if($scope.confirm) {
                        return;
                    }
                    $scope.confirm = true;
                    $scope.warmboot_confirm = true;
                };

                $scope.coldReboot = function(){
                    $scope.warmReboot();
                };
                $scope.coldRebootConfirm = function(){
                    if($scope.confirm) {
                        return;
                    }
                    $scope.confirm = true;
                    $scope.coldboot_confirm = true;
                };

                $scope.orderlyShutdown = function(){
                    //@TODO:show progress
                    APIUtils.hostPowerOff(function(response){
                        if(response){
                            dataService.setPowerOffState();
                        }else{
                            //@TODO:hide progress & show error message
                        }
                    });
                };
                $scope.orderlyShutdownConfirm = function(){
                    if($scope.confirm) {
                        return;
                    }
                    $scope.confirm = true;
                    $scope.orderly_confirm = true;
                };

                $scope.immediateShutdown = function(){
                    $scope.orderlyShutdown();
                };
                $scope.immediateShutdownConfirm = function(){
                    if($scope.confirm) {
                        return;
                    }
                    $scope.confirm = true;
                    $scope.immediately_confirm = true;
                };
            }
        ]
    );

})(angular);
OpenPOWER on IntegriCloud