xref: /openbmc/phosphor-webui/app/overview/controllers/system-overview-controller.js (revision 565efda513bbcda6c1c675eaebac6138782febe4)
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
12d27bb135SAndrew Geissler  angular.module('app.overview').controller('systemOverviewController', [
13006aaa0fSGunnar Mills    '$scope', '$window', 'APIUtils', 'dataService', 'Constants', '$q',
14006aaa0fSGunnar Mills    function($scope, $window, APIUtils, dataService, Constants, $q) {
1599d199f3SIftekharul Islam      $scope.dataService = dataService;
16cd789508SIftekharul Islam      $scope.dropdown_selected = false;
1754c22e4fSIftekharul Islam      $scope.logs = [];
1817708f2aSGunnar Mills      $scope.server_info = {};
19ba5e3f34SAndrew Geissler      $scope.bmc_firmware = '';
20ba5e3f34SAndrew Geissler      $scope.bmc_time = '';
21ba5e3f34SAndrew Geissler      $scope.server_firmware = '';
22ba5e3f34SAndrew Geissler      $scope.power_consumption = '';
23ba5e3f34SAndrew Geissler      $scope.power_cap = '';
24fbb63db4SCamVan Nguyen      $scope.bmc_ip_addresses = [];
25428375e8SMichael Davis      $scope.loading = false;
26e56bb445SGunnar Mills      $scope.edit_hostname = false;
27*565efda5Sdixsie      $scope.newHostname = '';
2854c22e4fSIftekharul Islam
2954c22e4fSIftekharul Islam      loadOverviewData();
30ba5e3f34SAndrew Geissler
3154c22e4fSIftekharul Islam      function loadOverviewData() {
32428375e8SMichael Davis        $scope.loading = true;
3354c22e4fSIftekharul Islam
34d27bb135SAndrew Geissler        var getLogsPromise = APIUtils.getLogs().then(
35d27bb135SAndrew Geissler            function(data) {
367db0e9acSCamVan Nguyen              $scope.logs = data.data.filter(function(log) {
3754c22e4fSIftekharul Islam                return log.severity_flags.high == true;
3854c22e4fSIftekharul Islam              });
39d27bb135SAndrew Geissler            },
40d27bb135SAndrew Geissler            function(error) {
417db0e9acSCamVan Nguyen              console.log(JSON.stringify(error));
42ba5e3f34SAndrew Geissler            });
4354c22e4fSIftekharul Islam
44d27bb135SAndrew Geissler        var getFirmwaresPromise = APIUtils.getFirmwares().then(
45d27bb135SAndrew Geissler            function(data) {
467db0e9acSCamVan Nguyen              $scope.bmc_firmware = data.bmcActiveVersion;
477db0e9acSCamVan Nguyen              $scope.server_firmware = data.hostActiveVersion;
48d27bb135SAndrew Geissler            },
49d27bb135SAndrew Geissler            function(error) {
507db0e9acSCamVan Nguyen              console.log(JSON.stringify(error));
51ba5e3f34SAndrew Geissler            });
5254c22e4fSIftekharul Islam
53d27bb135SAndrew Geissler        var getLEDStatePromise = APIUtils.getLEDState().then(
54d27bb135SAndrew Geissler            function(data) {
557db0e9acSCamVan Nguyen              if (data == APIUtils.LED_STATE.on) {
5654c22e4fSIftekharul Islam                dataService.LED_state = APIUtils.LED_STATE_TEXT.on;
57d27bb135SAndrew Geissler              } else {
5854c22e4fSIftekharul Islam                dataService.LED_state = APIUtils.LED_STATE_TEXT.off;
5954c22e4fSIftekharul Islam              }
60d27bb135SAndrew Geissler            },
61d27bb135SAndrew Geissler            function(error) {
627db0e9acSCamVan Nguyen              console.log(JSON.stringify(error));
63ba5e3f34SAndrew Geissler            });
647db0e9acSCamVan Nguyen
65d27bb135SAndrew Geissler        var getBMCTimePromise = APIUtils.getBMCTime().then(
66d27bb135SAndrew Geissler            function(data) {
677db0e9acSCamVan Nguyen              $scope.bmc_time = data.data.Elapsed / 1000;
68d27bb135SAndrew Geissler            },
69d27bb135SAndrew Geissler            function(error) {
707db0e9acSCamVan Nguyen              console.log(JSON.stringify(error));
71ba5e3f34SAndrew Geissler            });
727db0e9acSCamVan Nguyen
73d27bb135SAndrew Geissler        var getServerInfoPromise = APIUtils.getServerInfo().then(
74d27bb135SAndrew Geissler            function(data) {
757db0e9acSCamVan Nguyen              $scope.server_info = data.data;
76d27bb135SAndrew Geissler            },
77d27bb135SAndrew Geissler            function(error) {
787db0e9acSCamVan Nguyen              console.log(JSON.stringify(error));
79ba5e3f34SAndrew Geissler            });
807db0e9acSCamVan Nguyen
81d27bb135SAndrew Geissler        var getPowerConsumptionPromise = APIUtils.getPowerConsumption().then(
82d27bb135SAndrew Geissler            function(data) {
837db0e9acSCamVan Nguyen              $scope.power_consumption = data;
84d27bb135SAndrew Geissler            },
85d27bb135SAndrew Geissler            function(error) {
867db0e9acSCamVan Nguyen              console.log(JSON.stringify(error));
87ba5e3f34SAndrew Geissler            });
887db0e9acSCamVan Nguyen
89d27bb135SAndrew Geissler        var getPowerCapPromise = APIUtils.getPowerCap().then(
90d27bb135SAndrew Geissler            function(data) {
91006aaa0fSGunnar Mills              if (data.data.PowerCapEnable == false) {
92006aaa0fSGunnar Mills                $scope.power_cap = Constants.POWER_CAP_TEXT.disabled;
93006aaa0fSGunnar Mills              } else {
94006aaa0fSGunnar Mills                $scope.power_cap =
95006aaa0fSGunnar Mills                    data.data.PowerCap + ' ' + Constants.POWER_CAP_TEXT.unit;
96006aaa0fSGunnar Mills              }
97d27bb135SAndrew Geissler            },
98d27bb135SAndrew Geissler            function(error) {
997db0e9acSCamVan Nguyen              console.log(JSON.stringify(error));
100ba5e3f34SAndrew Geissler            });
1017db0e9acSCamVan Nguyen
102d27bb135SAndrew Geissler        var getNetworkInfoPromise = APIUtils.getNetworkInfo().then(
103d27bb135SAndrew Geissler            function(data) {
1047db0e9acSCamVan Nguyen              // TODO: openbmc/openbmc#3150 Support IPV6 when
1057db0e9acSCamVan Nguyen              // officially supported by the backend
106d27bb135SAndrew Geissler              $scope.bmc_ip_addresses = data.formatted_data.ip_addresses.ipv4;
107*565efda5Sdixsie              $scope.newHostname = data.hostname;
108d27bb135SAndrew Geissler            },
109d27bb135SAndrew Geissler            function(error) {
1107db0e9acSCamVan Nguyen              console.log(JSON.stringify(error));
111ba5e3f34SAndrew Geissler            });
1127db0e9acSCamVan Nguyen
1137db0e9acSCamVan Nguyen        var promises = [
1147db0e9acSCamVan Nguyen          getLogsPromise,
1157db0e9acSCamVan Nguyen          getFirmwaresPromise,
1167db0e9acSCamVan Nguyen          getLEDStatePromise,
1177db0e9acSCamVan Nguyen          getBMCTimePromise,
1187db0e9acSCamVan Nguyen          getServerInfoPromise,
1197db0e9acSCamVan Nguyen          getPowerConsumptionPromise,
1207db0e9acSCamVan Nguyen          getPowerCapPromise,
1217db0e9acSCamVan Nguyen          getNetworkInfoPromise,
1227db0e9acSCamVan Nguyen        ];
1237db0e9acSCamVan Nguyen
1247db0e9acSCamVan Nguyen        $q.all(promises).finally(function() {
1257db0e9acSCamVan Nguyen          $scope.loading = false;
1267db0e9acSCamVan Nguyen        });
12754c22e4fSIftekharul Islam      }
12854c22e4fSIftekharul Islam
12954c22e4fSIftekharul Islam      $scope.toggleLED = function() {
130d27bb135SAndrew Geissler        var toggleState =
131d27bb135SAndrew Geissler            (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ?
132d27bb135SAndrew Geissler            APIUtils.LED_STATE.off :
133d27bb135SAndrew Geissler            APIUtils.LED_STATE.on;
134d27bb135SAndrew Geissler        dataService.LED_state =
135d27bb135SAndrew Geissler            (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ?
136d27bb135SAndrew Geissler            APIUtils.LED_STATE_TEXT.off :
137d27bb135SAndrew Geissler            APIUtils.LED_STATE_TEXT.on;
138ba5e3f34SAndrew Geissler        APIUtils.setLEDState(toggleState, function(status) {});
139ba5e3f34SAndrew Geissler      };
14023217daeSCamVan Nguyen
141ff2313dbSAndrew Geissler      $scope.saveHostname = function(hostname) {
142e56bb445SGunnar Mills        $scope.edit_hostname = false;
143ff2313dbSAndrew Geissler        $scope.loading = true;
144d27bb135SAndrew Geissler        APIUtils.setHostname(hostname).then(
145d27bb135SAndrew Geissler            function(data) {
146ff2313dbSAndrew Geissler              APIUtils.getNetworkInfo().then(function(data) {
147ff2313dbSAndrew Geissler                dataService.setNetworkInfo(data);
148ff2313dbSAndrew Geissler              });
149ff2313dbSAndrew Geissler            },
150ff2313dbSAndrew Geissler            function(error) {
151ff2313dbSAndrew Geissler              console.log(error);
152ff2313dbSAndrew Geissler            });
153ff2313dbSAndrew Geissler        $scope.loading = false;
154ba5e3f34SAndrew Geissler      };
155845acdc5SMatt Spinler
156845acdc5SMatt Spinler      $scope.getEventLogTitle = function(event) {
157845acdc5SMatt Spinler        var title = event.type;
158845acdc5SMatt Spinler        if ((event.eventID != 'None') && (event.description != 'None')) {
159845acdc5SMatt Spinler          title = event.eventID + ': ' + event.description;
160845acdc5SMatt Spinler        }
161845acdc5SMatt Spinler        return title;
162845acdc5SMatt Spinler      };
163ff2313dbSAndrew Geissler    }
164ba5e3f34SAndrew Geissler  ]);
16599d199f3SIftekharul Islam})(angular);
166