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', [ |
| 16 | '$scope', |
| 17 | '$window', |
| 18 | 'APIUtils', |
| 19 | 'dataService', |
Michael Davis | 428375e | 2017-08-01 15:48:34 -0500 | [diff] [blame^] | 20 | '$q', |
| 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 = {}; |
| 28 | $scope.bmc_firmware = ""; |
| 29 | $scope.server_firmware = ""; |
Michael Davis | 428375e | 2017-08-01 15:48:34 -0500 | [diff] [blame^] | 30 | $scope.loading = false; |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 31 | |
| 32 | loadOverviewData(); |
| 33 | function loadOverviewData(){ |
Michael Davis | 428375e | 2017-08-01 15:48:34 -0500 | [diff] [blame^] | 34 | $scope.loading = true; |
| 35 | var promises = { |
| 36 | logs: APIUtils.getLogs(), |
| 37 | firmware: APIUtils.getFirmwares(), |
| 38 | led: APIUtils.getLEDState(), |
| 39 | ethernet: APIUtils.getBMCEthernetInfo(), |
| 40 | bmc_info: APIUtils.getBMCInfo() |
| 41 | }; |
| 42 | $q.all(promises) |
| 43 | .then(function(data){ |
| 44 | $scope.displayLogs(data.logs.data); |
| 45 | $scope.displayServerInfo( |
| 46 | data.firmware.data, |
| 47 | data.firmware.bmcActiveVersion, |
| 48 | data.firmware.hostActiveVersion |
| 49 | ); |
| 50 | $scope.displayLEDState(data.led); |
| 51 | $scope.displayBMCEthernetInfo(data.ethernet); |
| 52 | $scope.displayBMCInfo(data.bmc_info); |
| 53 | }) |
| 54 | .finally(function(){ |
| 55 | $scope.loading = false; |
| 56 | }); |
Iftekharul Islam | 54c22e4 | 2017-06-28 11:06:16 -0500 | [diff] [blame] | 57 | } |
| 58 | $scope.displayBMCEthernetInfo = function(data){ |
| 59 | $scope.mac_address = data.MACAddress; |
| 60 | } |
| 61 | |
| 62 | $scope.displayBMCInfo = function(data){ |
| 63 | $scope.bmc_info = data; |
| 64 | } |
| 65 | |
| 66 | $scope.displayLogs = function(data){ |
| 67 | $scope.logs = data.filter(function(log){ |
| 68 | return log.severity_flags.high == true; |
| 69 | }); |
| 70 | } |
| 71 | |
| 72 | $scope.displayServerInfo = function(data, bmcActiveVersion, hostActiveVersion){ |
| 73 | $scope.bmc_firmware = bmcActiveVersion; |
| 74 | $scope.server_firmware = hostActiveVersion; |
| 75 | } |
| 76 | |
| 77 | $scope.displayLEDState = function(state){ |
| 78 | if(state == APIUtils.LED_STATE.on){ |
| 79 | dataService.LED_state = APIUtils.LED_STATE_TEXT.on; |
| 80 | }else{ |
| 81 | dataService.LED_state = APIUtils.LED_STATE_TEXT.off; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | $scope.toggleLED = function(){ |
| 86 | var toggleState = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ? |
| 87 | APIUtils.LED_STATE.off : APIUtils.LED_STATE.on; |
| 88 | dataService.LED_state = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ? |
| 89 | APIUtils.LED_STATE_TEXT.off : APIUtils.LED_STATE_TEXT.on; |
| 90 | APIUtils.setLEDState(toggleState, function(status){ |
| 91 | }); |
| 92 | } |
Iftekharul Islam | 99d199f | 2017-03-24 15:28:25 -0500 | [diff] [blame] | 93 | } |
| 94 | ] |
| 95 | ); |
| 96 | |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 97 | })(angular); |