Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order by term in terms agg #4285

Merged
merged 3 commits into from
Jun 26, 2015
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,11 +137,16 @@ define(function (require) {
output.params.valueType = agg.field().type === 'number' ? 'float' : agg.field().type;
}

if (!orderAgg || orderAgg.type.name === 'count') {
if (orderAgg && orderAgg.type.name === 'count') {
order._count = dir;
return;
}

if (!orderAgg) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this up so it returns first when met, and remove the orderAgg && bit from what is currently line 140?

order[agg.params.orderBy || '_count'] = dir;
return;
}

var orderAggId = orderAgg.id;
if (orderAgg.parentId) {
orderAgg = vis.aggs.byId[orderAgg.parentId];
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
Loading