Skip to content

Commit

Permalink
#76 Add an assignee filter to case list
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani authored and To-om committed Feb 1, 2017
1 parent 7ece97c commit c155a4d
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 3 deletions.
40 changes: 39 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, CasesUISrv, StreamStatSrv, PSearchSrv, EntitySrv, UserInfoSrv, TagSrv, CaseResolutionStatus) {
function CaseListCtrl($scope, $q, CasesUISrv, StreamStatSrv, PSearchSrv, EntitySrv, UserInfoSrv, TagSrv, UserSrv, AuthenticationSrv, CaseResolutionStatus) {
var self = this;

this.showFlow = true;
Expand Down Expand Up @@ -135,6 +135,44 @@
return TagSrv.fromCases(query);
};

this.getUsers = function(query) {
return UserSrv.list({
_and: [
{
status: 'Ok'
}
]
}).then(function(data) {
return _.map(data, function(user) {
return {
label: user.name,
text: user.id
};
});
}).then(function(users) {
var filtered = _.filter(users, function(user) {
var regex = new RegExp(query, 'gi');
return regex.test(user.label);
});

return filtered;
});
};

this.filterMyCases = function() {
this.uiSrv.clearFilters()
.then(function(){
var currentUser = AuthenticationSrv.currentUser;
self.uiSrv.activeFilters.owner = {
value: [{
text: currentUser.id,
label: currentUser.name
}]
};
self.filter();
});
};

this.filterByStatus = function(status) {
this.uiSrv.clearFilters()
.then(function(){
Expand Down
5 changes: 5 additions & 0 deletions ui/app/scripts/services/CasesUISrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
type: 'list',
defaultValue: []
},
owner: {
field: 'owner',
type: 'list',
defaultValue: []
},
tlp: {
field: 'tlp',
type: 'number',
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/services/TagSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
limit: 1000
}).then(function(response) {
var tags = [];
var regex = new RegExp(query);

tags = _.map(_.filter(_.keys(response.data), function(tag) {
var regex = new RegExp(query, 'gi');
return regex.test(tag);
}), function(tag) {
return {text: tag};
Expand Down
18 changes: 17 additions & 1 deletion ui/app/scripts/services/UserSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ angular.module('theHiveServices')
} else {
var ret = {
'name': login,
'id': login
'id': login
};
res.get({
'userId': login
Expand Down Expand Up @@ -70,5 +70,21 @@ angular.module('theHiveServices')
return defer.promise;
};

res.list = function(query) {
var defer = $q.defer();

var post = {
range: 'all',
query: query
};

$http.post('/api/user/_search', post)
.then(function(response) {
defer.resolve(response.data);
});

return defer.promise;
};

return res;
});
13 changes: 13 additions & 0 deletions ui/app/views/partials/case/list/filters.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ <h4>Filters</h4>
</tags-input>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Assignee</label>
<div class="col-sm-8">
<tags-input class="form-control form-control-wrapper"
min-length="2"
ng-model="$vm.uiSrv.activeFilters.owner.value"
placeholder="ex: Firstname Lastname"
replace-spaces-with-dashes="false"
display-property="label">
<auto-complete debounceDelay="400" source="$vm.getUsers($query)" display-property="label"></auto-complete>
</tags-input>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
Expand Down
3 changes: 3 additions & 0 deletions ui/app/views/partials/case/list/toolbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li>
<a ng-click="$vm.filterMyCases()">My cases</a>
</li>
<li>
<a ng-click="$vm.filterByStatus('Open')">Open Cases ({{$vm.caseStats.Open.count}})</a>
</li>
Expand Down

0 comments on commit c155a4d

Please sign in to comment.