blob: d68b31f5722e66497230f1fbaca56765ae32aee6 [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";
35 $scope.jsonData = function(data){
36 var dt = {};
37 data.data.forEach(function(item){
38 dt[item.original_data.key] = item.original_data.value;
39 });
40 return JSON.stringify(dt);
41 };
42
43 $scope.doSearchOnEnter = function (event) {
44 var search = $scope.customSearch.replace(/^\s+/g,'').replace(/\s+$/g,'');
45 if (event.keyCode === 13 &&
46 search.length >= 2) {
47 $scope.searchTerms = $scope.customSearch.split(" ");
48 }else{
49 if(search.length == 0){
50 $scope.searchTerms = [];
51 }
52 }
53 };
54
55 $scope.doSearchOnClick = function() {
56 var search = $scope.customSearch.replace(/^\s+/g,'').replace(/\s+$/g,'');
57 if (search.length >= 2) {
58 $scope.searchTerms = $scope.customSearch.split(" ");
59 }else{
60 if(search.length == 0){
61 $scope.searchTerms = [];
62 }
63 }
64 }
65
66 $scope.toggleSeverityAll = function(){
Iftekharul Islam8947e702017-07-27 10:28:07 -050067
68 if($scope.selectedSeverity.all !== true){
69 $scope.selectedSeverity.all = !$scope.selectedSeverity.all;
70 }
Iftekharul Islamd2269e22017-05-02 09:32:45 -050071
72 if($scope.selectedSeverity.all){
73 $scope.selectedSeverity.normal = false;
74 $scope.selectedSeverity.warning = false;
75 $scope.selectedSeverity.critical = false;
76 }
77 }
78
79 $scope.toggleSeverity = function(severity){
80 $scope.selectedSeverity[severity] = !$scope.selectedSeverity[severity];
81
82 if($scope.selectedSeverity.normal &&
83 $scope.selectedSeverity.warning &&
84 $scope.selectedSeverity.critical){
85 $scope.selectedSeverity.all = true;
86 $scope.selectedSeverity.normal = false;
87 $scope.selectedSeverity.warning = false;
88 $scope.selectedSeverity.critical = false;
89 }else{
90 $scope.selectedSeverity.all = false;
91 }
92 }
93
94 $scope.filterBySeverity = function(sensor){
95 if($scope.selectedSeverity.all) return true;
96
97 return( (sensor.severity_flags.normal && $scope.selectedSeverity.normal) ||
98 (sensor.severity_flags.warning && $scope.selectedSeverity.warning) ||
99 (sensor.severity_flags.critical && $scope.selectedSeverity.critical)
100 );
101 }
102 $scope.filterBySearchTerms = function(sensor){
103
104 if(!$scope.searchTerms.length) return true;
105
106 for(var i = 0, length = $scope.searchTerms.length; i < length; i++){
107 if(sensor.search_text.indexOf($scope.searchTerms[i].toLowerCase()) == -1) return false;
108 }
109 return true;
110 }
111
112 $scope.loadSensorData = function(){
113 APIUtils.getAllSensorStatus(function(data, originalData){
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500114 $scope.data = data;
115 $scope.originalData = originalData;
Iftekharul Islamc1535922017-06-19 12:49:04 -0500116 dataService.sensorData = data;
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500117 $scope.export_data = JSON.stringify(originalData);
118 });
119 };
120
121 $scope.loadSensorData();
Michael Davis994a93b2017-04-18 10:01:04 -0500122 }
123 ]
124 );
125
Iftekharul Islamcd789502017-04-19 14:37:55 -0500126})(angular);