199d199f3SIftekharul Islam/** 2cd789508SIftekharul Islam * Controller for systemOverview 399d199f3SIftekharul Islam * 499d199f3SIftekharul Islam * @module app/overview 599d199f3SIftekharul Islam * @exports systemOverviewController 699d199f3SIftekharul Islam * @name systemOverviewController 799d199f3SIftekharul Islam * @version 0.1.0 899d199f3SIftekharul Islam */ 999d199f3SIftekharul Islam 1099d199f3SIftekharul Islamwindow.angular && (function (angular) { 1199d199f3SIftekharul Islam 'use strict'; 1299d199f3SIftekharul Islam 1399d199f3SIftekharul Islam angular 1499d199f3SIftekharul Islam .module('app.overview') 1599d199f3SIftekharul Islam .controller('systemOverviewController', [ 16*23217daeSCamVan Nguyen '$rootScope', 1799d199f3SIftekharul Islam '$scope', 1899d199f3SIftekharul Islam '$window', 1999d199f3SIftekharul Islam 'APIUtils', 2099d199f3SIftekharul Islam 'dataService', 21428375e8SMichael Davis '$q', 22*23217daeSCamVan Nguyen function($rootScope, $scope, $window, APIUtils, dataService, $q){ 2399d199f3SIftekharul Islam $scope.dataService = dataService; 24cd789508SIftekharul Islam $scope.dropdown_selected = false; 2554c22e4fSIftekharul Islam $scope.tmz = 'EDT'; 2654c22e4fSIftekharul Islam $scope.logs = []; 2754c22e4fSIftekharul Islam $scope.mac_address = ""; 2854c22e4fSIftekharul Islam $scope.bmc_info = {}; 2954c22e4fSIftekharul Islam $scope.bmc_firmware = ""; 3054c22e4fSIftekharul Islam $scope.server_firmware = ""; 31428375e8SMichael Davis $scope.loading = false; 3254c22e4fSIftekharul Islam 3354c22e4fSIftekharul Islam loadOverviewData(); 3454c22e4fSIftekharul Islam function loadOverviewData(){ 35428375e8SMichael Davis $scope.loading = true; 36428375e8SMichael Davis var promises = { 37428375e8SMichael Davis logs: APIUtils.getLogs(), 38428375e8SMichael Davis firmware: APIUtils.getFirmwares(), 39428375e8SMichael Davis led: APIUtils.getLEDState(), 40428375e8SMichael Davis ethernet: APIUtils.getBMCEthernetInfo(), 41428375e8SMichael Davis bmc_info: APIUtils.getBMCInfo() 42428375e8SMichael Davis }; 43428375e8SMichael Davis $q.all(promises) 44428375e8SMichael Davis .then(function(data){ 45428375e8SMichael Davis $scope.displayLogs(data.logs.data); 46428375e8SMichael Davis $scope.displayServerInfo( 47428375e8SMichael Davis data.firmware.data, 48428375e8SMichael Davis data.firmware.bmcActiveVersion, 49428375e8SMichael Davis data.firmware.hostActiveVersion 50428375e8SMichael Davis ); 51428375e8SMichael Davis $scope.displayLEDState(data.led); 52428375e8SMichael Davis $scope.displayBMCEthernetInfo(data.ethernet); 53428375e8SMichael Davis $scope.displayBMCInfo(data.bmc_info); 54428375e8SMichael Davis }) 55428375e8SMichael Davis .finally(function(){ 56428375e8SMichael Davis $scope.loading = false; 5754c22e4fSIftekharul Islam }); 5854c22e4fSIftekharul Islam } 5954c22e4fSIftekharul Islam $scope.displayBMCEthernetInfo = function(data){ 6054c22e4fSIftekharul Islam $scope.mac_address = data.MACAddress; 6154c22e4fSIftekharul Islam } 6254c22e4fSIftekharul Islam 6354c22e4fSIftekharul Islam $scope.displayBMCInfo = function(data){ 6454c22e4fSIftekharul Islam $scope.bmc_info = data; 6554c22e4fSIftekharul Islam } 6654c22e4fSIftekharul Islam 6754c22e4fSIftekharul Islam $scope.displayLogs = function(data){ 6854c22e4fSIftekharul Islam $scope.logs = data.filter(function(log){ 6954c22e4fSIftekharul Islam return log.severity_flags.high == true; 7054c22e4fSIftekharul Islam }); 7154c22e4fSIftekharul Islam } 7254c22e4fSIftekharul Islam 7354c22e4fSIftekharul Islam $scope.displayServerInfo = function(data, bmcActiveVersion, hostActiveVersion){ 7454c22e4fSIftekharul Islam $scope.bmc_firmware = bmcActiveVersion; 7554c22e4fSIftekharul Islam $scope.server_firmware = hostActiveVersion; 7654c22e4fSIftekharul Islam } 7754c22e4fSIftekharul Islam 7854c22e4fSIftekharul Islam $scope.displayLEDState = function(state){ 7954c22e4fSIftekharul Islam if(state == APIUtils.LED_STATE.on){ 8054c22e4fSIftekharul Islam dataService.LED_state = APIUtils.LED_STATE_TEXT.on; 8154c22e4fSIftekharul Islam }else{ 8254c22e4fSIftekharul Islam dataService.LED_state = APIUtils.LED_STATE_TEXT.off; 8354c22e4fSIftekharul Islam } 8454c22e4fSIftekharul Islam } 8554c22e4fSIftekharul Islam 8654c22e4fSIftekharul Islam $scope.toggleLED = function(){ 8754c22e4fSIftekharul Islam var toggleState = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ? 8854c22e4fSIftekharul Islam APIUtils.LED_STATE.off : APIUtils.LED_STATE.on; 8954c22e4fSIftekharul Islam dataService.LED_state = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ? 9054c22e4fSIftekharul Islam APIUtils.LED_STATE_TEXT.off : APIUtils.LED_STATE_TEXT.on; 9154c22e4fSIftekharul Islam APIUtils.setLEDState(toggleState, function(status){ 9254c22e4fSIftekharul Islam }); 9354c22e4fSIftekharul Islam } 94*23217daeSCamVan Nguyen 95*23217daeSCamVan Nguyen var refreshDataListener = $rootScope.$on('refresh-data', function(event, args) { 96*23217daeSCamVan Nguyen loadOverviewData(); 97*23217daeSCamVan Nguyen }); 98*23217daeSCamVan Nguyen 99*23217daeSCamVan Nguyen $scope.$on('$destroy', function() { 100*23217daeSCamVan Nguyen refreshDataListener(); 101*23217daeSCamVan Nguyen }); 10299d199f3SIftekharul Islam } 10399d199f3SIftekharul Islam ] 10499d199f3SIftekharul Islam ); 10599d199f3SIftekharul Islam 10699d199f3SIftekharul Islam})(angular); 107