1/** 2 * Controller for systemOverview 3 * 4 * @module app/overview 5 * @exports systemOverviewController 6 * @name systemOverviewController 7 * @version 0.1.0 8 */ 9 10window.angular && (function (angular) { 11 'use strict'; 12 13 angular 14 .module('app.overview') 15 .controller('systemOverviewController', [ 16 '$rootScope', 17 '$scope', 18 '$window', 19 'APIUtils', 20 'dataService', 21 '$q', 22 function($rootScope, $scope, $window, APIUtils, dataService, $q){ 23 $scope.dataService = dataService; 24 $scope.dropdown_selected = false; 25 $scope.tmz = 'EDT'; 26 $scope.logs = []; 27 $scope.mac_address = ""; 28 $scope.bmc_info = {}; 29 $scope.bmc_firmware = ""; 30 $scope.server_firmware = ""; 31 $scope.power_consumption = ""; 32 $scope.power_cap = ""; 33 $scope.loading = false; 34 35 loadOverviewData(); 36 function loadOverviewData(){ 37 $scope.loading = true; 38 var promises = { 39 logs: APIUtils.getLogs(), 40 firmware: APIUtils.getFirmwares(), 41 led: APIUtils.getLEDState(), 42 ethernet: APIUtils.getBMCEthernetInfo(), 43 bmc_info: APIUtils.getBMCInfo(), 44 power_consumption: APIUtils.getPowerConsumption(), 45 power_cap: APIUtils.getPowerCap(), 46 }; 47 $q.all(promises) 48 .then(function(data){ 49 $scope.displayLogs(data.logs.data); 50 $scope.displayServerInfo( 51 data.firmware.data, 52 data.firmware.bmcActiveVersion, 53 data.firmware.hostActiveVersion 54 ); 55 $scope.displayLEDState(data.led); 56 $scope.displayBMCEthernetInfo(data.ethernet); 57 $scope.displayBMCInfo(data.bmc_info); 58 $scope.displayPowerConsumption(data.power_consumption); 59 $scope.displayPowerCap(data.power_cap); 60 }) 61 .finally(function(){ 62 $scope.loading = false; 63 }); 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 } 100 101 $scope.displayPowerConsumption = function(data){ 102 $scope.power_consumption = data; 103 } 104 105 $scope.displayPowerCap = function(data){ 106 $scope.power_cap = data; 107 } 108 109 var refreshDataListener = $rootScope.$on('refresh-data', function(event, args) { 110 loadOverviewData(); 111 }); 112 113 $scope.$on('$destroy', function() { 114 refreshDataListener(); 115 }); 116 } 117 ] 118 ); 119 120})(angular); 121