Skip to content

Commit

Permalink
Merge pull request #1660 from w33ble/exclude-terms
Browse files Browse the repository at this point in the history
Include and Exclude params on terms agg
  • Loading branch information
w33ble committed Oct 20, 2014
2 parents cde3120 + fc4b00f commit 7560531
Show file tree
Hide file tree
Showing 25 changed files with 436 additions and 35 deletions.
2 changes: 2 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
"angular": "~1.2.14",
"angular-bindonce": "~0.3.1",
"angular-bootstrap": "~0.10.0",
"angular-chosen-localytics": "~1.0.6",
"angular-elastic": "~2.3.3",
"angular-mocks": "~1.2.14",
"angular-route": "~1.2.14",
"angular-ui-ace": "bower",
"async": "~0.2.10",
"bluebird": "~2.1.3",
"bootstrap": "~3.1.1",
"bootstrap-chosen": "*",
"d3": "~3.4.8",
"elasticsearch": "*",
"Faker": "~1.1.0",
Expand Down
1 change: 0 additions & 1 deletion src/kibana/apps/dashboard/directives/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ define(function (require) {
var $ = require('jquery');

require('gridster');
require('css!bower_components/gridster/dist/jquery.gridster.css');

var app = require('modules').get('app/dashboard');

Expand Down
73 changes: 55 additions & 18 deletions src/kibana/apps/visualize/editor/agg.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
define(function (require) {
require('modules')
.get('app/visualize')
.get('app/visualize', ['localytics.directives'])
.directive('visEditorAgg', function ($compile, $parse, Private, Notifier) {
var _ = require('lodash');
var $ = require('jquery');
var aggTypes = Private(require('components/agg_types/index'));
var aggSelectHtml = require('text!apps/visualize/editor/agg_select.html');
var advancedToggleHtml = require('text!apps/visualize/partials/advanced_toggle.html');

var chosen = require('angular-chosen');
require('apps/visualize/editor/agg_param');

var notify = new Notifier({
Expand All @@ -28,6 +30,7 @@ define(function (require) {
link: function ($scope, $el) {
$scope.aggTypeOptions = aggTypes.byType[$scope.groupName];
$scope.editorOpen = $scope.agg.brandNew;
$scope.advancedToggled = false;

$scope.$watchMulti([
'$index',
Expand All @@ -54,8 +57,8 @@ define(function (require) {
var $aggSelect = $(aggSelectHtml).appendTo($editorContainer);
$compile($aggSelect)($scope);

// params for the selected agg, these are rebuilt every time the agg changes
var $aggParamEditors;
// params for the selected agg, these are rebuilt every time the agg in $aggSelect changes
var $aggParamEditors; // container for agg type param editors
var $aggParamEditorsScope;
$scope.$watch('agg.type', function updateAggParamEditor(newType, oldType) {
if ($aggParamEditors) {
Expand All @@ -81,25 +84,59 @@ define(function (require) {

if (!type) return;

var editors = type.params.map(function (param, i) {
if (!param.editor) return;

return $('<vis-agg-param-editor>')
.attr({
'agg-type': 'agg.type',
'agg-config': 'agg',
'agg-param': 'agg.type.params[' + i + ']',
'params': 'agg.params'
})
.append(param.editor)
.get(0);
}).filter(Boolean);

$aggParamEditors = $(editors).appendTo($editorContainer);
var aggParamHTML = {
basic: [],
advanced: []
};

// build collection of agg params html
type.params.forEach(function (param, i) {
var aggParam;
var type = 'basic';
if (param.advanced) type = 'advanced';

if (aggParam = getAggParamHTML(param, i)) {
aggParamHTML[type].push(aggParam);
}
});

// compile the paramEditors html elements
var paramEditors = aggParamHTML.basic;

if (aggParamHTML.advanced.length) {
paramEditors.push($(advancedToggleHtml).get(0));
paramEditors = paramEditors.concat(aggParamHTML.advanced);
}

$aggParamEditorsScope = $scope.$new();
$aggParamEditors = $(paramEditors).appendTo($editorContainer);
$compile($aggParamEditors)($aggParamEditorsScope);
});

// build HTML editor given an aggParam and index
function getAggParamHTML(param, idx) {
// don't show params without an editor
if (!param.editor) {
return;
}

var attrs = {
'agg-type': 'agg.type',
'agg-config': 'agg',
'params': 'agg.params'
};

attrs['agg-param'] = 'agg.type.params[' + idx + ']';
if (param.advanced) {
attrs['ng-show'] = 'advancedToggled';
}

return $('<vis-agg-param-editor>')
.attr(attrs)
.append(param.editor)
.get(0);
}

// generic child scope creation, for both schema and agg
function editorScope() {
var $editorScope = $scope.$new();
Expand Down
2 changes: 1 addition & 1 deletion src/kibana/apps/visualize/editor/agg_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
list="group">
</nesting-indicator>

<!-- agg.html -->
<!-- agg.html - controls for aggregation -->
<vis-editor-agg
vis="vis"
group="group"
Expand Down
10 changes: 10 additions & 0 deletions src/kibana/apps/visualize/editor/styles/editor.less
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@
}
}
}

.regex .flags {
.docs {
text-align: right;
}

a {
color: @link-color;
}
}
}

&-form-row {
Expand Down
8 changes: 8 additions & 0 deletions src/kibana/apps/visualize/partials/advanced_toggle.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="advanced-toggle">
<div ng-show="!advancedToggled">
<a ng-click="advancedToggled = !advancedToggled">Advanced Parameters</a>
</div>
<div ng-show="advancedToggled">
<a ng-click="advancedToggled = !advancedToggled">Hide Advanced</a>
</div>
</div>
6 changes: 5 additions & 1 deletion src/kibana/components/agg_types/_agg_params.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ define(function (require) {
var BaseAggParam = Private(require('components/agg_types/param_types/base'));
var FieldAggParam = Private(require('components/agg_types/param_types/field'));
var OptionedAggParam = Private(require('components/agg_types/param_types/optioned'));
var RegexAggParam = Private(require('components/agg_types/param_types/regex'));

/**
* Wraps a list of {{#crossLink "AggParam"}}{{/crossLink}} objects; owned by an {{#crossLink "AggType"}}{{/crossLink}}
Expand Down Expand Up @@ -36,9 +37,12 @@ define(function (require) {
if (param.name === 'field') {
return new FieldAggParam(param);
}
else if (param.options) {
else if (param.type === 'optioned') {
return new OptionedAggParam(param);
}
else if (param.type === 'regex') {
return new RegexAggParam(param);
}
else {
return new BaseAggParam(param);
}
Expand Down
1 change: 1 addition & 0 deletions src/kibana/components/agg_types/buckets/date_histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ define(function (require) {

{
name: 'interval',
type: 'optioned',
default: 'auto',
options: Private(require('components/agg_types/buckets/_interval_options')),
editor: require('text!components/agg_types/controls/interval.html'),
Expand Down
12 changes: 12 additions & 0 deletions src/kibana/components/agg_types/buckets/terms.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
define(function (require) {
return function TermsAggDefinition(Private) {
var _ = require('lodash');
require('filters/label');
var AggType = Private(require('components/agg_types/_agg_type'));
var bucketCountBetween = Private(require('components/agg_types/buckets/_bucket_count_between'));

Expand All @@ -22,6 +23,7 @@ define(function (require) {
},
{
name: 'order',
type: 'optioned',
options: [
{ display: 'Top', val: 'desc' },
{ display: 'Bottom', val: 'asc' }
Expand Down Expand Up @@ -54,6 +56,16 @@ define(function (require) {
output.subAggs.push(metricAggConfig);
}
}
},
{
name: 'exclude',
type: 'regex',
advanced: true
},
{
name: 'include',
type: 'regex',
advanced: true
}
]
});
Expand Down
22 changes: 22 additions & 0 deletions src/kibana/components/agg_types/controls/regular_expression.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div class="form-group regex">
<label>{{ aggParam.name | label }}</label>
<input
type="text"
class="form-control"
ng-model="params[aggParam.name].pattern"
>
<div class="flags">
<div class="docs">
<small><a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#field_detail"
target="_blank">Regex Flags</a></small>
</div>
<select
multiple
chosen
width="'100%'"
data-placeholder="Flags"
ng-model="params[aggParam.name].flags"
ng-options="label for label in aggParam.flags">
</select>
</div>
</div>
2 changes: 1 addition & 1 deletion src/kibana/components/agg_types/param_types/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ define(function (require) {
* @param {AggConfig} aggConfig - the entire configuration for this agg
* @param {object} output - the result of calling write on all of the aggregations
* parameters.
* @param {object} output.param - the final object that will be included as the params
* @param {object} output.params - the final object that will be included as the params
* for the agg
* @return {undefined}
*/
Expand Down
3 changes: 1 addition & 2 deletions src/kibana/components/agg_types/param_types/optioned.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ define(function (require) {
var _ = require('lodash');

var Registry = require('utils/registry/registry');
var editorHtml = require('text!components/agg_types/controls/field.html');
var BaseAggParam = Private(require('components/agg_types/param_types/base'));

_(OptionedAggParam).inherits(BaseAggParam);
Expand Down Expand Up @@ -43,7 +42,7 @@ define(function (require) {
* @param {AggConfig} aggConfig - the entire configuration for this agg
* @param {object} output - the result of calling write on all of the aggregations
* parameters.
* @param {object} output.param - the final object that will be included as the params
* @param {object} output.params - the final object that will be included as the params
* for the agg
* @return {undefined}
*/
Expand Down
62 changes: 62 additions & 0 deletions src/kibana/components/agg_types/param_types/regex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
define(function (require) {
return function RegexAggParamFactory(Private) {
var _ = require('lodash');

var BaseAggParam = Private(require('components/agg_types/param_types/base'));
var editorHtml = require('text!components/agg_types/controls/regular_expression.html');

_(RegexAggParam).inherits(BaseAggParam);
function RegexAggParam(config) {
// Java RegExp flags
var flags = [
'CANON_EQ',
'CASE_INSENSITIVE',
'COMMENTS',
'DOTALL',
'LITERAL',
'MULTILINE',
'UNICODE_CASE',
'UNICODE_CHARACTER_CLASS',
'UNIX_LINES'
];

_.defaults(config, { pattern: '', flags: flags });
RegexAggParam.Super.call(this, config);
}

RegexAggParam.prototype.editor = editorHtml;

/**
* Write the aggregation parameter.
*
* @param {AggConfig} aggConfig - the entire configuration for this agg
* @param {object} output - the result of calling write on all of the aggregations
* parameters.
* @param {object} output.params - the final object that will be included as the params
* for the agg
* @return {undefined}
*/
RegexAggParam.prototype.write = function (aggConfig, output) {
var param = aggConfig.params[this.name];

// clear aggParam if pattern is not set
if (!param || !param.pattern || !param.pattern.length) {
delete output.params[this.name];
return;
}

var obj = {
pattern: param.pattern
};

// include any selected flags
if (_.isArray(param.flags) && param.flags.length) {
obj.flags = param.flags.join('|');
}

output.params[this.name] = obj;
};

return RegexAggParam;
};
});
1 change: 0 additions & 1 deletion src/kibana/controllers/kibana.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ define(function (require) {
require('directives/style_compile');
require('directives/rows');


require('angular-bootstrap');
require('services/private');

Expand Down
16 changes: 16 additions & 0 deletions src/kibana/filters/label.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
define(function (require) {
require('modules')
.get('kibana')
.filter('label', function () {
return function (str) {
var words = str.split(' ');
return words.map(capFirst).join(' ');
};
});

function capFirst(str) {
var i = str[0];
var r = new RegExp(i, 'i');
return str.replace(r, i.toUpperCase());
}
});
Loading

0 comments on commit 7560531

Please sign in to comment.