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 1299d199f3SIftekharul Islam angular 1399d199f3SIftekharul Islam .module('app.overview') 1499d199f3SIftekharul Islam .controller('systemOverviewController', [ 1599d199f3SIftekharul Islam '$scope', 1699d199f3SIftekharul Islam '$window', 1799d199f3SIftekharul Islam 'APIUtils', 1899d199f3SIftekharul Islam 'dataService', 19428375e8SMichael Davis '$q', 20cf862007SAndrew Geissler function($scope, $window, APIUtils, dataService, $q) { 2199d199f3SIftekharul Islam $scope.dataService = dataService; 22cd789508SIftekharul Islam $scope.dropdown_selected = false; 2354c22e4fSIftekharul Islam $scope.tmz = 'EDT'; 2454c22e4fSIftekharul Islam $scope.logs = []; 2517708f2aSGunnar Mills $scope.server_info = {}; 26*ba5e3f34SAndrew Geissler $scope.bmc_firmware = ''; 27*ba5e3f34SAndrew Geissler $scope.bmc_time = ''; 28*ba5e3f34SAndrew Geissler $scope.server_firmware = ''; 29*ba5e3f34SAndrew Geissler $scope.power_consumption = ''; 30*ba5e3f34SAndrew Geissler $scope.power_cap = ''; 31fbb63db4SCamVan Nguyen $scope.bmc_ip_addresses = []; 32428375e8SMichael Davis $scope.loading = false; 33e56bb445SGunnar Mills $scope.edit_hostname = false; 3454c22e4fSIftekharul Islam 3554c22e4fSIftekharul Islam loadOverviewData(); 36*ba5e3f34SAndrew Geissler 3754c22e4fSIftekharul Islam function loadOverviewData() { 38428375e8SMichael Davis $scope.loading = true; 3954c22e4fSIftekharul Islam 407db0e9acSCamVan Nguyen var getLogsPromise = 417db0e9acSCamVan Nguyen APIUtils.getLogs().then(function(data) { 427db0e9acSCamVan Nguyen $scope.logs = data.data.filter(function(log) { 4354c22e4fSIftekharul Islam return log.severity_flags.high == true; 4454c22e4fSIftekharul Islam }); 457db0e9acSCamVan Nguyen }, function(error) { 467db0e9acSCamVan Nguyen console.log(JSON.stringify(error)); 47*ba5e3f34SAndrew Geissler }); 4854c22e4fSIftekharul Islam 497db0e9acSCamVan Nguyen var getFirmwaresPromise = 507db0e9acSCamVan Nguyen APIUtils.getFirmwares().then(function(data) { 517db0e9acSCamVan Nguyen $scope.bmc_firmware = data.bmcActiveVersion; 527db0e9acSCamVan Nguyen $scope.server_firmware = data.hostActiveVersion; 537db0e9acSCamVan Nguyen }, function(error) { 547db0e9acSCamVan Nguyen console.log(JSON.stringify(error)); 55*ba5e3f34SAndrew Geissler }); 5654c22e4fSIftekharul Islam 577db0e9acSCamVan Nguyen var getLEDStatePromise = 587db0e9acSCamVan Nguyen APIUtils.getLEDState().then(function(data) { 597db0e9acSCamVan Nguyen if (data == APIUtils.LED_STATE.on) { 6054c22e4fSIftekharul Islam dataService.LED_state = APIUtils.LED_STATE_TEXT.on; 61*ba5e3f34SAndrew Geissler } 62*ba5e3f34SAndrew Geissler else { 6354c22e4fSIftekharul Islam dataService.LED_state = APIUtils.LED_STATE_TEXT.off; 6454c22e4fSIftekharul Islam } 657db0e9acSCamVan Nguyen }, function(error) { 667db0e9acSCamVan Nguyen console.log(JSON.stringify(error)); 67*ba5e3f34SAndrew Geissler }); 687db0e9acSCamVan Nguyen 697db0e9acSCamVan Nguyen var getBMCTimePromise = 707db0e9acSCamVan Nguyen APIUtils.getBMCTime().then(function(data) { 717db0e9acSCamVan Nguyen $scope.bmc_time = data.data.Elapsed / 1000; 727db0e9acSCamVan Nguyen }, function(error) { 737db0e9acSCamVan Nguyen console.log(JSON.stringify(error)); 74*ba5e3f34SAndrew Geissler }); 757db0e9acSCamVan Nguyen 767db0e9acSCamVan Nguyen var getServerInfoPromise = 777db0e9acSCamVan Nguyen APIUtils.getServerInfo().then(function(data) { 787db0e9acSCamVan Nguyen $scope.server_info = data.data; 797db0e9acSCamVan Nguyen }, function(error) { 807db0e9acSCamVan Nguyen console.log(JSON.stringify(error)); 81*ba5e3f34SAndrew Geissler }); 827db0e9acSCamVan Nguyen 837db0e9acSCamVan Nguyen var getPowerConsumptionPromise = 847db0e9acSCamVan Nguyen APIUtils.getPowerConsumption().then(function(data) { 857db0e9acSCamVan Nguyen $scope.power_consumption = data; 867db0e9acSCamVan Nguyen }, function(error) { 877db0e9acSCamVan Nguyen console.log(JSON.stringify(error)); 88*ba5e3f34SAndrew Geissler }); 897db0e9acSCamVan Nguyen 907db0e9acSCamVan Nguyen var getPowerCapPromise = 917db0e9acSCamVan Nguyen APIUtils.getPowerCap().then(function(data) { 927db0e9acSCamVan Nguyen $scope.power_cap = data; 937db0e9acSCamVan Nguyen }, function(error) { 947db0e9acSCamVan Nguyen console.log(JSON.stringify(error)); 95*ba5e3f34SAndrew Geissler }); 967db0e9acSCamVan Nguyen 977db0e9acSCamVan Nguyen var getNetworkInfoPromise = 987db0e9acSCamVan Nguyen APIUtils.getNetworkInfo().then(function(data) { 997db0e9acSCamVan Nguyen // TODO: openbmc/openbmc#3150 Support IPV6 when 1007db0e9acSCamVan Nguyen // officially supported by the backend 1017db0e9acSCamVan Nguyen $scope.bmc_ip_addresses = 1027db0e9acSCamVan Nguyen data.formatted_data.ip_addresses.ipv4; 1037db0e9acSCamVan Nguyen }, function(error) { 1047db0e9acSCamVan Nguyen console.log(JSON.stringify(error)); 105*ba5e3f34SAndrew 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() { 12454c22e4fSIftekharul Islam var toggleState = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ? 12554c22e4fSIftekharul Islam APIUtils.LED_STATE.off : APIUtils.LED_STATE.on; 12654c22e4fSIftekharul Islam dataService.LED_state = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ? 12754c22e4fSIftekharul Islam APIUtils.LED_STATE_TEXT.off : APIUtils.LED_STATE_TEXT.on; 128*ba5e3f34SAndrew Geissler APIUtils.setLEDState(toggleState, function(status) {}); 129*ba5e3f34SAndrew Geissler }; 13023217daeSCamVan Nguyen 131ff2313dbSAndrew Geissler $scope.saveHostname = function(hostname) { 132e56bb445SGunnar Mills $scope.edit_hostname = false; 133ff2313dbSAndrew Geissler $scope.loading = true; 134ff2313dbSAndrew Geissler APIUtils.setHostname(hostname).then(function(data) { 135ff2313dbSAndrew Geissler APIUtils.getNetworkInfo().then(function(data) { 136ff2313dbSAndrew Geissler dataService.setNetworkInfo(data); 137ff2313dbSAndrew Geissler }); 138ff2313dbSAndrew Geissler }, 139ff2313dbSAndrew Geissler function(error) { 140ff2313dbSAndrew Geissler console.log(error); 141ff2313dbSAndrew Geissler }); 142ff2313dbSAndrew Geissler $scope.loading = false; 143*ba5e3f34SAndrew Geissler }; 144ff2313dbSAndrew Geissler } 145*ba5e3f34SAndrew Geissler ]); 14699d199f3SIftekharul Islam 14799d199f3SIftekharul Islam})(angular); 148