Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 1 | angular |
| 2 | .module('app.controllers', []) |
| 3 | .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 | }; |
| 11 | $scope.login = function(username, password){ |
| 12 | $scope.error = false; |
| 13 | if(!username || username == "" || |
| 14 | !password || password == ""){ |
| 15 | return false; |
| 16 | }else{ |
| 17 | if(userModel.login(username, password)){ |
| 18 | $window.location.hash = '#/system-overview'; |
| 19 | }else{ |
| 20 | $scope.error = true; |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 21 | } |
| 22 | } |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 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 | }]) |
| 31 | .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 | }]) |
| 37 | .controller('powerOperationsController', ['$scope', 'APIUtils', 'dataService', '$timeout', function($scope, APIUtils, dataService, $timeout){ |
| 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; |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 45 | |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 46 | //@TODO: call api and get proper state |
| 47 | $scope.toggleState = function(){ |
| 48 | dataService.server_state = (dataService.server_state == 'Running') ? 'Off': 'Running'; |
| 49 | } |
| 50 | |
| 51 | $scope.togglePower = function(){ |
| 52 | var method = (dataService.server_state == 'Running') ? 'hostPowerOff' : 'hostPowerOn'; |
| 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 | //@TODO::need to get the server status |
| 61 | if(dataService.server_state == 'Running'){ |
| 62 | dataService.setPowerOffState(); |
| 63 | }else{ |
| 64 | dataService.setPowerOnState(); |
Michael Davis | 29825e4 | 2017-07-12 16:13:22 -0500 | [diff] [blame] | 65 | } |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 66 | } |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 67 | }); |
| 68 | } |
| 69 | $scope.powerOnConfirm = function(){ |
| 70 | if($scope.confirm) { |
| 71 | return; |
Michael Davis | 29825e4 | 2017-07-12 16:13:22 -0500 | [diff] [blame] | 72 | } |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 73 | $scope.confirm = true; |
| 74 | $scope.power_confirm = true; |
| 75 | }; |
| 76 | $scope.warmReboot = function(){ |
| 77 | //@TODO:show progress |
| 78 | dataService.loading = true; |
| 79 | APIUtils.hostPowerOff(function(response){ |
| 80 | if(response){ |
| 81 | dataService.setPowerOffState(); |
| 82 | APIUtils.hostPowerOn(function(response){ |
| 83 | if(response){ |
| 84 | dataService.setPowerOnState(); |
| 85 | }else{ |
| 86 | //@TODO:show error message |
| 87 | } |
| 88 | //@TODO:hide progress, set proper server state |
| 89 | dataService.loading = false; |
| 90 | }); |
| 91 | }else{ |
| 92 | //@TODO:hide progress & show error message |
| 93 | dataService.loading = false; |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 94 | } |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 95 | }); |
| 96 | }; |
| 97 | $scope.testState = function(){ |
| 98 | //@TODO:show progress |
| 99 | dataService.loading = true; |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 100 | |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 101 | $timeout(function(){ |
| 102 | dataService.setPowerOffState(); |
| 103 | $timeout(function(){ |
| 104 | dataService.setPowerOnState(); |
| 105 | dataService.loading = false; |
| 106 | }, 2000); |
| 107 | }, 1000); |
| 108 | }; |
| 109 | $scope.warmRebootConfirm = function(){ |
| 110 | if($scope.confirm) { |
| 111 | return; |
| 112 | } |
| 113 | $scope.confirm = true; |
| 114 | $scope.warmboot_confirm = true; |
| 115 | }; |
| 116 | |
| 117 | $scope.coldReboot = function(){ |
| 118 | $scope.warmReboot(); |
| 119 | }; |
| 120 | $scope.coldRebootConfirm = function(){ |
| 121 | if($scope.confirm) { |
| 122 | return; |
| 123 | } |
| 124 | $scope.confirm = true; |
| 125 | $scope.coldboot_confirm = true; |
| 126 | }; |
| 127 | |
| 128 | $scope.orderlyShutdown = function(){ |
| 129 | //@TODO:show progress |
| 130 | dataService.loading = true; |
| 131 | APIUtils.hostPowerOff(function(response){ |
| 132 | if(response){ |
| 133 | dataService.setPowerOffState(); |
| 134 | }else{ |
| 135 | //@TODO:hide progress & show error message |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 136 | } |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 137 | dataService.loading = false; |
| 138 | }); |
| 139 | }; |
| 140 | $scope.orderlyShutdownConfirm = function(){ |
| 141 | if($scope.confirm) { |
| 142 | return; |
| 143 | } |
| 144 | $scope.confirm = true; |
| 145 | $scope.orderly_confirm = true; |
| 146 | }; |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 147 | |
Iftekharul Islam | ccfe245 | 2017-03-16 10:47:04 -0500 | [diff] [blame^] | 148 | $scope.immediateShutdown = function(){ |
| 149 | $scope.orderlyShutdown(); |
| 150 | }; |
| 151 | $scope.immediateShutdownConfirm = function(){ |
| 152 | if($scope.confirm) { |
| 153 | return; |
| 154 | } |
| 155 | $scope.confirm = true; |
| 156 | $scope.immediately_confirm = true; |
| 157 | }; |
| 158 | }]); |