xref: /openbmc/phosphor-webui/app/overview/controllers/system-overview-controller.js (revision 428375e827eae425c6e08dcc27ccdc13c035e6f9)
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',
20*428375e8SMichael Davis            '$q',
21*428375e8SMichael Davis            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 = "";
30*428375e8SMichael Davis                $scope.loading = false;
3154c22e4fSIftekharul Islam
3254c22e4fSIftekharul Islam                loadOverviewData();
3354c22e4fSIftekharul Islam                function loadOverviewData(){
34*428375e8SMichael Davis                    $scope.loading = true;
35*428375e8SMichael Davis                    var promises = {
36*428375e8SMichael Davis                      logs: APIUtils.getLogs(),
37*428375e8SMichael Davis                      firmware: APIUtils.getFirmwares(),
38*428375e8SMichael Davis                      led: APIUtils.getLEDState(),
39*428375e8SMichael Davis                      ethernet: APIUtils.getBMCEthernetInfo(),
40*428375e8SMichael Davis                      bmc_info: APIUtils.getBMCInfo()
41*428375e8SMichael Davis                    };
42*428375e8SMichael Davis                    $q.all(promises)
43*428375e8SMichael Davis                      .then(function(data){
44*428375e8SMichael Davis                        $scope.displayLogs(data.logs.data);
45*428375e8SMichael Davis                        $scope.displayServerInfo(
46*428375e8SMichael Davis                            data.firmware.data,
47*428375e8SMichael Davis                            data.firmware.bmcActiveVersion,
48*428375e8SMichael Davis                            data.firmware.hostActiveVersion
49*428375e8SMichael Davis                        );
50*428375e8SMichael Davis                        $scope.displayLEDState(data.led);
51*428375e8SMichael Davis                        $scope.displayBMCEthernetInfo(data.ethernet);
52*428375e8SMichael Davis                        $scope.displayBMCInfo(data.bmc_info);
53*428375e8SMichael Davis                      })
54*428375e8SMichael Davis                      .finally(function(){
55*428375e8SMichael Davis                        $scope.loading = false;
5654c22e4fSIftekharul Islam                      });
5754c22e4fSIftekharul Islam                }
5854c22e4fSIftekharul Islam                $scope.displayBMCEthernetInfo = function(data){
5954c22e4fSIftekharul Islam                    $scope.mac_address = data.MACAddress;
6054c22e4fSIftekharul Islam                }
6154c22e4fSIftekharul Islam
6254c22e4fSIftekharul Islam                $scope.displayBMCInfo = function(data){
6354c22e4fSIftekharul Islam                    $scope.bmc_info = data;
6454c22e4fSIftekharul Islam                }
6554c22e4fSIftekharul Islam
6654c22e4fSIftekharul Islam                $scope.displayLogs = function(data){
6754c22e4fSIftekharul Islam                    $scope.logs = data.filter(function(log){
6854c22e4fSIftekharul Islam                        return log.severity_flags.high == true;
6954c22e4fSIftekharul Islam                    });
7054c22e4fSIftekharul Islam                }
7154c22e4fSIftekharul Islam
7254c22e4fSIftekharul Islam                $scope.displayServerInfo = function(data, bmcActiveVersion, hostActiveVersion){
7354c22e4fSIftekharul Islam                    $scope.bmc_firmware = bmcActiveVersion;
7454c22e4fSIftekharul Islam                    $scope.server_firmware = hostActiveVersion;
7554c22e4fSIftekharul Islam                }
7654c22e4fSIftekharul Islam
7754c22e4fSIftekharul Islam                $scope.displayLEDState = function(state){
7854c22e4fSIftekharul Islam                    if(state == APIUtils.LED_STATE.on){
7954c22e4fSIftekharul Islam                        dataService.LED_state = APIUtils.LED_STATE_TEXT.on;
8054c22e4fSIftekharul Islam                    }else{
8154c22e4fSIftekharul Islam                        dataService.LED_state = APIUtils.LED_STATE_TEXT.off;
8254c22e4fSIftekharul Islam                    }
8354c22e4fSIftekharul Islam                }
8454c22e4fSIftekharul Islam
8554c22e4fSIftekharul Islam                $scope.toggleLED = function(){
8654c22e4fSIftekharul Islam                    var toggleState = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ?
8754c22e4fSIftekharul Islam                        APIUtils.LED_STATE.off : APIUtils.LED_STATE.on;
8854c22e4fSIftekharul Islam                        dataService.LED_state = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ?
8954c22e4fSIftekharul Islam                        APIUtils.LED_STATE_TEXT.off : APIUtils.LED_STATE_TEXT.on;
9054c22e4fSIftekharul Islam                    APIUtils.setLEDState(toggleState, function(status){
9154c22e4fSIftekharul Islam                    });
9254c22e4fSIftekharul Islam                }
9399d199f3SIftekharul Islam            }
9499d199f3SIftekharul Islam        ]
9599d199f3SIftekharul Islam    );
9699d199f3SIftekharul Islam
9799d199f3SIftekharul Islam})(angular);