summaryrefslogtreecommitdiffstats
path: root/app/server-health/controllers/sensors-overview-controller.js
blob: 213a4e3afd3f4351c554c8a71e660924f65835cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
 * Controller for sensors-overview
 *
 * @module app/serverHealth
 * @exports sensorsOverviewController
 * @name sensorsOverviewController
 * @version 0.1.0
 */

window.angular && (function (angular) {
    'use strict';
    angular
        .module('app.overview')
        .controller('sensorsOverviewController', [
            '$scope',
            '$log',
            '$window', 
            'APIUtils', 
            'dataService',
            function($scope, $log, $window, APIUtils, dataService, userModel){
                $scope.dataService = dataService;

                $scope.dropdown_selected = false;

                $scope.$log = $log;
                $scope.customSearch = "";
                $scope.searchTerms = [];
                $scope.selectedSeverity = {
                    all: true,
                    normal: false,
                    warning: false,
                    critical: false
                };
                $scope.export_name = "sensors.json";
                $scope.jsonData = function(data){
                    var dt = {};
                    data.data.forEach(function(item){
                        dt[item.original_data.key] = item.original_data.value;
                    });
                    return JSON.stringify(dt);
                };

                $scope.doSearchOnEnter = function (event) {
                    var search = $scope.customSearch.replace(/^\s+/g,'').replace(/\s+$/g,'');
                    if (event.keyCode === 13 &&
                        search.length >= 2) {
                        $scope.searchTerms = $scope.customSearch.split(" ");
                    }else{
                        if(search.length == 0){
                            $scope.searchTerms = [];
                        }
                    }
                };

                $scope.doSearchOnClick = function() {
                    var search = $scope.customSearch.replace(/^\s+/g,'').replace(/\s+$/g,'');
                    if (search.length >= 2) {
                        $scope.searchTerms = $scope.customSearch.split(" ");
                    }else{
                        if(search.length == 0){
                            $scope.searchTerms = [];
                        }
                    }
                }

                $scope.toggleSeverityAll = function(){
                    $scope.selectedSeverity.all = !$scope.selectedSeverity.all;

                    if($scope.selectedSeverity.all){
                        $scope.selectedSeverity.normal = false;
                        $scope.selectedSeverity.warning = false;
                        $scope.selectedSeverity.critical = false;
                    }
                }

                $scope.toggleSeverity = function(severity){
                    $scope.selectedSeverity[severity] = !$scope.selectedSeverity[severity];

                    if($scope.selectedSeverity.normal && 
                       $scope.selectedSeverity.warning && 
                       $scope.selectedSeverity.critical){
                        $scope.selectedSeverity.all = true;
                        $scope.selectedSeverity.normal = false;
                        $scope.selectedSeverity.warning = false;
                        $scope.selectedSeverity.critical = false;
                    }else{
                        $scope.selectedSeverity.all = false;
                    }
                }

                $scope.filterBySeverity = function(sensor){
                    if($scope.selectedSeverity.all) return true;

                    return( (sensor.severity_flags.normal && $scope.selectedSeverity.normal) ||
                            (sensor.severity_flags.warning && $scope.selectedSeverity.warning) ||
                            (sensor.severity_flags.critical && $scope.selectedSeverity.critical)
                    );
                }
                $scope.filterBySearchTerms = function(sensor){

                    if(!$scope.searchTerms.length) return true; 

                    for(var i = 0, length = $scope.searchTerms.length; i < length; i++){
                        if(sensor.search_text.indexOf($scope.searchTerms[i].toLowerCase()) == -1) return false;
                    }
                    return true;
                }

                $scope.loadSensorData = function(){
                    APIUtils.getAllSensorStatus(function(data, originalData){
                        $scope.data = data;
                        $scope.originalData = originalData;
                        dataService.sensorData = data;
                        $scope.export_data = JSON.stringify(originalData);
                    });
                };

                $scope.loadSensorData();
            }
        ]
    );

})(angular);
OpenPOWER on IntegriCloud