blob: 854af781601c4685848f13b4c2746974dbc9cb03 [file] [log] [blame]
Iftekharul Islamf157d372017-03-08 11:11:27 -06001 angular
2 .module('app.controllers', [])
3 .controller('loginController', ['$scope', '$window', 'APIUtils', 'dataService', function($scope, $window, APIUtils, dataService){
4 $scope.login = function(username, password){
5 $scope.error = false;
6 $scope.dataService = dataService;
7 if(!username || username == "" ||
8 !password || password == ""){
9 return false;
10 }else{
11 //@TODO: service should handle
12 if(username == APIUtils.LOGIN_CREDENTIALS.username &&
13 password == APIUtils.LOGIN_CREDENTIALS.password){
14 $window.location.hash = '#/dashboard';
15 }else{
16 $scope.error = true;
17 //@TODO: show error message
18 }
19 }
20 }
21 }])
22 .controller('dashboardController', ['$scope', 'dataService', function($scope, dataService){
23 $scope.dataService = dataService;
24 }])
25 .controller('systemOverviewController', ['$scope', 'dataService', function($scope, dataService){
26 $scope.dataService = dataService;
27 }])
Iftekharul Islamb37fdfb2017-07-12 15:36:20 -050028 .controller('unitIDController', ['$scope', 'dataService', function($scope, dataService){
29 $scope.dataService = dataService;
30 }])
31 .controller('bmcRebootController', ['$scope', 'dataService', function($scope, dataService){
32 $scope.dataService = dataService;
33 }])
Iftekharul Islamf157d372017-03-08 11:11:27 -060034 .controller('powerOperationsController', ['$scope', 'APIUtils', 'dataService', function($scope, APIUtils, dataService){
35 $scope.dataService = dataService;
36 $scope.confirm = false;
37 $scope.power_confirm = false;
38 $scope.warmboot_confirm = false;
39 $scope.coldboot_confirm = false;
40 $scope.orderly_confirm = false;
41 $scope.immediately_confirm = false;
42
43 //@TODO: call api and get proper state
44 $scope.toggleState = function(){
45 dataService.server_state = (dataService.server_state == 'On') ? 'Off': 'On';
46 }
47
48 $scope.togglePower = function(){
49 var method = (dataService.server_state == 'On') ? 'chassisPowerOff' : 'chassisPowerOn';
50 //@TODO: show progress or set class orange
51 APIUtils[method](function(response){
52 //update state based on response
53 //error case?
54 if(response == null){
55 console.log("Failed request.");
56 }else{
57 dataService.server_state = response;
58 }
59 });
60 }
61 $scope.powerOnConfirm = function(){
62 if($scope.confirm) {
63 return;
64 }
65 $scope.confirm = true;
66 $scope.power_confirm = true;
67 };
68 $scope.warmReboot = function(){
69 //@TODO:show progress
70 APIUtils.hostPowerOff(function(response){
71 if(response){
72 APIUtils.hostPowerOn(function(response){
73 if(response){
74
75 }else{
76 //@TODO:show error message
77 }
78 //@TODO:hide progress, set proper server state
79 });
80 }else{
81 //@TODO:hide progress & show error message
82 }
83 });
84 };
85 $scope.warmRebootConfirm = function(){
86 if($scope.confirm) {
87 return;
88 }
89 $scope.confirm = true;
90 $scope.warmboot_confirm = true;
91 };
92
93 $scope.coldReboot = function(){
94 //@TODO:show progress
95 APIUtils.chassisPowerOff(function(response){
96 if(response){
97 APIUtils.chassisPowerOn(function(response){
98 if(response){
99
100 }else{
101 //@TODO:show error message
102 }
103 //@TODO:hide progress, set proper server state
104 });
105 }else{
106 //@TODO:hide progress & show error message
107 }
108 });
109 };
110 $scope.coldRebootConfirm = function(){
111 if($scope.confirm) {
112 return;
113 }
114 $scope.confirm = true;
115 $scope.coldboot_confirm = true;
116 };
117
118 $scope.orderlyShutdown = function(){
119 //@TODO:show progress
120 APIUtils.hostPowerOff(function(response){
121 if(response){
122 APIUtils.chassisPowerOff(function(response){
123 if(response){
124
125 }else{
126 //@TODO:show error message
127 }
128 //@TODO:hide progress, set proper server state
129 });
130 }else{
131 //@TODO:hide progress & show error message
132 }
133 });
134 };
135 $scope.orderlyShutdownConfirm = function(){
136 if($scope.confirm) {
137 return;
138 }
139 $scope.confirm = true;
140 $scope.orderly_confirm = true;
141 };
142
143 $scope.immediateShutdown = function(){
144 //@TODO:show progress
145 APIUtils.chassisPowerOff(function(response){
146 if(response){
147 //@TODO: set proper server state
148 }else{
149 //@TODO:show error message
150 }
151 //@TODO:hide progress
152 });
153 };
154 $scope.immediateShutdownConfirm = function(){
155 if($scope.confirm) {
156 return;
157 }
158 $scope.confirm = true;
159 $scope.immediately_confirm = true;
160 };
161 }]);