Michael Davis | 29825e4 | 2017-07-12 16:13:22 -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; |
Iftekharul Islam | 115984a | 2017-03-09 09:47:35 -0600 | [diff] [blame] | 5 | |
Michael Davis | 29825e4 | 2017-07-12 16:13:22 -0500 | [diff] [blame] | 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 == "" || !password || password == "") { |
| 14 | return false; |
| 15 | } else { |
| 16 | if (userModel.login(username, password)) { |
| 17 | $window.location.hash = '#/system-overview'; |
| 18 | } else { |
| 19 | $scope.error = true; |
| 20 | } |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 21 | } |
| 22 | } |
Michael Davis | 29825e4 | 2017-07-12 16:13:22 -0500 | [diff] [blame] | 23 | }]) |
| 24 | .controller('dashboardController', ['$scope', 'dataService', function ($scope, dataService) { |
| 25 | $scope.dataService = dataService; |
| 26 | }]) |
| 27 | .controller('systemOverviewController', ['$scope', 'dataService', function ($scope, dataService) { |
| 28 | $scope.dataService = dataService; |
| 29 | }]) |
| 30 | .controller('unitIDController', ['$scope', 'dataService', function ($scope, dataService) { |
| 31 | $scope.dataService = dataService; |
| 32 | }]) |
| 33 | .controller('bmcRebootController', ['$scope', 'dataService', function ($scope, dataService) { |
| 34 | $scope.dataService = dataService; |
| 35 | $scope.bmcReboot_confirm = false; |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 36 | |
Michael Davis | 29825e4 | 2017-07-12 16:13:22 -0500 | [diff] [blame] | 37 | // BMC reboot |
| 38 | $scope.bmcReboot = function () { |
| 39 | //@TODO:show progress |
| 40 | APIUtils.bmcReboot(function (response) { |
| 41 | if (response) { |
| 42 | //@TODO: set proper server state |
| 43 | } else { |
| 44 | //@TODO:show error message |
| 45 | } |
| 46 | //@TODO:hide progress |
| 47 | }); |
| 48 | }; |
| 49 | $scope.bmcRebootConfirm = function () { |
| 50 | if ($scope.confirm) { |
| 51 | return; |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 52 | } |
Michael Davis | 29825e4 | 2017-07-12 16:13:22 -0500 | [diff] [blame] | 53 | $scope.confirm = true; |
| 54 | $scope.bmcReboot_confirm = true; |
| 55 | }; |
| 56 | }]) |
| 57 | .controller('powerOperationsController', ['$scope', 'APIUtils', 'dataService', function ($scope, APIUtils, dataService) { |
| 58 | $scope.dataService = dataService; |
| 59 | $scope.confirm = false; |
| 60 | $scope.power_confirm = false; |
| 61 | $scope.warmboot_confirm = false; |
| 62 | $scope.coldboot_confirm = false; |
| 63 | $scope.orderly_confirm = false; |
| 64 | $scope.immediately_confirm = false; |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 65 | |
Michael Davis | 29825e4 | 2017-07-12 16:13:22 -0500 | [diff] [blame] | 66 | //@TODO: call api and get proper state |
| 67 | $scope.toggleState = function () { |
| 68 | dataService.server_state = (dataService.server_state == 'On') ? 'Off' : 'On'; |
| 69 | }; |
| 70 | |
| 71 | $scope.togglePower = function () { |
| 72 | var method = (dataService.server_state == 'On') ? 'chassisPowerOff' : 'chassisPowerOn'; |
| 73 | //@TODO: show progress or set class orange |
| 74 | APIUtils[method](function (response) { |
| 75 | //update state based on response |
| 76 | //error case? |
| 77 | if (response == null) { |
| 78 | console.log("Failed request."); |
| 79 | } else { |
| 80 | dataService.server_state = response; |
| 81 | } |
| 82 | }); |
| 83 | } |
| 84 | $scope.powerOnConfirm = function () { |
| 85 | if ($scope.confirm) { |
| 86 | return; |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 87 | } |
Michael Davis | 29825e4 | 2017-07-12 16:13:22 -0500 | [diff] [blame] | 88 | $scope.confirm = true; |
| 89 | $scope.power_confirm = true; |
| 90 | }; |
| 91 | $scope.warmReboot = function () { |
| 92 | //@TODO:show progress |
| 93 | APIUtils.hostPowerOff(function (response) { |
| 94 | if (response) { |
| 95 | APIUtils.hostPowerOn(function (response) { |
| 96 | if (response) { |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 97 | |
Michael Davis | 29825e4 | 2017-07-12 16:13:22 -0500 | [diff] [blame] | 98 | } else { |
| 99 | //@TODO:show error message |
| 100 | } |
| 101 | //@TODO:hide progress, set proper server state |
| 102 | }); |
| 103 | } else { |
| 104 | //@TODO:hide progress & show error message |
| 105 | } |
| 106 | }); |
| 107 | }; |
| 108 | $scope.warmRebootConfirm = function () { |
| 109 | if ($scope.confirm) { |
| 110 | return; |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 111 | } |
Michael Davis | 29825e4 | 2017-07-12 16:13:22 -0500 | [diff] [blame] | 112 | $scope.confirm = true; |
| 113 | $scope.warmboot_confirm = true; |
| 114 | }; |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 115 | |
Michael Davis | 29825e4 | 2017-07-12 16:13:22 -0500 | [diff] [blame] | 116 | $scope.coldReboot = function () { |
| 117 | //@TODO:show progress |
| 118 | APIUtils.chassisPowerOff(function (response) { |
| 119 | if (response) { |
| 120 | APIUtils.chassisPowerOn(function (response) { |
| 121 | if (response) { |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 122 | |
Michael Davis | 29825e4 | 2017-07-12 16:13:22 -0500 | [diff] [blame] | 123 | } else { |
| 124 | //@TODO:show error message |
| 125 | } |
| 126 | //@TODO:hide progress, set proper server state |
| 127 | }); |
| 128 | } else { |
| 129 | //@TODO:hide progress & show error message |
| 130 | } |
| 131 | }); |
| 132 | }; |
| 133 | $scope.coldRebootConfirm = function () { |
| 134 | if ($scope.confirm) { |
| 135 | return; |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 136 | } |
Michael Davis | 29825e4 | 2017-07-12 16:13:22 -0500 | [diff] [blame] | 137 | $scope.confirm = true; |
| 138 | $scope.coldboot_confirm = true; |
| 139 | }; |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 140 | |
Michael Davis | 29825e4 | 2017-07-12 16:13:22 -0500 | [diff] [blame] | 141 | $scope.orderlyShutdown = function () { |
| 142 | //@TODO:show progress |
| 143 | APIUtils.hostPowerOff(function (response) { |
| 144 | if (response) { |
| 145 | APIUtils.chassisPowerOff(function (response) { |
| 146 | if (response) { |
| 147 | |
| 148 | } else { |
| 149 | //@TODO:show error message |
| 150 | } |
| 151 | //@TODO:hide progress, set proper server state |
| 152 | }); |
| 153 | } else { |
| 154 | //@TODO:hide progress & show error message |
| 155 | } |
| 156 | }); |
| 157 | }; |
| 158 | $scope.orderlyShutdownConfirm = function () { |
| 159 | if ($scope.confirm) { |
| 160 | return; |
Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 161 | } |
Michael Davis | 29825e4 | 2017-07-12 16:13:22 -0500 | [diff] [blame] | 162 | $scope.confirm = true; |
| 163 | $scope.orderly_confirm = true; |
| 164 | }; |
| 165 | |
| 166 | $scope.immediateShutdown = function () { |
| 167 | //@TODO:show progress |
| 168 | APIUtils.chassisPowerOff(function (response) { |
| 169 | if (response) { |
| 170 | //@TODO: set proper server state |
| 171 | } else { |
| 172 | //@TODO:show error message |
| 173 | } |
| 174 | //@TODO:hide progress |
| 175 | }); |
| 176 | }; |
| 177 | $scope.immediateShutdownConfirm = function () { |
| 178 | if ($scope.confirm) { |
| 179 | return; |
| 180 | } |
| 181 | $scope.confirm = true; |
| 182 | $scope.immediately_confirm = true; |
| 183 | }; |
| 184 | |
| 185 | }]); |