1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
/**
* Controller for log
*
* @module app/serverHealth
* @exports sysLogController
* @name sysLogController
*/
window.angular && (function(angular) {
'use strict';
angular.module('app.serverHealth')
.config([
'paginationTemplateProvider',
function(paginationTemplateProvider) {
paginationTemplateProvider.setString(
require('../../common/directives/dirPagination.tpl.html'));
}
])
.controller('sysLogController', [
'$scope', 'APIUtils', 'Constants',
function($scope, APIUtils, Constants) {
$scope.itemsPerPage = Constants.PAGINATION.LOG_ITEMS_PER_PAGE;
$scope.loading = true;
$scope.sysLogs = [];
$scope.customSearch = '';
$scope.searchTerms = [];
$scope.sortKey = 'Id';
$scope.showLogDropdown = false;
$scope.recordTypeList =
['SEL', 'Event', 'Oem']; // From Redfish specification.
$scope.selectedRecordType = 'SEL'; // Default Select to SEL.
$scope.typeFilter = false;
$scope.selectedSeverityList = [];
$scope.severityList = ['All', 'Critical', 'Warning', 'Ok'];
$scope.filterTypes = [];
$scope.selectedType = 'All';
$scope.selectRecordType = function(recordType) {
$scope.selectedRecordType = recordType;
$scope.showLogDropdown = false;
$scope.filterTypes = [];
APIUtils.getSystemLogs(recordType)
.then(
function(res) {
$scope.sysLogs = res;
$scope.filterTypes.push('All');
$scope.sysLogs.forEach(function(log) {
if ($scope.filterTypes.indexOf(log.SensorType) < 0) {
$scope.filterTypes.push(log.SensorType);
}
});
},
function(error) {
console.log(JSON.stringify(error));
})
.finally(function() {
$scope.loading = false;
});
};
$scope.clearSystemLogEntries = function() {
$scope.confirm = false;
APIUtils.clearSystemLogs()
.then(
function(res) {
console.log(JSON.stringify(res));
},
function(error) {
console.log(JSON.stringify(error));
})
.finally(function() {
$scope.selectRecordType($scope.selectedRecordType);
});
};
$scope.sortBy = function(keyname, isReverse) {
$scope.sortKey = keyname;
$scope.reverse = isReverse;
};
$scope.clear = function() {
$scope.customSearch = '';
$scope.searchTerms = [];
};
$scope.doSearchOnEnter = function(event) {
var search =
$scope.customSearch.replace(/^\s+/g, '').replace(/\s+$/g, '');
if (event.keyCode === 13 && search.length >= 2) {
$scope.searchTerms = $scope.customSearch.split(' ');
} else {
if (search.length == 0) {
$scope.searchTerms = [];
}
}
};
$scope.doSearchOnClick = function() {
var search =
$scope.customSearch.replace(/^\s+/g, '').replace(/\s+$/g, '');
if (search.length >= 2) {
$scope.searchTerms = $scope.customSearch.split(' ');
} else {
if (search.length == 0) {
$scope.searchTerms = [];
}
}
};
$scope.filterBySearchTerms = function(log) {
if (!$scope.searchTerms.length) {
return true;
}
for (var i = 0, length = $scope.searchTerms.length; i < length;
i++) {
// TODO: Form it while getting data
var search_text = log.Id + ' ' + log.Name.toLowerCase() + ' ' +
log.Message.toLowerCase();
if (search_text.indexOf($scope.searchTerms[i].toLowerCase()) ==
-1)
return false;
}
return true;
};
$scope.filterBySeverity = function(log) {
if ($scope.selectedSeverityList.length == 0) {
return true;
}
return ($scope.selectedSeverityList.indexOf(log.Severity) > -1);
};
$scope.filterByType = function(log) {
if ($scope.selectedType == 'All') {
return true;
}
return (($scope.selectedType == log.SensorType));
};
$scope.filterByDate = function(log) {
var logDate = new Date(log.Created);
if ($scope.start_date && $scope.end_date) {
return (
logDate >= $scope.start_date && logDate <= $scope.end_date);
} else {
return true;
}
};
setTimeout($scope.selectRecordType($scope.selectedRecordType), 2000);
}
]);
})(angular);
|