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