Michael Davis | 994a93b | 2017-04-18 10:01:04 -0500 | [diff] [blame] | 1 | /** |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 2 | * Controller for sensors-overview |
Michael Davis | 994a93b | 2017-04-18 10:01:04 -0500 | [diff] [blame] | 3 | * |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 4 | * @module app/serverHealth |
| 5 | * @exports sensorsOverviewController |
| 6 | * @name sensorsOverviewController |
Michael Davis | 994a93b | 2017-04-18 10:01:04 -0500 | [diff] [blame] | 7 | * @version 0.1.0 |
| 8 | */ |
| 9 | |
| 10 | window.angular && (function (angular) { |
| 11 | 'use strict'; |
Michael Davis | 994a93b | 2017-04-18 10:01:04 -0500 | [diff] [blame] | 12 | angular |
| 13 | .module('app.overview') |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 14 | .controller('sensorsOverviewController', [ |
Michael Davis | 994a93b | 2017-04-18 10:01:04 -0500 | [diff] [blame] | 15 | '$scope', |
| 16 | '$log', |
Gunnar Mills | eedefd3 | 2018-02-28 17:02:34 -0600 | [diff] [blame] | 17 | '$window', |
| 18 | 'APIUtils', |
Michael Davis | 994a93b | 2017-04-18 10:01:04 -0500 | [diff] [blame] | 19 | 'dataService', |
Iftekharul Islam | 81a49de | 2018-02-08 13:28:09 -0600 | [diff] [blame] | 20 | 'Constants', |
Andrew Geissler | cf86200 | 2018-04-11 12:19:39 -0700 | [diff] [blame] | 21 | function($scope, $log, $window, APIUtils, dataService, Constants){ |
Michael Davis | 994a93b | 2017-04-18 10:01:04 -0500 | [diff] [blame] | 22 | $scope.dataService = dataService; |
| 23 | |
| 24 | $scope.dropdown_selected = false; |
| 25 | |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 26 | $scope.$log = $log; |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 27 | $scope.customSearch = ""; |
| 28 | $scope.searchTerms = []; |
Iftekharul Islam | 81a49de | 2018-02-08 13:28:09 -0600 | [diff] [blame] | 29 | $scope.messages = Constants.MESSAGES.SENSOR; |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 30 | $scope.selectedSeverity = { |
| 31 | all: true, |
| 32 | normal: false, |
| 33 | warning: false, |
| 34 | critical: false |
| 35 | }; |
| 36 | $scope.export_name = "sensors.json"; |
Michael Davis | 428375e | 2017-08-01 15:48:34 -0500 | [diff] [blame] | 37 | $scope.loading = false; |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 38 | $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 Islam | 171c6a1 | 2017-08-11 08:35:47 -0500 | [diff] [blame] | 46 | $scope.clear = function(){ |
| 47 | $scope.customSearch = ""; |
| 48 | $scope.searchTerms = []; |
| 49 | } |
| 50 | |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 51 | $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 Islam | c22425f | 2017-09-06 10:04:14 -0500 | [diff] [blame] | 75 | $scope.selectedSeverity.all = !$scope.selectedSeverity.all; |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 76 | |
| 77 | if($scope.selectedSeverity.all){ |
Iftekharul Islam | 13ac3af | 2018-03-20 11:15:17 -0500 | [diff] [blame^] | 78 | $scope.selectedSeverity.normal = false; |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 79 | $scope.selectedSeverity.warning = false; |
| 80 | $scope.selectedSeverity.critical = false; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | $scope.toggleSeverity = function(severity){ |
| 85 | $scope.selectedSeverity[severity] = !$scope.selectedSeverity[severity]; |
| 86 | |
Iftekharul Islam | 13ac3af | 2018-03-20 11:15:17 -0500 | [diff] [blame^] | 87 | if(['normal', 'warning', 'critical'].indexOf(severity) > -1){ |
Iftekharul Islam | 96bbf31 | 2017-08-22 13:44:38 -0500 | [diff] [blame] | 88 | if($scope.selectedSeverity[severity] == false && |
Iftekharul Islam | 13ac3af | 2018-03-20 11:15:17 -0500 | [diff] [blame^] | 89 | (!$scope.selectedSeverity.normal && |
| 90 | !$scope.selectedSeverity.warning && |
Iftekharul Islam | 96bbf31 | 2017-08-22 13:44:38 -0500 | [diff] [blame] | 91 | !$scope.selectedSeverity.critical |
| 92 | )){ |
| 93 | $scope.selectedSeverity.all = true; |
| 94 | return; |
| 95 | } |
| 96 | } |
| 97 | |
Iftekharul Islam | 13ac3af | 2018-03-20 11:15:17 -0500 | [diff] [blame^] | 98 | if($scope.selectedSeverity.normal && |
| 99 | $scope.selectedSeverity.warning && |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 100 | $scope.selectedSeverity.critical){ |
| 101 | $scope.selectedSeverity.all = true; |
Iftekharul Islam | 13ac3af | 2018-03-20 11:15:17 -0500 | [diff] [blame^] | 102 | $scope.selectedSeverity.normal = false; |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 103 | $scope.selectedSeverity.warning = false; |
| 104 | $scope.selectedSeverity.critical = false; |
| 105 | }else{ |
| 106 | $scope.selectedSeverity.all = false; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | $scope.filterBySeverity = function(sensor){ |
| 111 | if($scope.selectedSeverity.all) return true; |
| 112 | |
| 113 | return( (sensor.severity_flags.normal && $scope.selectedSeverity.normal) || |
| 114 | (sensor.severity_flags.warning && $scope.selectedSeverity.warning) || |
| 115 | (sensor.severity_flags.critical && $scope.selectedSeverity.critical) |
| 116 | ); |
| 117 | } |
| 118 | $scope.filterBySearchTerms = function(sensor){ |
| 119 | |
Gunnar Mills | eedefd3 | 2018-02-28 17:02:34 -0600 | [diff] [blame] | 120 | if(!$scope.searchTerms.length) return true; |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 121 | |
| 122 | for(var i = 0, length = $scope.searchTerms.length; i < length; i++){ |
| 123 | if(sensor.search_text.indexOf($scope.searchTerms[i].toLowerCase()) == -1) return false; |
| 124 | } |
| 125 | return true; |
| 126 | } |
| 127 | |
| 128 | $scope.loadSensorData = function(){ |
Michael Davis | 428375e | 2017-08-01 15:48:34 -0500 | [diff] [blame] | 129 | $scope.loading = true; |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 130 | APIUtils.getAllSensorStatus(function(data, originalData){ |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 131 | $scope.data = data; |
| 132 | $scope.originalData = originalData; |
Iftekharul Islam | c153592 | 2017-06-19 12:49:04 -0500 | [diff] [blame] | 133 | dataService.sensorData = data; |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 134 | $scope.export_data = JSON.stringify(originalData); |
Michael Davis | 428375e | 2017-08-01 15:48:34 -0500 | [diff] [blame] | 135 | $scope.loading = false; |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 136 | }); |
| 137 | }; |
| 138 | |
| 139 | $scope.loadSensorData(); |
Michael Davis | 994a93b | 2017-04-18 10:01:04 -0500 | [diff] [blame] | 140 | } |
| 141 | ] |
| 142 | ); |
| 143 | |
Andrew Geissler | cf86200 | 2018-04-11 12:19:39 -0700 | [diff] [blame] | 144 | })(angular); |