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.loading = false; 32 33 loadOverviewData(); 34 function loadOverviewData(){ 35 $scope.loading = true; 36 var promises = { 37 logs: APIUtils.getLogs(), 38 firmware: APIUtils.getFirmwares(), 39 led: APIUtils.getLEDState(), 40 ethernet: APIUtils.getBMCEthernetInfo(), 41 bmc_info: APIUtils.getBMCInfo() 42 }; 43 $q.all(promises) 44 .then(function(data){ 45 $scope.displayLogs(data.logs.data); 46 $scope.displayServerInfo( 47 data.firmware.data, 48 data.firmware.bmcActiveVersion, 49 data.firmware.hostActiveVersion 50 ); 51 $scope.displayLEDState(data.led); 52 $scope.displayBMCEthernetInfo(data.ethernet); 53 $scope.displayBMCInfo(data.bmc_info); 54 }) 55 .finally(function(){ 56 $scope.loading = false; 57 }); 58 } 59 $scope.displayBMCEthernetInfo = function(data){ 60 $scope.mac_address = data.MACAddress; 61 } 62 63 $scope.displayBMCInfo = function(data){ 64 $scope.bmc_info = data; 65 } 66 67 $scope.displayLogs = function(data){ 68 $scope.logs = data.filter(function(log){ 69 return log.severity_flags.high == true; 70 }); 71 } 72 73 $scope.displayServerInfo = function(data, bmcActiveVersion, hostActiveVersion){ 74 $scope.bmc_firmware = bmcActiveVersion; 75 $scope.server_firmware = hostActiveVersion; 76 } 77 78 $scope.displayLEDState = function(state){ 79 if(state == APIUtils.LED_STATE.on){ 80 dataService.LED_state = APIUtils.LED_STATE_TEXT.on; 81 }else{ 82 dataService.LED_state = APIUtils.LED_STATE_TEXT.off; 83 } 84 } 85 86 $scope.toggleLED = function(){ 87 var toggleState = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ? 88 APIUtils.LED_STATE.off : APIUtils.LED_STATE.on; 89 dataService.LED_state = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ? 90 APIUtils.LED_STATE_TEXT.off : APIUtils.LED_STATE_TEXT.on; 91 APIUtils.setLEDState(toggleState, function(status){ 92 }); 93 } 94 95 var refreshDataListener = $rootScope.$on('refresh-data', function(event, args) { 96 loadOverviewData(); 97 }); 98 99 $scope.$on('$destroy', function() { 100 refreshDataListener(); 101 }); 102 } 103 ] 104 ); 105 106})(angular); 107