blob: 4dd012dfc12f5d7e79d590aa143dd91bafb778eb [file] [log] [blame]
Iftekharul Islam99d199f2017-03-24 15:28:25 -05001/**
Iftekharul Islamcd789502017-04-19 14:37:55 -05002 * Controller for systemOverview
Iftekharul Islam99d199f2017-03-24 15:28:25 -05003 *
4 * @module app/overview
5 * @exports systemOverviewController
6 * @name systemOverviewController
7 * @version 0.1.0
8 */
9
10window.angular && (function (angular) {
11 'use strict';
12
13 angular
14 .module('app.overview')
15 .controller('systemOverviewController', [
16 '$scope',
17 '$window',
18 'APIUtils',
19 'dataService',
Michael Davis428375e2017-08-01 15:48:34 -050020 '$q',
21 function($scope, $window, APIUtils, dataService, $q){
Iftekharul Islam99d199f2017-03-24 15:28:25 -050022 $scope.dataService = dataService;
Iftekharul Islamcd789502017-04-19 14:37:55 -050023 $scope.dropdown_selected = false;
Iftekharul Islam54c22e42017-06-28 11:06:16 -050024 $scope.tmz = 'EDT';
25 $scope.logs = [];
26 $scope.mac_address = "";
27 $scope.bmc_info = {};
28 $scope.bmc_firmware = "";
29 $scope.server_firmware = "";
Michael Davis428375e2017-08-01 15:48:34 -050030 $scope.loading = false;
Iftekharul Islam54c22e42017-06-28 11:06:16 -050031
32 loadOverviewData();
33 function loadOverviewData(){
Michael Davis428375e2017-08-01 15:48:34 -050034 $scope.loading = true;
35 var promises = {
36 logs: APIUtils.getLogs(),
37 firmware: APIUtils.getFirmwares(),
38 led: APIUtils.getLEDState(),
39 ethernet: APIUtils.getBMCEthernetInfo(),
40 bmc_info: APIUtils.getBMCInfo()
41 };
42 $q.all(promises)
43 .then(function(data){
44 $scope.displayLogs(data.logs.data);
45 $scope.displayServerInfo(
46 data.firmware.data,
47 data.firmware.bmcActiveVersion,
48 data.firmware.hostActiveVersion
49 );
50 $scope.displayLEDState(data.led);
51 $scope.displayBMCEthernetInfo(data.ethernet);
52 $scope.displayBMCInfo(data.bmc_info);
53 })
54 .finally(function(){
55 $scope.loading = false;
56 });
Iftekharul Islam54c22e42017-06-28 11:06:16 -050057 }
58 $scope.displayBMCEthernetInfo = function(data){
59 $scope.mac_address = data.MACAddress;
60 }
61
62 $scope.displayBMCInfo = function(data){
63 $scope.bmc_info = data;
64 }
65
66 $scope.displayLogs = function(data){
67 $scope.logs = data.filter(function(log){
68 return log.severity_flags.high == true;
69 });
70 }
71
72 $scope.displayServerInfo = function(data, bmcActiveVersion, hostActiveVersion){
73 $scope.bmc_firmware = bmcActiveVersion;
74 $scope.server_firmware = hostActiveVersion;
75 }
76
77 $scope.displayLEDState = function(state){
78 if(state == APIUtils.LED_STATE.on){
79 dataService.LED_state = APIUtils.LED_STATE_TEXT.on;
80 }else{
81 dataService.LED_state = APIUtils.LED_STATE_TEXT.off;
82 }
83 }
84
85 $scope.toggleLED = function(){
86 var toggleState = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ?
87 APIUtils.LED_STATE.off : APIUtils.LED_STATE.on;
88 dataService.LED_state = (dataService.LED_state == APIUtils.LED_STATE_TEXT.on) ?
89 APIUtils.LED_STATE_TEXT.off : APIUtils.LED_STATE_TEXT.on;
90 APIUtils.setLEDState(toggleState, function(status){
91 });
92 }
Iftekharul Islam99d199f2017-03-24 15:28:25 -050093 }
94 ]
95 );
96
Iftekharul Islamcd789502017-04-19 14:37:55 -050097})(angular);