From 401fd72cefc28712e57d2e9d3d9b7f7b7a7700af Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Mon, 13 Oct 2014 13:59:18 -0700 Subject: [PATCH 01/30] fix comments, remove unused code --- src/kibana/apps/visualize/editor/agg_group.html | 2 +- src/kibana/components/agg_types/param_types/field.js | 2 +- src/kibana/components/agg_types/param_types/optioned.js | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/kibana/apps/visualize/editor/agg_group.html b/src/kibana/apps/visualize/editor/agg_group.html index 4ccaaebf3a8e3..9b13bfcd7b45a 100644 --- a/src/kibana/apps/visualize/editor/agg_group.html +++ b/src/kibana/apps/visualize/editor/agg_group.html @@ -13,7 +13,7 @@ list="group"> - + Date: Mon, 13 Oct 2014 14:05:28 -0700 Subject: [PATCH 02/30] add aggParam.type, use it in agg param initialization --- src/kibana/components/agg_types/_agg_params.js | 2 +- src/kibana/components/agg_types/buckets/date_histogram.js | 1 + src/kibana/components/agg_types/buckets/terms.js | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/kibana/components/agg_types/_agg_params.js b/src/kibana/components/agg_types/_agg_params.js index 2965e0848c619..ab24ea234e714 100644 --- a/src/kibana/components/agg_types/_agg_params.js +++ b/src/kibana/components/agg_types/_agg_params.js @@ -36,7 +36,7 @@ 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 { diff --git a/src/kibana/components/agg_types/buckets/date_histogram.js b/src/kibana/components/agg_types/buckets/date_histogram.js index 6c92f1d350eae..ef4669fe2af10 100644 --- a/src/kibana/components/agg_types/buckets/date_histogram.js +++ b/src/kibana/components/agg_types/buckets/date_histogram.js @@ -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'), diff --git a/src/kibana/components/agg_types/buckets/terms.js b/src/kibana/components/agg_types/buckets/terms.js index a7d60c976b588..36acef30448b1 100644 --- a/src/kibana/components/agg_types/buckets/terms.js +++ b/src/kibana/components/agg_types/buckets/terms.js @@ -22,6 +22,7 @@ define(function (require) { }, { name: 'order', + type: 'optioned', options: [ { display: 'Top', val: 'desc' }, { display: 'Bottom', val: 'asc' } From f048f03415116a82182052bc48570cb99d45e6b5 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Mon, 13 Oct 2014 14:12:06 -0700 Subject: [PATCH 03/30] add exclude filter to terms agg, use regex aggParam --- .../components/agg_types/_agg_params.js | 4 +++ .../components/agg_types/buckets/terms.js | 7 +++++ .../components/agg_types/param_types/regex.js | 28 +++++++++++++++++++ src/kibana/filters/label.js | 16 +++++++++++ 4 files changed, 55 insertions(+) create mode 100644 src/kibana/components/agg_types/param_types/regex.js create mode 100644 src/kibana/filters/label.js diff --git a/src/kibana/components/agg_types/_agg_params.js b/src/kibana/components/agg_types/_agg_params.js index ab24ea234e714..086cbccbce332 100644 --- a/src/kibana/components/agg_types/_agg_params.js +++ b/src/kibana/components/agg_types/_agg_params.js @@ -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}} @@ -39,6 +40,9 @@ define(function (require) { else if (param.type === 'optioned') { return new OptionedAggParam(param); } + else if (param.type === 'regex') { + return new RegexAggParam(param); + } else { return new BaseAggParam(param); } diff --git a/src/kibana/components/agg_types/buckets/terms.js b/src/kibana/components/agg_types/buckets/terms.js index 36acef30448b1..cab421eba642e 100644 --- a/src/kibana/components/agg_types/buckets/terms.js +++ b/src/kibana/components/agg_types/buckets/terms.js @@ -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')); @@ -55,6 +56,12 @@ define(function (require) { output.subAggs.push(metricAggConfig); } } + }, + { + name: 'exclude', + type: 'regex', + advanced: true, + editor: require('text!components/agg_types/controls/regular_expression.html') } ] }); diff --git a/src/kibana/components/agg_types/param_types/regex.js b/src/kibana/components/agg_types/param_types/regex.js new file mode 100644 index 0000000000000..bf8bec983a15b --- /dev/null +++ b/src/kibana/components/agg_types/param_types/regex.js @@ -0,0 +1,28 @@ +define(function (require) { + return function RegexAggParamFactory(Private) { + var _ = require('lodash'); + + var BaseAggParam = Private(require('components/agg_types/param_types/base')); + + _(RegexAggParam).inherits(BaseAggParam); + function RegexAggParam(config) { + RegexAggParam.Super.call(this, config); + } + + /** + * 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) { + output.params[this.name] = aggConfig.params[this.name]; + }; + + return RegexAggParam; + }; +}); \ No newline at end of file diff --git a/src/kibana/filters/label.js b/src/kibana/filters/label.js new file mode 100644 index 0000000000000..e5b59021e1e26 --- /dev/null +++ b/src/kibana/filters/label.js @@ -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()); + } +}); \ No newline at end of file From 8ed3a8ea28a828d0b7ddbf5fefe93012cea09d0f Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Mon, 13 Oct 2014 15:30:19 -0700 Subject: [PATCH 04/30] set up regular express editor --- .../agg_types/controls/regular_expression.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/kibana/components/agg_types/controls/regular_expression.html diff --git a/src/kibana/components/agg_types/controls/regular_expression.html b/src/kibana/components/agg_types/controls/regular_expression.html new file mode 100644 index 0000000000000..68744cb103033 --- /dev/null +++ b/src/kibana/components/agg_types/controls/regular_expression.html @@ -0,0 +1,15 @@ +
+ + +
+
+ {{ flag }} +
+
+
\ No newline at end of file From 921fc364ed9b832561cd11260b8ebcb1cd1be224 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Mon, 13 Oct 2014 15:30:49 -0700 Subject: [PATCH 05/30] correctly build the regex agg query --- .../components/agg_types/param_types/regex.js | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/kibana/components/agg_types/param_types/regex.js b/src/kibana/components/agg_types/param_types/regex.js index bf8bec983a15b..0167f80cfec29 100644 --- a/src/kibana/components/agg_types/param_types/regex.js +++ b/src/kibana/components/agg_types/param_types/regex.js @@ -20,7 +20,30 @@ define(function (require) { * @return {undefined} */ RegexAggParam.prototype.write = function (aggConfig, output) { - output.params[this.name] = aggConfig.params[this.name]; + 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 + var flags = param.flags; + var selectedFlags = []; + Object.keys(flags).forEach(function (key) { + if (flags[key]) selectedFlags.push(key); + }); + + if (selectedFlags.length) { + obj.flags = selectedFlags.join('|'); + } + + output.params[this.name] = obj; }; return RegexAggParam; From 97158ce9f9a5819c2f0017d9ba195ea1938863c7 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Mon, 13 Oct 2014 15:31:11 -0700 Subject: [PATCH 06/30] add include field to terms aggs --- src/kibana/components/agg_types/buckets/terms.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/kibana/components/agg_types/buckets/terms.js b/src/kibana/components/agg_types/buckets/terms.js index cab421eba642e..5388356bab268 100644 --- a/src/kibana/components/agg_types/buckets/terms.js +++ b/src/kibana/components/agg_types/buckets/terms.js @@ -62,6 +62,12 @@ define(function (require) { type: 'regex', advanced: true, editor: require('text!components/agg_types/controls/regular_expression.html') + }, + { + name: 'include', + type: 'regex', + advanced: true, + editor: require('text!components/agg_types/controls/regular_expression.html') } ] }); From 53d58303ef4d270eed9ef58d075ff03753fb5525 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Mon, 13 Oct 2014 15:46:23 -0700 Subject: [PATCH 07/30] fix optioned text, add regex test --- .../specs/components/agg_types/_agg_params.js | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/test/unit/specs/components/agg_types/_agg_params.js b/test/unit/specs/components/agg_types/_agg_params.js index ae73d78f77308..b34ad96e7f185 100644 --- a/test/unit/specs/components/agg_types/_agg_params.js +++ b/test/unit/specs/components/agg_types/_agg_params.js @@ -6,6 +6,7 @@ define(function (require) { var BaseAggParam; var FieldAggParam; var OptionedAggParam; + var RegexAggParam; beforeEach(module('kibana')); // stub out the param classes before we get the AggParams @@ -16,6 +17,7 @@ define(function (require) { BaseAggParam = Private(require('components/agg_types/param_types/base')); FieldAggParam = Private(require('components/agg_types/param_types/field')); OptionedAggParam = Private(require('components/agg_types/param_types/optioned')); + RegexAggParam = Private(require('components/agg_types/param_types/regex')); })); describe('constructor args', function () { @@ -53,14 +55,11 @@ define(function (require) { expect(aggParams[0]).to.be.a(BaseAggParam); }); - it('Uses the OptionedAggParam class for params with defined options', function () { + it('Uses the OptionedAggParam class for params of type "optioned"', function () { var aggParams = new AggParams([ { name: 'interval', - options: [ - { display: 'Automatic', val: 'auto' }, - { display: '2 Hours', val: '2h' } - ] + type: 'optioned' } ]); @@ -69,6 +68,19 @@ define(function (require) { expect(aggParams[0]).to.be.a(BaseAggParam); }); + it('Uses the RegexAggParam class for params of type "regex"', function () { + var aggParams = new AggParams([ + { + name: 'exclude', + type: 'regex' + } + ]); + + expect(aggParams).to.have.length(1); + expect(aggParams[0]).to.be.a(RegexAggParam); + expect(aggParams[0]).to.be.a(BaseAggParam); + }); + it('Always converts the params to a BaseAggParam', function () { var aggParams = new AggParams([ { From dd55ff48b76b825b8af468c7175f79bd7272218a Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Mon, 13 Oct 2014 15:46:41 -0700 Subject: [PATCH 08/30] add label filter test --- test/unit/specs/filters/label.js | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/unit/specs/filters/label.js diff --git a/test/unit/specs/filters/label.js b/test/unit/specs/filters/label.js new file mode 100644 index 0000000000000..1e92486081357 --- /dev/null +++ b/test/unit/specs/filters/label.js @@ -0,0 +1,42 @@ +define(function (require) { + var angular = require('angular'); + var _ = require('lodash'); + var faker = require('faker'); + + // Load the kibana app dependencies. + require('angular-route'); + + // Load kibana and its applications + require('apps/discover/index'); + + var filter; + + var init = function (expandable) { + // Load the application + module('kibana'); + + // Create the scope + inject(function ($filter) { + filter = $filter('label'); + }); + }; + + describe('label filter', function () { + beforeEach(function () { + init(); + }); + + it('should have a label filter', function () { + expect(filter).to.not.be(null); + }); + + it('should capitalize the first letter in a string', function () { + expect(filter('something')).to.be('Something'); + }); + + it('should capitalize the first letter in every word', function () { + expect(filter('foo bar fizz buzz')).to.be('Foo Bar Fizz Buzz'); + }); + }); + +}); From 1dd879cde448407fe202ce82d138f0025c38071a Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Mon, 13 Oct 2014 16:48:46 -0700 Subject: [PATCH 09/30] add paramType tests, move instance checking there --- test/unit/index.html | 1 + .../specs/components/agg_types/_agg_params.js | 3 --- .../agg_types/param_types/_field.js | 25 ++++++++++++++++++ .../agg_types/param_types/_optioned.js | 26 +++++++++++++++++++ .../agg_types/param_types/_regex.js | 26 +++++++++++++++++++ .../components/agg_types/param_types/index.js | 11 ++++++++ 6 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 test/unit/specs/components/agg_types/param_types/_field.js create mode 100644 test/unit/specs/components/agg_types/param_types/_optioned.js create mode 100644 test/unit/specs/components/agg_types/param_types/_regex.js create mode 100644 test/unit/specs/components/agg_types/param_types/index.js diff --git a/test/unit/index.html b/test/unit/index.html index 182d471d40615..ada5d9e4975bc 100644 --- a/test/unit/index.html +++ b/test/unit/index.html @@ -137,6 +137,7 @@ 'specs/utils/registry/index', 'specs/directives/filter_bar', 'specs/components/agg_types/index', + 'specs/components/agg_types/param_types/index', 'specs/components/vis/index', 'specs/components/reflow_watcher', 'specs/components/clipboard' diff --git a/test/unit/specs/components/agg_types/_agg_params.js b/test/unit/specs/components/agg_types/_agg_params.js index b34ad96e7f185..86e614d56ca4b 100644 --- a/test/unit/specs/components/agg_types/_agg_params.js +++ b/test/unit/specs/components/agg_types/_agg_params.js @@ -52,7 +52,6 @@ define(function (require) { expect(aggParams).to.have.length(1); expect(aggParams[0]).to.be.a(FieldAggParam); - expect(aggParams[0]).to.be.a(BaseAggParam); }); it('Uses the OptionedAggParam class for params of type "optioned"', function () { @@ -65,7 +64,6 @@ define(function (require) { expect(aggParams).to.have.length(1); expect(aggParams[0]).to.be.a(OptionedAggParam); - expect(aggParams[0]).to.be.a(BaseAggParam); }); it('Uses the RegexAggParam class for params of type "regex"', function () { @@ -78,7 +76,6 @@ define(function (require) { expect(aggParams).to.have.length(1); expect(aggParams[0]).to.be.a(RegexAggParam); - expect(aggParams[0]).to.be.a(BaseAggParam); }); it('Always converts the params to a BaseAggParam', function () { diff --git a/test/unit/specs/components/agg_types/param_types/_field.js b/test/unit/specs/components/agg_types/param_types/_field.js new file mode 100644 index 0000000000000..6dc0ac92df91e --- /dev/null +++ b/test/unit/specs/components/agg_types/param_types/_field.js @@ -0,0 +1,25 @@ +define(function (require) { + return ['Regex', function () { + var _ = require('lodash'); + + var BaseAggParam; + var FieldAggParam; + + beforeEach(module('kibana')); + // fetch out deps + beforeEach(inject(function (Private) { + BaseAggParam = Private(require('components/agg_types/param_types/base')); + FieldAggParam = Private(require('components/agg_types/param_types/field')); + })); + + describe('constructor', function () { + it('it is an instance of BaseAggParam', function () { + var aggParam = new FieldAggParam({ + name: 'field' + }); + + expect(aggParam).to.be.a(BaseAggParam); + }); + }); + }]; +}); \ No newline at end of file diff --git a/test/unit/specs/components/agg_types/param_types/_optioned.js b/test/unit/specs/components/agg_types/param_types/_optioned.js new file mode 100644 index 0000000000000..3aaa6fb8a9dc8 --- /dev/null +++ b/test/unit/specs/components/agg_types/param_types/_optioned.js @@ -0,0 +1,26 @@ +define(function (require) { + return ['Regex', function () { + var _ = require('lodash'); + + var BaseAggParam; + var OptionedAggParam; + + beforeEach(module('kibana')); + // fetch out deps + beforeEach(inject(function (Private) { + BaseAggParam = Private(require('components/agg_types/param_types/base')); + OptionedAggParam = Private(require('components/agg_types/param_types/optioned')); + })); + + describe('constructor', function () { + it('it is an instance of BaseAggParam', function () { + var aggParam = new OptionedAggParam({ + name: 'some_param', + type: 'optioned' + }); + + expect(aggParam).to.be.a(BaseAggParam); + }); + }); + }]; +}); \ No newline at end of file diff --git a/test/unit/specs/components/agg_types/param_types/_regex.js b/test/unit/specs/components/agg_types/param_types/_regex.js new file mode 100644 index 0000000000000..d352a19af0ac8 --- /dev/null +++ b/test/unit/specs/components/agg_types/param_types/_regex.js @@ -0,0 +1,26 @@ +define(function (require) { + return ['Regex', function () { + var _ = require('lodash'); + + var BaseAggParam; + var RegexAggParam; + + beforeEach(module('kibana')); + // fetch out deps + beforeEach(inject(function (Private) { + BaseAggParam = Private(require('components/agg_types/param_types/base')); + RegexAggParam = Private(require('components/agg_types/param_types/regex')); + })); + + describe('constructor', function () { + it('it is an instance of BaseAggParam', function () { + var aggParam = new RegexAggParam({ + name: 'some_param', + type: 'regex' + }); + + expect(aggParam).to.be.a(BaseAggParam); + }); + }); + }]; +}); \ No newline at end of file diff --git a/test/unit/specs/components/agg_types/param_types/index.js b/test/unit/specs/components/agg_types/param_types/index.js new file mode 100644 index 0000000000000..d77bc9a88edf8 --- /dev/null +++ b/test/unit/specs/components/agg_types/param_types/index.js @@ -0,0 +1,11 @@ +define(function (require) { + describe('ParamTypes', function () { + var childSuites = [ + require('specs/components/agg_types/param_types/_field'), + require('specs/components/agg_types/param_types/_optioned'), + require('specs/components/agg_types/param_types/_regex') + ].forEach(function (s) { + describe(s[0], s[1]); + }); + }); +}); \ No newline at end of file From cfd20ab3c427867771290cf0988439b24cda623d Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Mon, 13 Oct 2014 17:02:47 -0700 Subject: [PATCH 10/30] add some tests for the regex param type --- .../agg_types/param_types/_regex.js | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/test/unit/specs/components/agg_types/param_types/_regex.js b/test/unit/specs/components/agg_types/param_types/_regex.js index d352a19af0ac8..f0d2c503c00a3 100644 --- a/test/unit/specs/components/agg_types/param_types/_regex.js +++ b/test/unit/specs/components/agg_types/param_types/_regex.js @@ -13,7 +13,7 @@ define(function (require) { })); describe('constructor', function () { - it('it is an instance of BaseAggParam', function () { + it('should be an instance of BaseAggParam', function () { var aggParam = new RegexAggParam({ name: 'some_param', type: 'regex' @@ -21,6 +21,49 @@ define(function (require) { expect(aggParam).to.be.a(BaseAggParam); }); + + it('should not include param in output', function () { + var paramName = 'exclude'; + var aggParam = new RegexAggParam({ + name: paramName, + type: 'regex' + }); + + var aggConfig = { params: {} }; + var output = { params: {} }; + aggConfig.params[paramName] = { + pattern: '' + }; + + expect(aggParam).to.have.property('write'); + + aggParam.write(aggConfig, output); + expect(output).to.be.an('object'); + expect(output).to.have.property('params'); + expect(output.params).not.to.have.property(paramName); + }); + + it('should include param in output', function () { + var paramName = 'exclude'; + var aggParam = new RegexAggParam({ + name: paramName, + type: 'regex' + }); + + var aggConfig = { params: {} }; + var output = { params: {} }; + aggConfig.params[paramName] = { + pattern: 'testing' + }; + + expect(aggParam).to.have.property('write'); + + aggParam.write(aggConfig, output); + expect(output).to.be.an('object'); + expect(output).to.have.property('params'); + expect(output.params).to.have.property(paramName); + expect(output.params[paramName]).to.eql({ pattern: 'testing' }); + }); }); }]; }); \ No newline at end of file From 2f86c05c5747f1263e7fbde655c493113f07b9b0 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Mon, 13 Oct 2014 17:14:17 -0700 Subject: [PATCH 11/30] add tests for write method, consolidate code --- .../agg_types/param_types/_regex.js | 50 ++++++++++++------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/test/unit/specs/components/agg_types/param_types/_regex.js b/test/unit/specs/components/agg_types/param_types/_regex.js index f0d2c503c00a3..29bbcbaae8ad6 100644 --- a/test/unit/specs/components/agg_types/param_types/_regex.js +++ b/test/unit/specs/components/agg_types/param_types/_regex.js @@ -20,23 +20,28 @@ define(function (require) { }); expect(aggParam).to.be.a(BaseAggParam); + expect(aggParam).to.have.property('write'); }); + }); - it('should not include param in output', function () { - var paramName = 'exclude'; - var aggParam = new RegexAggParam({ + describe('write results', function () { + var aggParam; + var aggConfig = { params: {} }; + var output = { params: {} }; + var paramName = 'exclude'; + + beforeEach(function () { + aggParam = new RegexAggParam({ name: paramName, type: 'regex' }); + }); - var aggConfig = { params: {} }; - var output = { params: {} }; + it('should not include param in output', function () { aggConfig.params[paramName] = { pattern: '' }; - expect(aggParam).to.have.property('write'); - aggParam.write(aggConfig, output); expect(output).to.be.an('object'); expect(output).to.have.property('params'); @@ -44,25 +49,32 @@ define(function (require) { }); it('should include param in output', function () { - var paramName = 'exclude'; - var aggParam = new RegexAggParam({ - name: paramName, - type: 'regex' - }); - - var aggConfig = { params: {} }; - var output = { params: {} }; aggConfig.params[paramName] = { pattern: 'testing' }; - expect(aggParam).to.have.property('write'); - aggParam.write(aggConfig, output); - expect(output).to.be.an('object'); - expect(output).to.have.property('params'); expect(output.params).to.have.property(paramName); expect(output.params[paramName]).to.eql({ pattern: 'testing' }); + expect(output.params[paramName]).not.to.have.property('flags'); + }); + + it('should include flags', function () { + aggConfig.params[paramName] = { + pattern: 'testing', + flags: { + TEST1: true, + TEST2: false, + TEST3: true + } + }; + + aggParam.write(aggConfig, output); + expect(output.params).to.have.property(paramName); + expect(output.params[paramName]).to.have.property('flags'); + expect(typeof output.params[paramName].flags).to.be('string'); + expect(/TEST2/.test(output.params[paramName].flags)).to.be(false); + expect(output.params[paramName].flags).to.be('TEST1|TEST3'); }); }); }]; From 1a92906cd4573017fcc938ab6fcf89cd5ae4c3ad Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Mon, 13 Oct 2014 17:22:25 -0700 Subject: [PATCH 12/30] remove superfluous condition --- test/unit/specs/components/agg_types/param_types/_regex.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unit/specs/components/agg_types/param_types/_regex.js b/test/unit/specs/components/agg_types/param_types/_regex.js index 29bbcbaae8ad6..a03f2750a37df 100644 --- a/test/unit/specs/components/agg_types/param_types/_regex.js +++ b/test/unit/specs/components/agg_types/param_types/_regex.js @@ -73,7 +73,6 @@ define(function (require) { expect(output.params).to.have.property(paramName); expect(output.params[paramName]).to.have.property('flags'); expect(typeof output.params[paramName].flags).to.be('string'); - expect(/TEST2/.test(output.params[paramName].flags)).to.be(false); expect(output.params[paramName].flags).to.be('TEST1|TEST3'); }); }); From 519cbee8110bb4294bddfdfebc0788125483f0a1 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Mon, 13 Oct 2014 17:34:15 -0700 Subject: [PATCH 13/30] only append flags of flags are set --- .../components/agg_types/param_types/regex.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/kibana/components/agg_types/param_types/regex.js b/src/kibana/components/agg_types/param_types/regex.js index 0167f80cfec29..2fe38d4816929 100644 --- a/src/kibana/components/agg_types/param_types/regex.js +++ b/src/kibana/components/agg_types/param_types/regex.js @@ -33,14 +33,15 @@ define(function (require) { }; // include any selected flags - var flags = param.flags; - var selectedFlags = []; - Object.keys(flags).forEach(function (key) { - if (flags[key]) selectedFlags.push(key); - }); - - if (selectedFlags.length) { - obj.flags = selectedFlags.join('|'); + if (param.flags) { + var selectedFlags = []; + Object.keys(param.flags).forEach(function (key) { + if (param.flags[key]) selectedFlags.push(key); + }); + + if (selectedFlags.length) { + obj.flags = selectedFlags.join('|'); + } } output.params[this.name] = obj; From defc4b3830356811fd359086e3e701ecaae35015 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Tue, 14 Oct 2014 13:32:29 -0700 Subject: [PATCH 14/30] move regex flag to the param type --- .../agg_types/controls/regular_expression.html | 2 +- .../components/agg_types/param_types/regex.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/kibana/components/agg_types/controls/regular_expression.html b/src/kibana/components/agg_types/controls/regular_expression.html index 68744cb103033..04dd1181de526 100644 --- a/src/kibana/components/agg_types/controls/regular_expression.html +++ b/src/kibana/components/agg_types/controls/regular_expression.html @@ -6,7 +6,7 @@ ng-model="params[aggParam.name].pattern" >
-
+
{{ flag }} diff --git a/src/kibana/components/agg_types/param_types/regex.js b/src/kibana/components/agg_types/param_types/regex.js index 2fe38d4816929..6da6835c2df7e 100644 --- a/src/kibana/components/agg_types/param_types/regex.js +++ b/src/kibana/components/agg_types/param_types/regex.js @@ -6,6 +6,20 @@ define(function (require) { _(RegexAggParam).inherits(BaseAggParam); function RegexAggParam(config) { + // Java RegExp flags + var flags = { + CANON_EQ: false, + CASE_INSENSITIVE: false, + COMMENTS: false, + DOTALL: false, + LITERAL: false, + MULTILINE: false, + UNICODE_CASE: false, + UNICODE_CHARACTER_CLASS: false, + UNIX_LINES: false + }; + + _.defaults(config, { pattern: '', flags: flags }); RegexAggParam.Super.call(this, config); } From 6a8dd588a115c5b36e315f8d0754763c74e82923 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Tue, 14 Oct 2014 13:33:09 -0700 Subject: [PATCH 15/30] fix issue where angular might not be loaded --- test/unit/index.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unit/index.html b/test/unit/index.html index ada5d9e4975bc..a0cb8846c2c2d 100644 --- a/test/unit/index.html +++ b/test/unit/index.html @@ -69,7 +69,7 @@ 'css!screencast_reporter_css' ], function (ScreencastReporter) { mocha.reporter(ScreencastReporter); - done() + done(); }); } @@ -77,6 +77,7 @@ require([ 'kibana', 'sinon/sinon', + 'angular', 'specs/apps/discover/hit_sort_fn', 'specs/apps/discover/directives/table', 'specs/apps/discover/directives/discover_field', From 1a21f55c1a2efaa8404f6695520046f997f225fd Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Tue, 14 Oct 2014 15:02:25 -0700 Subject: [PATCH 16/30] style the regex flags, add link to docs --- .../apps/visualize/editor/styles/editor.less | 16 ++++++++++++++++ .../agg_types/controls/regular_expression.html | 15 ++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/kibana/apps/visualize/editor/styles/editor.less b/src/kibana/apps/visualize/editor/styles/editor.less index 94266240ac912..c6baad494f32b 100644 --- a/src/kibana/apps/visualize/editor/styles/editor.less +++ b/src/kibana/apps/visualize/editor/styles/editor.less @@ -161,6 +161,22 @@ } } } + + .regex .flags { + .docs { + float: right; + margin: @vis-editor-agg-editor-spacing; + + a { + color: @gray-lighter; + } + } + + label { + padding: 0 @vis-editor-agg-editor-spacing; + font-weight: normal; + } + } } &-form-row { diff --git a/src/kibana/components/agg_types/controls/regular_expression.html b/src/kibana/components/agg_types/controls/regular_expression.html index 04dd1181de526..1c77696958ec0 100644 --- a/src/kibana/components/agg_types/controls/regular_expression.html +++ b/src/kibana/components/agg_types/controls/regular_expression.html @@ -1,15 +1,20 @@ -
+
-
-
+
+ + regex flags + +
+ ng-model="params[aggParam.name].flags[flag]"> + {{ flag }} +
\ No newline at end of file From 0f467e81d7148041591db1bcce75a2958c72d099 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Tue, 14 Oct 2014 15:06:45 -0700 Subject: [PATCH 17/30] remove label margin --- src/kibana/apps/visualize/editor/styles/editor.less | 1 + 1 file changed, 1 insertion(+) diff --git a/src/kibana/apps/visualize/editor/styles/editor.less b/src/kibana/apps/visualize/editor/styles/editor.less index c6baad494f32b..e426f5de2f640 100644 --- a/src/kibana/apps/visualize/editor/styles/editor.less +++ b/src/kibana/apps/visualize/editor/styles/editor.less @@ -173,6 +173,7 @@ } label { + margin: 0; padding: 0 @vis-editor-agg-editor-spacing; font-weight: normal; } From f776637f2ac3a291805f22190f3845b434403f7f Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Tue, 14 Oct 2014 15:29:31 -0700 Subject: [PATCH 18/30] move the regex editor into the param definition --- src/kibana/components/agg_types/buckets/terms.js | 6 ++---- src/kibana/components/agg_types/param_types/regex.js | 3 +++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/kibana/components/agg_types/buckets/terms.js b/src/kibana/components/agg_types/buckets/terms.js index 5388356bab268..8ca92c771a3db 100644 --- a/src/kibana/components/agg_types/buckets/terms.js +++ b/src/kibana/components/agg_types/buckets/terms.js @@ -60,14 +60,12 @@ define(function (require) { { name: 'exclude', type: 'regex', - advanced: true, - editor: require('text!components/agg_types/controls/regular_expression.html') + advanced: true }, { name: 'include', type: 'regex', - advanced: true, - editor: require('text!components/agg_types/controls/regular_expression.html') + advanced: true } ] }); diff --git a/src/kibana/components/agg_types/param_types/regex.js b/src/kibana/components/agg_types/param_types/regex.js index 6da6835c2df7e..5afb3ff30544e 100644 --- a/src/kibana/components/agg_types/param_types/regex.js +++ b/src/kibana/components/agg_types/param_types/regex.js @@ -3,6 +3,7 @@ define(function (require) { 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) { @@ -23,6 +24,8 @@ define(function (require) { RegexAggParam.Super.call(this, config); } + RegexAggParam.prototype.editor = editorHtml; + /** * Write the aggregation parameter. * From 3cbf76304dd7f54f336ac9c5e5924d16ae37bc6b Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Wed, 15 Oct 2014 11:23:24 -0700 Subject: [PATCH 19/30] change regex flags to multi select --- .../controls/regular_expression.html | 11 +++---- .../components/agg_types/param_types/regex.js | 33 ++++++++----------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/kibana/components/agg_types/controls/regular_expression.html b/src/kibana/components/agg_types/controls/regular_expression.html index 1c77696958ec0..71d5b4cca3dfa 100644 --- a/src/kibana/components/agg_types/controls/regular_expression.html +++ b/src/kibana/components/agg_types/controls/regular_expression.html @@ -10,11 +10,10 @@ regex flags - +
\ No newline at end of file diff --git a/src/kibana/components/agg_types/param_types/regex.js b/src/kibana/components/agg_types/param_types/regex.js index 5afb3ff30544e..947882f7e4941 100644 --- a/src/kibana/components/agg_types/param_types/regex.js +++ b/src/kibana/components/agg_types/param_types/regex.js @@ -8,17 +8,17 @@ define(function (require) { _(RegexAggParam).inherits(BaseAggParam); function RegexAggParam(config) { // Java RegExp flags - var flags = { - CANON_EQ: false, - CASE_INSENSITIVE: false, - COMMENTS: false, - DOTALL: false, - LITERAL: false, - MULTILINE: false, - UNICODE_CASE: false, - UNICODE_CHARACTER_CLASS: false, - UNIX_LINES: false - }; + 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); @@ -50,15 +50,8 @@ define(function (require) { }; // include any selected flags - if (param.flags) { - var selectedFlags = []; - Object.keys(param.flags).forEach(function (key) { - if (param.flags[key]) selectedFlags.push(key); - }); - - if (selectedFlags.length) { - obj.flags = selectedFlags.join('|'); - } + if (_.isArray(param.flags) && param.flags.length) { + obj.flags = param.flags.join('|'); } output.params[this.name] = obj; From 5ea60d394af004b6c623e15a9e56b47525e1f7e4 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Wed, 15 Oct 2014 13:39:35 -0700 Subject: [PATCH 20/30] add angular-chosen --- bower.json | 1 + src/kibana/require.config.js | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 6c370e343b478..0a373d6f97ec2 100644 --- a/bower.json +++ b/bower.json @@ -23,6 +23,7 @@ "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", diff --git a/src/kibana/require.config.js b/src/kibana/require.config.js index 9a075dbebde42..18ac6fa3610ec 100644 --- a/src/kibana/require.config.js +++ b/src/kibana/require.config.js @@ -14,11 +14,12 @@ require.config({ 'angular-elastic': 'bower_components/angular-elastic/elastic', 'angular-route': 'bower_components/angular-route/angular-route', 'angular-ui-ace': 'bower_components/angular-ui-ace/ui-ace', - 'ng-clip': 'bower_components/ng-clip/src/ngClip', + 'angular-chosen': 'bower_components/angular-chosen-localytics/chosen', ace: 'bower_components/ace-builds/src-noconflict/ace', angular: 'bower_components/angular/angular', async: 'bower_components/async/lib/async', bower_components: 'bower_components', + chosen: 'bower_components/chosen/chosen.jquery.min', css: 'bower_components/require-css/css', d3: 'bower_components/d3/d3', elasticsearch: 'bower_components/elasticsearch/elasticsearch.angular', @@ -30,6 +31,7 @@ require.config({ jsonpath: 'bower_components/jsonpath/lib/jsonpath', lodash_src: 'bower_components/lodash/dist/lodash', moment: 'bower_components/moment/moment', + 'ng-clip': 'bower_components/ng-clip/src/ngClip', text: 'bower_components/requirejs-text/text', zeroclipboard: 'bower_components/zeroclipboard/dist/ZeroClipboard' }, @@ -42,6 +44,7 @@ require.config({ exports: 'jsonPath' }, gridster: ['jquery'], + 'angular-chosen': ['jquery', 'chosen', 'css!bower_components/chosen/chosen.min.css'], 'angular-route': ['angular'], 'elasticsearch': ['angular'], 'angular-bootstrap': ['angular'], From 9a4062cc32caa9320f57f57a9c6370c82b85b3be Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Wed, 15 Oct 2014 13:40:12 -0700 Subject: [PATCH 21/30] move gridster css dep to require config --- src/kibana/apps/dashboard/directives/grid.js | 1 - src/kibana/require.config.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/kibana/apps/dashboard/directives/grid.js b/src/kibana/apps/dashboard/directives/grid.js index 0ec35574668e0..7264540d7609c 100644 --- a/src/kibana/apps/dashboard/directives/grid.js +++ b/src/kibana/apps/dashboard/directives/grid.js @@ -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'); diff --git a/src/kibana/require.config.js b/src/kibana/require.config.js index 18ac6fa3610ec..39bfe3ab34915 100644 --- a/src/kibana/require.config.js +++ b/src/kibana/require.config.js @@ -43,7 +43,7 @@ require.config({ jsonpath: { exports: 'jsonPath' }, - gridster: ['jquery'], + gridster: ['jquery', 'css!bower_components/gridster/dist/jquery.gridster.css'], 'angular-chosen': ['jquery', 'chosen', 'css!bower_components/chosen/chosen.min.css'], 'angular-route': ['angular'], 'elasticsearch': ['angular'], From 85623ce24e4b91e7efe357634ad1b2d835a0dc8d Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Wed, 15 Oct 2014 17:44:47 -0700 Subject: [PATCH 22/30] use chosen for the multi select --- src/kibana/apps/visualize/editor/agg.js | 3 ++- .../components/agg_types/controls/regular_expression.html | 3 +++ src/kibana/controllers/kibana.js | 1 - 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/kibana/apps/visualize/editor/agg.js b/src/kibana/apps/visualize/editor/agg.js index 9bcb4d046cbde..961fc7fc07abf 100644 --- a/src/kibana/apps/visualize/editor/agg.js +++ b/src/kibana/apps/visualize/editor/agg.js @@ -1,12 +1,13 @@ 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 chosen = require('angular-chosen'); require('apps/visualize/editor/agg_param'); var notify = new Notifier({ diff --git a/src/kibana/components/agg_types/controls/regular_expression.html b/src/kibana/components/agg_types/controls/regular_expression.html index 71d5b4cca3dfa..5f285adbcf430 100644 --- a/src/kibana/components/agg_types/controls/regular_expression.html +++ b/src/kibana/components/agg_types/controls/regular_expression.html @@ -12,6 +12,9 @@ diff --git a/src/kibana/controllers/kibana.js b/src/kibana/controllers/kibana.js index 6d561cfbc2880..0bb862ff19b58 100644 --- a/src/kibana/controllers/kibana.js +++ b/src/kibana/controllers/kibana.js @@ -23,7 +23,6 @@ define(function (require) { require('directives/style_compile'); require('directives/rows'); - require('angular-bootstrap'); require('services/private'); From 6b434c583093e896452bdeb2a56310568d6ed80b Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Wed, 15 Oct 2014 17:45:42 -0700 Subject: [PATCH 23/30] use bootstrap-chosen to fix styles use custom chosen styles to fix them further --- bower.json | 1 + src/kibana/require.config.js | 2 +- src/kibana/styles/_chosen.less | 50 ++++++++++++++++++++++++++++++++++ src/kibana/styles/main.less | 3 ++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/kibana/styles/_chosen.less diff --git a/bower.json b/bower.json index 0a373d6f97ec2..15080a8be0a47 100644 --- a/bower.json +++ b/bower.json @@ -31,6 +31,7 @@ "async": "~0.2.10", "bluebird": "~2.1.3", "bootstrap": "~3.1.1", + "bootstrap-chosen": "*", "d3": "~3.4.8", "elasticsearch": "*", "Faker": "~1.1.0", diff --git a/src/kibana/require.config.js b/src/kibana/require.config.js index 39bfe3ab34915..b95dd94a61f43 100644 --- a/src/kibana/require.config.js +++ b/src/kibana/require.config.js @@ -44,7 +44,7 @@ require.config({ exports: 'jsonPath' }, gridster: ['jquery', 'css!bower_components/gridster/dist/jquery.gridster.css'], - 'angular-chosen': ['jquery', 'chosen', 'css!bower_components/chosen/chosen.min.css'], + 'angular-chosen': ['jquery', 'chosen'], 'angular-route': ['angular'], 'elasticsearch': ['angular'], 'angular-bootstrap': ['angular'], diff --git a/src/kibana/styles/_chosen.less b/src/kibana/styles/_chosen.less new file mode 100644 index 0000000000000..e7caa8110405a --- /dev/null +++ b/src/kibana/styles/_chosen.less @@ -0,0 +1,50 @@ +@import "../bower_components/bootstrap-chosen/bootstrap-chosen.less"; +@chosen-sprite-path: "/bower_components/bootstrap-chosen/chosen-sprite.png"; +@chosen-sprite-retina-path: "/bower_components/bootstrap-chosen/chosen-sprite@2x.png"; +@chosen-border-width: @input-border-width; +@chosen-box-shadow: none; +@chosen-focus-box-shadow: none; +@chosen-drop-box-shadow: none; +@chosen-drop-border: @input-border-focus; + +// border overrides to match our theme +.chosen-container-single { + .chosen-single, + .chosen-search input[type="text"] { + border: @input-border-width solid @chosen-border; + } +} +.chosen-container-multi { + .chosen-choices { + border: @input-border-width solid @chosen-border; + + .search-choice { + border: @input-border-width solid @chosen-border; + } + } +} +.chosen-container-active { + .chosen-single, + &.chosen-with-drop .chosen-single, + .chosen-choices { + border: @input-border-width solid @chosen-focus-border; + } +} + +// focus rules used to match our theme +.chosen-container-active:focus { + .chosen-single, + &.chosen-with-drop .chosen-single, + .chosen-choices { + .box-shadow(@chosen-focus-box-shadow); + } +} + +// remove the gradient on the choices +.chosen-container-multi { + .chosen-choices { + .search-choice { + background-image: none; + } + } +} diff --git a/src/kibana/styles/main.less b/src/kibana/styles/main.less index 29080534f0cd8..65189b2df4b9c 100644 --- a/src/kibana/styles/main.less +++ b/src/kibana/styles/main.less @@ -13,6 +13,9 @@ // bootstrap modifications @import "./theme/_theme.less"; +// chosen +@import "./_chosen.less"; + // call outs @import "./_callout.less"; From 9138159d84f3f9263c6cd6c9cb4df8ed0c15e867 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Wed, 15 Oct 2014 17:46:09 -0700 Subject: [PATCH 24/30] change the link to the flags docs --- src/kibana/apps/visualize/editor/styles/editor.less | 13 +++---------- .../agg_types/controls/regular_expression.html | 8 ++++---- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/kibana/apps/visualize/editor/styles/editor.less b/src/kibana/apps/visualize/editor/styles/editor.less index e426f5de2f640..a04b20361fb23 100644 --- a/src/kibana/apps/visualize/editor/styles/editor.less +++ b/src/kibana/apps/visualize/editor/styles/editor.less @@ -164,18 +164,11 @@ .regex .flags { .docs { - float: right; - margin: @vis-editor-agg-editor-spacing; - - a { - color: @gray-lighter; - } + text-align: right; } - label { - margin: 0; - padding: 0 @vis-editor-agg-editor-spacing; - font-weight: normal; + a { + color: @link-color; } } } diff --git a/src/kibana/components/agg_types/controls/regular_expression.html b/src/kibana/components/agg_types/controls/regular_expression.html index 5f285adbcf430..51d8db60ac436 100644 --- a/src/kibana/components/agg_types/controls/regular_expression.html +++ b/src/kibana/components/agg_types/controls/regular_expression.html @@ -6,10 +6,10 @@ ng-model="params[aggParam.name].pattern" >
- - regex flags - +