Skip to content

Commit

Permalink
#165 Add a severity column and filter in case list page
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Apr 7, 2017
1 parent 4264bd2 commit 9631f52
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 5 deletions.
25 changes: 24 additions & 1 deletion ui/app/scripts/controllers/case/CaseListCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
angular.module('theHiveControllers')
.controller('CaseListCtrl', CaseListCtrl);

function CaseListCtrl($scope, $q, $state, $window, CasesUISrv, StreamStatSrv, PSearchSrv, EntitySrv, UserInfoSrv, TagSrv, UserSrv, AuthenticationSrv, CaseResolutionStatus) {
function CaseListCtrl($scope, $q, $state, $window, CasesUISrv, StreamStatSrv, PSearchSrv, EntitySrv, UserInfoSrv, TagSrv, UserSrv, AuthenticationSrv, CaseResolutionStatus, Severity) {
var self = this;

this.showFlow = true;
Expand Down Expand Up @@ -133,6 +133,25 @@
]);
};

this.getSeverities = function(query) {
var defer = $q.defer();

$q.resolve(_.map(Severity.keys, function(value, key) {
return {text: key};
})).then(function(response) {
var severities = [];

severities = _.filter(response, function(sev) {
var regex = new RegExp(query, 'gi');
return regex.test(sev.text);
});

defer.resolve(severities);
});

return defer.promise;
};

this.getTags = function(query) {
return TagSrv.fromCases(query);
};
Expand Down Expand Up @@ -182,6 +201,10 @@
});
};

this.filterBySeverity = function(numericSev) {
self.addFilterValue('severity', Severity.values[numericSev]);
};

this.sortBy = function(sort) {
this.list.sort = sort;
this.list.update();
Expand Down
18 changes: 14 additions & 4 deletions ui/app/scripts/services/CasesUISrv.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {
'use strict';
angular.module('theHiveServices')
.factory('CasesUISrv', function($q, localStorageService) {
.factory('CasesUISrv', function($q, localStorageService, Severity) {
var defaultFilter = {
status: {
field: 'status',
Expand Down Expand Up @@ -29,6 +29,15 @@
type: 'list',
defaultValue: []
},
severity: {
field: 'severity',
type: 'list',
defaultValue: [],
convert: function(value) {
// Convert the text value to its numeric representation
return Severity.keys[value];
}
},
resolutionStatus: {
field: 'resolutionStatus',
type: 'list',
Expand Down Expand Up @@ -147,14 +156,15 @@

addFilter: function(field, value) {
var query,
filterDef = factory.filterDefs[field];
filterDef = factory.filterDefs[field],
convertFn = filterDef.convert || angular.identity;

// Prepare the filter value
if (field === 'keyword') {
query = value;
} else if (angular.isArray(value) && value.length > 0) {
query = _.map(value, function(val) {
return field + ':"' + val.text + '"';
return field + ':"' + convertFn(val.text) + '"';
}).join(' OR ');
query = '(' + query + ')';
} else if (filterDef.type === 'date') {
Expand All @@ -164,7 +174,7 @@
query = field + ':[ ' + fromDate + ' TO ' + toDate + ' ]';

} else {
query = field + ':' + value;
query = field + ':' + convertFn(value);
}

factory.filters[field] = {
Expand Down
14 changes: 14 additions & 0 deletions ui/app/scripts/services/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,19 @@
NoImpact: 'No Impact',
WithImpact: 'With impact',
NotApplicable: 'Not Applicable'
})
.value('Severity', {
keys: {
High: 3,
Medium: 2,
Low: 1
},
values: ['Unknown', 'Low', 'Medium', 'High']
})
.value('Tlp', {
RED: 3,
AMBER: 2,
GREEN: 1,
WHITE: 1
});
})();
6 changes: 6 additions & 0 deletions ui/app/views/partials/case/case.list.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ <h3 class="box-title">List of cases ({{$vm.list.total || 0}} of {{$vm.caseStats.
<tr>
<th style="width: 10px;" class="p-0"></th>
<th>Title</th>
<th style="width: 100px;text-align:center;">Severity</th>
<th style="width: 100px;">Tasks</th>
<th style="width: 100px;">Observables</th>
<th style="width: 60px;">Assignee</th>
Expand Down Expand Up @@ -82,6 +83,11 @@ <h3 class="box-title">List of cases ({{$vm.list.total || 0}} of {{$vm.caseStats.
</small>
</div>
</td>
<td align="center">
<div class="clickable" ng-click="$vm.filterBySeverity(currentCase.severity)">
<severity active="false" value="currentCase.severity"></severity>
</div>
</td>
<td>
<a ui-sref="app.case.tasks({caseId: currentCase.id})">
<ng-pluralize count="currentCase.stats.tasks.total" when="{'0': 'No Tasks', '1': '1 Task', 'other': '{} Tasks'}"></ng-pluralize>
Expand Down
12 changes: 12 additions & 0 deletions ui/app/views/partials/case/list/filters.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ <h4>Filters</h4>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="col-sm-4 control-label">Severity</label>
<div class="col-sm-8">
<tags-input class="form-control form-control-wrapper"
min-length="2"
ng-model="$vm.uiSrv.activeFilters.severity.value"
placeholder="ex: High, Medium, Low"
replace-spaces-with-dashes="false">
<auto-complete load-on-focus="true" min-length="1" source="$vm.getSeverities($query)"></auto-complete>
</tags-input>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Title</label>
<div class="col-sm-8">
Expand Down

0 comments on commit 9631f52

Please sign in to comment.