Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add back in filtering and ensure filters can be persistent via the URL
  • Loading branch information
gashcrumb committed Oct 4, 2013
1 parent 2a9755a commit 2f6eaee
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 105 deletions.
2 changes: 1 addition & 1 deletion hawtio-web/src/main/webapp/app/log/js/logPlugin.ts
Expand Up @@ -3,7 +3,7 @@ module Log {
angular.module(pluginName, ['bootstrap', 'ngResource', 'ngGrid', 'datatable', 'hawtioCore']).
config(($routeProvider) => {
$routeProvider.
when('/logs', {templateUrl: 'app/log/html/logs.html'})
when('/logs', {templateUrl: 'app/log/html/logs.html', reloadOnSearch: false})
}).
run(($location:ng.ILocationService, workspace:Workspace, viewRegistry, layoutFull) => {

Expand Down
195 changes: 91 additions & 104 deletions hawtio-web/src/main/webapp/app/log/js/logs.ts
Expand Up @@ -8,21 +8,66 @@ module Log {
level: string;
}

export function LogController($scope, $location, localStorage, workspace:Workspace, $window, $document) {
export function LogController($scope, $routeParams, $location, localStorage, workspace:Workspace, $window, $document) {
$scope.logs = [];
$scope.filteredLogs = [];
$scope.selectedItems = [];
$scope.searchText = "";
$scope.filter = {
// The default logging level to show, empty string => show all
logLevelQuery: "",
// The default value of the exact match logging filter
logLevelExactMatch: false


$scope.init = () => {
$scope.searchText = $routeParams['s'];

if (!angular.isDefined($scope.searchText)){
$scope.searchText = '';
}

$scope.filter = {
// The default logging level to show, empty string => show all
logLevelQuery: $routeParams['l'],
// The default value of the exact match logging filter
logLevelExactMatch: Core.parseBooleanValue($routeParams['e'])
};

if (!angular.isDefined($scope.filter.logLevelQuery)) {
$scope.filter.logLevelQuery = '';
}
if (!angular.isDefined($scope.filter.logLevelExactMatch)) {
$scope.filter.logLevelExactMatch = false;
}
};

$scope.$on('$routeUpdate', $scope.init);

$scope.$watch('searchText', (newValue, oldValue) => {
if (newValue !== oldValue) {
$location.search('s', newValue);
}
});

$scope.$watch('filter.logLevelQuery', (newValue, oldValue) => {
if (newValue !== oldValue) {
$location.search('l', newValue);
}
});

$scope.$watch('filter.logLevelExactMatch', (newValue, oldValue) => {
if (newValue !== oldValue) {
$location.search('e', newValue);
}
});

$scope.init();

$scope.toTime = 0;
$scope.queryJSON = { type: "EXEC", mbean: logQueryMBean, operation: "logResultsSince", arguments: [$scope.toTime], ignoreErrors: true};


$scope.logLevels = ["TRACE", "DEBUG", "INFO", "WARN", "ERROR"];
$scope.logLevelMap = {};

angular.forEach($scope.logLevels, (name, idx) => {
$scope.logLevelMap[name] = idx;
$scope.logLevelMap[name.toLowerCase()] = idx;
});

$scope.logClass = (log) => {
return logLevelClass(log['level']);
};
Expand Down Expand Up @@ -54,71 +99,48 @@ module Log {
};

$scope.getSupport = () => {
if ($scope.selectedItems.length) {
var log = $scope.selectedItems[0];
var text = log["message"];
var uri = "https://access.redhat.com/knowledge/solutions?logger=" + log["logger"] + "&text=" + text;
window.location.href = uri;
var uri = "https://access.redhat.com/knowledge/solutions"
var expanded = $scope.logs.filter((log) => { return log.expanded; });
if (expanded.length > 0) {
// guess we'll take the most recent expanded event
var last = expanded.last();
var text = last.message;
var logger = last.logger;
uri = uri + "?logger=" + logger + "&text=" + text;
}
window.location.href = uri;
};

var columnDefs:any[] = [
{
field: 'timestamp',
displayName: 'Timestamp',
cellFilter: "logDateFilter",
width: 146
},
{
field: 'level',
displayName: 'Level',
cellTemplate: '<div class="ngCellText"><span class="text-{{logClass(row.entity)}}"><i class="{{logIcon(row.entity)}}"></i> {{row.entity.level}}</span></div>',
cellFilter: null,
width: 74,
resizable: false
},
{
field: 'logger',
displayName: 'Logger',
cellTemplate: '<div class="ngCellText" ng-switch="hasLogSourceHref(row)" title="{{row.entity.logger}}"><a ng-href="{{logSourceHref(row)}}" ng-switch-when="true">{{row.entity.logger}}</a><div ng-switch-default>{{row.entity.logger}}</div></div>',
cellFilter: null,
//width: "**"
width: "20%"
},
{
field: 'message',
displayName: 'Message',
//width: "****"
width: "60%"
}
];


$scope.gridOptions = {
selectedItems: $scope.selectedItems,
data: 'filteredLogs',
displayFooter: false,
showFilter: false,
sortInfo: { field: 'timestamp', direction: 'DESC'},
filterOptions: {
filterText: "searchText"
},
columnDefs: columnDefs,
rowDetailTemplateId: "logDetailTemplate"
//rowTemplate: '<div ng-style="{\'cursor\': row.cursor}" ng-repeat="col in visibleColumns()" class="{{logClass(row.entity)}} ngCell col{{$index}} {{col.cellClass}}" ng-cell></div>'
};

$scope.$watch('filter.logLevelExactMatch', function () {
checkIfFilterChanged();
});
$scope.$watch('filter.logLevelQuery', function () {
checkIfFilterChanged();
});

$scope.filterLogMessage = (log) => {
return true;

if ($scope.filter.logLevelQuery !== "") {
var logLevelExactMatch = $scope.filter.logLevelExactMatch;
var logLevelQuery = $scope.filter.logLevelQuery;
var logLevelQueryOrdinal = (logLevelExactMatch) ? 0 : $scope.logLevelMap[logLevelQuery];

if (logLevelExactMatch) {
if (log.level !== logLevelQuery) {
return false;
}
} else {
var idx = $scope.logLevelMap[log.level];
if ( !(idx >= logLevelQueryOrdinal || idx < 0) ) {
return false;
}
}
}

if ($scope.searchText.startsWith("l=")) {
return log.logger.has($scope.searchText.last($scope.searchText.length - 2));
}
if ($scope.searchText.startsWith("m=")) {
return log.message.has($scope.searchText.last($scope.searchText.length - 2));
}
return log.logger.has($scope.searchText) || log.message.has($scope.searchText);
};


$scope.formatStackTrace = (exception) => {
if (!exception) {
return "";
Expand All @@ -131,6 +153,7 @@ module Log {
return answer;
};


var updateValues = function (response) {
var scrollToBottom = false;
var window = $($window);
Expand Down Expand Up @@ -177,7 +200,6 @@ module Log {
}
}
if (counter) {
refilter();
if (scrollToBottom) {
setTimeout(() => {
$document.scrollTop( $document.height() - window.height());
Expand All @@ -188,6 +210,7 @@ module Log {
}
};


var jolokia = workspace.jolokia;
jolokia.execute(logQueryMBean, "allLogResults", onSuccess(updateValues));

Expand All @@ -210,41 +233,5 @@ module Log {

scopeStoreJolokiaHandle($scope, jolokia, jolokia.register(callback, $scope.queryJSON));

var logLevels = ["TRACE", "DEBUG", "INFO", "WARN", "ERROR"];
var logLevelMap = {};
angular.forEach(logLevels, (name, idx) => {
logLevelMap[name] = idx;
logLevelMap[name.toLowerCase()] = idx;
});

function checkIfFilterChanged() {
if ($scope.logLevelExactMatch !== $scope.filter.logLevelExactMatch ||
$scope.logLevelQuery !== $scope.filter.logLevelExactMatch) {
refilter();
}
}

function refilter() {
//console.log("refilter logs");
var logLevelExactMatch = $scope.filter.logLevelExactMatch;
var logLevelQuery = $scope.filter.logLevelQuery;
var logLevelQueryOrdinal = (logLevelExactMatch) ? 0 : logLevelMap[logLevelQuery];

$scope.logLevelExactMatch = logLevelExactMatch;
$scope.logLevelQuery = logLevelQuery;

$scope.filteredLogs = $scope.logs.filter((log) => {
if (logLevelQuery) {
if (logLevelExactMatch) {
return log.level === logLevelQuery;
} else {
var idx = logLevelMap[log.level];
return idx >= logLevelQueryOrdinal || idx < 0;
}
}
return true;
});
Core.$apply($scope);
}
}
}

0 comments on commit 2f6eaee

Please sign in to comment.