blob: 1e53829b71d785c002ddbffdc118437a4d9d6d7e [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';
Iftekharul Islamd2269e22017-05-02 09:32:45 -050012 var sensorData = [], originalData = {};
Michael Davis994a93b2017-04-18 10:01:04 -050013 angular
14 .module('app.overview')
Iftekharul Islamcd789502017-04-19 14:37:55 -050015 .controller('sensorsOverviewController', [
Michael Davis994a93b2017-04-18 10:01:04 -050016 '$scope',
17 '$log',
18 '$window',
19 'APIUtils',
20 'dataService',
21 function($scope, $log, $window, APIUtils, dataService, userModel){
22 $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 = [];
29 $scope.selectedSeverity = {
30 all: true,
31 normal: false,
32 warning: false,
33 critical: false
34 };
35 $scope.export_name = "sensors.json";
36 $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
44 $scope.doSearchOnEnter = function (event) {
45 var search = $scope.customSearch.replace(/^\s+/g,'').replace(/\s+$/g,'');
46 if (event.keyCode === 13 &&
47 search.length >= 2) {
48 $scope.searchTerms = $scope.customSearch.split(" ");
49 }else{
50 if(search.length == 0){
51 $scope.searchTerms = [];
52 }
53 }
54 };
55
56 $scope.doSearchOnClick = function() {
57 var search = $scope.customSearch.replace(/^\s+/g,'').replace(/\s+$/g,'');
58 if (search.length >= 2) {
59 $scope.searchTerms = $scope.customSearch.split(" ");
60 }else{
61 if(search.length == 0){
62 $scope.searchTerms = [];
63 }
64 }
65 }
66
67 $scope.toggleSeverityAll = function(){
68 $scope.selectedSeverity.all = !$scope.selectedSeverity.all;
69
70 if($scope.selectedSeverity.all){
71 $scope.selectedSeverity.normal = false;
72 $scope.selectedSeverity.warning = false;
73 $scope.selectedSeverity.critical = false;
74 }
75 }
76
77 $scope.toggleSeverity = function(severity){
78 $scope.selectedSeverity[severity] = !$scope.selectedSeverity[severity];
79
80 if($scope.selectedSeverity.normal &&
81 $scope.selectedSeverity.warning &&
82 $scope.selectedSeverity.critical){
83 $scope.selectedSeverity.all = true;
84 $scope.selectedSeverity.normal = false;
85 $scope.selectedSeverity.warning = false;
86 $scope.selectedSeverity.critical = false;
87 }else{
88 $scope.selectedSeverity.all = false;
89 }
90 }
91
92 $scope.filterBySeverity = function(sensor){
93 if($scope.selectedSeverity.all) return true;
94
95 return( (sensor.severity_flags.normal && $scope.selectedSeverity.normal) ||
96 (sensor.severity_flags.warning && $scope.selectedSeverity.warning) ||
97 (sensor.severity_flags.critical && $scope.selectedSeverity.critical)
98 );
99 }
100 $scope.filterBySearchTerms = function(sensor){
101
102 if(!$scope.searchTerms.length) return true;
103
104 for(var i = 0, length = $scope.searchTerms.length; i < length; i++){
105 if(sensor.search_text.indexOf($scope.searchTerms[i].toLowerCase()) == -1) return false;
106 }
107 return true;
108 }
109
110 $scope.loadSensorData = function(){
111 APIUtils.getAllSensorStatus(function(data, originalData){
112 sensorData = data;
113 originalData = originalData;
114 $scope.data = data;
115 $scope.originalData = originalData;
116 dataService.sensorData = sensorData;
117 $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);