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'; 11*d27bb135SAndrew Geissler angular.module('app.overview').controller('sensorsOverviewController', [ 12*d27bb135SAndrew Geissler '$scope', '$log', '$window', 'APIUtils', 'dataService', 'Constants', 13cf862007SAndrew Geissler function($scope, $log, $window, APIUtils, dataService, Constants) { 14cd789508SIftekharul Islam $scope.dataService = dataService; 15cd789508SIftekharul Islam 16cd789508SIftekharul Islam $scope.dropdown_selected = false; 17cd789508SIftekharul Islam 18cd789508SIftekharul Islam $scope.$log = $log; 19ba5e3f34SAndrew Geissler $scope.customSearch = ''; 20d2269e22SIftekharul Islam $scope.searchTerms = []; 2181a49deaSIftekharul Islam $scope.messages = Constants.MESSAGES.SENSOR; 22*d27bb135SAndrew Geissler $scope.selectedSeverity = 23*d27bb135SAndrew Geissler {all: true, normal: false, warning: false, critical: false}; 24ba5e3f34SAndrew Geissler $scope.export_name = 'sensors.json'; 25428375e8SMichael Davis $scope.loading = false; 26d2269e22SIftekharul Islam $scope.jsonData = function(data) { 27d2269e22SIftekharul Islam var dt = {}; 28d2269e22SIftekharul Islam data.data.forEach(function(item) { 29d2269e22SIftekharul Islam dt[item.original_data.key] = item.original_data.value; 30d2269e22SIftekharul Islam }); 31d2269e22SIftekharul Islam return JSON.stringify(dt); 32d2269e22SIftekharul Islam }; 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) { 40*d27bb135SAndrew Geissler var search = 41*d27bb135SAndrew Geissler $scope.customSearch.replace(/^\s+/g, '').replace(/\s+$/g, ''); 42*d27bb135SAndrew Geissler if (event.keyCode === 13 && search.length >= 2) { 43ba5e3f34SAndrew Geissler $scope.searchTerms = $scope.customSearch.split(' '); 44*d27bb135SAndrew 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() { 52*d27bb135SAndrew Geissler var search = 53*d27bb135SAndrew Geissler $scope.customSearch.replace(/^\s+/g, '').replace(/\s+$/g, ''); 54d2269e22SIftekharul Islam if (search.length >= 2) { 55ba5e3f34SAndrew Geissler $scope.searchTerms = $scope.customSearch.split(' '); 56*d27bb135SAndrew 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) { 6713ac3af4SIftekharul Islam $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 7613ac3af4SIftekharul Islam if (['normal', 'warning', 'critical'].indexOf(severity) > -1) { 7796bbf310SIftekharul Islam if ($scope.selectedSeverity[severity] == false && 7813ac3af4SIftekharul Islam (!$scope.selectedSeverity.normal && 7913ac3af4SIftekharul Islam !$scope.selectedSeverity.warning && 80*d27bb135SAndrew Geissler !$scope.selectedSeverity.critical)) { 8196bbf310SIftekharul Islam $scope.selectedSeverity.all = true; 8296bbf310SIftekharul Islam return; 8396bbf310SIftekharul Islam } 8496bbf310SIftekharul Islam } 8596bbf310SIftekharul Islam 86*d27bb135SAndrew Geissler if ($scope.selectedSeverity.normal && $scope.selectedSeverity.warning && 87d2269e22SIftekharul Islam $scope.selectedSeverity.critical) { 88d2269e22SIftekharul Islam $scope.selectedSeverity.all = true; 8913ac3af4SIftekharul Islam $scope.selectedSeverity.normal = false; 90d2269e22SIftekharul Islam $scope.selectedSeverity.warning = false; 91d2269e22SIftekharul Islam $scope.selectedSeverity.critical = false; 92*d27bb135SAndrew 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 100*d27bb135SAndrew Geissler return ( 101*d27bb135SAndrew Geissler (sensor.severity_flags.normal && $scope.selectedSeverity.normal) || 102*d27bb135SAndrew Geissler (sensor.severity_flags.warning && 103*d27bb135SAndrew Geissler $scope.selectedSeverity.warning) || 104*d27bb135SAndrew Geissler (sensor.severity_flags.critical && 105*d27bb135SAndrew Geissler $scope.selectedSeverity.critical)); 106ba5e3f34SAndrew Geissler }; 107d2269e22SIftekharul Islam $scope.filterBySearchTerms = function(sensor) { 108d2269e22SIftekharul Islam 109d2269e22SIftekharul Islam if (!$scope.searchTerms.length) return true; 110d2269e22SIftekharul Islam 111d2269e22SIftekharul Islam for (var i = 0, length = $scope.searchTerms.length; i < length; i++) { 112*d27bb135SAndrew Geissler if (sensor.search_text.indexOf($scope.searchTerms[i].toLowerCase()) == 113*d27bb135SAndrew Geissler -1) 114*d27bb135SAndrew Geissler return false; 115d2269e22SIftekharul Islam } 116d2269e22SIftekharul Islam return true; 117ba5e3f34SAndrew Geissler }; 118d2269e22SIftekharul Islam 119d2269e22SIftekharul Islam $scope.loadSensorData = function() { 120428375e8SMichael Davis $scope.loading = true; 121d2269e22SIftekharul Islam APIUtils.getAllSensorStatus(function(data, originalData) { 122d2269e22SIftekharul Islam $scope.data = data; 123d2269e22SIftekharul Islam $scope.originalData = originalData; 124c1535926SIftekharul Islam dataService.sensorData = data; 125d2269e22SIftekharul Islam $scope.export_data = JSON.stringify(originalData); 126428375e8SMichael Davis $scope.loading = false; 127d2269e22SIftekharul Islam }); 128d2269e22SIftekharul Islam }; 129d2269e22SIftekharul Islam 130d2269e22SIftekharul Islam $scope.loadSensorData(); 131cd789508SIftekharul Islam } 132ba5e3f34SAndrew Geissler ]); 133cd789508SIftekharul Islam 134cd789508SIftekharul Islam})(angular); 135