blob: 921847616e56c2388431752ecf28b83c9e4146e9 [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
9window.angular && (function (angular) {
10 'use strict';
Michael Davis994a93b2017-04-18 10:01:04 -050011 angular
12 .module('app.overview')
Iftekharul Islamcd789502017-04-19 14:37:55 -050013 .controller('sensorsOverviewController', [
Michael Davis994a93b2017-04-18 10:01:04 -050014 '$scope',
15 '$log',
Gunnar Millseedefd32018-02-28 17:02:34 -060016 '$window',
17 'APIUtils',
Michael Davis994a93b2017-04-18 10:01:04 -050018 'dataService',
Iftekharul Islam81a49de2018-02-08 13:28:09 -060019 'Constants',
Andrew Geisslercf862002018-04-11 12:19:39 -070020 function($scope, $log, $window, APIUtils, dataService, Constants){
Michael Davis994a93b2017-04-18 10:01:04 -050021 $scope.dataService = dataService;
22
23 $scope.dropdown_selected = false;
24
Iftekharul Islamcd789502017-04-19 14:37:55 -050025 $scope.$log = $log;
Iftekharul Islamd2269e22017-05-02 09:32:45 -050026 $scope.customSearch = "";
27 $scope.searchTerms = [];
Iftekharul Islam81a49de2018-02-08 13:28:09 -060028 $scope.messages = Constants.MESSAGES.SENSOR;
Iftekharul Islamd2269e22017-05-02 09:32:45 -050029 $scope.selectedSeverity = {
30 all: true,
31 normal: false,
32 warning: false,
33 critical: false
34 };
35 $scope.export_name = "sensors.json";
Michael Davis428375e2017-08-01 15:48:34 -050036 $scope.loading = false;
Iftekharul Islamd2269e22017-05-02 09:32:45 -050037 $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 };
44
Iftekharul Islam171c6a12017-08-11 08:35:47 -050045 $scope.clear = function(){
46 $scope.customSearch = "";
47 $scope.searchTerms = [];
48 }
49
Iftekharul Islamd2269e22017-05-02 09:32:45 -050050 $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 }else{
56 if(search.length == 0){
57 $scope.searchTerms = [];
58 }
59 }
60 };
61
62 $scope.doSearchOnClick = function() {
63 var search = $scope.customSearch.replace(/^\s+/g,'').replace(/\s+$/g,'');
64 if (search.length >= 2) {
65 $scope.searchTerms = $scope.customSearch.split(" ");
66 }else{
67 if(search.length == 0){
68 $scope.searchTerms = [];
69 }
70 }
71 }
72
73 $scope.toggleSeverityAll = function(){
Iftekharul Islamc22425f2017-09-06 10:04:14 -050074 $scope.selectedSeverity.all = !$scope.selectedSeverity.all;
Iftekharul Islamd2269e22017-05-02 09:32:45 -050075
76 if($scope.selectedSeverity.all){
Iftekharul Islam13ac3af2018-03-20 11:15:17 -050077 $scope.selectedSeverity.normal = false;
Iftekharul Islamd2269e22017-05-02 09:32:45 -050078 $scope.selectedSeverity.warning = false;
79 $scope.selectedSeverity.critical = false;
80 }
81 }
82
83 $scope.toggleSeverity = function(severity){
84 $scope.selectedSeverity[severity] = !$scope.selectedSeverity[severity];
85
Iftekharul Islam13ac3af2018-03-20 11:15:17 -050086 if(['normal', 'warning', 'critical'].indexOf(severity) > -1){
Iftekharul Islam96bbf312017-08-22 13:44:38 -050087 if($scope.selectedSeverity[severity] == false &&
Iftekharul Islam13ac3af2018-03-20 11:15:17 -050088 (!$scope.selectedSeverity.normal &&
89 !$scope.selectedSeverity.warning &&
Iftekharul Islam96bbf312017-08-22 13:44:38 -050090 !$scope.selectedSeverity.critical
91 )){
92 $scope.selectedSeverity.all = true;
93 return;
94 }
95 }
96
Iftekharul Islam13ac3af2018-03-20 11:15:17 -050097 if($scope.selectedSeverity.normal &&
98 $scope.selectedSeverity.warning &&
Iftekharul Islamd2269e22017-05-02 09:32:45 -050099 $scope.selectedSeverity.critical){
100 $scope.selectedSeverity.all = true;
Iftekharul Islam13ac3af2018-03-20 11:15:17 -0500101 $scope.selectedSeverity.normal = false;
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500102 $scope.selectedSeverity.warning = false;
103 $scope.selectedSeverity.critical = false;
104 }else{
105 $scope.selectedSeverity.all = false;
106 }
107 }
108
109 $scope.filterBySeverity = function(sensor){
110 if($scope.selectedSeverity.all) return true;
111
112 return( (sensor.severity_flags.normal && $scope.selectedSeverity.normal) ||
113 (sensor.severity_flags.warning && $scope.selectedSeverity.warning) ||
114 (sensor.severity_flags.critical && $scope.selectedSeverity.critical)
115 );
116 }
117 $scope.filterBySearchTerms = function(sensor){
118
Gunnar Millseedefd32018-02-28 17:02:34 -0600119 if(!$scope.searchTerms.length) return true;
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500120
121 for(var i = 0, length = $scope.searchTerms.length; i < length; i++){
122 if(sensor.search_text.indexOf($scope.searchTerms[i].toLowerCase()) == -1) return false;
123 }
124 return true;
125 }
126
127 $scope.loadSensorData = function(){
Michael Davis428375e2017-08-01 15:48:34 -0500128 $scope.loading = true;
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500129 APIUtils.getAllSensorStatus(function(data, originalData){
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500130 $scope.data = data;
131 $scope.originalData = originalData;
Iftekharul Islamc1535922017-06-19 12:49:04 -0500132 dataService.sensorData = data;
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500133 $scope.export_data = JSON.stringify(originalData);
Michael Davis428375e2017-08-01 15:48:34 -0500134 $scope.loading = false;
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500135 });
136 };
137
138 $scope.loadSensorData();
Michael Davis994a93b2017-04-18 10:01:04 -0500139 }
140 ]
141 );
142
Andrew Geisslercf862002018-04-11 12:19:39 -0700143})(angular);