1cd789508SIftekharul Islam/** 2cd789508SIftekharul Islam * Controller for sensors-overview 3cd789508SIftekharul Islam * 4cd789508SIftekharul Islam * @module app/serverHealth 5cd789508SIftekharul Islam * @exports sensorsOverviewController 6cd789508SIftekharul Islam * @name sensorsOverviewController 7cd789508SIftekharul Islam * @version 0.1.0 8cd789508SIftekharul Islam */ 9cd789508SIftekharul Islam 10cd789508SIftekharul Islamwindow.angular && (function (angular) { 11cd789508SIftekharul Islam 'use strict'; 12cd789508SIftekharul Islam angular 13cd789508SIftekharul Islam .module('app.overview') 14cd789508SIftekharul Islam .controller('sensorsOverviewController', [ 15cd789508SIftekharul Islam '$scope', 16cd789508SIftekharul Islam '$log', 17cd789508SIftekharul Islam '$window', 18cd789508SIftekharul Islam 'APIUtils', 19cd789508SIftekharul Islam 'dataService', 20*81a49deaSIftekharul Islam 'Constants', 21*81a49deaSIftekharul Islam function($scope, $log, $window, APIUtils, dataService, Constants){ 22cd789508SIftekharul Islam $scope.dataService = dataService; 23cd789508SIftekharul Islam 24cd789508SIftekharul Islam $scope.dropdown_selected = false; 25cd789508SIftekharul Islam 26cd789508SIftekharul Islam $scope.$log = $log; 27d2269e22SIftekharul Islam $scope.customSearch = ""; 28d2269e22SIftekharul Islam $scope.searchTerms = []; 29*81a49deaSIftekharul Islam $scope.messages = Constants.MESSAGES.SENSOR; 30d2269e22SIftekharul Islam $scope.selectedSeverity = { 31d2269e22SIftekharul Islam all: true, 32d2269e22SIftekharul Islam normal: false, 33d2269e22SIftekharul Islam warning: false, 34d2269e22SIftekharul Islam critical: false 35d2269e22SIftekharul Islam }; 36d2269e22SIftekharul Islam $scope.export_name = "sensors.json"; 37428375e8SMichael Davis $scope.loading = false; 38d2269e22SIftekharul Islam $scope.jsonData = function(data){ 39d2269e22SIftekharul Islam var dt = {}; 40d2269e22SIftekharul Islam data.data.forEach(function(item){ 41d2269e22SIftekharul Islam dt[item.original_data.key] = item.original_data.value; 42d2269e22SIftekharul Islam }); 43d2269e22SIftekharul Islam return JSON.stringify(dt); 44d2269e22SIftekharul Islam }; 45d2269e22SIftekharul Islam 46171c6a1eSIftekharul Islam $scope.clear = function(){ 47171c6a1eSIftekharul Islam $scope.customSearch = ""; 48171c6a1eSIftekharul Islam $scope.searchTerms = []; 49171c6a1eSIftekharul Islam } 50171c6a1eSIftekharul Islam 51d2269e22SIftekharul Islam $scope.doSearchOnEnter = function (event) { 52d2269e22SIftekharul Islam var search = $scope.customSearch.replace(/^\s+/g,'').replace(/\s+$/g,''); 53d2269e22SIftekharul Islam if (event.keyCode === 13 && 54d2269e22SIftekharul Islam search.length >= 2) { 55d2269e22SIftekharul Islam $scope.searchTerms = $scope.customSearch.split(" "); 56d2269e22SIftekharul Islam }else{ 57d2269e22SIftekharul Islam if(search.length == 0){ 58d2269e22SIftekharul Islam $scope.searchTerms = []; 59d2269e22SIftekharul Islam } 60d2269e22SIftekharul Islam } 61d2269e22SIftekharul Islam }; 62d2269e22SIftekharul Islam 63d2269e22SIftekharul Islam $scope.doSearchOnClick = function() { 64d2269e22SIftekharul Islam var search = $scope.customSearch.replace(/^\s+/g,'').replace(/\s+$/g,''); 65d2269e22SIftekharul Islam if (search.length >= 2) { 66d2269e22SIftekharul Islam $scope.searchTerms = $scope.customSearch.split(" "); 67d2269e22SIftekharul Islam }else{ 68d2269e22SIftekharul Islam if(search.length == 0){ 69d2269e22SIftekharul Islam $scope.searchTerms = []; 70d2269e22SIftekharul Islam } 71d2269e22SIftekharul Islam } 72d2269e22SIftekharul Islam } 73d2269e22SIftekharul Islam 74d2269e22SIftekharul Islam $scope.toggleSeverityAll = function(){ 75d2269e22SIftekharul Islam $scope.selectedSeverity.all = !$scope.selectedSeverity.all; 76d2269e22SIftekharul Islam 77d2269e22SIftekharul Islam if($scope.selectedSeverity.all){ 78d2269e22SIftekharul Islam $scope.selectedSeverity.warning = false; 79d2269e22SIftekharul Islam $scope.selectedSeverity.critical = false; 80d2269e22SIftekharul Islam } 81d2269e22SIftekharul Islam } 82d2269e22SIftekharul Islam 83d2269e22SIftekharul Islam $scope.toggleSeverity = function(severity){ 84d2269e22SIftekharul Islam $scope.selectedSeverity[severity] = !$scope.selectedSeverity[severity]; 85d2269e22SIftekharul Islam 8696bbf310SIftekharul Islam if(['warning', 'critical'].indexOf(severity) > -1){ 8796bbf310SIftekharul Islam if($scope.selectedSeverity[severity] == false && 8896bbf310SIftekharul Islam (!$scope.selectedSeverity.warning && 8996bbf310SIftekharul Islam !$scope.selectedSeverity.critical 9096bbf310SIftekharul Islam )){ 9196bbf310SIftekharul Islam $scope.selectedSeverity.all = true; 9296bbf310SIftekharul Islam return; 9396bbf310SIftekharul Islam } 9496bbf310SIftekharul Islam } 9596bbf310SIftekharul Islam 9696bbf310SIftekharul Islam if($scope.selectedSeverity.warning && 97d2269e22SIftekharul Islam $scope.selectedSeverity.critical){ 98d2269e22SIftekharul Islam $scope.selectedSeverity.all = true; 99d2269e22SIftekharul Islam $scope.selectedSeverity.warning = false; 100d2269e22SIftekharul Islam $scope.selectedSeverity.critical = false; 101d2269e22SIftekharul Islam }else{ 102d2269e22SIftekharul Islam $scope.selectedSeverity.all = false; 103d2269e22SIftekharul Islam } 104d2269e22SIftekharul Islam } 105d2269e22SIftekharul Islam 106d2269e22SIftekharul Islam $scope.filterBySeverity = function(sensor){ 107d2269e22SIftekharul Islam if($scope.selectedSeverity.all) return true; 108d2269e22SIftekharul Islam 109d2269e22SIftekharul Islam return( (sensor.severity_flags.normal && $scope.selectedSeverity.normal) || 110d2269e22SIftekharul Islam (sensor.severity_flags.warning && $scope.selectedSeverity.warning) || 111d2269e22SIftekharul Islam (sensor.severity_flags.critical && $scope.selectedSeverity.critical) 112d2269e22SIftekharul Islam ); 113d2269e22SIftekharul Islam } 114d2269e22SIftekharul Islam $scope.filterBySearchTerms = function(sensor){ 115d2269e22SIftekharul Islam 116d2269e22SIftekharul Islam if(!$scope.searchTerms.length) return true; 117d2269e22SIftekharul Islam 118d2269e22SIftekharul Islam for(var i = 0, length = $scope.searchTerms.length; i < length; i++){ 119d2269e22SIftekharul Islam if(sensor.search_text.indexOf($scope.searchTerms[i].toLowerCase()) == -1) return false; 120d2269e22SIftekharul Islam } 121d2269e22SIftekharul Islam return true; 122d2269e22SIftekharul Islam } 123d2269e22SIftekharul Islam 124d2269e22SIftekharul Islam $scope.loadSensorData = function(){ 125428375e8SMichael Davis $scope.loading = true; 126d2269e22SIftekharul Islam APIUtils.getAllSensorStatus(function(data, originalData){ 127d2269e22SIftekharul Islam $scope.data = data; 128d2269e22SIftekharul Islam $scope.originalData = originalData; 129c1535926SIftekharul Islam dataService.sensorData = data; 130d2269e22SIftekharul Islam $scope.export_data = JSON.stringify(originalData); 131428375e8SMichael Davis $scope.loading = false; 132d2269e22SIftekharul Islam }); 133d2269e22SIftekharul Islam }; 134d2269e22SIftekharul Islam 135d2269e22SIftekharul Islam $scope.loadSensorData(); 136cd789508SIftekharul Islam } 137cd789508SIftekharul Islam ] 138cd789508SIftekharul Islam ); 139cd789508SIftekharul Islam 140cd789508SIftekharul Islam})(angular);