xref: /openbmc/phosphor-webui/app/overview/controllers/system-overview-controller.js (revision cf86200753abb86347d78e1b2df37f97a36ec5c4)
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', [
1699d199f3SIftekharul Islam            '$scope',
1799d199f3SIftekharul Islam            '$window',
1899d199f3SIftekharul Islam            'APIUtils',
1999d199f3SIftekharul Islam            'dataService',
20428375e8SMichael Davis            '$q',
21*cf862007SAndrew Geissler            function($scope, $window, APIUtils, dataService, $q){
2299d199f3SIftekharul Islam                $scope.dataService = dataService;
23cd789508SIftekharul Islam                $scope.dropdown_selected = false;
2454c22e4fSIftekharul Islam                $scope.tmz = 'EDT';
2554c22e4fSIftekharul Islam                $scope.logs = [];
2654c22e4fSIftekharul Islam                $scope.mac_address = "";
2754c22e4fSIftekharul Islam                $scope.bmc_info = {};
2854c22e4fSIftekharul Islam                $scope.bmc_firmware = "";
2954c22e4fSIftekharul Islam                $scope.server_firmware = "";
3033275839SCamVan Nguyen                $scope.power_consumption = "";
3133275839SCamVan Nguyen                $scope.power_cap = "";
32428375e8SMichael Davis                $scope.loading = false;
3354c22e4fSIftekharul Islam
3454c22e4fSIftekharul Islam                loadOverviewData();
3554c22e4fSIftekharul Islam                function loadOverviewData(){
36428375e8SMichael Davis                    $scope.loading = true;
37428375e8SMichael Davis                    var promises = {
38428375e8SMichael Davis                      logs: APIUtils.getLogs(),
39428375e8SMichael Davis                      firmware: APIUtils.getFirmwares(),
40428375e8SMichael Davis                      led: APIUtils.getLEDState(),
41428375e8SMichael Davis                      ethernet: APIUtils.getBMCEthernetInfo(),
4233275839SCamVan Nguyen                      bmc_info: APIUtils.getBMCInfo(),
4333275839SCamVan Nguyen                      power_consumption: APIUtils.getPowerConsumption(),
4433275839SCamVan Nguyen                      power_cap: APIUtils.getPowerCap(),
45428375e8SMichael Davis                    };
46428375e8SMichael Davis                    $q.all(promises)
47428375e8SMichael Davis                      .then(function(data){
48428375e8SMichael Davis                        $scope.displayLogs(data.logs.data);
49428375e8SMichael Davis                        $scope.displayServerInfo(
50428375e8SMichael Davis                            data.firmware.data,
51428375e8SMichael Davis                            data.firmware.bmcActiveVersion,
52428375e8SMichael Davis                            data.firmware.hostActiveVersion
53428375e8SMichael Davis                        );
54428375e8SMichael Davis                        $scope.displayLEDState(data.led);
55428375e8SMichael Davis                        $scope.displayBMCEthernetInfo(data.ethernet);
56428375e8SMichael Davis                        $scope.displayBMCInfo(data.bmc_info);
5733275839SCamVan Nguyen                        $scope.displayPowerConsumption(data.power_consumption);
5833275839SCamVan Nguyen                        $scope.displayPowerCap(data.power_cap);
59428375e8SMichael Davis                      })
60428375e8SMichael Davis                      .finally(function(){
61428375e8SMichael Davis                        $scope.loading = false;
6254c22e4fSIftekharul Islam                      });
6354c22e4fSIftekharul Islam                }
6454c22e4fSIftekharul Islam                $scope.displayBMCEthernetInfo = function(data){
6554c22e4fSIftekharul Islam                    $scope.mac_address = data.MACAddress;
6654c22e4fSIftekharul Islam                }
6754c22e4fSIftekharul Islam
6854c22e4fSIftekharul Islam                $scope.displayBMCInfo = function(data){
6954c22e4fSIftekharul Islam                    $scope.bmc_info = data;
7054c22e4fSIftekharul Islam                }
7154c22e4fSIftekharul Islam
7254c22e4fSIftekharul Islam                $scope.displayLogs = function(data){
7354c22e4fSIftekharul Islam                    $scope.logs = data.filter(function(log){
7454c22e4fSIftekharul Islam                        return log.severity_flags.high == true;
7554c22e4fSIftekharul Islam                    });
7654c22e4fSIftekharul Islam                }
7754c22e4fSIftekharul Islam
7854c22e4fSIftekharul Islam                $scope.displayServerInfo = function(data, bmcActiveVersion, hostActiveVersion){
7954c22e4fSIftekharul Islam                    $scope.bmc_firmware = bmcActiveVersion;
8054c22e4fSIftekharul Islam                    $scope.server_firmware = hostActiveVersion;
8154c22e4fSIftekharul Islam                }
8254c22e4fSIftekharul Islam
8354c22e4fSIftekharul Islam                $scope.displayLEDState = function(state){
8454c22e4fSIftekharul Islam                    if(state == APIUtils.LED_STATE.on){
8554c22e4fSIftekharul Islam                        dataService.LED_state = APIUtils.LED_STATE_TEXT.on;
8654c22e4fSIftekharul Islam                    }else{
8754c22e4fSIftekharul Islam                        dataService.LED_state = APIUtils.LED_STATE_TEXT.off;
8854c22e4fSIftekharul Islam                    }
8954c22e4fSIftekharul Islam                }
9054c22e4fSIftekharul Islam
9154c22e4fSIftekharul Islam                $scope.toggleLED = function(){
9254c22e4fSIftekharul Islam                    var toggleState = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ?
9354c22e4fSIftekharul Islam                        APIUtils.LED_STATE.off : APIUtils.LED_STATE.on;
9454c22e4fSIftekharul Islam                        dataService.LED_state = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ?
9554c22e4fSIftekharul Islam                        APIUtils.LED_STATE_TEXT.off : APIUtils.LED_STATE_TEXT.on;
9654c22e4fSIftekharul Islam                    APIUtils.setLEDState(toggleState, function(status){
9754c22e4fSIftekharul Islam                    });
9854c22e4fSIftekharul Islam                }
9923217daeSCamVan Nguyen
10033275839SCamVan Nguyen                $scope.displayPowerConsumption = function(data){
10133275839SCamVan Nguyen                    $scope.power_consumption = data;
10233275839SCamVan Nguyen                }
10333275839SCamVan Nguyen
10433275839SCamVan Nguyen                $scope.displayPowerCap = function(data){
10533275839SCamVan Nguyen                    $scope.power_cap = data;
10633275839SCamVan Nguyen                }
10799d199f3SIftekharul Islam            }
10899d199f3SIftekharul Islam        ]
10999d199f3SIftekharul Islam    );
11099d199f3SIftekharul Islam
11199d199f3SIftekharul Islam})(angular);
112