blob: bd8683398439c39f09526eeb5ff806297e0e2ad7 [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 * @version 0.1.0
8 */
9
10window.angular && (function (angular) {
11 'use strict';
Michael Davis994a93b2017-04-18 10:01:04 -050012 angular
13 .module('app.overview')
Iftekharul Islamcd789502017-04-19 14:37:55 -050014 .controller('sensorsOverviewController', [
Michael Davis994a93b2017-04-18 10:01:04 -050015 '$scope',
16 '$log',
Gunnar Millseedefd32018-02-28 17:02:34 -060017 '$window',
18 'APIUtils',
Michael Davis994a93b2017-04-18 10:01:04 -050019 'dataService',
Iftekharul Islam81a49de2018-02-08 13:28:09 -060020 'Constants',
Andrew Geisslercf862002018-04-11 12:19:39 -070021 function($scope, $log, $window, APIUtils, dataService, Constants){
Michael Davis994a93b2017-04-18 10:01:04 -050022 $scope.dataService = dataService;
23
24 $scope.dropdown_selected = false;
25
Iftekharul Islamcd789502017-04-19 14:37:55 -050026 $scope.$log = $log;
Iftekharul Islamd2269e22017-05-02 09:32:45 -050027 $scope.customSearch = "";
28 $scope.searchTerms = [];
Iftekharul Islam81a49de2018-02-08 13:28:09 -060029 $scope.messages = Constants.MESSAGES.SENSOR;
Iftekharul Islamd2269e22017-05-02 09:32:45 -050030 $scope.selectedSeverity = {
31 all: true,
32 normal: false,
33 warning: false,
34 critical: false
35 };
36 $scope.export_name = "sensors.json";
Michael Davis428375e2017-08-01 15:48:34 -050037 $scope.loading = false;
Iftekharul Islamd2269e22017-05-02 09:32:45 -050038 $scope.jsonData = function(data){
39 var dt = {};
40 data.data.forEach(function(item){
41 dt[item.original_data.key] = item.original_data.value;
42 });
43 return JSON.stringify(dt);
44 };
45
Iftekharul Islam171c6a12017-08-11 08:35:47 -050046 $scope.clear = function(){
47 $scope.customSearch = "";
48 $scope.searchTerms = [];
49 }
50
Iftekharul Islamd2269e22017-05-02 09:32:45 -050051 $scope.doSearchOnEnter = function (event) {
52 var search = $scope.customSearch.replace(/^\s+/g,'').replace(/\s+$/g,'');
53 if (event.keyCode === 13 &&
54 search.length >= 2) {
55 $scope.searchTerms = $scope.customSearch.split(" ");
56 }else{
57 if(search.length == 0){
58 $scope.searchTerms = [];
59 }
60 }
61 };
62
63 $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 }else{
68 if(search.length == 0){
69 $scope.searchTerms = [];
70 }
71 }
72 }
73
74 $scope.toggleSeverityAll = function(){
Iftekharul Islamc22425f2017-09-06 10:04:14 -050075 $scope.selectedSeverity.all = !$scope.selectedSeverity.all;
Iftekharul Islamd2269e22017-05-02 09:32:45 -050076
77 if($scope.selectedSeverity.all){
Iftekharul Islam13ac3af2018-03-20 11:15:17 -050078 $scope.selectedSeverity.normal = false;
Iftekharul Islamd2269e22017-05-02 09:32:45 -050079 $scope.selectedSeverity.warning = false;
80 $scope.selectedSeverity.critical = false;
81 }
82 }
83
84 $scope.toggleSeverity = function(severity){
85 $scope.selectedSeverity[severity] = !$scope.selectedSeverity[severity];
86
Iftekharul Islam13ac3af2018-03-20 11:15:17 -050087 if(['normal', 'warning', 'critical'].indexOf(severity) > -1){
Iftekharul Islam96bbf312017-08-22 13:44:38 -050088 if($scope.selectedSeverity[severity] == false &&
Iftekharul Islam13ac3af2018-03-20 11:15:17 -050089 (!$scope.selectedSeverity.normal &&
90 !$scope.selectedSeverity.warning &&
Iftekharul Islam96bbf312017-08-22 13:44:38 -050091 !$scope.selectedSeverity.critical
92 )){
93 $scope.selectedSeverity.all = true;
94 return;
95 }
96 }
97
Iftekharul Islam13ac3af2018-03-20 11:15:17 -050098 if($scope.selectedSeverity.normal &&
99 $scope.selectedSeverity.warning &&
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500100 $scope.selectedSeverity.critical){
101 $scope.selectedSeverity.all = true;
Iftekharul Islam13ac3af2018-03-20 11:15:17 -0500102 $scope.selectedSeverity.normal = false;
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500103 $scope.selectedSeverity.warning = false;
104 $scope.selectedSeverity.critical = false;
105 }else{
106 $scope.selectedSeverity.all = false;
107 }
108 }
109
110 $scope.filterBySeverity = function(sensor){
111 if($scope.selectedSeverity.all) return true;
112
113 return( (sensor.severity_flags.normal && $scope.selectedSeverity.normal) ||
114 (sensor.severity_flags.warning && $scope.selectedSeverity.warning) ||
115 (sensor.severity_flags.critical && $scope.selectedSeverity.critical)
116 );
117 }
118 $scope.filterBySearchTerms = function(sensor){
119
Gunnar Millseedefd32018-02-28 17:02:34 -0600120 if(!$scope.searchTerms.length) return true;
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500121
122 for(var i = 0, length = $scope.searchTerms.length; i < length; i++){
123 if(sensor.search_text.indexOf($scope.searchTerms[i].toLowerCase()) == -1) return false;
124 }
125 return true;
126 }
127
128 $scope.loadSensorData = function(){
Michael Davis428375e2017-08-01 15:48:34 -0500129 $scope.loading = true;
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500130 APIUtils.getAllSensorStatus(function(data, originalData){
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500131 $scope.data = data;
132 $scope.originalData = originalData;
Iftekharul Islamc1535922017-06-19 12:49:04 -0500133 dataService.sensorData = data;
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500134 $scope.export_data = JSON.stringify(originalData);
Michael Davis428375e2017-08-01 15:48:34 -0500135 $scope.loading = false;
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500136 });
137 };
138
139 $scope.loadSensorData();
Michael Davis994a93b2017-04-18 10:01:04 -0500140 }
141 ]
142 );
143
Andrew Geisslercf862002018-04-11 12:19:39 -0700144})(angular);