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', [ |
CamVan Nguyen | 23217da | 2018-03-22 00:22:50 -0500 | [diff] [blame] | 16 | '$rootScope', |
Gunnar Mills | eedefd3 | 2018-02-28 17:02:34 -0600 | [diff] [blame] | 17 | '$scope', |
| 18 | '$window', |
| 19 | 'APIUtils', |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 20 | 'dataService', |
Michael Davis | 428375e | 2017-08-01 15:48:34 -0500 | [diff] [blame] | 21 | '$q', |
CamVan Nguyen | 23217da | 2018-03-22 00:22:50 -0500 | [diff] [blame] | 22 | function($rootScope, $scope, $window, APIUtils, dataService, $q){ |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 23 | $scope.dataService = dataService; |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 24 | $scope.dropdown_selected = false; |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 25 | $scope.tmz = 'EDT'; |
| 26 | $scope.logs = []; |
| 27 | $scope.mac_address = ""; |
| 28 | $scope.bmc_info = {}; |
| 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(), |
| 44 | power_consumption: APIUtils.getPowerConsumption(), |
| 45 | power_cap: APIUtils.getPowerCap(), |
Michael Davis | 428375e | 2017-08-01 15:48:34 -0500 | [diff] [blame] | 46 | }; |
| 47 | $q.all(promises) |
| 48 | .then(function(data){ |
| 49 | $scope.displayLogs(data.logs.data); |
| 50 | $scope.displayServerInfo( |
Gunnar Mills | eedefd3 | 2018-02-28 17:02:34 -0600 | [diff] [blame] | 51 | data.firmware.data, |
| 52 | data.firmware.bmcActiveVersion, |
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); |
| 57 | $scope.displayBMCInfo(data.bmc_info); |
CamVan Nguyen | 3327583 | 2018-03-13 18:38:37 -0500 | [diff] [blame^] | 58 | $scope.displayPowerConsumption(data.power_consumption); |
| 59 | $scope.displayPowerCap(data.power_cap); |
Michael Davis | 428375e | 2017-08-01 15:48:34 -0500 | [diff] [blame] | 60 | }) |
| 61 | .finally(function(){ |
| 62 | $scope.loading = false; |
| 63 | }); |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 64 | } |
| 65 | $scope.displayBMCEthernetInfo = function(data){ |
| 66 | $scope.mac_address = data.MACAddress; |
| 67 | } |
| 68 | |
| 69 | $scope.displayBMCInfo = function(data){ |
| 70 | $scope.bmc_info = data; |
| 71 | } |
| 72 | |
| 73 | $scope.displayLogs = function(data){ |
| 74 | $scope.logs = data.filter(function(log){ |
| 75 | return log.severity_flags.high == true; |
| 76 | }); |
| 77 | } |
| 78 | |
| 79 | $scope.displayServerInfo = function(data, bmcActiveVersion, hostActiveVersion){ |
| 80 | $scope.bmc_firmware = bmcActiveVersion; |
| 81 | $scope.server_firmware = hostActiveVersion; |
| 82 | } |
| 83 | |
| 84 | $scope.displayLEDState = function(state){ |
| 85 | if(state == APIUtils.LED_STATE.on){ |
| 86 | dataService.LED_state = APIUtils.LED_STATE_TEXT.on; |
| 87 | }else{ |
| 88 | dataService.LED_state = APIUtils.LED_STATE_TEXT.off; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | $scope.toggleLED = function(){ |
| 93 | var toggleState = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ? |
| 94 | APIUtils.LED_STATE.off : APIUtils.LED_STATE.on; |
| 95 | dataService.LED_state = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ? |
| 96 | APIUtils.LED_STATE_TEXT.off : APIUtils.LED_STATE_TEXT.on; |
| 97 | APIUtils.setLEDState(toggleState, function(status){ |
| 98 | }); |
| 99 | } |
CamVan Nguyen | 23217da | 2018-03-22 00:22:50 -0500 | [diff] [blame] | 100 | |
CamVan Nguyen | 3327583 | 2018-03-13 18:38:37 -0500 | [diff] [blame^] | 101 | $scope.displayPowerConsumption = function(data){ |
| 102 | $scope.power_consumption = data; |
| 103 | } |
| 104 | |
| 105 | $scope.displayPowerCap = function(data){ |
| 106 | $scope.power_cap = data; |
| 107 | } |
| 108 | |
CamVan Nguyen | 23217da | 2018-03-22 00:22:50 -0500 | [diff] [blame] | 109 | var refreshDataListener = $rootScope.$on('refresh-data', function(event, args) { |
| 110 | loadOverviewData(); |
| 111 | }); |
| 112 | |
| 113 | $scope.$on('$destroy', function() { |
| 114 | refreshDataListener(); |
| 115 | }); |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 116 | } |
| 117 | ] |
| 118 | ); |
| 119 | |
CamVan Nguyen | 23217da | 2018-03-22 00:22:50 -0500 | [diff] [blame] | 120 | })(angular); |