blob: 5e6db6dfcad9744c39873cf2bb1d5c40ea5b7b89 [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
Andrew Geisslerba5e3f32018-05-24 10:58:00 -07009window.angular && (function(angular) {
10 'use strict';
Andrew Geisslerd27bb132018-05-24 11:07:27 -070011 angular.module('app.serverHealth')
Ed Tanous26539862018-08-15 16:16:37 -070012 .config([
13 'paginationTemplateProvider',
14 function(paginationTemplateProvider) {
15 paginationTemplateProvider.setString(
16 require('../../common/directives/dirPagination.tpl.html'));
17 }
18 ])
Andrew Geisslerd27bb132018-05-24 11:07:27 -070019 .controller('logController', [
20 '$scope', '$window', 'APIUtils', 'dataService', 'Constants',
21 '$routeParams', '$filter',
22 function(
23 $scope, $window, APIUtils, dataService, Constants, $routeParams,
24 $filter) {
25 $scope.dataService = dataService;
26 $scope.logs = [];
Gunnar Millsa4ae7db2018-09-06 16:47:01 -050027 $scope.filteredLogs = [];
Andrew Geisslerd27bb132018-05-24 11:07:27 -070028 $scope.tmz = 'EDT';
29 $scope.itemsPerPage = Constants.PAGINATION.LOG_ITEMS_PER_PAGE;
30 $scope.loading = false;
31 var expandedSelectedIdOnce = false;
Michael Davis428375e2017-08-01 15:48:34 -050032
Andrew Geisslerd27bb132018-05-24 11:07:27 -070033 var sensorType = $routeParams.type;
34 var eventId = $routeParams.id;
Michael Davis428375e2017-08-01 15:48:34 -050035
Andrew Geisslerd27bb132018-05-24 11:07:27 -070036 // priority buttons
37 $scope.selectedSeverity =
38 {all: true, low: false, medium: false, high: false};
Michael Davis428375e2017-08-01 15:48:34 -050039
Andrew Geisslerd27bb132018-05-24 11:07:27 -070040 if (sensorType == 'high') {
41 $scope.selectedSeverity.all = false;
42 $scope.selectedSeverity.high = true;
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070043 }
44
Andrew Geisslerd27bb132018-05-24 11:07:27 -070045 $scope.selectedStatus = {all: true, resolved: false};
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070046
Andrew Geisslerd27bb132018-05-24 11:07:27 -070047 $scope.customSearch = '';
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070048 $scope.searchItems = [];
Andrew Geisslerd27bb132018-05-24 11:07:27 -070049 $scope.selectedEvents = [];
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070050
Andrew Geisslerd27bb132018-05-24 11:07:27 -070051 if (eventId) {
52 $scope.customSearch = '#' + eventId;
53 $scope.searchItems.push('#' + eventId);
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070054 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070055
Andrew Geisslerd27bb132018-05-24 11:07:27 -070056 $scope.loadLogs = function() {
57 $scope.loading = true;
58 APIUtils.getLogs().then(function(result) {
59 if (eventId && expandedSelectedIdOnce == false) {
60 var log = result.data.filter(function(item) {
61 return item.Id == eventId;
62 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070063
Andrew Geisslerd27bb132018-05-24 11:07:27 -070064 if (log.length) {
65 log[0].meta = true;
66 }
67 expandedSelectedIdOnce = true;
68 }
69 dataService.updateServerHealth(result.data);
70 $scope.logs = result.data;
71 $scope.originalData = result.original;
72 $scope.loading = false;
73 });
74 };
75 $scope.jsonData = function(data) {
76 return JSON.stringify(data);
77 };
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070078
Andrew Geisslerd27bb132018-05-24 11:07:27 -070079 $scope.filterBySeverity = function(log) {
80 if ($scope.selectedSeverity.all) return true;
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070081
Andrew Geisslerd27bb132018-05-24 11:07:27 -070082 return (
83 (log.severity_flags.low && $scope.selectedSeverity.low) ||
84 (log.severity_flags.medium && $scope.selectedSeverity.medium) ||
85 (log.severity_flags.high && $scope.selectedSeverity.high));
86 };
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070087
Andrew Geisslerd27bb132018-05-24 11:07:27 -070088 $scope.filterByStatus = function(log) {
89 if ($scope.selectedStatus.all) return true;
90 return (
91 (log.Resolved && $scope.selectedStatus.resolved) ||
92 (!log.Resolved && !$scope.selectedStatus.resolved));
93 };
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070094
Andrew Geisslerd27bb132018-05-24 11:07:27 -070095 $scope.filterByDate = function(log) {
96 var endDate;
97 if ($scope.end_date &&
98 typeof $scope.end_date.getTime === 'function') {
99 endDate = new Date($scope.end_date.getTime());
100 endDate.setTime(endDate.getTime() + 86399000);
101 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700102
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700103 if ($scope.start_date && endDate) {
104 var date = new Date($filter('date')(
105 log.Timestamp, 'MM/dd/yyyy HH:mm:ss', $scope.tmz));
106 return (date >= $scope.start_date && date <= endDate);
107 } else {
108 return true;
109 }
110 };
111
112 $scope.filterBySearchTerms = function(log) {
113 if (!$scope.searchItems.length) return true;
114
115 for (var i = 0, length = $scope.searchItems.length; i < length;
116 i++) {
117 if (log.search_text.indexOf(
118 $scope.searchItems[i].toLowerCase()) == -1)
119 return false;
120 }
121 return true;
122 };
123
124 $scope.addSearchItem = function(searchTerms) {
125 var terms = searchTerms.split(' ');
126 terms.forEach(function(searchTerm) {
127 if ($scope.searchItems.indexOf(searchTerm) == -1) {
128 $scope.searchItems.push(searchTerm);
129 }
130 });
131 };
132
133 $scope.clearSearchItem = function(searchTerm) {
134 $scope.searchItems = [];
135 };
136
137 $scope.removeSearchItem = function(searchTerm) {
138 var termIndex = $scope.searchItems.indexOf(searchTerm);
139
140 if (termIndex > -1) {
141 $scope.searchItems.splice(termIndex, 1);
142 }
143 };
144
145 $scope.$watch('all', function() {
beccabroek1ca1d7e2018-08-30 14:18:22 -0500146 $scope.filteredLogs.forEach(function(item) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700147 item.selected = $scope.all;
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700148 });
149 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700150
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700151 function updateExportData() {
152 $scope.export_name = ($scope.selectedEvents.length == 1) ?
153 $scope.selectedEvents[0].Id + '.json' :
154 'export.json';
155 var data = {};
156 $scope.selectedEvents.forEach(function(item) {
157 data[item.data.key] = item.data.value;
158 });
159 $scope.export_data = JSON.stringify(data);
160 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700161
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700162 $scope.accept = function() {
163 APIUtils.deleteLogs($scope.selectedEvents).then(function() {
164 $scope.confirm = false;
165 $scope.loadLogs();
166 });
167 };
168
169 $scope.resolve = function() {
170 var events = $scope.selectedEvents.filter(function(item) {
171 return item.Resolved != 1;
172 });
173
174 if (!events.length) return;
175
176 APIUtils.resolveLogs(events).then(function() {
177 events.forEach(function(item) {
178 item.Resolved = 1;
179 });
180 });
181 };
182
183 $scope.$watch('logs', function() {
184 $scope.selectedEvents = $scope.logs.filter(function(item) {
185 return item.selected;
186 });
187 updateExportData();
188 }, true);
189
190 $scope.loadLogs();
191 }
192 ]);
Iftekharul Islam8b4828a2017-04-19 14:37:55 -0500193})(angular);