blob: 88fac771e2b247281e95f3cfbe89699578248315 [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 = [];
27 $scope.tmz = 'EDT';
28 $scope.itemsPerPage = Constants.PAGINATION.LOG_ITEMS_PER_PAGE;
29 $scope.loading = false;
30 var expandedSelectedIdOnce = false;
Michael Davis428375e2017-08-01 15:48:34 -050031
Andrew Geisslerd27bb132018-05-24 11:07:27 -070032 var sensorType = $routeParams.type;
33 var eventId = $routeParams.id;
Michael Davis428375e2017-08-01 15:48:34 -050034
Andrew Geisslerd27bb132018-05-24 11:07:27 -070035 // priority buttons
36 $scope.selectedSeverity =
37 {all: true, low: false, medium: false, high: false};
Michael Davis428375e2017-08-01 15:48:34 -050038
Andrew Geisslerd27bb132018-05-24 11:07:27 -070039 if (sensorType == 'high') {
40 $scope.selectedSeverity.all = false;
41 $scope.selectedSeverity.high = true;
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070042 }
43
Andrew Geisslerd27bb132018-05-24 11:07:27 -070044 $scope.selectedStatus = {all: true, resolved: false};
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070045
Andrew Geisslerd27bb132018-05-24 11:07:27 -070046 $scope.customSearch = '';
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070047 $scope.searchItems = [];
Andrew Geisslerd27bb132018-05-24 11:07:27 -070048 $scope.selectedEvents = [];
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070049
Andrew Geisslerd27bb132018-05-24 11:07:27 -070050 if (eventId) {
51 $scope.customSearch = '#' + eventId;
52 $scope.searchItems.push('#' + eventId);
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070053 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070054
Andrew Geisslerd27bb132018-05-24 11:07:27 -070055 $scope.loadLogs = function() {
56 $scope.loading = true;
57 APIUtils.getLogs().then(function(result) {
58 if (eventId && expandedSelectedIdOnce == false) {
59 var log = result.data.filter(function(item) {
60 return item.Id == eventId;
61 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070062
Andrew Geisslerd27bb132018-05-24 11:07:27 -070063 if (log.length) {
64 log[0].meta = true;
65 }
66 expandedSelectedIdOnce = true;
67 }
68 dataService.updateServerHealth(result.data);
69 $scope.logs = result.data;
70 $scope.originalData = result.original;
71 $scope.loading = false;
72 });
73 };
74 $scope.jsonData = function(data) {
75 return JSON.stringify(data);
76 };
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070077
Andrew Geisslerd27bb132018-05-24 11:07:27 -070078 $scope.filterBySeverity = function(log) {
79 if ($scope.selectedSeverity.all) return true;
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070080
Andrew Geisslerd27bb132018-05-24 11:07:27 -070081 return (
82 (log.severity_flags.low && $scope.selectedSeverity.low) ||
83 (log.severity_flags.medium && $scope.selectedSeverity.medium) ||
84 (log.severity_flags.high && $scope.selectedSeverity.high));
85 };
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070086
Andrew Geisslerd27bb132018-05-24 11:07:27 -070087 $scope.filterByStatus = function(log) {
88 if ($scope.selectedStatus.all) return true;
89 return (
90 (log.Resolved && $scope.selectedStatus.resolved) ||
91 (!log.Resolved && !$scope.selectedStatus.resolved));
92 };
Andrew Geisslerba5e3f32018-05-24 10:58:00 -070093
Andrew Geisslerd27bb132018-05-24 11:07:27 -070094 $scope.filterByDate = function(log) {
95 var endDate;
96 if ($scope.end_date &&
97 typeof $scope.end_date.getTime === 'function') {
98 endDate = new Date($scope.end_date.getTime());
99 endDate.setTime(endDate.getTime() + 86399000);
100 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700101
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700102 if ($scope.start_date && endDate) {
103 var date = new Date($filter('date')(
104 log.Timestamp, 'MM/dd/yyyy HH:mm:ss', $scope.tmz));
105 return (date >= $scope.start_date && date <= endDate);
106 } else {
107 return true;
108 }
109 };
110
111 $scope.filterBySearchTerms = function(log) {
112 if (!$scope.searchItems.length) return true;
113
114 for (var i = 0, length = $scope.searchItems.length; i < length;
115 i++) {
116 if (log.search_text.indexOf(
117 $scope.searchItems[i].toLowerCase()) == -1)
118 return false;
119 }
120 return true;
121 };
122
123 $scope.addSearchItem = function(searchTerms) {
124 var terms = searchTerms.split(' ');
125 terms.forEach(function(searchTerm) {
126 if ($scope.searchItems.indexOf(searchTerm) == -1) {
127 $scope.searchItems.push(searchTerm);
128 }
129 });
130 };
131
132 $scope.clearSearchItem = function(searchTerm) {
133 $scope.searchItems = [];
134 };
135
136 $scope.removeSearchItem = function(searchTerm) {
137 var termIndex = $scope.searchItems.indexOf(searchTerm);
138
139 if (termIndex > -1) {
140 $scope.searchItems.splice(termIndex, 1);
141 }
142 };
143
144 $scope.$watch('all', function() {
beccabroek1ca1d7e2018-08-30 14:18:22 -0500145 $scope.filteredLogs.forEach(function(item) {
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700146 item.selected = $scope.all;
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700147 });
148 });
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700149
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700150 function updateExportData() {
151 $scope.export_name = ($scope.selectedEvents.length == 1) ?
152 $scope.selectedEvents[0].Id + '.json' :
153 'export.json';
154 var data = {};
155 $scope.selectedEvents.forEach(function(item) {
156 data[item.data.key] = item.data.value;
157 });
158 $scope.export_data = JSON.stringify(data);
159 }
Andrew Geisslerba5e3f32018-05-24 10:58:00 -0700160
Andrew Geisslerd27bb132018-05-24 11:07:27 -0700161 $scope.accept = function() {
162 APIUtils.deleteLogs($scope.selectedEvents).then(function() {
163 $scope.confirm = false;
164 $scope.loadLogs();
165 });
166 };
167
168 $scope.resolve = function() {
169 var events = $scope.selectedEvents.filter(function(item) {
170 return item.Resolved != 1;
171 });
172
173 if (!events.length) return;
174
175 APIUtils.resolveLogs(events).then(function() {
176 events.forEach(function(item) {
177 item.Resolved = 1;
178 });
179 });
180 };
181
182 $scope.$watch('logs', function() {
183 $scope.selectedEvents = $scope.logs.filter(function(item) {
184 return item.selected;
185 });
186 updateExportData();
187 }, true);
188
189 $scope.loadLogs();
190 }
191 ]);
Iftekharul Islam8b4828a2017-04-19 14:37:55 -0500192})(angular);