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 '$scope', 17 '$window', 18 'APIUtils', 19 'dataService', 20 '$q', 21 function($scope, $window, APIUtils, dataService, $q){ 22 $scope.dataService = dataService; 23 $scope.dropdown_selected = false; 24 $scope.tmz = 'EDT'; 25 $scope.logs = []; 26 $scope.mac_address = ""; 27 $scope.bmc_info = {}; 28 $scope.server_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 server_info: APIUtils.getServerInfo(), 45 power_consumption: APIUtils.getPowerConsumption(), 46 power_cap: APIUtils.getPowerCap(), 47 }; 48 $q.all(promises) 49 .then(function(data){ 50 $scope.displayLogs(data.logs.data); 51 $scope.displayServerInfo( 52 data.server_info, 53 data.firmware.hostActiveVersion 54 ); 55 $scope.displayLEDState(data.led); 56 $scope.displayBMCEthernetInfo(data.ethernet); 57 $scope.displayBMCInfo( 58 data.bmc_info, 59 data.firmware.bmcActiveVersion 60 ); 61 $scope.displayPowerConsumption(data.power_consumption); 62 $scope.displayPowerCap(data.power_cap); 63 }) 64 .finally(function(){ 65 $scope.loading = false; 66 }); 67 } 68 $scope.displayBMCEthernetInfo = function(data){ 69 $scope.mac_address = data.MACAddress; 70 } 71 72 $scope.displayBMCInfo = function(data, bmcActiveVersion){ 73 $scope.bmc_info = data; 74 $scope.bmc_firmware = bmcActiveVersion; 75 } 76 77 $scope.displayLogs = function(data){ 78 $scope.logs = data.filter(function(log){ 79 return log.severity_flags.high == true; 80 }); 81 } 82 83 $scope.displayServerInfo = function(data, hostActiveVersion){ 84 $scope.server_info = data.data; 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 } 104 105 $scope.displayPowerConsumption = function(data){ 106 $scope.power_consumption = data; 107 } 108 109 $scope.displayPowerCap = function(data){ 110 $scope.power_cap = data; 111 } 112 } 113 ] 114 ); 115 116})(angular); 117