Skip to content

Commit

Permalink
#1171 Add tag filter config for case list page
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Oct 14, 2020
1 parent 2e38867 commit 67f70f8
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 35 deletions.
7 changes: 4 additions & 3 deletions ui/app/scripts/services/CasesUISrv.js
@@ -1,7 +1,7 @@
(function() {
'use strict';
angular.module('theHiveServices')
.factory('CasesUISrv', function($q, localStorageService, Severity, Tlp) {
.factory('CasesUISrv', function($q, localStorageService, Severity, Tlp, UiSettingsSrv) {
var defaultFilter = {
status: {
field: 'status',
Expand Down Expand Up @@ -88,7 +88,7 @@
},
currentState: null,
currentPageSize: null,

useAndForCaseTagsFilter: UiSettingsSrv.useAndForCaseTagsFilter() ? ' AND ' : ' OR ',
initContext: function(state) {
var storedContext = localStorageService.get('cases-section');
if (storedContext) {
Expand Down Expand Up @@ -167,9 +167,10 @@
if (field === 'keyword') {
query = value.replace(/"/gi, '\\"');
} else if (angular.isArray(value) && value.length > 0) {
var useAndForCaseTagsFilter = UiSettingsSrv.useAndForCaseTagsFilter() ? ' AND ' : ' OR ';
query = _.map(value, function(val) {
return field + ':"' + convertFn(val.text.replace(/"/gi, '\\"')) + '"';
}).join(' OR ');
}).join(field === 'tags' ? useAndForCaseTagsFilter : ' OR ');
query = '(' + query + ')';
} else if (filterDef.type === 'date') {
var fromDate = value.from ? moment(value.from).hour(0).minutes(0).seconds(0).valueOf() : '*',
Expand Down
6 changes: 3 additions & 3 deletions ui/app/scripts/services/FilteringSrv.js
Expand Up @@ -21,9 +21,9 @@
sort: this.defaults.sort || []
};

this.useAndFiltering = UiSettingsSrv.useAndFiltering();
this.useAndForAlertTagsFilter = UiSettingsSrv.useAndForAlertTagsFilter();

this.filterString = self.useAndFiltering ? ' AND ' : ' OR ';
this.filterString = self.useAndForAlertTagsFilter ? ' AND ' : ' OR ';

this.initContext = function(state) {
var storedContext = localStorageService.get(self.sectionName);
Expand Down Expand Up @@ -102,7 +102,7 @@
} else if (angular.isArray(value) && value.length > 0) {
query = _.map(value, function(val) {
return field + ':"' + convertFn(val.text) + '"';
}).join(self.filterString);
}).join(filterDef.type === 'tags' ? self.filterString : ' OR ');
query = '(' + query + ')';
} else if (filterDef.type === 'date') {
var fromDate = value.from ? moment(value.from).hour(0).minutes(0).seconds(0).valueOf() : '*',
Expand Down
3 changes: 2 additions & 1 deletion ui/app/scripts/services/UiSettingsSrv.js
Expand Up @@ -6,7 +6,8 @@

var keys = [
'hideEmptyCaseButton',
'useAndFiltering'
'useAndForCaseTagsFilter',
'useAndForAlertTagsFilter'
];

var factory = {
Expand Down
98 changes: 70 additions & 28 deletions ui/app/views/partials/admin/ui-settings.html
@@ -1,40 +1,82 @@
<div class="row">
<div class="col-md-12">
<form name="settingsForm" class="form-horizontal" ng-submit="$vm.save(settingsForm)" novalidate>
<div class="box">
<div class="box-header">
<h3 class="box-title">UI Settings</h3>
</div>
<div class="box-body">

<div class="form-group">
<label class="col-md-3 control-label">Hide <em>Empty Case</em> button</label>
<div class="col-md-9">
<div class="checkbox">
<label>
<input name="hideEmptyCaseButton" type="checkbox" ng-model="$vm.configs.hideEmptyCaseButton"> Check this to disallow creating empty cases
</label>
<form name="settingsForm" class="form-horizontal" ng-submit="$vm.save(settingsForm)" novalidate>

<section class="content-header">
<h1>
UI Settings
</h1>
</section>

<section class="content">
<div class="row">
<div class="col-md-6 col-sm-12">
<div class="box">
<div class="box-header">
<h3 class="box-title">General configuration</h3>
</div>
<div class="box-body">

<div class="form-group">
<label class="col-md-4 control-label">Hide <em>Empty Case</em> button</label>
<div class="col-md-8">
<div class="checkbox">
<label>
<input name="hideEmptyCaseButton" type="checkbox" ng-model="$vm.configs.hideEmptyCaseButton"> Check this to disallow creating empty cases
</label>
</div>
</div>
</div>
</div>
</div>

<div class="box">
<div class="box-header">
<h3 class="box-title">Case section configuration</h3>
</div>
<div class="box-body">

<div class="form-group">
<label class="col-md-3 control-label">Use <strong>AND</strong> instead of <strong>OR</strong> for alert filtering</label>
<div class="col-md-9">
<div class="checkbox">
<label>
<input name="tagsUseAndCheckbox" type="checkbox" ng-model="$vm.configs.useAndFiltering"> Check this to change how alert filters are combined
</label>
<div class="form-group">
<label class="col-md-4 control-label">Case's tag filter operator</label>
<div class="col-md-8">
<div class="checkbox">
<label>
<input type="checkbox" ng-model="$vm.configs.useAndForCaseTagsFilter">
Check this to use <strong>AND</strong> instead of <strong>OR</strong> to combine case tags filter values
</label>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6 col-sm-12">

<div class="mt-s">
<button class="btn btn-primary pull-right" ng-disabled="settingsForm.$invalid" type="submit">Save</button>
<div class="box">
<div class="box-header">
<h3 class="box-title">Alert section configuration</h3>
</div>
<div class="box-body">

<div class="form-group">
<label class="col-md-4 control-label">Alert's tag filter operator</label>
<div class="col-md-8">
<div class="checkbox">
<label>
<input type="checkbox" ng-model="$vm.configs.useAndForAlertTagsFilter">
Check this to use <strong>AND</strong> instead of <strong>OR</strong> to combine alert tags filter values
</label>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="row mt-s">
<div class="col-sm-12">
<button class="btn btn-primary pull-right" ng-disabled="settingsForm.$invalid" type="submit">Save</button>
</div>
</div>
</section>


</form>

0 comments on commit 67f70f8

Please sign in to comment.