Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 1 | /** |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 2 | * Controller for systemOverview |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 3 | * |
| 4 | * @module app/overview |
| 5 | * @exports systemOverviewController |
| 6 | * @name systemOverviewController |
| 7 | * @version 0.1.0 |
| 8 | */ |
| 9 | |
| 10 | window.angular && (function (angular) { |
| 11 | 'use strict'; |
| 12 | |
| 13 | angular |
| 14 | .module('app.overview') |
| 15 | .controller('systemOverviewController', [ |
Gunnar Mills | eedefd3 | 2018-02-28 17:02:34 -0600 | [diff] [blame] | 16 | '$scope', |
| 17 | '$window', |
| 18 | 'APIUtils', |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 19 | 'dataService', |
Michael Davis | 428375e | 2017-08-01 15:48:34 -0500 | [diff] [blame] | 20 | '$q', |
Andrew Geissler | cf86200 | 2018-04-11 12:19:39 -0700 | [diff] [blame] | 21 | function($scope, $window, APIUtils, dataService, $q){ |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 22 | $scope.dataService = dataService; |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 23 | $scope.dropdown_selected = false; |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 24 | $scope.tmz = 'EDT'; |
| 25 | $scope.logs = []; |
| 26 | $scope.mac_address = ""; |
| 27 | $scope.bmc_info = {}; |
Gunnar Mills | 17708f2 | 2018-04-13 14:21:31 -0500 | [diff] [blame] | 28 | $scope.server_info = {}; |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 29 | $scope.bmc_firmware = ""; |
| 30 | $scope.server_firmware = ""; |
CamVan Nguyen | 3327583 | 2018-03-13 18:38:37 -0500 | [diff] [blame] | 31 | $scope.power_consumption = ""; |
| 32 | $scope.power_cap = ""; |
Michael Davis | 428375e | 2017-08-01 15:48:34 -0500 | [diff] [blame] | 33 | $scope.loading = false; |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 34 | |
| 35 | loadOverviewData(); |
| 36 | function loadOverviewData(){ |
Michael Davis | 428375e | 2017-08-01 15:48:34 -0500 | [diff] [blame] | 37 | $scope.loading = true; |
| 38 | var promises = { |
| 39 | logs: APIUtils.getLogs(), |
| 40 | firmware: APIUtils.getFirmwares(), |
| 41 | led: APIUtils.getLEDState(), |
| 42 | ethernet: APIUtils.getBMCEthernetInfo(), |
CamVan Nguyen | 3327583 | 2018-03-13 18:38:37 -0500 | [diff] [blame] | 43 | bmc_info: APIUtils.getBMCInfo(), |
Gunnar Mills | 17708f2 | 2018-04-13 14:21:31 -0500 | [diff] [blame] | 44 | server_info: APIUtils.getServerInfo(), |
CamVan Nguyen | 3327583 | 2018-03-13 18:38:37 -0500 | [diff] [blame] | 45 | power_consumption: APIUtils.getPowerConsumption(), |
| 46 | power_cap: APIUtils.getPowerCap(), |
Michael Davis | 428375e | 2017-08-01 15:48:34 -0500 | [diff] [blame] | 47 | }; |
| 48 | $q.all(promises) |
| 49 | .then(function(data){ |
| 50 | $scope.displayLogs(data.logs.data); |
| 51 | $scope.displayServerInfo( |
Gunnar Mills | 17708f2 | 2018-04-13 14:21:31 -0500 | [diff] [blame] | 52 | data.server_info, |
Michael Davis | 428375e | 2017-08-01 15:48:34 -0500 | [diff] [blame] | 53 | data.firmware.hostActiveVersion |
| 54 | ); |
| 55 | $scope.displayLEDState(data.led); |
| 56 | $scope.displayBMCEthernetInfo(data.ethernet); |
Gunnar Mills | 5dbcfb1 | 2018-04-13 14:56:41 -0500 | [diff] [blame] | 57 | $scope.displayBMCInfo( |
| 58 | data.bmc_info, |
| 59 | data.firmware.bmcActiveVersion |
| 60 | ); |
CamVan Nguyen | 3327583 | 2018-03-13 18:38:37 -0500 | [diff] [blame] | 61 | $scope.displayPowerConsumption(data.power_consumption); |
| 62 | $scope.displayPowerCap(data.power_cap); |
Michael Davis | 428375e | 2017-08-01 15:48:34 -0500 | [diff] [blame] | 63 | }) |
| 64 | .finally(function(){ |
| 65 | $scope.loading = false; |
| 66 | }); |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 67 | } |
| 68 | $scope.displayBMCEthernetInfo = function(data){ |
| 69 | $scope.mac_address = data.MACAddress; |
| 70 | } |
| 71 | |
Gunnar Mills | 5dbcfb1 | 2018-04-13 14:56:41 -0500 | [diff] [blame] | 72 | $scope.displayBMCInfo = function(data, bmcActiveVersion){ |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 73 | $scope.bmc_info = data; |
Gunnar Mills | 5dbcfb1 | 2018-04-13 14:56:41 -0500 | [diff] [blame] | 74 | $scope.bmc_firmware = bmcActiveVersion; |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | $scope.displayLogs = function(data){ |
| 78 | $scope.logs = data.filter(function(log){ |
| 79 | return log.severity_flags.high == true; |
| 80 | }); |
| 81 | } |
| 82 | |
Gunnar Mills | 5dbcfb1 | 2018-04-13 14:56:41 -0500 | [diff] [blame] | 83 | $scope.displayServerInfo = function(data, hostActiveVersion){ |
Gunnar Mills | 17708f2 | 2018-04-13 14:21:31 -0500 | [diff] [blame] | 84 | $scope.server_info = data.data; |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 85 | $scope.server_firmware = hostActiveVersion; |
| 86 | } |
| 87 | |
| 88 | $scope.displayLEDState = function(state){ |
| 89 | if(state == APIUtils.LED_STATE.on){ |
| 90 | dataService.LED_state = APIUtils.LED_STATE_TEXT.on; |
| 91 | }else{ |
| 92 | dataService.LED_state = APIUtils.LED_STATE_TEXT.off; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | $scope.toggleLED = function(){ |
| 97 | var toggleState = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ? |
| 98 | APIUtils.LED_STATE.off : APIUtils.LED_STATE.on; |
| 99 | dataService.LED_state = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ? |
| 100 | APIUtils.LED_STATE_TEXT.off : APIUtils.LED_STATE_TEXT.on; |
| 101 | APIUtils.setLEDState(toggleState, function(status){ |
| 102 | }); |
| 103 | } |
CamVan Nguyen | 23217da | 2018-03-22 00:22:50 -0500 | [diff] [blame] | 104 | |
CamVan Nguyen | 3327583 | 2018-03-13 18:38:37 -0500 | [diff] [blame] | 105 | $scope.displayPowerConsumption = function(data){ |
| 106 | $scope.power_consumption = data; |
| 107 | } |
| 108 | |
| 109 | $scope.displayPowerCap = function(data){ |
| 110 | $scope.power_cap = data; |
| 111 | } |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 112 | } |
| 113 | ] |
| 114 | ); |
| 115 | |
CamVan Nguyen | 23217da | 2018-03-22 00:22:50 -0500 | [diff] [blame] | 116 | })(angular); |