blob: 8c5df7c9175071cf5c8af886671b9d472bfd99cc [file] [log] [blame]
Iftekharul Islam8b4828a2017-04-19 14:37:55 -05001/**
2 * Controller for log
3 *
4 * @module app/serverHealth
5 * @exports logController
6 * @name logController
Iftekharul Islam8b4828a2017-04-19 14:37:55 -05007 */
8
9window.angular && (function (angular) {
10 'use strict';
Iftekharul Islam8b4828a2017-04-19 14:37:55 -050011 angular
12 .module('app.serverHealth')
Ed Tanousbbcf6702017-10-06 13:53:06 -070013 .config(function(paginationTemplateProvider) {
14 paginationTemplateProvider.setString(require('../../common/directives/dirPagination.tpl.html'));
15 })
Iftekharul Islam8b4828a2017-04-19 14:37:55 -050016 .controller('logController', [
Gunnar Millseedefd32018-02-28 17:02:34 -060017 '$scope',
18 '$window',
19 'APIUtils',
Iftekharul Islam8b4828a2017-04-19 14:37:55 -050020 'dataService',
21 'Constants',
Michael Davis428375e2017-08-01 15:48:34 -050022 '$routeParams',
Iftekharul Islam857e78b2017-09-11 11:09:31 -050023 '$filter',
Andrew Geissler4dcc1422018-04-11 12:24:22 -070024 function($scope, $window, APIUtils, dataService, Constants, $routeParams, $filter){
Iftekharul Islam8b4828a2017-04-19 14:37:55 -050025 $scope.dataService = dataService;
26 $scope.logs = [];
27 $scope.tmz = 'EDT';
28 $scope.itemsPerPage = Constants.PAGINATION.LOG_ITEMS_PER_PAGE;
Michael Davis428375e2017-08-01 15:48:34 -050029 $scope.loading = false;
Iftekharul Islam96bbf312017-08-22 13:44:38 -050030 var expandedSelectedIdOnce = false;
Michael Davis428375e2017-08-01 15:48:34 -050031
32 var sensorType = $routeParams.type;
Iftekharul Islam96bbf312017-08-22 13:44:38 -050033 var eventId = $routeParams.id;
Michael Davis428375e2017-08-01 15:48:34 -050034
Iftekharul Islam8b4828a2017-04-19 14:37:55 -050035 // priority buttons
36 $scope.selectedSeverity = {
37 all: true,
38 low: false,
39 medium: false,
40 high: false
41 };
Michael Davis428375e2017-08-01 15:48:34 -050042
43 if(sensorType == 'high'){
44 $scope.selectedSeverity.all = false;
45 $scope.selectedSeverity.high = true;
46 }
47
Iftekharul Islam8b4828a2017-04-19 14:37:55 -050048 $scope.selectedStatus = {
49 all: true,
50 resolved: false
51 };
52
53 $scope.customSearch = "";
54 $scope.searchItems = [];
55 $scope.selectedEvents = [];
56
Iftekharul Islam96bbf312017-08-22 13:44:38 -050057
58 if(eventId){
59 $scope.customSearch = "#"+eventId;
60 $scope.searchItems.push("#"+eventId);
61 }
62
Iftekharul Islam8b4828a2017-04-19 14:37:55 -050063 $scope.loadLogs = function(){
Michael Davis428375e2017-08-01 15:48:34 -050064 $scope.loading = true;
65 APIUtils.getLogs().then(function(result){
Iftekharul Islam96bbf312017-08-22 13:44:38 -050066 if(eventId && expandedSelectedIdOnce == false){
67 var log = result.data.filter(function(item){
68 return item.Id == eventId;
69 });
70
71 if(log.length){
72 log[0].meta = true;
73 }
74 expandedSelectedIdOnce = true;
75 }
Iftekharul Islamc22425f2017-09-06 10:04:14 -050076 dataService.updateServerHealth(result.data);
Michael Davis428375e2017-08-01 15:48:34 -050077 $scope.logs = result.data;
78 $scope.originalData = result.original;
79 $scope.loading = false;
Iftekharul Islam8b4828a2017-04-19 14:37:55 -050080 });
81 };
82 $scope.jsonData = function(data){
83 return JSON.stringify(data);
84 };
85
86 $scope.filterBySeverity = function(log){
87 if($scope.selectedSeverity.all) return true;
88
89 return( (log.severity_flags.low && $scope.selectedSeverity.low) ||
90 (log.severity_flags.medium && $scope.selectedSeverity.medium) ||
91 (log.severity_flags.high && $scope.selectedSeverity.high)
92 );
93 }
94
Iftekharul Islam8b4828a2017-04-19 14:37:55 -050095 $scope.filterByStatus = function(log){
96 if ($scope.selectedStatus.all) return true;
97 return( (log.Resolved && $scope.selectedStatus.resolved)||
98 (!log.Resolved && !$scope.selectedStatus.resolved)
99 );
100 }
101
102 $scope.filterByDate = function(log){
Iftekharul Islam857e78b2017-09-11 11:09:31 -0500103 var endDate;
104 if($scope.end_date && typeof $scope.end_date.getTime === 'function'){
105 endDate = new Date($scope.end_date.getTime());
106 endDate.setTime(endDate.getTime() + 86399000);
107 }
108
109 if($scope.start_date && endDate){
110 var date = new Date($filter('date')(log.Timestamp, 'MM/dd/yyyy HH:mm:ss', $scope.tmz));
Iftekharul Islam8b4828a2017-04-19 14:37:55 -0500111 return (date >= $scope.start_date &&
Iftekharul Islam857e78b2017-09-11 11:09:31 -0500112 date <= endDate );
Iftekharul Islam8b4828a2017-04-19 14:37:55 -0500113 }else{
114 return true;
115 }
116 }
117
118 $scope.filterBySearchTerms = function(log){
Gunnar Millseedefd32018-02-28 17:02:34 -0600119 if(!$scope.searchItems.length) return true;
Iftekharul Islam8b4828a2017-04-19 14:37:55 -0500120
Iftekharul Islam8b4828a2017-04-19 14:37:55 -0500121 for(var i = 0, length = $scope.searchItems.length; i < length; i++){
122 if(log.search_text.indexOf($scope.searchItems[i].toLowerCase()) == -1) return false;
123 }
124 return true;
125 }
126
127 $scope.addSearchItem = function(searchTerms){
128 var terms = searchTerms.split(" ");
129 terms.forEach(function(searchTerm){
130 if($scope.searchItems.indexOf(searchTerm) == -1){
131 $scope.searchItems.push(searchTerm);
Gunnar Millseedefd32018-02-28 17:02:34 -0600132 }
Iftekharul Islam8b4828a2017-04-19 14:37:55 -0500133 });
134 }
135
136 $scope.clearSearchItem = function(searchTerm){
137 $scope.searchItems = [];
138 }
139
140 $scope.removeSearchItem = function(searchTerm){
141 var termIndex = $scope.searchItems.indexOf(searchTerm);
142
143 if(termIndex > -1){
144 $scope.searchItems.splice(termIndex,1);
145 }
146 }
147
148 $scope.$watch('all', function(){
149 $scope.logs.forEach(function(item){
150 item.selected = $scope.all;
151 });
152 });
153
154 function updateExportData(){
155 $scope.export_name = ($scope.selectedEvents.length == 1) ? $scope.selectedEvents[0].Id + ".json" : "export.json";
156 var data = {};
157 $scope.selectedEvents.forEach(function(item){
158 data[item.data.key] = item.data.value;
159 });
160 $scope.export_data = JSON.stringify(data);
161 }
162
Iftekharul Islamf2d74642017-07-10 16:42:14 -0500163
164 $scope.accept = function(){
165 APIUtils.deleteLogs($scope.selectedEvents).then(function(){
166 $scope.confirm = false;
167 $scope.loadLogs();
168 });
169 }
170
171 $scope.resolve = function(){
172 var events = $scope.selectedEvents.filter(function(item){
173 return item.Resolved != 1;
174 });
175
176 if(!events.length) return;
177
178 APIUtils.resolveLogs(events).then(function(){
179 events.forEach(function(item){
180 item.Resolved = 1;
181 });
182 });
183 }
184
Iftekharul Islam8b4828a2017-04-19 14:37:55 -0500185 $scope.$watch('logs', function(){
186 $scope.selectedEvents = $scope.logs.filter(function(item){
187 return item.selected;
188 });
189 updateExportData();
190 }, true);
191
192 $scope.loadLogs();
Iftekharul Islam8b4828a2017-04-19 14:37:55 -0500193 }
194 ]
195 );
196
197})(angular);