18b4828a6SIftekharul Islam/** 28b4828a6SIftekharul Islam * Controller for log 38b4828a6SIftekharul Islam * 48b4828a6SIftekharul Islam * @module app/serverHealth 58b4828a6SIftekharul Islam * @exports logController 68b4828a6SIftekharul Islam * @name logController 78b4828a6SIftekharul Islam * @version 0.1.0 88b4828a6SIftekharul Islam */ 98b4828a6SIftekharul Islam 108b4828a6SIftekharul Islamwindow.angular && (function (angular) { 118b4828a6SIftekharul Islam 'use strict'; 128b4828a6SIftekharul Islam angular 138b4828a6SIftekharul Islam .module('app.serverHealth') 148b4828a6SIftekharul Islam .controller('logController', [ 158b4828a6SIftekharul Islam '$scope', 168b4828a6SIftekharul Islam '$window', 178b4828a6SIftekharul Islam 'APIUtils', 188b4828a6SIftekharul Islam 'dataService', 198b4828a6SIftekharul Islam 'Constants', 208b4828a6SIftekharul Islam function($scope, $window, APIUtils, dataService, Constants){ 218b4828a6SIftekharul Islam $scope.dataService = dataService; 228b4828a6SIftekharul Islam $scope.logs = []; 238b4828a6SIftekharul Islam $scope.tmz = 'EDT'; 248b4828a6SIftekharul Islam $scope.itemsPerPage = Constants.PAGINATION.LOG_ITEMS_PER_PAGE; 258b4828a6SIftekharul Islam // priority buttons 268b4828a6SIftekharul Islam $scope.selectedSeverity = { 278b4828a6SIftekharul Islam all: true, 288b4828a6SIftekharul Islam low: false, 298b4828a6SIftekharul Islam medium: false, 308b4828a6SIftekharul Islam high: false 318b4828a6SIftekharul Islam }; 328b4828a6SIftekharul Islam $scope.selectedStatus = { 338b4828a6SIftekharul Islam all: true, 348b4828a6SIftekharul Islam resolved: false 358b4828a6SIftekharul Islam }; 368b4828a6SIftekharul Islam 378b4828a6SIftekharul Islam $scope.customSearch = ""; 388b4828a6SIftekharul Islam $scope.searchItems = []; 398b4828a6SIftekharul Islam $scope.selectedEvents = []; 408b4828a6SIftekharul Islam 418b4828a6SIftekharul Islam $scope.loadLogs = function(){ 428b4828a6SIftekharul Islam APIUtils.getLogs(function(data, originalData){ 438b4828a6SIftekharul Islam $scope.logs = data; 448b4828a6SIftekharul Islam $scope.originalData = originalData; 458b4828a6SIftekharul Islam }); 468b4828a6SIftekharul Islam }; 478b4828a6SIftekharul Islam $scope.jsonData = function(data){ 488b4828a6SIftekharul Islam return JSON.stringify(data); 498b4828a6SIftekharul Islam }; 508b4828a6SIftekharul Islam 518b4828a6SIftekharul Islam $scope.filterBySeverity = function(log){ 528b4828a6SIftekharul Islam if($scope.selectedSeverity.all) return true; 538b4828a6SIftekharul Islam 548b4828a6SIftekharul Islam return( (log.severity_flags.low && $scope.selectedSeverity.low) || 558b4828a6SIftekharul Islam (log.severity_flags.medium && $scope.selectedSeverity.medium) || 568b4828a6SIftekharul Islam (log.severity_flags.high && $scope.selectedSeverity.high) 578b4828a6SIftekharul Islam ); 588b4828a6SIftekharul Islam } 598b4828a6SIftekharul Islam 608b4828a6SIftekharul Islam 618b4828a6SIftekharul Islam $scope.filterByStatus = function(log){ 628b4828a6SIftekharul Islam if ($scope.selectedStatus.all) return true; 638b4828a6SIftekharul Islam return( (log.Resolved && $scope.selectedStatus.resolved)|| 648b4828a6SIftekharul Islam (!log.Resolved && !$scope.selectedStatus.resolved) 658b4828a6SIftekharul Islam ); 668b4828a6SIftekharul Islam } 678b4828a6SIftekharul Islam 688b4828a6SIftekharul Islam $scope.filterByDate = function(log){ 698b4828a6SIftekharul Islam if($scope.start_date && $scope.end_date){ 708b4828a6SIftekharul Islam var date = new Date(log.Timestamp); 718b4828a6SIftekharul Islam return (date >= $scope.start_date && 728b4828a6SIftekharul Islam date <= $scope.end_date ); 738b4828a6SIftekharul Islam }else{ 748b4828a6SIftekharul Islam return true; 758b4828a6SIftekharul Islam } 768b4828a6SIftekharul Islam } 778b4828a6SIftekharul Islam 788b4828a6SIftekharul Islam $scope.filterBySearchTerms = function(log){ 798b4828a6SIftekharul Islam if(!$scope.searchItems.length) return true; 808b4828a6SIftekharul Islam 818b4828a6SIftekharul Islam for(var i = 0, length = $scope.searchItems.length; i < length; i++){ 828b4828a6SIftekharul Islam if(log.search_text.indexOf($scope.searchItems[i].toLowerCase()) == -1) return false; 838b4828a6SIftekharul Islam } 848b4828a6SIftekharul Islam return true; 858b4828a6SIftekharul Islam } 868b4828a6SIftekharul Islam 878b4828a6SIftekharul Islam $scope.addSearchItem = function(searchTerms){ 888b4828a6SIftekharul Islam var terms = searchTerms.split(" "); 898b4828a6SIftekharul Islam terms.forEach(function(searchTerm){ 908b4828a6SIftekharul Islam if($scope.searchItems.indexOf(searchTerm) == -1){ 918b4828a6SIftekharul Islam $scope.searchItems.push(searchTerm); 928b4828a6SIftekharul Islam } 938b4828a6SIftekharul Islam }); 948b4828a6SIftekharul Islam } 958b4828a6SIftekharul Islam 968b4828a6SIftekharul Islam $scope.clearSearchItem = function(searchTerm){ 978b4828a6SIftekharul Islam $scope.searchItems = []; 988b4828a6SIftekharul Islam } 998b4828a6SIftekharul Islam 1008b4828a6SIftekharul Islam $scope.removeSearchItem = function(searchTerm){ 1018b4828a6SIftekharul Islam var termIndex = $scope.searchItems.indexOf(searchTerm); 1028b4828a6SIftekharul Islam 1038b4828a6SIftekharul Islam if(termIndex > -1){ 1048b4828a6SIftekharul Islam $scope.searchItems.splice(termIndex,1); 1058b4828a6SIftekharul Islam } 1068b4828a6SIftekharul Islam } 1078b4828a6SIftekharul Islam 1088b4828a6SIftekharul Islam $scope.$watch('all', function(){ 1098b4828a6SIftekharul Islam $scope.logs.forEach(function(item){ 1108b4828a6SIftekharul Islam item.selected = $scope.all; 1118b4828a6SIftekharul Islam }); 1128b4828a6SIftekharul Islam }); 1138b4828a6SIftekharul Islam 1148b4828a6SIftekharul Islam function updateExportData(){ 1158b4828a6SIftekharul Islam $scope.export_name = ($scope.selectedEvents.length == 1) ? $scope.selectedEvents[0].Id + ".json" : "export.json"; 1168b4828a6SIftekharul Islam var data = {}; 1178b4828a6SIftekharul Islam $scope.selectedEvents.forEach(function(item){ 1188b4828a6SIftekharul Islam data[item.data.key] = item.data.value; 1198b4828a6SIftekharul Islam }); 1208b4828a6SIftekharul Islam $scope.export_data = JSON.stringify(data); 1218b4828a6SIftekharul Islam } 1228b4828a6SIftekharul Islam 123*f2d74644SIftekharul Islam 124*f2d74644SIftekharul Islam $scope.accept = function(){ 125*f2d74644SIftekharul Islam APIUtils.deleteLogs($scope.selectedEvents).then(function(){ 126*f2d74644SIftekharul Islam $scope.confirm = false; 127*f2d74644SIftekharul Islam $scope.loadLogs(); 128*f2d74644SIftekharul Islam }); 129*f2d74644SIftekharul Islam } 130*f2d74644SIftekharul Islam 131*f2d74644SIftekharul Islam $scope.resolve = function(){ 132*f2d74644SIftekharul Islam var events = $scope.selectedEvents.filter(function(item){ 133*f2d74644SIftekharul Islam return item.Resolved != 1; 134*f2d74644SIftekharul Islam }); 135*f2d74644SIftekharul Islam 136*f2d74644SIftekharul Islam if(!events.length) return; 137*f2d74644SIftekharul Islam 138*f2d74644SIftekharul Islam APIUtils.resolveLogs(events).then(function(){ 139*f2d74644SIftekharul Islam events.forEach(function(item){ 140*f2d74644SIftekharul Islam item.Resolved = 1; 141*f2d74644SIftekharul Islam }); 142*f2d74644SIftekharul Islam }); 143*f2d74644SIftekharul Islam } 144*f2d74644SIftekharul Islam 1458b4828a6SIftekharul Islam $scope.$watch('logs', function(){ 1468b4828a6SIftekharul Islam $scope.selectedEvents = $scope.logs.filter(function(item){ 1478b4828a6SIftekharul Islam return item.selected; 1488b4828a6SIftekharul Islam }); 1498b4828a6SIftekharul Islam updateExportData(); 1508b4828a6SIftekharul Islam }, true); 1518b4828a6SIftekharul Islam 1528b4828a6SIftekharul Islam $scope.loadLogs(); 1538b4828a6SIftekharul Islam } 1548b4828a6SIftekharul Islam ] 1558b4828a6SIftekharul Islam ); 1568b4828a6SIftekharul Islam 1578b4828a6SIftekharul Islam})(angular); 158