Skip to content

Commit

Permalink
Merge pull request #4285 from rashidkpc/feature/order-by-term
Browse files Browse the repository at this point in the history
Order by term in terms agg
  • Loading branch information
lukasolson committed Jun 26, 2015
2 parents 8ef51c4 + 099da2f commit 41ab57a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
45 changes: 28 additions & 17 deletions src/kibana/components/agg_types/buckets/terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ define(function (require) {
title: 'Terms',
makeLabel: function (agg) {
var params = agg.params;
return params.order.display + ' ' + params.size + ' ' + params.field.displayName;
return params.field.displayName + ': ' + params.order.display;
},
createFilter: createFilter,
params: [
Expand All @@ -53,21 +53,6 @@ define(function (require) {
name: 'size',
default: 5
},
{
name: 'order',
type: 'optioned',
default: 'desc',
editor: require('text!components/agg_types/controls/order_and_size.html'),
options: [
{ display: 'Top', val: 'desc' },
{ display: 'Bottom', val: 'asc' }
],
write: _.noop // prevent default write, it's handled by orderAgg
},
{
name: 'orderBy',
write: _.noop // prevent default write, it's handled by orderAgg
},
{
name: 'orderAgg',
type: AggConfig,
Expand Down Expand Up @@ -122,6 +107,12 @@ define(function (require) {
// we aren't creating a custom aggConfig
if (!orderBy || orderBy !== 'custom') {
params.orderAgg = null;

if (orderBy === '_term') {
params.orderBy = '_term';
return;
}

// ensure that orderBy is set to a valid agg
if (!_.find($scope.responseValueAggs, { id: orderBy })) {
params.orderBy = null;
Expand All @@ -146,7 +137,12 @@ define(function (require) {
output.params.valueType = agg.field().type === 'number' ? 'float' : agg.field().type;
}

if (!orderAgg || orderAgg.type.name === 'count') {
if (!orderAgg) {
order[agg.params.orderBy || '_count'] = dir;
return;
}

if (orderAgg.type.name === 'count') {
order._count = dir;
return;
}
Expand All @@ -159,6 +155,21 @@ define(function (require) {
output.subAggs = (output.subAggs || []).concat(orderAgg);
order[orderAggId] = dir;
}
},
{
name: 'order',
type: 'optioned',
default: 'desc',
editor: require('text!components/agg_types/controls/order_and_size.html'),
options: [
{ display: 'Descending', val: 'desc' },
{ display: 'Ascending', val: 'asc' }
],
write: _.noop // prevent default write, it's handled by orderAgg
},
{
name: 'orderBy',
write: _.noop // prevent default write, it's handled by orderAgg
}
]
});
Expand Down
3 changes: 3 additions & 0 deletions src/kibana/components/agg_types/controls/order_agg.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<option value="custom" ng-selected="agg.params.orderBy === 'custom'">
Custom Metric
</option>
<option value="_term" ng-selected="agg.params.orderBy === '_term'">
Term
</option>
</select>
</div>
<div ng-show="agg.params.orderAgg" class="vis-editor-agg-order-agg">
Expand Down

0 comments on commit 41ab57a

Please sign in to comment.