blob: 683d07136438aafe1910983524b8902b26887ce2 [file] [log] [blame]
Michael Davis994a93b2017-04-18 10:01:04 -05001/**
Iftekharul Islamcd789502017-04-19 14:37:55 -05002 * Controller for sensors-overview
Michael Davis994a93b2017-04-18 10:01:04 -05003 *
Iftekharul Islamcd789502017-04-19 14:37:55 -05004 * @module app/serverHealth
5 * @exports sensorsOverviewController
6 * @name sensorsOverviewController
Michael Davis994a93b2017-04-18 10:01:04 -05007 */
8
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07009window.angular && (function(angular) {
10 'use strict';
11 angular
12 .module('app.overview')
13 .controller('sensorsOverviewController', [
14 '$scope',
15 '$log',
16 '$window',
17 'APIUtils',
18 'dataService',
19 'Constants',
20 function($scope, $log, $window, APIUtils, dataService, Constants) {
21 $scope.dataService = dataService;
Michael Davis994a93b2017-04-18 10:01:04 -050022
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070023 $scope.dropdown_selected = false;
Michael Davis994a93b2017-04-18 10:01:04 -050024
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070025 $scope.$log = $log;
26 $scope.customSearch = '';
27 $scope.searchTerms = [];
28 $scope.messages = Constants.MESSAGES.SENSOR;
29 $scope.selectedSeverity = {
30 all: true,
31 normal: false,
32 warning: false,
33 critical: false
34 };
35 $scope.export_name = 'sensors.json';
36 $scope.loading = false;
37 $scope.jsonData = function(data) {
38 var dt = {};
39 data.data.forEach(function(item) {
40 dt[item.original_data.key] = item.original_data.value;
41 });
42 return JSON.stringify(dt);
43 };
Iftekharul Islamd2269e22017-05-02 09:32:45 -050044
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070045 $scope.clear = function() {
46 $scope.customSearch = '';
47 $scope.searchTerms = [];
48 };
Iftekharul Islam171c6a12017-08-11 08:35:47 -050049
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070050 $scope.doSearchOnEnter = function(event) {
51 var search = $scope.customSearch.replace(/^\s+/g, '').replace(/\s+$/g, '');
52 if (event.keyCode === 13 &&
53 search.length >= 2) {
54 $scope.searchTerms = $scope.customSearch.split(' ');
55 }
56 else {
57 if (search.length == 0) {
58 $scope.searchTerms = [];
Michael Davis994a93b2017-04-18 10:01:04 -050059 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070060 }
61 };
Michael Davis994a93b2017-04-18 10:01:04 -050062
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070063 $scope.doSearchOnClick = function() {
64 var search = $scope.customSearch.replace(/^\s+/g, '').replace(/\s+$/g, '');
65 if (search.length >= 2) {
66 $scope.searchTerms = $scope.customSearch.split(' ');
67 }
68 else {
69 if (search.length == 0) {
70 $scope.searchTerms = [];
71 }
72 }
73 };
74
75 $scope.toggleSeverityAll = function() {
76 $scope.selectedSeverity.all = !$scope.selectedSeverity.all;
77
78 if ($scope.selectedSeverity.all) {
79 $scope.selectedSeverity.normal = false;
80 $scope.selectedSeverity.warning = false;
81 $scope.selectedSeverity.critical = false;
82 }
83 };
84
85 $scope.toggleSeverity = function(severity) {
86 $scope.selectedSeverity[severity] = !$scope.selectedSeverity[severity];
87
88 if (['normal', 'warning', 'critical'].indexOf(severity) > -1) {
89 if ($scope.selectedSeverity[severity] == false &&
90 (!$scope.selectedSeverity.normal &&
91 !$scope.selectedSeverity.warning &&
92 !$scope.selectedSeverity.critical
93 )) {
94 $scope.selectedSeverity.all = true;
95 return;
96 }
97 }
98
99 if ($scope.selectedSeverity.normal &&
100 $scope.selectedSeverity.warning &&
101 $scope.selectedSeverity.critical) {
102 $scope.selectedSeverity.all = true;
103 $scope.selectedSeverity.normal = false;
104 $scope.selectedSeverity.warning = false;
105 $scope.selectedSeverity.critical = false;
106 }
107 else {
108 $scope.selectedSeverity.all = false;
109 }
110 };
111
112 $scope.filterBySeverity = function(sensor) {
113 if ($scope.selectedSeverity.all) return true;
114
115 return ((sensor.severity_flags.normal && $scope.selectedSeverity.normal) ||
116 (sensor.severity_flags.warning && $scope.selectedSeverity.warning) ||
117 (sensor.severity_flags.critical && $scope.selectedSeverity.critical)
118 );
119 };
120 $scope.filterBySearchTerms = function(sensor) {
121
122 if (!$scope.searchTerms.length) return true;
123
124 for (var i = 0, length = $scope.searchTerms.length; i < length; i++) {
125 if (sensor.search_text.indexOf($scope.searchTerms[i].toLowerCase()) == -1) return false;
126 }
127 return true;
128 };
129
130 $scope.loadSensorData = function() {
131 $scope.loading = true;
132 APIUtils.getAllSensorStatus(function(data, originalData) {
133 $scope.data = data;
134 $scope.originalData = originalData;
135 dataService.sensorData = data;
136 $scope.export_data = JSON.stringify(originalData);
137 $scope.loading = false;
138 });
139 };
140
141 $scope.loadSensorData();
142 }
143 ]);
144
145})(angular);