Skip to content

Commit

Permalink
#1579 Add support to the new ui settings that defines the default fil…
Browse files Browse the repository at this point in the history
…ter of the alert similar cases section
  • Loading branch information
nadouani authored and To-om committed Nov 13, 2020
1 parent 9c7a456 commit 6badf58
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 18 deletions.
36 changes: 22 additions & 14 deletions frontend/app/scripts/components/alert/AlertSimilarCaseListCmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

angular.module('theHiveComponents')
.component('alertSimilarCaseList', {
controller: function($scope, FilteringSrv, PaginatedQuerySrv, CaseResolutionStatus, UiSettingsSrv) {
controller: function($scope, AlertingSrv, FilteringSrv, PaginatedQuerySrv, CaseResolutionStatus, UiSettingsSrv) {
var self = this;

self.CaseResolutionStatus = CaseResolutionStatus;
Expand Down Expand Up @@ -49,19 +49,12 @@

self.filtering.initContext('alert.dialog.similar-cases')
.then(function() {
var defaultFilter = {
field: 'status',
type: 'enumeration',
value: {
list: [{
text: 'Open',
label: 'Open'
}]
}
};

if(_.isEmpty(self.filtering.context.filters)) {
self.filtering.addFilter(defaultFilter);
var defaultFilter = AlertingSrv.getSimilarityFilter(self.state.defaultAlertSimilarCaseFilter);

if(_.isEmpty(self.filtering.context.filters) && defaultFilter && defaultFilter.length > 0) {
_.each(defaultFilter, function(item) {
self.filtering.addFilter(item);
});
}

self.load();
Expand Down Expand Up @@ -173,6 +166,21 @@
});
};

this.applyDefaultFilter = function() {
self.filtering.clearFilters()
.then(function(){
var defaultFilter = AlertingSrv.getSimilarityFilter(self.state.defaultAlertSimilarCaseFilter);

if(defaultFilter && defaultFilter.length > 0) {
_.each(defaultFilter, function(item) {
self.filtering.addFilter(item);
});

self.search();
}
});
};

this.filterSimilarities = function(data) {
return data;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

angular.module('theHiveComponents')
.component('orgConfigList', {
controller: function($scope, $q, NotificationSrv, UiSettingsSrv) {
controller: function($scope, $q, NotificationSrv, AlertingSrv, UiSettingsSrv) {
var self = this;

self.alertSimilarityFilters = [];

self.isDirtySetting = function(key, newValue) {
return newValue !== self.currentSettings[key];
};
Expand Down Expand Up @@ -62,6 +64,8 @@

self.$onInit = function() {
self.loadSettings(this.uiConfig);

self.alertSimilarityFilters = AlertingSrv.getSimilarityFilters();
};
},
controllerAs: '$ctrl',
Expand Down
120 changes: 119 additions & 1 deletion frontend/app/scripts/services/api/AlertingSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,126 @@

var baseUrl = './api/alert';

var factory = {
var similarityFilters = {
'open-cases': {
label: 'Open Cases',
filters: [{
field: 'status',
type: 'enumeration',
value: {
list: [{
text: 'Open',
label: 'Open'
}]
}
}]
},
'open-cases-last-7days': {
label: 'Open Cases in the last 7 days',
filters: [{
field: 'status',
type: 'enumeration',
value: {
list: [{
text: 'Open',
label: 'Open'
}]
}
}, {
field: '_createdAt',
type: 'date',
value: {
operator: 'last7days',
from: null,
to: null
}
}]
},
'open-cases-last-30days': {
label: 'Open Cases in the last 30 days',
filters: [{
field: 'status',
type: 'enumeration',
value: {
list: [{
text: 'Open',
label: 'Open'
}]
}
}, {
field: '_createdAt',
type: 'date',
value: {
operator: 'last30days',
from: null,
to: null
}
}]
},
'open-cases-last-3months': {
label: 'Open Cases in the last 3 months',
filters: [{
field: 'status',
type: 'enumeration',
value: {
list: [{
text: 'Open',
label: 'Open'
}]
}
}, {
field: '_createdAt',
type: 'date',
value: {
operator: 'last3months',
from: null,
to: null
}
}]
},
'open-cases-last-year': {
label: 'Open Cases in the last year',
filters: [{
field: 'status',
type: 'enumeration',
value: {
list: [{
text: 'Open',
label: 'Open'
}]
}
}, {
field: '_createdAt',
type: 'date',
value: {
operator: 'lastyear',
from: null,
to: null
}
}]
},
'resolved-cases': {
label: 'Resolved cases',
filters: [{
field: 'status',
type: 'enumeration',
value: {
list: [{
text: 'Resolved',
label: 'Resolved'
}]
}
}]
}
};

var factory = {
getSimilarityFilters: function() {
return similarityFilters;
},
getSimilarityFilter: function(name) {
return (similarityFilters[name] || {}).filters;
},
list: function(config, callback) {
return new PaginatedQuerySrv({
name: 'alerts',
Expand Down
4 changes: 4 additions & 0 deletions frontend/app/views/components/alert/similarity/toolbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<span class="caret"></span>
</button>
<ul class="dropdown-menu" uib-dropdown-menu>
<li>
<a ng-click="$cmp.applyDefaultFilter()"><i class="fa fa-filter"></i> Default filter</a>
</li>
<li class="divider"></li>
<li>
<a ng-click="$cmp.filterBy('status', 'Open')"><i class="fa fa-folder-open-o"></i> Open cases</a>
</li>
Expand Down
6 changes: 4 additions & 2 deletions frontend/app/views/components/org/config.list.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
</div>

<div class="form-group">
<label class="col-md-3 control-label">Hide <em>Empty Case</em> button</label>
<label class="col-md-3 control-label">Select the default filter of alert case similarity panel</label>
<div class="col-md-3">
<select class="form-control" name="defaultAlertSimilarCaseFilter" ng-options="o for o in ['open-cases', 'resolved-cases']" ng-model="$ctrl.configs['defaultAlertSimilarCaseFilter']">
<select class="form-control" name="defaultAlertSimilarCaseFilter"
ng-options="k as o.label for (k, o) in $ctrl.alertSimilarityFilters"
ng-model="$ctrl.configs['defaultAlertSimilarCaseFilter']">
</select>
</div>
</div>
Expand Down

0 comments on commit 6badf58

Please sign in to comment.