@@ -74,6 +74,7 @@ function Filter(app_expr, severity_expr, action, state) {
74
74
return matchRuleShort ( appname , this . app_expr ) ;
75
75
} ;
76
76
77
+ // TODO refactor this so that apps can reuse this logic!
77
78
this . evaluateSeverity = function ( severity ) {
78
79
rule_int = this . severityToInt ( this . sev_expr . replace ( / \W / g, '' ) ) ;
79
80
sev_int = this . severityToInt ( severity ) ;
@@ -158,6 +159,17 @@ function Filter(app_expr, severity_expr, action, state) {
158
159
} ;
159
160
}
160
161
162
+ function App ( app_expr , state ) {
163
+ this . app_expr = app_expr ;
164
+ // state = enabled | disabled
165
+ this . state = state ;
166
+
167
+ // TODO at some point refactor this as this is the same for the filter!
168
+ this . evaluateApp = function ( appname ) {
169
+ return matchRuleShort ( appname , this . app_expr ) ;
170
+ } ;
171
+ }
172
+
161
173
/* Class that acts as a wrapper around the WebSocket class.
162
174
It's goal is to create a robust connection with the server.
163
175
This means that it will test the connection & reconnect if needed.
@@ -256,16 +268,51 @@ app.controller('MessagesController', ['$scope', '$window', function ($scope, $wi
256
268
// this buffer will hold messages while the app is paused
257
269
$scope . paused_messages = [ ] ;
258
270
271
+ $scope . apps = [ ] ;
272
+ // put a placeholder app
273
+ $scope . apps . push ( new App ( "my_app" , "disabled" ) ) ;
274
+
259
275
$scope . filters = [ ] ;
260
276
// put a placeholder filter
261
277
var filter = new Filter ( "myapp" , ">= warning" , "hide" , "disabled" ) ;
262
278
$scope . filters . push ( filter ) ;
263
279
280
+ $scope . applyApps = function ( message ) {
281
+ if ( ! message )
282
+ return null ;
283
+
284
+ var hasAppEnabled = false ;
285
+
286
+ for ( var index = 0 ; index < $scope . apps . length ; index ++ ) {
287
+ var app = $scope . apps [ index ] ;
288
+ if ( app . state == "enabled" ) {
289
+ hasAppEnabled = true ;
290
+ if ( app . evaluateApp ( message . appname ) ) {
291
+ return message ;
292
+ }
293
+ }
294
+ else
295
+ continue ;
296
+ }
297
+
298
+ // if we got here and an enabled app was found, it means none of them match the message so we discard it
299
+ if ( hasAppEnabled ) {
300
+ console . log ( "discarded message with non-matching app" ) ;
301
+ return null ;
302
+ }
303
+ else {
304
+ return message ;
305
+ }
306
+ } ;
307
+
264
308
/*
265
309
* Function to evaluate all user-specified filters on a message.
266
310
* These filters will modify the message and return it.
267
311
*/
268
312
$scope . applyFilters = function ( message ) {
313
+ if ( ! message )
314
+ return null ;
315
+
269
316
for ( var index = 0 ; index < $scope . filters . length ; index ++ ) {
270
317
message = $scope . filters [ index ] . handleMessage ( message ) ;
271
318
// if filter removed the message, stop immediately
@@ -284,7 +331,10 @@ app.controller('MessagesController', ['$scope', '$window', function ($scope, $wi
284
331
return ;
285
332
}
286
333
287
- // first evaluate filters, if this becomes too intense for the browser, offload it to server
334
+ // first check if only specific apps should be shown
335
+ message = $scope . applyApps ( message ) ;
336
+
337
+ // evaluate filters, if this becomes too intense for the browser, offload it to server
288
338
message = $scope . applyFilters ( message ) ;
289
339
if ( ! message ) {
290
340
console . log ( "filtered out message" ) ;
@@ -342,6 +392,14 @@ app.controller('MessagesController', ['$scope', '$window', function ($scope, $wi
342
392
$scope . filters . splice ( index , 1 ) ;
343
393
} ;
344
394
395
+ $scope . addApp = function ( ) {
396
+ $scope . apps . push ( new App ( "my_app" , "disabled" ) ) ;
397
+ } ;
398
+
399
+ $scope . removeApp = function ( index ) {
400
+ $scope . apps . splice ( index , 1 ) ;
401
+ } ;
402
+
345
403
$scope . gotoEndTable = function ( ) {
346
404
// scroll to bottom of table
347
405
var objDiv = document . getElementById ( "viewer" ) ;
0 commit comments