blob: 213a4e3afd3f4351c554c8a71e660924f65835cd [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(){
67 $scope.selectedSeverity.all = !$scope.selectedSeverity.all;
68
69 if($scope.selectedSeverity.all){
70 $scope.selectedSeverity.normal = false;
71 $scope.selectedSeverity.warning = false;
72 $scope.selectedSeverity.critical = false;
73 }
74 }
75
76 $scope.toggleSeverity = function(severity){
77 $scope.selectedSeverity[severity] = !$scope.selectedSeverity[severity];
78
79 if($scope.selectedSeverity.normal &&
80 $scope.selectedSeverity.warning &&
81 $scope.selectedSeverity.critical){
82 $scope.selectedSeverity.all = true;
83 $scope.selectedSeverity.normal = false;
84 $scope.selectedSeverity.warning = false;
85 $scope.selectedSeverity.critical = false;
86 }else{
87 $scope.selectedSeverity.all = false;
88 }
89 }
90
91 $scope.filterBySeverity = function(sensor){
92 if($scope.selectedSeverity.all) return true;
93
94 return( (sensor.severity_flags.normal && $scope.selectedSeverity.normal) ||
95 (sensor.severity_flags.warning && $scope.selectedSeverity.warning) ||
96 (sensor.severity_flags.critical && $scope.selectedSeverity.critical)
97 );
98 }
99 $scope.filterBySearchTerms = function(sensor){
100
101 if(!$scope.searchTerms.length) return true;
102
103 for(var i = 0, length = $scope.searchTerms.length; i < length; i++){
104 if(sensor.search_text.indexOf($scope.searchTerms[i].toLowerCase()) == -1) return false;
105 }
106 return true;
107 }
108
109 $scope.loadSensorData = function(){
110 APIUtils.getAllSensorStatus(function(data, originalData){
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500111 $scope.data = data;
112 $scope.originalData = originalData;
Iftekharul Islamc1535922017-06-19 12:49:04 -0500113 dataService.sensorData = data;
Iftekharul Islamd2269e22017-05-02 09:32:45 -0500114 $scope.export_data = JSON.stringify(originalData);
115 });
116 };
117
118 $scope.loadSensorData();
Michael Davis994a93b2017-04-18 10:01:04 -0500119 }
120 ]
121 );
122
Iftekharul Islamcd789502017-04-19 14:37:55 -0500123})(angular);