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 */ 8cd789508SIftekharul Islam 9cd789508SIftekharul Islamwindow.angular && (function(angular) { 10cd789508SIftekharul Islam 'use strict'; 11d27bb135SAndrew Geissler angular.module('app.overview').controller('sensorsOverviewController', [ 12*615a2f89SGunnar Mills '$scope', '$log', '$window', 'APIUtils', 'dataService', 'Constants', 13*615a2f89SGunnar Mills function($scope, $log, $window, APIUtils, dataService, Constants) { 14cd789508SIftekharul Islam $scope.dataService = dataService; 15cd789508SIftekharul Islam 16*615a2f89SGunnar Mills $scope.dropdown_selected = false; 17*615a2f89SGunnar Mills 18*615a2f89SGunnar Mills $scope.$log = $log; 19ba5e3f34SAndrew Geissler $scope.customSearch = ''; 20d2269e22SIftekharul Islam $scope.searchTerms = []; 2181a49deaSIftekharul Islam $scope.messages = Constants.MESSAGES.SENSOR; 22d27bb135SAndrew Geissler $scope.selectedSeverity = 23*615a2f89SGunnar Mills {all: true, normal: false, warning: false, critical: false}; 24ba5e3f34SAndrew Geissler $scope.export_name = 'sensors.json'; 25*615a2f89SGunnar Mills $scope.loading = false; 26*615a2f89SGunnar Mills $scope.jsonData = function(data) { 27*615a2f89SGunnar Mills var dt = {}; 28*615a2f89SGunnar Mills data.data.forEach(function(item) { 29*615a2f89SGunnar Mills dt[item.original_data.key] = item.original_data.value; 30*615a2f89SGunnar Mills }); 31*615a2f89SGunnar Mills return JSON.stringify(dt); 32*615a2f89SGunnar Mills }; 33d2269e22SIftekharul Islam 34171c6a1eSIftekharul Islam $scope.clear = function() { 35ba5e3f34SAndrew Geissler $scope.customSearch = ''; 36171c6a1eSIftekharul Islam $scope.searchTerms = []; 37ba5e3f34SAndrew Geissler }; 38171c6a1eSIftekharul Islam 39d2269e22SIftekharul Islam $scope.doSearchOnEnter = function(event) { 40d27bb135SAndrew Geissler var search = 41d27bb135SAndrew Geissler $scope.customSearch.replace(/^\s+/g, '').replace(/\s+$/g, ''); 42d27bb135SAndrew Geissler if (event.keyCode === 13 && search.length >= 2) { 43ba5e3f34SAndrew Geissler $scope.searchTerms = $scope.customSearch.split(' '); 44d27bb135SAndrew Geissler } else { 45d2269e22SIftekharul Islam if (search.length == 0) { 46d2269e22SIftekharul Islam $scope.searchTerms = []; 47d2269e22SIftekharul Islam } 48d2269e22SIftekharul Islam } 49d2269e22SIftekharul Islam }; 50d2269e22SIftekharul Islam 51d2269e22SIftekharul Islam $scope.doSearchOnClick = function() { 52d27bb135SAndrew Geissler var search = 53d27bb135SAndrew Geissler $scope.customSearch.replace(/^\s+/g, '').replace(/\s+$/g, ''); 54d2269e22SIftekharul Islam if (search.length >= 2) { 55ba5e3f34SAndrew Geissler $scope.searchTerms = $scope.customSearch.split(' '); 56d27bb135SAndrew Geissler } else { 57d2269e22SIftekharul Islam if (search.length == 0) { 58d2269e22SIftekharul Islam $scope.searchTerms = []; 59d2269e22SIftekharul Islam } 60d2269e22SIftekharul Islam } 61ba5e3f34SAndrew Geissler }; 62d2269e22SIftekharul Islam 63d2269e22SIftekharul Islam $scope.toggleSeverityAll = function() { 64d2269e22SIftekharul Islam $scope.selectedSeverity.all = !$scope.selectedSeverity.all; 65d2269e22SIftekharul Islam 66d2269e22SIftekharul Islam if ($scope.selectedSeverity.all) { 67*615a2f89SGunnar Mills $scope.selectedSeverity.normal = false; 68d2269e22SIftekharul Islam $scope.selectedSeverity.warning = false; 69d2269e22SIftekharul Islam $scope.selectedSeverity.critical = false; 70d2269e22SIftekharul Islam } 71ba5e3f34SAndrew Geissler }; 72d2269e22SIftekharul Islam 73d2269e22SIftekharul Islam $scope.toggleSeverity = function(severity) { 74d2269e22SIftekharul Islam $scope.selectedSeverity[severity] = !$scope.selectedSeverity[severity]; 75d2269e22SIftekharul Islam 76*615a2f89SGunnar Mills if (['normal', 'warning', 'critical'].indexOf(severity) > -1) { 7796bbf310SIftekharul Islam if ($scope.selectedSeverity[severity] == false && 78*615a2f89SGunnar Mills (!$scope.selectedSeverity.normal && 7913ac3af4SIftekharul Islam !$scope.selectedSeverity.warning && 80d27bb135SAndrew Geissler !$scope.selectedSeverity.critical)) { 8196bbf310SIftekharul Islam $scope.selectedSeverity.all = true; 8296bbf310SIftekharul Islam return; 8396bbf310SIftekharul Islam } 8496bbf310SIftekharul Islam } 8596bbf310SIftekharul Islam 86*615a2f89SGunnar Mills if ($scope.selectedSeverity.normal && $scope.selectedSeverity.warning && 87d2269e22SIftekharul Islam $scope.selectedSeverity.critical) { 88d2269e22SIftekharul Islam $scope.selectedSeverity.all = true; 89*615a2f89SGunnar Mills $scope.selectedSeverity.normal = false; 90d2269e22SIftekharul Islam $scope.selectedSeverity.warning = false; 91d2269e22SIftekharul Islam $scope.selectedSeverity.critical = false; 92d27bb135SAndrew Geissler } else { 93d2269e22SIftekharul Islam $scope.selectedSeverity.all = false; 94d2269e22SIftekharul Islam } 95ba5e3f34SAndrew Geissler }; 96d2269e22SIftekharul Islam 97d2269e22SIftekharul Islam $scope.filterBySeverity = function(sensor) { 98d2269e22SIftekharul Islam if ($scope.selectedSeverity.all) return true; 99d2269e22SIftekharul Islam 100d27bb135SAndrew Geissler return ( 101*615a2f89SGunnar Mills (sensor.severity_flags.normal && $scope.selectedSeverity.normal) || 102*615a2f89SGunnar Mills (sensor.severity_flags.warning && 103d27bb135SAndrew Geissler $scope.selectedSeverity.warning) || 104*615a2f89SGunnar Mills (sensor.severity_flags.critical && 105d27bb135SAndrew Geissler $scope.selectedSeverity.critical)); 106ba5e3f34SAndrew Geissler }; 107d2269e22SIftekharul Islam $scope.filterBySearchTerms = function(sensor) { 108d2269e22SIftekharul Islam if (!$scope.searchTerms.length) return true; 109d2269e22SIftekharul Islam 110d2269e22SIftekharul Islam for (var i = 0, length = $scope.searchTerms.length; i < length; i++) { 111*615a2f89SGunnar Mills if (sensor.search_text.indexOf($scope.searchTerms[i].toLowerCase()) == 112*615a2f89SGunnar Mills -1) 113d27bb135SAndrew Geissler return false; 114d2269e22SIftekharul Islam } 115d2269e22SIftekharul Islam return true; 116ba5e3f34SAndrew Geissler }; 117d2269e22SIftekharul Islam 118d2269e22SIftekharul Islam $scope.loadSensorData = function() { 119428375e8SMichael Davis $scope.loading = true; 120*615a2f89SGunnar Mills APIUtils.getAllSensorStatus(function(data, originalData) { 121*615a2f89SGunnar Mills $scope.data = data; 122*615a2f89SGunnar Mills $scope.originalData = originalData; 123*615a2f89SGunnar Mills $scope.export_data = JSON.stringify(originalData); 124428375e8SMichael Davis $scope.loading = false; 125d2269e22SIftekharul Islam }); 126d2269e22SIftekharul Islam }; 127d2269e22SIftekharul Islam 128d2269e22SIftekharul Islam $scope.loadSensorData(); 129cd789508SIftekharul Islam } 130ba5e3f34SAndrew Geissler ]); 131cd789508SIftekharul Islam})(angular); 132