xref: /openbmc/phosphor-webui/app/overview/controllers/system-overview-controller.js (revision fbb63db499eadba214d368977b08af6ee9330f7f)
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 = [];
2554c22e4fSIftekharul Islam                $scope.mac_address = "";
2654c22e4fSIftekharul Islam                $scope.bmc_info = {};
2717708f2aSGunnar Mills                $scope.server_info = {};
2854c22e4fSIftekharul Islam                $scope.bmc_firmware = "";
29ed96f8bbSGunnar Mills                $scope.bmc_time = "";
3054c22e4fSIftekharul Islam                $scope.server_firmware = "";
3133275839SCamVan Nguyen                $scope.power_consumption = "";
3233275839SCamVan Nguyen                $scope.power_cap = "";
33*fbb63db4SCamVan Nguyen                $scope.bmc_ip_addresses = [];
34428375e8SMichael Davis                $scope.loading = false;
3554c22e4fSIftekharul Islam
3654c22e4fSIftekharul Islam                loadOverviewData();
3754c22e4fSIftekharul Islam                function loadOverviewData(){
38428375e8SMichael Davis                    $scope.loading = true;
39428375e8SMichael Davis                    var promises = {
40428375e8SMichael Davis                      logs: APIUtils.getLogs(),
41428375e8SMichael Davis                      firmware: APIUtils.getFirmwares(),
42428375e8SMichael Davis                      led: APIUtils.getLEDState(),
43428375e8SMichael Davis                      ethernet: APIUtils.getBMCEthernetInfo(),
4433275839SCamVan Nguyen                      bmc_info: APIUtils.getBMCInfo(),
45ed96f8bbSGunnar Mills                      bmc_time: APIUtils.getBMCTime(),
4617708f2aSGunnar Mills                      server_info: APIUtils.getServerInfo(),
4733275839SCamVan Nguyen                      power_consumption: APIUtils.getPowerConsumption(),
4833275839SCamVan Nguyen                      power_cap: APIUtils.getPowerCap(),
49*fbb63db4SCamVan Nguyen                      network_info: APIUtils.getNetworkInfo(),
50428375e8SMichael Davis                    };
51428375e8SMichael Davis                    $q.all(promises)
52428375e8SMichael Davis                      .then(function(data){
53428375e8SMichael Davis                        $scope.displayLogs(data.logs.data);
54428375e8SMichael Davis                        $scope.displayServerInfo(
5517708f2aSGunnar Mills                            data.server_info,
56428375e8SMichael Davis                            data.firmware.hostActiveVersion
57428375e8SMichael Davis                        );
58428375e8SMichael Davis                        $scope.displayLEDState(data.led);
59428375e8SMichael Davis                        $scope.displayBMCEthernetInfo(data.ethernet);
605dbcfb17SGunnar Mills                        $scope.displayBMCInfo(
615dbcfb17SGunnar Mills                            data.bmc_info,
625dbcfb17SGunnar Mills                            data.firmware.bmcActiveVersion
635dbcfb17SGunnar Mills                        );
64ed96f8bbSGunnar Mills                        $scope.displayBMCTime(data.bmc_time);
6533275839SCamVan Nguyen                        $scope.displayPowerConsumption(data.power_consumption);
6633275839SCamVan Nguyen                        $scope.displayPowerCap(data.power_cap);
67*fbb63db4SCamVan Nguyen                        $scope.displayNetworkInfo(data.network_info);
68428375e8SMichael Davis                      })
69428375e8SMichael Davis                      .finally(function(){
70428375e8SMichael Davis                        $scope.loading = false;
7154c22e4fSIftekharul Islam                      });
7254c22e4fSIftekharul Islam                }
7354c22e4fSIftekharul Islam                $scope.displayBMCEthernetInfo = function(data){
7454c22e4fSIftekharul Islam                    $scope.mac_address = data.MACAddress;
7554c22e4fSIftekharul Islam                }
7654c22e4fSIftekharul Islam
775dbcfb17SGunnar Mills                $scope.displayBMCInfo = function(data, bmcActiveVersion){
7854c22e4fSIftekharul Islam                    $scope.bmc_info = data;
795dbcfb17SGunnar Mills                    $scope.bmc_firmware = bmcActiveVersion;
8054c22e4fSIftekharul Islam                }
8154c22e4fSIftekharul Islam
82ed96f8bbSGunnar Mills                $scope.displayBMCTime = function(data){
83ed96f8bbSGunnar Mills                    $scope.bmc_time = data.data.Elapsed / 1000;
84ed96f8bbSGunnar Mills                }
85ed96f8bbSGunnar Mills
8654c22e4fSIftekharul Islam                $scope.displayLogs = function(data){
8754c22e4fSIftekharul Islam                    $scope.logs = data.filter(function(log){
8854c22e4fSIftekharul Islam                        return log.severity_flags.high == true;
8954c22e4fSIftekharul Islam                    });
9054c22e4fSIftekharul Islam                }
9154c22e4fSIftekharul Islam
925dbcfb17SGunnar Mills                $scope.displayServerInfo = function(data, hostActiveVersion){
9317708f2aSGunnar Mills                    $scope.server_info = data.data;
9454c22e4fSIftekharul Islam                    $scope.server_firmware = hostActiveVersion;
9554c22e4fSIftekharul Islam                }
9654c22e4fSIftekharul Islam
9754c22e4fSIftekharul Islam                $scope.displayLEDState = function(state){
9854c22e4fSIftekharul Islam                    if(state == APIUtils.LED_STATE.on){
9954c22e4fSIftekharul Islam                        dataService.LED_state = APIUtils.LED_STATE_TEXT.on;
10054c22e4fSIftekharul Islam                    }else{
10154c22e4fSIftekharul Islam                        dataService.LED_state = APIUtils.LED_STATE_TEXT.off;
10254c22e4fSIftekharul Islam                    }
10354c22e4fSIftekharul Islam                }
10454c22e4fSIftekharul Islam
10554c22e4fSIftekharul Islam                $scope.toggleLED = function(){
10654c22e4fSIftekharul Islam                    var toggleState = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ?
10754c22e4fSIftekharul Islam                        APIUtils.LED_STATE.off : APIUtils.LED_STATE.on;
10854c22e4fSIftekharul Islam                        dataService.LED_state = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ?
10954c22e4fSIftekharul Islam                        APIUtils.LED_STATE_TEXT.off : APIUtils.LED_STATE_TEXT.on;
11054c22e4fSIftekharul Islam                    APIUtils.setLEDState(toggleState, function(status){
11154c22e4fSIftekharul Islam                    });
11254c22e4fSIftekharul Islam                }
11323217daeSCamVan Nguyen
11433275839SCamVan Nguyen                $scope.displayPowerConsumption = function(data){
11533275839SCamVan Nguyen                    $scope.power_consumption = data;
11633275839SCamVan Nguyen                }
11733275839SCamVan Nguyen
11833275839SCamVan Nguyen                $scope.displayPowerCap = function(data){
11933275839SCamVan Nguyen                    $scope.power_cap = data;
12033275839SCamVan Nguyen                }
121*fbb63db4SCamVan Nguyen
122*fbb63db4SCamVan Nguyen                $scope.displayNetworkInfo = function(data){
123*fbb63db4SCamVan Nguyen                    // TODO: openbmc/openbmc#3150 Support IPV6 when officially
124*fbb63db4SCamVan Nguyen                    // supported by the backend
125*fbb63db4SCamVan Nguyen                    $scope.bmc_ip_addresses =
126*fbb63db4SCamVan Nguyen                        data.formatted_data.ip_addresses.ipv4;
127*fbb63db4SCamVan Nguyen                }
12899d199f3SIftekharul Islam            }
12999d199f3SIftekharul Islam        ]
13099d199f3SIftekharul Islam    );
13199d199f3SIftekharul Islam
13299d199f3SIftekharul Islam})(angular);
133