1/** 2 * Controller for systemOverview 3 * 4 * @module app/overview 5 * @exports systemOverviewController 6 * @name systemOverviewController 7 */ 8 9window.angular && (function (angular) { 10 'use strict'; 11 12 angular 13 .module('app.overview') 14 .controller('systemOverviewController', [ 15 '$scope', 16 '$window', 17 'APIUtils', 18 'dataService', 19 '$q', 20 function($scope, $window, APIUtils, dataService, $q){ 21 $scope.dataService = dataService; 22 $scope.dropdown_selected = false; 23 $scope.tmz = 'EDT'; 24 $scope.logs = []; 25 $scope.mac_address = ""; 26 $scope.bmc_info = {}; 27 $scope.server_info = {}; 28 $scope.bmc_firmware = ""; 29 $scope.bmc_time = ""; 30 $scope.server_firmware = ""; 31 $scope.power_consumption = ""; 32 $scope.power_cap = ""; 33 $scope.bmc_ip_addresses = []; 34 $scope.loading = false; 35 $scope.edit_server_name = false; 36 37 loadOverviewData(); 38 function loadOverviewData(){ 39 $scope.loading = true; 40 var promises = { 41 logs: APIUtils.getLogs(), 42 firmware: APIUtils.getFirmwares(), 43 led: APIUtils.getLEDState(), 44 ethernet: APIUtils.getBMCEthernetInfo(), 45 bmc_info: APIUtils.getBMCInfo(), 46 bmc_time: APIUtils.getBMCTime(), 47 server_info: APIUtils.getServerInfo(), 48 power_consumption: APIUtils.getPowerConsumption(), 49 power_cap: APIUtils.getPowerCap(), 50 network_info: APIUtils.getNetworkInfo(), 51 }; 52 $q.all(promises) 53 .then(function(data){ 54 $scope.displayLogs(data.logs.data); 55 $scope.displayServerInfo( 56 data.server_info, 57 data.firmware.hostActiveVersion 58 ); 59 $scope.displayLEDState(data.led); 60 $scope.displayBMCEthernetInfo(data.ethernet); 61 $scope.displayBMCInfo( 62 data.bmc_info, 63 data.firmware.bmcActiveVersion 64 ); 65 $scope.displayBMCTime(data.bmc_time); 66 $scope.displayPowerConsumption(data.power_consumption); 67 $scope.displayPowerCap(data.power_cap); 68 $scope.displayNetworkInfo(data.network_info); 69 }) 70 .finally(function(){ 71 $scope.loading = false; 72 }); 73 } 74 $scope.displayBMCEthernetInfo = function(data){ 75 $scope.mac_address = data.MACAddress; 76 } 77 78 $scope.displayBMCInfo = function(data, bmcActiveVersion){ 79 $scope.bmc_info = data; 80 $scope.bmc_firmware = bmcActiveVersion; 81 } 82 83 $scope.displayBMCTime = function(data){ 84 $scope.bmc_time = data.data.Elapsed / 1000; 85 } 86 87 $scope.displayLogs = function(data){ 88 $scope.logs = data.filter(function(log){ 89 return log.severity_flags.high == true; 90 }); 91 } 92 93 $scope.displayServerInfo = function(data, hostActiveVersion){ 94 $scope.server_info = data.data; 95 $scope.server_firmware = hostActiveVersion; 96 } 97 98 $scope.displayLEDState = function(state){ 99 if(state == APIUtils.LED_STATE.on){ 100 dataService.LED_state = APIUtils.LED_STATE_TEXT.on; 101 }else{ 102 dataService.LED_state = APIUtils.LED_STATE_TEXT.off; 103 } 104 } 105 106 $scope.toggleLED = function(){ 107 var toggleState = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ? 108 APIUtils.LED_STATE.off : APIUtils.LED_STATE.on; 109 dataService.LED_state = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ? 110 APIUtils.LED_STATE_TEXT.off : APIUtils.LED_STATE_TEXT.on; 111 APIUtils.setLEDState(toggleState, function(status){ 112 }); 113 } 114 115 $scope.displayPowerConsumption = function(data){ 116 $scope.power_consumption = data; 117 } 118 119 $scope.displayPowerCap = function(data){ 120 $scope.power_cap = data; 121 } 122 123 $scope.displayNetworkInfo = function(data){ 124 // TODO: openbmc/openbmc#3150 Support IPV6 when officially 125 // supported by the backend 126 $scope.bmc_ip_addresses = 127 data.formatted_data.ip_addresses.ipv4; 128 } 129 130 $scope.saveHostname = function(hostname) { 131 $scope.edit_server_name = false; 132 $scope.loading = true; 133 APIUtils.setHostname(hostname).then(function(data){ 134 APIUtils.getNetworkInfo().then(function(data){ 135 dataService.setNetworkInfo(data); 136 }); 137 }, 138 function(error){ 139 console.log(error); 140 }); 141 $scope.loading = false; 142 } 143 } 144 ] 145 ); 146 147})(angular); 148