Skip to content

Commit

Permalink
#170 Add mark as read alert feature
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Apr 13, 2017
1 parent 726dafd commit 0c8987b
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 21 deletions.
6 changes: 3 additions & 3 deletions ui/app/scripts/controllers/alert/AlertEventCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
data: []
};
self.filteredArtifacts = [];

this.filterArtifacts = function(value) {
self.pagination.currentPage = 1;
this.pagination.filter= value;
Expand All @@ -25,9 +25,9 @@
var end = self.pagination.currentPage * self.pagination.pageSize;
var start = end - self.pagination.pageSize;

self.filteredArtifacts = self.pagination.filter === '' ? self.event.artifacts : _.filter(self.event.artifacts, function(item) {
self.filteredArtifacts = (self.pagination.filter === '' ? self.event.artifacts : _.filter(self.event.artifacts, function(item) {
return item.dataType === self.pagination.filter;
});
})) || [];

var data = [];
angular.forEach(self.filteredArtifacts.slice(start, end), function(d) {
Expand Down
29 changes: 29 additions & 0 deletions ui/app/scripts/controllers/alert/AlertListCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
defaultValue: [],
label: 'Source'
},
type: {
field: 'type',
type: 'list',
defaultValue: [],
label: 'Type'
},
severity: {
field: 'severity',
type: 'list',
Expand Down Expand Up @@ -99,6 +105,29 @@
this.filtering.toggleFilters();
};

this.canMarkAsRead = function(event) {
return event.status === 'New' || event.status === 'Update';
};

this.canMarkAsUnread = function(event) {
return event.status === 'Imported' || event.status === 'Ignore';
};

this.markAsRead = function(event) {
var fn = angular.noop;

if(this.canMarkAsRead(event)) {
fn = AlertingSrv.markAsRead;
} else {
fn = AlertingSrv.markAsUnread;
}

fn(event.id).then(function( /*data*/ ) {
}, function(response) {
NotificationSrv.error('AlertListCtrl', response.data, response.status);
});
};

self.follow = function(event) {
var fn = angular.noop;

Expand Down
11 changes: 7 additions & 4 deletions ui/app/scripts/services/AlertingSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
loadAll: config.loadAll || false,
pageSize: config.pageSize || 10,
filter: config.filter || '',
onUpdate: callback || angular.noop,
streamObjectType: 'alert'
onUpdate: callback || angular.noop
});
},

Expand All @@ -27,8 +26,12 @@
return $http.post(baseUrl + '/' + alertId + '/createCase', {});
},

ignore: function(alertId) {
return $http.get(baseUrl + '/ignore/' + alertId);
markAsRead: function(alertId) {
return $http.post(baseUrl + '/' + alertId + '/markAsRead');
},

markAsUnread: function(alertId) {
return $http.post(baseUrl + '/' + alertId + '/markAsUnread');
},

follow: function(alertId) {
Expand Down
2 changes: 1 addition & 1 deletion ui/app/views/components/header.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<li ui-sref-active="active">
<a href ui-sref="app.alert-list">
Alerts
<span class="badge alert-danger">{{alertEvents.count}}</span>
<span class="badge alert-danger">{{(alertEvents.New.count || 0) + (alertEvents.Update.count || 0)}}</span>
</a>
</li>
<li class="hdivider hidden-xs"></li>
Expand Down
6 changes: 3 additions & 3 deletions ui/app/views/partials/alert/event.dialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ <h4 class="vpad10 text-primary">

<div class="alert-artifacts" ng-if="dialog.event.artifacts.length > 0">
<h4 class="vpad10 text-primary">
Artifacts ({{dialog.event.artifacts.length}})
Artifacts ({{dialog.event.artifacts.length || 0}})
</h4>
<div class="mb-xs" ng-if="dialog.dataTypes">
<span class="label label-lg label-default mr-xxs clickable"
ng-click="dialog.filterArtifacts('');"
ng-class="{'label-primary': dialog.pagination.filter===''}">All ({{dialog.event.artifacts.length}})</a></span>
ng-class="{'label-primary': dialog.pagination.filter===''}">All ({{dialog.event.artifacts.length || 0}})</a></span>

<span class="label label-lg label-default mr-xxs clickable"
ng-repeat="(type, count) in dialog.dataTypes"
Expand All @@ -65,7 +65,7 @@ <h4 class="vpad10 text-primary">
<tbody>
<tr ng-repeat="attribute in dialog.pagination.data">
<td>{{attribute.dataType}}</td>
<td class="wrap">{{attribute.data | fang | ellipsis:250}}</td>
<td class="wrap">{{(attribute.data.filename || attribute.data) | fang | ellipsis:250}}</td>
</tr>
</tbody>
</table>
Expand Down
13 changes: 8 additions & 5 deletions ui/app/views/partials/alert/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ <h3 class="box-title">List of alerts ({{$vm.list.total || 0}} of {{alertEvents.c
<span>
<strong>{{filter.label}}:</strong>
{{filter.value | filterValue}}</span>
<a href="" ng-click="$vm.removeFilter(field)">
<a href ng-click="$vm.removeFilter(field)">
<span class="filter-close fa fa-times text-danger"></span>
</a>
</li>
<li>
<a href="" ng-click="$vm.clearFilters()">Clear filters</a>
<a href ng-click="$vm.clearFilters()">Clear filters</a>
</li>
</ul>
</div>
Expand Down Expand Up @@ -91,7 +91,7 @@ <h3 class="box-title">List of alerts ({{$vm.list.total || 0}} of {{alertEvents.c
<severity active="false" value="event.severity"></severity>
</div>
</td>
<td class="text-center">{{::event.artifacts.length}}</td>
<td class="text-center">{{::event.artifacts.length || 0}}</td>
<td><a href ng-click="$vm.addFilterValue('date', event.date)">{{event.date | showDate}}</a></td>
<td class="clearfix">
<div class="pull-left">
Expand All @@ -104,8 +104,11 @@ <h3 class="box-title">List of alerts ({{$vm.list.total || 0}} of {{alertEvents.c
<a class="btn btn-xs btn-icon btn-clear" href ng-click="$vm.follow(event)" uib-tooltip="{{event.follow ? 'Ignore new updates' : 'Track new updates'}}">
<i class="text-info text-20 fa" ng-class="{'fa-eye': event.follow, 'fa-eye-slash': !event.follow}"></i>
</a>
<a class="btn btn-xs btn-icon btn-clear" href ng-click="$vm.ignore(event)" uib-tooltip="Mark as unread" ng-if="event.status !== 'Ignore' && !event.case">
<i class="text-info text-20 fa fa-check"></i>
<a class="btn btn-xs btn-icon btn-clear" href ng-click="$vm.markAsRead(event)" uib-tooltip="Mark as read" ng-if="$vm.canMarkAsRead(event)">
<i class="text-info text-20 fa fa-envelope"></i>
</a>
<a class="btn btn-xs btn-icon btn-clear" href ng-click="$vm.markAsRead(event)" uib-tooltip="Mark as unread" ng-if="$vm.canMarkAsUnread(event)">
<i class="text-info text-20 fa fa-envelope-open-o"></i>
</a>
</div>
</td>
Expand Down
10 changes: 5 additions & 5 deletions ui/app/views/partials/alert/list/mini-stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ <h4>Statistics</h4>
</div>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">Events by Status</div>
<div class="panel-heading">Alerts by Status</div>
<div class="panel-body">
<table class="table table-condensed">
<tr ng-repeat="item in statsCtrl.byStatus.details">
<td class="active">{{item.key}}</td>
<td>
<a href ng-click="misp.addFilterValue('eventStatus', item.key)">{{item.count}}</a>
<a href ng-click="$vm.addFilterValue('status', item.key)">{{item.count}}</a>
</td>
</tr>
</table>
Expand All @@ -20,13 +20,13 @@ <h4>Statistics</h4>

<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">Top 5 Sources</div>
<div class="panel-heading">Top 5 Types</div>
<div class="panel-body">
<table class="table table-condensed">
<tr ng-repeat="item in statsCtrl.byType.details">
<td class="active">{{item.key}}</td>
<td>
<a href ng-click="misp.addFilterValue('type', item.key)">{{item.count}}</a>
<a href ng-click="$vm.addFilterValue('type', item.key)">{{item.count}}</a>
</td>
</tr>
</table>
Expand All @@ -42,7 +42,7 @@ <h4>Statistics</h4>
<tr ng-repeat="item in statsCtrl.byTags.details">
<td class="active">{{item.key}}</td>
<td>
<a href ng-click="misp.addFilterValue('tags', item.key)">{{item.count}}</a>
<a href ng-click="$vm.addFilterValue('tags', item.key)">{{item.count}}</a>
</td>
</tr>
</table>
Expand Down

0 comments on commit 0c8987b

Please sign in to comment.