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'; |
Iftekharul Islam | d2269e2 | 2017-05-02 09:32:45 -0500 | [diff] [blame] | 12 | var sensorData = [], originalData = {}; |
Michael Davis | 994a93b | 2017-04-18 10:01:04 -0500 | [diff] [blame] | 13 | angular |
| 14 | .module('app.overview') |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 15 | .controller('sensorsOverviewController', [ |
Michael Davis | 994a93b | 2017-04-18 10:01:04 -0500 | [diff] [blame] | 16 | '$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 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 = []; |
| 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 Davis | 994a93b | 2017-04-18 10:01:04 -0500 | [diff] [blame] | 122 | } |
| 123 | ] |
| 124 | ); |
| 125 | |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 126 | })(angular); |