blob: 40e0b584c882391f213faee477206e5d93e1c24f [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';
Andrew Geisslerd27bb132018-05-24 11:07:27 -070011 angular.module('app.overview').controller('sensorsOverviewController', [
Gunnar Mills615a2f82019-04-17 14:30:39 -050012 '$scope', '$log', '$window', 'APIUtils', 'dataService', 'Constants',
13 function($scope, $log, $window, APIUtils, dataService, Constants) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -070014 $scope.dataService = dataService;
Michael Davis994a93b2017-04-18 10:01:04 -050015
Gunnar Mills615a2f82019-04-17 14:30:39 -050016 $scope.dropdown_selected = false;
17
18 $scope.$log = $log;
Andrew Geisslerd27bb132018-05-24 11:07:27 -070019 $scope.customSearch = '';
20 $scope.searchTerms = [];
21 $scope.messages = Constants.MESSAGES.SENSOR;
22 $scope.selectedSeverity =
Gunnar Mills615a2f82019-04-17 14:30:39 -050023 {all: true, normal: false, warning: false, critical: false};
Andrew Geisslerd27bb132018-05-24 11:07:27 -070024 $scope.export_name = 'sensors.json';
Gunnar Mills615a2f82019-04-17 14:30:39 -050025 $scope.loading = false;
26 $scope.jsonData = function(data) {
27 var dt = {};
28 data.data.forEach(function(item) {
29 dt[item.original_data.key] = item.original_data.value;
30 });
31 return JSON.stringify(dt);
32 };
Andrew Geisslerd27bb132018-05-24 11:07:27 -070033
34 $scope.clear = function() {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070035 $scope.customSearch = '';
36 $scope.searchTerms = [];
Andrew Geisslerd27bb132018-05-24 11:07:27 -070037 };
Iftekharul Islamd2269e22017-05-02 09:32:45 -050038
Andrew Geisslerd27bb132018-05-24 11:07:27 -070039 $scope.doSearchOnEnter = function(event) {
40 var search =
41 $scope.customSearch.replace(/^\s+/g, '').replace(/\s+$/g, '');
42 if (event.keyCode === 13 && search.length >= 2) {
43 $scope.searchTerms = $scope.customSearch.split(' ');
44 } else {
45 if (search.length == 0) {
46 $scope.searchTerms = [];
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070047 }
Andrew Geisslerd27bb132018-05-24 11:07:27 -070048 }
49 };
50
51 $scope.doSearchOnClick = function() {
52 var search =
53 $scope.customSearch.replace(/^\s+/g, '').replace(/\s+$/g, '');
54 if (search.length >= 2) {
55 $scope.searchTerms = $scope.customSearch.split(' ');
56 } else {
57 if (search.length == 0) {
58 $scope.searchTerms = [];
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070059 }
Andrew Geisslerd27bb132018-05-24 11:07:27 -070060 }
61 };
Michael Davis994a93b2017-04-18 10:01:04 -050062
Andrew Geisslerd27bb132018-05-24 11:07:27 -070063 $scope.toggleSeverityAll = function() {
64 $scope.selectedSeverity.all = !$scope.selectedSeverity.all;
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070065
Andrew Geisslerd27bb132018-05-24 11:07:27 -070066 if ($scope.selectedSeverity.all) {
Gunnar Mills615a2f82019-04-17 14:30:39 -050067 $scope.selectedSeverity.normal = false;
Andrew Geisslerd27bb132018-05-24 11:07:27 -070068 $scope.selectedSeverity.warning = false;
69 $scope.selectedSeverity.critical = false;
70 }
71 };
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070072
Andrew Geisslerd27bb132018-05-24 11:07:27 -070073 $scope.toggleSeverity = function(severity) {
74 $scope.selectedSeverity[severity] = !$scope.selectedSeverity[severity];
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070075
Gunnar Mills615a2f82019-04-17 14:30:39 -050076 if (['normal', 'warning', 'critical'].indexOf(severity) > -1) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -070077 if ($scope.selectedSeverity[severity] == false &&
Gunnar Mills615a2f82019-04-17 14:30:39 -050078 (!$scope.selectedSeverity.normal &&
Andrew Geisslerd27bb132018-05-24 11:07:27 -070079 !$scope.selectedSeverity.warning &&
80 !$scope.selectedSeverity.critical)) {
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070081 $scope.selectedSeverity.all = true;
Andrew Geisslerd27bb132018-05-24 11:07:27 -070082 return;
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070083 }
Andrew Geisslerd27bb132018-05-24 11:07:27 -070084 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070085
Gunnar Mills615a2f82019-04-17 14:30:39 -050086 if ($scope.selectedSeverity.normal && $scope.selectedSeverity.warning &&
Andrew Geisslerd27bb132018-05-24 11:07:27 -070087 $scope.selectedSeverity.critical) {
88 $scope.selectedSeverity.all = true;
Gunnar Mills615a2f82019-04-17 14:30:39 -050089 $scope.selectedSeverity.normal = false;
Andrew Geisslerd27bb132018-05-24 11:07:27 -070090 $scope.selectedSeverity.warning = false;
91 $scope.selectedSeverity.critical = false;
92 } else {
93 $scope.selectedSeverity.all = false;
94 }
95 };
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070096
Andrew Geisslerd27bb132018-05-24 11:07:27 -070097 $scope.filterBySeverity = function(sensor) {
98 if ($scope.selectedSeverity.all) return true;
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070099
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700100 return (
Gunnar Mills615a2f82019-04-17 14:30:39 -0500101 (sensor.severity_flags.normal && $scope.selectedSeverity.normal) ||
102 (sensor.severity_flags.warning &&
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700103 $scope.selectedSeverity.warning) ||
Gunnar Mills615a2f82019-04-17 14:30:39 -0500104 (sensor.severity_flags.critical &&
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700105 $scope.selectedSeverity.critical));
106 };
107 $scope.filterBySearchTerms = function(sensor) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700108 if (!$scope.searchTerms.length) return true;
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700109
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700110 for (var i = 0, length = $scope.searchTerms.length; i < length; i++) {
Gunnar Mills615a2f82019-04-17 14:30:39 -0500111 if (sensor.search_text.indexOf($scope.searchTerms[i].toLowerCase()) ==
112 -1)
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700113 return false;
114 }
115 return true;
116 };
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700117
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700118 $scope.loadSensorData = function() {
119 $scope.loading = true;
Gunnar Mills615a2f82019-04-17 14:30:39 -0500120 APIUtils.getAllSensorStatus(function(data, originalData) {
121 $scope.data = data;
122 $scope.originalData = originalData;
123 $scope.export_data = JSON.stringify(originalData);
124 $scope.loading = false;
125 });
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700126 };
127
128 $scope.loadSensorData();
129 }
130 ]);
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700131})(angular);