blob: 04502caa687d00a95b34747fbee6fe6c61a00a56 [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 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 Islam96bbf312017-08-22 13:44:38 -050086 if(['warning', 'critical'].indexOf(severity) > -1){
87 if($scope.selectedSeverity[severity] == false &&
88 (!$scope.selectedSeverity.warning &&
89 !$scope.selectedSeverity.critical
90 )){
91 $scope.selectedSeverity.all = true;
92 return;
93 }
94 }
95
Gunnar Millseedefd32018-02-28 17:02:34 -060096 if($scope.selectedSeverity.warning &&
Iftekharul Islamd2269e22017-05-02 09:32:45 -050097 $scope.selectedSeverity.critical){
98 $scope.selectedSeverity.all = true;
Iftekharul Islamd2269e22017-05-02 09:32:45 -050099 $scope.selectedSeverity.warning = false;
100 $scope.selectedSeverity.critical = false;
101 }else{
102 $scope.selectedSeverity.all = false;
103 }
104 }
105
106 $scope.filterBySeverity = function(sensor){
107 if($scope.selectedSeverity.all) return true;
108
109 return( (sensor.severity_flags.normal && $scope.selectedSeverity.normal) ||
110 (sensor.severity_flags.warning && $scope.selectedSeverity.warning) ||
111 (sensor.severity_flags.critical && $scope.selectedSeverity.critical)
112 );
113 }
114 $scope.filterBySearchTerms = function(sensor){
115
Gunnar Millseedefd32018-02-28 17:02:34 -0600116 if(!$scope.searchTerms.length) return true;
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500117
118 for(var i = 0, length = $scope.searchTerms.length; i < length; i++){
119 if(sensor.search_text.indexOf($scope.searchTerms[i].toLowerCase()) == -1) return false;
120 }
121 return true;
122 }
123
124 $scope.loadSensorData = function(){
Michael Davis428375e2017-08-01 15:48:34 -0500125 $scope.loading = true;
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500126 APIUtils.getAllSensorStatus(function(data, originalData){
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500127 $scope.data = data;
128 $scope.originalData = originalData;
Iftekharul Islamc1535922017-06-19 12:49:04 -0500129 dataService.sensorData = data;
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500130 $scope.export_data = JSON.stringify(originalData);
Michael Davis428375e2017-08-01 15:48:34 -0500131 $scope.loading = false;
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500132 });
133 };
134
135 $scope.loadSensorData();
Michael Davis994a93b2017-04-18 10:01:04 -0500136 }
137 ]
138 );
139
Andrew Geisslercf862002018-04-11 12:19:39 -0700140})(angular);