xref: /openbmc/phosphor-webui/app/overview/controllers/system-overview-controller.js (revision ff2313db3686ed23bec93871b1f3f31cbbd6e399)
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 = "";
33fbb63db4SCamVan Nguyen                $scope.bmc_ip_addresses = [];
34428375e8SMichael Davis                $scope.loading = false;
35*ff2313dbSAndrew Geissler                $scope.edit_server_name = false;
3654c22e4fSIftekharul Islam
3754c22e4fSIftekharul Islam                loadOverviewData();
3854c22e4fSIftekharul Islam                function loadOverviewData(){
39428375e8SMichael Davis                    $scope.loading = true;
40428375e8SMichael Davis                    var promises = {
41428375e8SMichael Davis                      logs: APIUtils.getLogs(),
42428375e8SMichael Davis                      firmware: APIUtils.getFirmwares(),
43428375e8SMichael Davis                      led: APIUtils.getLEDState(),
44428375e8SMichael Davis                      ethernet: APIUtils.getBMCEthernetInfo(),
4533275839SCamVan Nguyen                      bmc_info: APIUtils.getBMCInfo(),
46ed96f8bbSGunnar Mills                      bmc_time: APIUtils.getBMCTime(),
4717708f2aSGunnar Mills                      server_info: APIUtils.getServerInfo(),
4833275839SCamVan Nguyen                      power_consumption: APIUtils.getPowerConsumption(),
4933275839SCamVan Nguyen                      power_cap: APIUtils.getPowerCap(),
50fbb63db4SCamVan Nguyen                      network_info: APIUtils.getNetworkInfo(),
51428375e8SMichael Davis                    };
52428375e8SMichael Davis                    $q.all(promises)
53428375e8SMichael Davis                      .then(function(data){
54428375e8SMichael Davis                        $scope.displayLogs(data.logs.data);
55428375e8SMichael Davis                        $scope.displayServerInfo(
5617708f2aSGunnar Mills                            data.server_info,
57428375e8SMichael Davis                            data.firmware.hostActiveVersion
58428375e8SMichael Davis                        );
59428375e8SMichael Davis                        $scope.displayLEDState(data.led);
60428375e8SMichael Davis                        $scope.displayBMCEthernetInfo(data.ethernet);
615dbcfb17SGunnar Mills                        $scope.displayBMCInfo(
625dbcfb17SGunnar Mills                            data.bmc_info,
635dbcfb17SGunnar Mills                            data.firmware.bmcActiveVersion
645dbcfb17SGunnar Mills                        );
65ed96f8bbSGunnar Mills                        $scope.displayBMCTime(data.bmc_time);
6633275839SCamVan Nguyen                        $scope.displayPowerConsumption(data.power_consumption);
6733275839SCamVan Nguyen                        $scope.displayPowerCap(data.power_cap);
68fbb63db4SCamVan Nguyen                        $scope.displayNetworkInfo(data.network_info);
69428375e8SMichael Davis                      })
70428375e8SMichael Davis                      .finally(function(){
71428375e8SMichael Davis                        $scope.loading = false;
7254c22e4fSIftekharul Islam                      });
7354c22e4fSIftekharul Islam                }
7454c22e4fSIftekharul Islam                $scope.displayBMCEthernetInfo = function(data){
7554c22e4fSIftekharul Islam                    $scope.mac_address = data.MACAddress;
7654c22e4fSIftekharul Islam                }
7754c22e4fSIftekharul Islam
785dbcfb17SGunnar Mills                $scope.displayBMCInfo = function(data, bmcActiveVersion){
7954c22e4fSIftekharul Islam                    $scope.bmc_info = data;
805dbcfb17SGunnar Mills                    $scope.bmc_firmware = bmcActiveVersion;
8154c22e4fSIftekharul Islam                }
8254c22e4fSIftekharul Islam
83ed96f8bbSGunnar Mills                $scope.displayBMCTime = function(data){
84ed96f8bbSGunnar Mills                    $scope.bmc_time = data.data.Elapsed / 1000;
85ed96f8bbSGunnar Mills                }
86ed96f8bbSGunnar Mills
8754c22e4fSIftekharul Islam                $scope.displayLogs = function(data){
8854c22e4fSIftekharul Islam                    $scope.logs = data.filter(function(log){
8954c22e4fSIftekharul Islam                        return log.severity_flags.high == true;
9054c22e4fSIftekharul Islam                    });
9154c22e4fSIftekharul Islam                }
9254c22e4fSIftekharul Islam
935dbcfb17SGunnar Mills                $scope.displayServerInfo = function(data, hostActiveVersion){
9417708f2aSGunnar Mills                    $scope.server_info = data.data;
9554c22e4fSIftekharul Islam                    $scope.server_firmware = hostActiveVersion;
9654c22e4fSIftekharul Islam                }
9754c22e4fSIftekharul Islam
9854c22e4fSIftekharul Islam                $scope.displayLEDState = function(state){
9954c22e4fSIftekharul Islam                    if(state == APIUtils.LED_STATE.on){
10054c22e4fSIftekharul Islam                        dataService.LED_state = APIUtils.LED_STATE_TEXT.on;
10154c22e4fSIftekharul Islam                    }else{
10254c22e4fSIftekharul Islam                        dataService.LED_state = APIUtils.LED_STATE_TEXT.off;
10354c22e4fSIftekharul Islam                    }
10454c22e4fSIftekharul Islam                }
10554c22e4fSIftekharul Islam
10654c22e4fSIftekharul Islam                $scope.toggleLED = function(){
10754c22e4fSIftekharul Islam                    var toggleState = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ?
10854c22e4fSIftekharul Islam                        APIUtils.LED_STATE.off : APIUtils.LED_STATE.on;
10954c22e4fSIftekharul Islam                        dataService.LED_state = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ?
11054c22e4fSIftekharul Islam                        APIUtils.LED_STATE_TEXT.off : APIUtils.LED_STATE_TEXT.on;
11154c22e4fSIftekharul Islam                    APIUtils.setLEDState(toggleState, function(status){
11254c22e4fSIftekharul Islam                    });
11354c22e4fSIftekharul Islam                }
11423217daeSCamVan Nguyen
11533275839SCamVan Nguyen                $scope.displayPowerConsumption = function(data){
11633275839SCamVan Nguyen                    $scope.power_consumption = data;
11733275839SCamVan Nguyen                }
11833275839SCamVan Nguyen
11933275839SCamVan Nguyen                $scope.displayPowerCap = function(data){
12033275839SCamVan Nguyen                    $scope.power_cap = data;
12133275839SCamVan Nguyen                }
122fbb63db4SCamVan Nguyen
123fbb63db4SCamVan Nguyen                $scope.displayNetworkInfo = function(data){
124fbb63db4SCamVan Nguyen                    // TODO: openbmc/openbmc#3150 Support IPV6 when officially
125fbb63db4SCamVan Nguyen                    // supported by the backend
126fbb63db4SCamVan Nguyen                    $scope.bmc_ip_addresses =
127fbb63db4SCamVan Nguyen                        data.formatted_data.ip_addresses.ipv4;
128fbb63db4SCamVan Nguyen                }
129*ff2313dbSAndrew Geissler
130*ff2313dbSAndrew Geissler                $scope.saveHostname = function(hostname) {
131*ff2313dbSAndrew Geissler                    $scope.edit_server_name = false;
132*ff2313dbSAndrew Geissler                    $scope.loading = true;
133*ff2313dbSAndrew Geissler                    APIUtils.setHostname(hostname).then(function(data){
134*ff2313dbSAndrew Geissler                        APIUtils.getNetworkInfo().then(function(data){
135*ff2313dbSAndrew Geissler                            dataService.setNetworkInfo(data);
136*ff2313dbSAndrew Geissler                        });
137*ff2313dbSAndrew Geissler                    },
138*ff2313dbSAndrew Geissler                    function(error){
139*ff2313dbSAndrew Geissler                        console.log(error);
140*ff2313dbSAndrew Geissler                    });
141*ff2313dbSAndrew Geissler                    $scope.loading = false;
142*ff2313dbSAndrew Geissler                }
14399d199f3SIftekharul Islam            }
14499d199f3SIftekharul Islam        ]
14599d199f3SIftekharul Islam    );
14699d199f3SIftekharul Islam
14799d199f3SIftekharul Islam})(angular);
148