199d199f3SIftekharul Islam/** 2cd789508SIftekharul Islam * Controller for systemOverview 399d199f3SIftekharul Islam * 499d199f3SIftekharul Islam * @module app/overview 599d199f3SIftekharul Islam * @exports systemOverviewController 699d199f3SIftekharul Islam * @name systemOverviewController 799d199f3SIftekharul Islam */ 899d199f3SIftekharul Islam 999d199f3SIftekharul Islamwindow.angular && (function(angular) { 1099d199f3SIftekharul Islam 'use strict'; 1199d199f3SIftekharul Islam 12d27bb135SAndrew Geissler angular.module('app.overview').controller('systemOverviewController', [ 13d27bb135SAndrew Geissler '$scope', '$window', 'APIUtils', 'dataService', '$q', 14cf862007SAndrew Geissler function($scope, $window, APIUtils, dataService, $q) { 1599d199f3SIftekharul Islam $scope.dataService = dataService; 16cd789508SIftekharul Islam $scope.dropdown_selected = false; 1754c22e4fSIftekharul Islam $scope.tmz = 'EDT'; 1854c22e4fSIftekharul Islam $scope.logs = []; 1917708f2aSGunnar Mills $scope.server_info = {}; 20ba5e3f34SAndrew Geissler $scope.bmc_firmware = ''; 21ba5e3f34SAndrew Geissler $scope.bmc_time = ''; 22ba5e3f34SAndrew Geissler $scope.server_firmware = ''; 23ba5e3f34SAndrew Geissler $scope.power_consumption = ''; 24ba5e3f34SAndrew Geissler $scope.power_cap = ''; 25fbb63db4SCamVan Nguyen $scope.bmc_ip_addresses = []; 26428375e8SMichael Davis $scope.loading = false; 27e56bb445SGunnar Mills $scope.edit_hostname = false; 2854c22e4fSIftekharul Islam 2954c22e4fSIftekharul Islam loadOverviewData(); 30ba5e3f34SAndrew Geissler 3154c22e4fSIftekharul Islam function loadOverviewData() { 32428375e8SMichael Davis $scope.loading = true; 3354c22e4fSIftekharul Islam 34d27bb135SAndrew Geissler var getLogsPromise = APIUtils.getLogs().then( 35d27bb135SAndrew Geissler function(data) { 367db0e9acSCamVan Nguyen $scope.logs = data.data.filter(function(log) { 3754c22e4fSIftekharul Islam return log.severity_flags.high == true; 3854c22e4fSIftekharul Islam }); 39d27bb135SAndrew Geissler }, 40d27bb135SAndrew Geissler function(error) { 417db0e9acSCamVan Nguyen console.log(JSON.stringify(error)); 42ba5e3f34SAndrew Geissler }); 4354c22e4fSIftekharul Islam 44d27bb135SAndrew Geissler var getFirmwaresPromise = APIUtils.getFirmwares().then( 45d27bb135SAndrew Geissler function(data) { 467db0e9acSCamVan Nguyen $scope.bmc_firmware = data.bmcActiveVersion; 477db0e9acSCamVan Nguyen $scope.server_firmware = data.hostActiveVersion; 48d27bb135SAndrew Geissler }, 49d27bb135SAndrew Geissler function(error) { 507db0e9acSCamVan Nguyen console.log(JSON.stringify(error)); 51ba5e3f34SAndrew Geissler }); 5254c22e4fSIftekharul Islam 53d27bb135SAndrew Geissler var getLEDStatePromise = APIUtils.getLEDState().then( 54d27bb135SAndrew Geissler function(data) { 557db0e9acSCamVan Nguyen if (data == APIUtils.LED_STATE.on) { 5654c22e4fSIftekharul Islam dataService.LED_state = APIUtils.LED_STATE_TEXT.on; 57d27bb135SAndrew Geissler } else { 5854c22e4fSIftekharul Islam dataService.LED_state = APIUtils.LED_STATE_TEXT.off; 5954c22e4fSIftekharul Islam } 60d27bb135SAndrew Geissler }, 61d27bb135SAndrew Geissler function(error) { 627db0e9acSCamVan Nguyen console.log(JSON.stringify(error)); 63ba5e3f34SAndrew Geissler }); 647db0e9acSCamVan Nguyen 65d27bb135SAndrew Geissler var getBMCTimePromise = APIUtils.getBMCTime().then( 66d27bb135SAndrew Geissler function(data) { 677db0e9acSCamVan Nguyen $scope.bmc_time = data.data.Elapsed / 1000; 68d27bb135SAndrew Geissler }, 69d27bb135SAndrew Geissler function(error) { 707db0e9acSCamVan Nguyen console.log(JSON.stringify(error)); 71ba5e3f34SAndrew Geissler }); 727db0e9acSCamVan Nguyen 73d27bb135SAndrew Geissler var getServerInfoPromise = APIUtils.getServerInfo().then( 74d27bb135SAndrew Geissler function(data) { 757db0e9acSCamVan Nguyen $scope.server_info = data.data; 76d27bb135SAndrew Geissler }, 77d27bb135SAndrew Geissler function(error) { 787db0e9acSCamVan Nguyen console.log(JSON.stringify(error)); 79ba5e3f34SAndrew Geissler }); 807db0e9acSCamVan Nguyen 81d27bb135SAndrew Geissler var getPowerConsumptionPromise = APIUtils.getPowerConsumption().then( 82d27bb135SAndrew Geissler function(data) { 837db0e9acSCamVan Nguyen $scope.power_consumption = data; 84d27bb135SAndrew Geissler }, 85d27bb135SAndrew Geissler function(error) { 867db0e9acSCamVan Nguyen console.log(JSON.stringify(error)); 87ba5e3f34SAndrew Geissler }); 887db0e9acSCamVan Nguyen 89d27bb135SAndrew Geissler var getPowerCapPromise = APIUtils.getPowerCap().then( 90d27bb135SAndrew Geissler function(data) { 917db0e9acSCamVan Nguyen $scope.power_cap = data; 92d27bb135SAndrew Geissler }, 93d27bb135SAndrew Geissler function(error) { 947db0e9acSCamVan Nguyen console.log(JSON.stringify(error)); 95ba5e3f34SAndrew Geissler }); 967db0e9acSCamVan Nguyen 97d27bb135SAndrew Geissler var getNetworkInfoPromise = APIUtils.getNetworkInfo().then( 98d27bb135SAndrew Geissler function(data) { 997db0e9acSCamVan Nguyen // TODO: openbmc/openbmc#3150 Support IPV6 when 1007db0e9acSCamVan Nguyen // officially supported by the backend 101d27bb135SAndrew Geissler $scope.bmc_ip_addresses = data.formatted_data.ip_addresses.ipv4; 102d27bb135SAndrew Geissler }, 103d27bb135SAndrew Geissler function(error) { 1047db0e9acSCamVan Nguyen console.log(JSON.stringify(error)); 105ba5e3f34SAndrew Geissler }); 1067db0e9acSCamVan Nguyen 1077db0e9acSCamVan Nguyen var promises = [ 1087db0e9acSCamVan Nguyen getLogsPromise, 1097db0e9acSCamVan Nguyen getFirmwaresPromise, 1107db0e9acSCamVan Nguyen getLEDStatePromise, 1117db0e9acSCamVan Nguyen getBMCTimePromise, 1127db0e9acSCamVan Nguyen getServerInfoPromise, 1137db0e9acSCamVan Nguyen getPowerConsumptionPromise, 1147db0e9acSCamVan Nguyen getPowerCapPromise, 1157db0e9acSCamVan Nguyen getNetworkInfoPromise, 1167db0e9acSCamVan Nguyen ]; 1177db0e9acSCamVan Nguyen 1187db0e9acSCamVan Nguyen $q.all(promises).finally(function() { 1197db0e9acSCamVan Nguyen $scope.loading = false; 1207db0e9acSCamVan Nguyen }); 12154c22e4fSIftekharul Islam } 12254c22e4fSIftekharul Islam 12354c22e4fSIftekharul Islam $scope.toggleLED = function() { 124d27bb135SAndrew Geissler var toggleState = 125d27bb135SAndrew Geissler (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ? 126d27bb135SAndrew Geissler APIUtils.LED_STATE.off : 127d27bb135SAndrew Geissler APIUtils.LED_STATE.on; 128d27bb135SAndrew Geissler dataService.LED_state = 129d27bb135SAndrew Geissler (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ? 130d27bb135SAndrew Geissler APIUtils.LED_STATE_TEXT.off : 131d27bb135SAndrew Geissler APIUtils.LED_STATE_TEXT.on; 132ba5e3f34SAndrew Geissler APIUtils.setLEDState(toggleState, function(status) {}); 133ba5e3f34SAndrew Geissler }; 13423217daeSCamVan Nguyen 135ff2313dbSAndrew Geissler $scope.saveHostname = function(hostname) { 136e56bb445SGunnar Mills $scope.edit_hostname = false; 137ff2313dbSAndrew Geissler $scope.loading = true; 138d27bb135SAndrew Geissler APIUtils.setHostname(hostname).then( 139d27bb135SAndrew Geissler function(data) { 140ff2313dbSAndrew Geissler APIUtils.getNetworkInfo().then(function(data) { 141ff2313dbSAndrew Geissler dataService.setNetworkInfo(data); 142ff2313dbSAndrew Geissler }); 143ff2313dbSAndrew Geissler }, 144ff2313dbSAndrew Geissler function(error) { 145ff2313dbSAndrew Geissler console.log(error); 146ff2313dbSAndrew Geissler }); 147ff2313dbSAndrew Geissler $scope.loading = false; 148ba5e3f34SAndrew Geissler }; 149*845acdc5SMatt Spinler 150*845acdc5SMatt Spinler $scope.getEventLogTitle = function(event) { 151*845acdc5SMatt Spinler var title = event.type; 152*845acdc5SMatt Spinler if ((event.eventID != 'None') && (event.description != 'None')) { 153*845acdc5SMatt Spinler title = event.eventID + ': ' + event.description; 154*845acdc5SMatt Spinler } 155*845acdc5SMatt Spinler return title; 156*845acdc5SMatt Spinler }; 157ff2313dbSAndrew Geissler } 158ba5e3f34SAndrew Geissler ]); 15999d199f3SIftekharul Islam 16099d199f3SIftekharul Islam})(angular); 161