xref: /openbmc/phosphor-webui/app/overview/controllers/system-overview-controller.js (revision 3327583964a2b38bf2fd75f75d1d1f148f82f006)
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', [
1623217daeSCamVan Nguyen            '$rootScope',
1799d199f3SIftekharul Islam            '$scope',
1899d199f3SIftekharul Islam            '$window',
1999d199f3SIftekharul Islam            'APIUtils',
2099d199f3SIftekharul Islam            'dataService',
21428375e8SMichael Davis            '$q',
2223217daeSCamVan 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 = "";
31*33275839SCamVan Nguyen                $scope.power_consumption = "";
32*33275839SCamVan Nguyen                $scope.power_cap = "";
33428375e8SMichael Davis                $scope.loading = false;
3454c22e4fSIftekharul Islam
3554c22e4fSIftekharul Islam                loadOverviewData();
3654c22e4fSIftekharul Islam                function loadOverviewData(){
37428375e8SMichael Davis                    $scope.loading = true;
38428375e8SMichael Davis                    var promises = {
39428375e8SMichael Davis                      logs: APIUtils.getLogs(),
40428375e8SMichael Davis                      firmware: APIUtils.getFirmwares(),
41428375e8SMichael Davis                      led: APIUtils.getLEDState(),
42428375e8SMichael Davis                      ethernet: APIUtils.getBMCEthernetInfo(),
43*33275839SCamVan Nguyen                      bmc_info: APIUtils.getBMCInfo(),
44*33275839SCamVan Nguyen                      power_consumption: APIUtils.getPowerConsumption(),
45*33275839SCamVan Nguyen                      power_cap: APIUtils.getPowerCap(),
46428375e8SMichael Davis                    };
47428375e8SMichael Davis                    $q.all(promises)
48428375e8SMichael Davis                      .then(function(data){
49428375e8SMichael Davis                        $scope.displayLogs(data.logs.data);
50428375e8SMichael Davis                        $scope.displayServerInfo(
51428375e8SMichael Davis                            data.firmware.data,
52428375e8SMichael Davis                            data.firmware.bmcActiveVersion,
53428375e8SMichael Davis                            data.firmware.hostActiveVersion
54428375e8SMichael Davis                        );
55428375e8SMichael Davis                        $scope.displayLEDState(data.led);
56428375e8SMichael Davis                        $scope.displayBMCEthernetInfo(data.ethernet);
57428375e8SMichael Davis                        $scope.displayBMCInfo(data.bmc_info);
58*33275839SCamVan Nguyen                        $scope.displayPowerConsumption(data.power_consumption);
59*33275839SCamVan Nguyen                        $scope.displayPowerCap(data.power_cap);
60428375e8SMichael Davis                      })
61428375e8SMichael Davis                      .finally(function(){
62428375e8SMichael Davis                        $scope.loading = false;
6354c22e4fSIftekharul Islam                      });
6454c22e4fSIftekharul Islam                }
6554c22e4fSIftekharul Islam                $scope.displayBMCEthernetInfo = function(data){
6654c22e4fSIftekharul Islam                    $scope.mac_address = data.MACAddress;
6754c22e4fSIftekharul Islam                }
6854c22e4fSIftekharul Islam
6954c22e4fSIftekharul Islam                $scope.displayBMCInfo = function(data){
7054c22e4fSIftekharul Islam                    $scope.bmc_info = data;
7154c22e4fSIftekharul Islam                }
7254c22e4fSIftekharul Islam
7354c22e4fSIftekharul Islam                $scope.displayLogs = function(data){
7454c22e4fSIftekharul Islam                    $scope.logs = data.filter(function(log){
7554c22e4fSIftekharul Islam                        return log.severity_flags.high == true;
7654c22e4fSIftekharul Islam                    });
7754c22e4fSIftekharul Islam                }
7854c22e4fSIftekharul Islam
7954c22e4fSIftekharul Islam                $scope.displayServerInfo = function(data, bmcActiveVersion, hostActiveVersion){
8054c22e4fSIftekharul Islam                    $scope.bmc_firmware = bmcActiveVersion;
8154c22e4fSIftekharul Islam                    $scope.server_firmware = hostActiveVersion;
8254c22e4fSIftekharul Islam                }
8354c22e4fSIftekharul Islam
8454c22e4fSIftekharul Islam                $scope.displayLEDState = function(state){
8554c22e4fSIftekharul Islam                    if(state == APIUtils.LED_STATE.on){
8654c22e4fSIftekharul Islam                        dataService.LED_state = APIUtils.LED_STATE_TEXT.on;
8754c22e4fSIftekharul Islam                    }else{
8854c22e4fSIftekharul Islam                        dataService.LED_state = APIUtils.LED_STATE_TEXT.off;
8954c22e4fSIftekharul Islam                    }
9054c22e4fSIftekharul Islam                }
9154c22e4fSIftekharul Islam
9254c22e4fSIftekharul Islam                $scope.toggleLED = function(){
9354c22e4fSIftekharul Islam                    var toggleState = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ?
9454c22e4fSIftekharul Islam                        APIUtils.LED_STATE.off : APIUtils.LED_STATE.on;
9554c22e4fSIftekharul Islam                        dataService.LED_state = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ?
9654c22e4fSIftekharul Islam                        APIUtils.LED_STATE_TEXT.off : APIUtils.LED_STATE_TEXT.on;
9754c22e4fSIftekharul Islam                    APIUtils.setLEDState(toggleState, function(status){
9854c22e4fSIftekharul Islam                    });
9954c22e4fSIftekharul Islam                }
10023217daeSCamVan Nguyen
101*33275839SCamVan Nguyen                $scope.displayPowerConsumption = function(data){
102*33275839SCamVan Nguyen                    $scope.power_consumption = data;
103*33275839SCamVan Nguyen                }
104*33275839SCamVan Nguyen
105*33275839SCamVan Nguyen                $scope.displayPowerCap = function(data){
106*33275839SCamVan Nguyen                    $scope.power_cap = data;
107*33275839SCamVan Nguyen                }
108*33275839SCamVan Nguyen
10923217daeSCamVan Nguyen                var refreshDataListener = $rootScope.$on('refresh-data', function(event, args) {
11023217daeSCamVan Nguyen                    loadOverviewData();
11123217daeSCamVan Nguyen                });
11223217daeSCamVan Nguyen
11323217daeSCamVan Nguyen                $scope.$on('$destroy', function() {
11423217daeSCamVan Nguyen                    refreshDataListener();
11523217daeSCamVan Nguyen                });
11699d199f3SIftekharul Islam            }
11799d199f3SIftekharul Islam        ]
11899d199f3SIftekharul Islam    );
11999d199f3SIftekharul Islam
12099d199f3SIftekharul Islam})(angular);
121