blob: ed74d0404c54b290ffefbf14083955ed52eddf52 [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',
17 '$window',
18 'APIUtils',
19 'dataService',
20 function($scope, $log, $window, APIUtils, dataService, userModel){
21 $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 = [];
28 $scope.selectedSeverity = {
29 all: true,
30 normal: false,
31 warning: false,
32 critical: false
33 };
34 $scope.export_name = "sensors.json";
Michael Davis428375e2017-08-01 15:48:34 -050035 $scope.loading = false;
Iftekharul Islamd2269e22017-05-02 09:32:45 -050036 $scope.jsonData = function(data){
37 var dt = {};
38 data.data.forEach(function(item){
39 dt[item.original_data.key] = item.original_data.value;
40 });
41 return JSON.stringify(dt);
42 };
43
Iftekharul Islam171c6a12017-08-11 08:35:47 -050044 $scope.clear = function(){
45 $scope.customSearch = "";
46 $scope.searchTerms = [];
47 }
48
Iftekharul Islamd2269e22017-05-02 09:32:45 -050049 $scope.doSearchOnEnter = function (event) {
50 var search = $scope.customSearch.replace(/^\s+/g,'').replace(/\s+$/g,'');
51 if (event.keyCode === 13 &&
52 search.length >= 2) {
53 $scope.searchTerms = $scope.customSearch.split(" ");
54 }else{
55 if(search.length == 0){
56 $scope.searchTerms = [];
57 }
58 }
59 };
60
61 $scope.doSearchOnClick = function() {
62 var search = $scope.customSearch.replace(/^\s+/g,'').replace(/\s+$/g,'');
63 if (search.length >= 2) {
64 $scope.searchTerms = $scope.customSearch.split(" ");
65 }else{
66 if(search.length == 0){
67 $scope.searchTerms = [];
68 }
69 }
70 }
71
72 $scope.toggleSeverityAll = function(){
Iftekharul Islamc22425f2017-09-06 10:04:14 -050073 $scope.selectedSeverity.all = !$scope.selectedSeverity.all;
Iftekharul Islamd2269e22017-05-02 09:32:45 -050074
75 if($scope.selectedSeverity.all){
Iftekharul Islamd2269e22017-05-02 09:32:45 -050076 $scope.selectedSeverity.warning = false;
77 $scope.selectedSeverity.critical = false;
78 }
79 }
80
81 $scope.toggleSeverity = function(severity){
82 $scope.selectedSeverity[severity] = !$scope.selectedSeverity[severity];
83
Iftekharul Islam96bbf312017-08-22 13:44:38 -050084 if(['warning', 'critical'].indexOf(severity) > -1){
85 if($scope.selectedSeverity[severity] == false &&
86 (!$scope.selectedSeverity.warning &&
87 !$scope.selectedSeverity.critical
88 )){
89 $scope.selectedSeverity.all = true;
90 return;
91 }
92 }
93
94 if($scope.selectedSeverity.warning &&
Iftekharul Islamd2269e22017-05-02 09:32:45 -050095 $scope.selectedSeverity.critical){
96 $scope.selectedSeverity.all = true;
Iftekharul Islamd2269e22017-05-02 09:32:45 -050097 $scope.selectedSeverity.warning = false;
98 $scope.selectedSeverity.critical = false;
99 }else{
100 $scope.selectedSeverity.all = false;
101 }
102 }
103
104 $scope.filterBySeverity = function(sensor){
105 if($scope.selectedSeverity.all) return true;
106
107 return( (sensor.severity_flags.normal && $scope.selectedSeverity.normal) ||
108 (sensor.severity_flags.warning && $scope.selectedSeverity.warning) ||
109 (sensor.severity_flags.critical && $scope.selectedSeverity.critical)
110 );
111 }
112 $scope.filterBySearchTerms = function(sensor){
113
114 if(!$scope.searchTerms.length) return true;
115
116 for(var i = 0, length = $scope.searchTerms.length; i < length; i++){
117 if(sensor.search_text.indexOf($scope.searchTerms[i].toLowerCase()) == -1) return false;
118 }
119 return true;
120 }
121
122 $scope.loadSensorData = function(){
Michael Davis428375e2017-08-01 15:48:34 -0500123 $scope.loading = true;
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500124 APIUtils.getAllSensorStatus(function(data, originalData){
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500125 $scope.data = data;
126 $scope.originalData = originalData;
Iftekharul Islamc1535922017-06-19 12:49:04 -0500127 dataService.sensorData = data;
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500128 $scope.export_data = JSON.stringify(originalData);
Michael Davis428375e2017-08-01 15:48:34 -0500129 $scope.loading = false;
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500130 });
131 };
132
133 $scope.loadSensorData();
Michael Davis994a93b2017-04-18 10:01:04 -0500134 }
135 ]
136 );
137
Iftekharul Islamcd789502017-04-19 14:37:55 -0500138})(angular);