Iftekharul Islam | f157d37 | 2017-03-08 11:11:27 -0600 | [diff] [blame] | 1 | 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 | }]) |
| 28 | .controller('powerOperationsController', ['$scope', 'APIUtils', 'dataService', function($scope, APIUtils, dataService){ |
| 29 | $scope.dataService = dataService; |
| 30 | $scope.confirm = false; |
| 31 | $scope.power_confirm = false; |
| 32 | $scope.warmboot_confirm = false; |
| 33 | $scope.coldboot_confirm = false; |
| 34 | $scope.orderly_confirm = false; |
| 35 | $scope.immediately_confirm = false; |
| 36 | |
| 37 | //@TODO: call api and get proper state |
| 38 | $scope.toggleState = function(){ |
| 39 | dataService.server_state = (dataService.server_state == 'On') ? 'Off': 'On'; |
| 40 | } |
| 41 | |
| 42 | $scope.togglePower = function(){ |
| 43 | var method = (dataService.server_state == 'On') ? 'chassisPowerOff' : 'chassisPowerOn'; |
| 44 | //@TODO: show progress or set class orange |
| 45 | APIUtils[method](function(response){ |
| 46 | //update state based on response |
| 47 | //error case? |
| 48 | if(response == null){ |
| 49 | console.log("Failed request."); |
| 50 | }else{ |
| 51 | dataService.server_state = response; |
| 52 | } |
| 53 | }); |
| 54 | } |
| 55 | $scope.powerOnConfirm = function(){ |
| 56 | if($scope.confirm) { |
| 57 | return; |
| 58 | } |
| 59 | $scope.confirm = true; |
| 60 | $scope.power_confirm = true; |
| 61 | }; |
| 62 | $scope.warmReboot = function(){ |
| 63 | //@TODO:show progress |
| 64 | APIUtils.hostPowerOff(function(response){ |
| 65 | if(response){ |
| 66 | APIUtils.hostPowerOn(function(response){ |
| 67 | if(response){ |
| 68 | |
| 69 | }else{ |
| 70 | //@TODO:show error message |
| 71 | } |
| 72 | //@TODO:hide progress, set proper server state |
| 73 | }); |
| 74 | }else{ |
| 75 | //@TODO:hide progress & show error message |
| 76 | } |
| 77 | }); |
| 78 | }; |
| 79 | $scope.warmRebootConfirm = function(){ |
| 80 | if($scope.confirm) { |
| 81 | return; |
| 82 | } |
| 83 | $scope.confirm = true; |
| 84 | $scope.warmboot_confirm = true; |
| 85 | }; |
| 86 | |
| 87 | $scope.coldReboot = function(){ |
| 88 | //@TODO:show progress |
| 89 | APIUtils.chassisPowerOff(function(response){ |
| 90 | if(response){ |
| 91 | APIUtils.chassisPowerOn(function(response){ |
| 92 | if(response){ |
| 93 | |
| 94 | }else{ |
| 95 | //@TODO:show error message |
| 96 | } |
| 97 | //@TODO:hide progress, set proper server state |
| 98 | }); |
| 99 | }else{ |
| 100 | //@TODO:hide progress & show error message |
| 101 | } |
| 102 | }); |
| 103 | }; |
| 104 | $scope.coldRebootConfirm = function(){ |
| 105 | if($scope.confirm) { |
| 106 | return; |
| 107 | } |
| 108 | $scope.confirm = true; |
| 109 | $scope.coldboot_confirm = true; |
| 110 | }; |
| 111 | |
| 112 | $scope.orderlyShutdown = function(){ |
| 113 | //@TODO:show progress |
| 114 | APIUtils.hostPowerOff(function(response){ |
| 115 | if(response){ |
| 116 | APIUtils.chassisPowerOff(function(response){ |
| 117 | if(response){ |
| 118 | |
| 119 | }else{ |
| 120 | //@TODO:show error message |
| 121 | } |
| 122 | //@TODO:hide progress, set proper server state |
| 123 | }); |
| 124 | }else{ |
| 125 | //@TODO:hide progress & show error message |
| 126 | } |
| 127 | }); |
| 128 | }; |
| 129 | $scope.orderlyShutdownConfirm = function(){ |
| 130 | if($scope.confirm) { |
| 131 | return; |
| 132 | } |
| 133 | $scope.confirm = true; |
| 134 | $scope.orderly_confirm = true; |
| 135 | }; |
| 136 | |
| 137 | $scope.immediateShutdown = function(){ |
| 138 | //@TODO:show progress |
| 139 | APIUtils.chassisPowerOff(function(response){ |
| 140 | if(response){ |
| 141 | //@TODO: set proper server state |
| 142 | }else{ |
| 143 | //@TODO:show error message |
| 144 | } |
| 145 | //@TODO:hide progress |
| 146 | }); |
| 147 | }; |
| 148 | $scope.immediateShutdownConfirm = function(){ |
| 149 | if($scope.confirm) { |
| 150 | return; |
| 151 | } |
| 152 | $scope.confirm = true; |
| 153 | $scope.immediately_confirm = true; |
| 154 | }; |
| 155 | }]); |