Skip to content

Commit

Permalink
#186 Enhance the tags filter of the statistics page
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Jun 8, 2017
1 parent 173e65a commit 6ef63fd
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 12 deletions.
55 changes: 44 additions & 11 deletions ui/app/scripts/controllers/StatisticsCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
$scope.globalFilters = StatisticSrv.getFilters() || {
fromDate: moment().subtract(30, 'd').toDate(),
toDate: moment().toDate(),
tags: []
tags: [],
tagsAggregator: 'any'
};

$scope.tagsAggregators = {
any: 'Any of',
all: 'All of',
none: 'None of'
};

$scope.caseByTlp = {
Expand Down Expand Up @@ -150,35 +157,61 @@
}
};

$scope.setTagsAggregator = function(aggregator) {
$scope.globalFilters.tagsAggregator = aggregator;
};


// Prepare the global query
$scope.prepareGlobalQuery = function() {
// Handle date queries
var start = $scope.globalFilters.fromDate ? $scope.globalFilters.fromDate.getTime() : '*';
var end = $scope.globalFilters.toDate ? $scope.globalFilters.toDate.setHours(23,59,59,999) : '*';

// Handle date queries
// Handle tags query
var tags = _.map($scope.globalFilters.tags, function(tag) {
return tag.text;
});

return function(options) {
return {
var queryCriteria = {
_and: [
{
_between: { _field: options.dateField, _from: start, _to: end}
},
{
_or: _.map(tags, function(t) {
return { _field: options.tagsField, _value: t };
})
}
]
};
};

//return segments.join(' AND ');

// Adding tags criteria
if(tags.length > 0) {
var tagsCriterions = _.map(tags, function(t) {
return { _field: options.tagsField, _value: t };
});
var tagsCriteria = {};
switch($scope.globalFilters.tagsAggregator) {
case 'all':
tagsCriteria = {
_and: tagsCriterions
};
break;
case 'none':
tagsCriteria = {
_not: {
_or: tagsCriterions
}
};
break;
case 'any':
default:
tagsCriteria = {
_or: tagsCriterions
}
}
queryCriteria._and.push(tagsCriteria);
}

return queryCriteria;
};
};

$scope.filter = function() {
Expand Down
15 changes: 14 additions & 1 deletion ui/app/views/partials/statistics.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,20 @@
</div>
<div class="form-group hpad10">
<label>Tags</label>
<tags-input class="form-control form-control-wrapper" style="width: 300px;" min-length="2" ng-model="globalFilters.tags" placeholder="Add tags" replace-spaces-with-dashes="false"></tags-input>
<div class="input-group">
<div class="input-group-btn" uib-dropdown>
<button type="button" class="btn btn-default dropdown-toggle" uib-dropdown-toggle>
{{tagsAggregators[globalFilters.tagsAggregator]}} <span class="caret"></span>
</button>
<ul class="dropdown-menu" uib-dropdown-menu>
<li><a href ng-click="setTagsAggregator('any')">Any of</a></li>
<li><a href ng-click="setTagsAggregator('all')">All of</a></li>
<li><a href ng-click="setTagsAggregator('none')">None of</a></li>
</ul>
</div>
<tags-input class="form-control form-control-wrapper" style="width: 300px;" min-length="2" ng-model="globalFilters.tags" placeholder="Add tags" replace-spaces-with-dashes="false"></tags-input>
</div>
<!-- <tags-input class="form-control form-control-wrapper" style="width: 300px;" min-length="2" ng-model="globalFilters.tags" placeholder="Add tags" replace-spaces-with-dashes="false"></tags-input> -->
</div>
<button type="submit" class="btn btn-primary" uib-tooltip="Apply global filters to all charts">
<i class="fa fa-search"></i>
Expand Down

0 comments on commit 6ef63fd

Please sign in to comment.