Merge branch 'master' of github.com:elastic/kibana into fix/3944

This commit is contained in:
Spencer Alger 2015-05-22 14:30:12 -07:00
commit 4bb8bd6d0c
25 changed files with 181 additions and 162 deletions

View file

@ -21,6 +21,7 @@ define(function (require) {
}
require('filters/field_type');
require('components/validateDateInterval');
return new BucketAggType({
name: 'date_histogram',

View file

@ -5,6 +5,8 @@ define(function (require) {
var BucketAggType = Private(require('components/agg_types/buckets/_bucket_agg_type'));
var createFilter = Private(require('components/agg_types/buckets/create_filter/histogram'));
require('components/validateDateInterval');
return new BucketAggType({
name: 'histogram',
title: 'Histogram',

View file

@ -20,8 +20,10 @@
</select>
<input
type="text"
name="customInterval"
ng-model="agg.params.customInterval"
ng-change="agg.write()"
validate-date-interval
ng-change="aggForm.customInterval.$valid && agg.write()"
ng-if="agg.params.interval.val == 'custom'"
class="form-control"
required />

View file

@ -206,13 +206,13 @@ define(function (require) {
// helper to run a function on all filters in all states
function executeOnFilters(fn) {
var appState = getAppState();
var appFilters;
if (appState && appState.filters) {
appFilters = appState.filters;
} else {
appFilters = [];
}
globalState.filters.concat(appFilters).forEach(fn);
var globalFilters = [];
var appFilters = [];
if (globalState.filters) globalFilters = globalState.filters;
if (appState && appState.filters) appFilters = appState.filters;
globalFilters.concat(appFilters).forEach(fn);
}
function mergeStateFilters(gFilters, aFilters, compareOptions) {

View file

@ -0,0 +1,23 @@
define(function (require) {
var parseInterval = require('utils/parse_interval');
require('modules')
.get('kibana')
.directive('validateDateInterval', function () {
return {
restrict: 'A',
require: 'ngModel',
link: function ($scope, $el, attrs, ngModelCntrl) {
ngModelCntrl.$parsers.push(check);
ngModelCntrl.$formatters.push(check);
function check(value) {
ngModelCntrl.$setValidity('dateInterval', parseInterval(value) != null);
return value;
}
}
};
});
});

View file

@ -82,7 +82,7 @@ define(function (require) {
Chart.prototype.destroy = function () {
var selection = d3.select(this.chartEl);
this.events.removeAllListeners();
this.tooltip.hide();
if (this.tooltip) this.tooltip.hide();
selection.remove();
selection = null;
};

View file

@ -21,9 +21,12 @@ define(function (require) {
link: function ($scope, $el, attrs, kbnForm) {
$scope.$bind('outputAgg', 'outputVis.aggs.byId[agg.id]', $scope);
$scope.editorOpen = !!$scope.agg.brandNew;
if (!$scope.editorOpen) {
$scope.$evalAsync(kbnForm.$setTouched);
}
$scope.$watch('editorOpen', function (open) {
// make sure that all of the form inputs are "touched"
// so that their errors propogate
if (!open) kbnForm.$setTouched();
});
$scope.$watchMulti([
'$index',

View file

@ -3,20 +3,19 @@ define(function (require) {
var moment = require('moment');
var datemath = require('utils/datemath');
return function parseInterval(interval) {
// Assume interval is in the form (value)(unit), such as "1h"
var regex = new RegExp('^([0-9\\.]*)\\s*(' + datemath.units.join('|') + ')$');
var matches = regex.exec(interval);
var value;
var unit;
// Assume interval is in the form (value)(unit), such as "1h"
var INTERVAL_STRING_RE = new RegExp('^([0-9\\.]*)\\s*(' + datemath.units.join('|') + ')$');
if (matches && matches.length) {
value = parseFloat(matches[1]) || 1;
unit = matches[2];
}
return function parseInterval(interval) {
var matches = String(interval).trim().match(INTERVAL_STRING_RE);
if (!matches) return null;
try {
interval = moment.duration(value, unit);
var value = parseFloat(matches[1]) || 1;
var unit = matches[2];
var duration = moment.duration(value, unit);
// There is an error with moment, where if you have a fractional interval between 0 and 1, then when you add that
// interval to an existing moment object, it will remain unchanged, which causes problems in the ordered_x_keys
@ -26,9 +25,10 @@ define(function (require) {
// the start date, you get the same exact date (instead of being ahead by 12 hours). So instead of returning
// a duration corresponding to 0.5 hours, we return a duration corresponding to 12 hours.
var selectedUnit = _.find(datemath.units, function (unit) {
return Math.abs(interval.as(unit)) >= 1;
return Math.abs(duration.as(unit)) >= 1;
});
return moment.duration(interval.as(selectedUnit), selectedUnit);
return moment.duration(duration.as(selectedUnit), selectedUnit);
} catch (e) {
return null;
}

View file

@ -18,6 +18,16 @@
reporter: 'html'
});
window.describe = (function (originalDescribe) {
return function (name, body) {
if (!body && name && name instanceof Array) {
originalDescribe(name[0], name[1]);
} else {
originalDescribe(name, body);
}
};
}(window.describe))
require.config({
baseUrl: '/',
paths: {

View file

@ -1,58 +1,65 @@
define(function (require) {
describe('buildHierarchicalData()', function () {
describe('transformAggregation()', function () {
var _ = require('lodash');
var transform;
var fixture;
beforeEach(module('kibana'));
beforeEach(inject(function (Private) {
transform = Private(require('components/agg_response/hierarchical/_transform_aggregation'));
}));
var fixture = {};
fixture.agg = { id: 'agg_2', name: 'test', schema: { group: 'buckets' }, getKey: function () {},
_next: { id: 'agg_3', name: 'example', schema: { group: 'buckets' }, getKey: function () {} } };
fixture.metric = { id: 'agg_1' };
fixture.aggData = {
buckets: [
{ key: 'foo', doc_count: 2, agg_3: { buckets: [ { key: 'win', doc_count: 1 }, { key: 'mac', doc_count: 1 }]}},
{ key: 'bar', doc_count: 4, agg_3: { buckets: [ { key: 'win', doc_count: 2 }, { key: 'mac', doc_count: 2 }]}}
]
};
beforeEach(function () {
it('should return an array of objects with the doc_count as the size if the metric does not exist', function () {
var agg = { id: 'agg_2', name: 'test', schema: { group: 'buckets' }, getKey: function () {}};
var aggData = {
function fakeAgg(id, name) {
return {
id: id,
name: name,
schema: { group: 'buckets' },
getKey: _.noop,
fieldFormatter: _.constant(String)
};
}
fixture = {};
fixture.agg = fakeAgg('agg_2', 'test');
fixture.agg._next = fakeAgg('agg_3', 'example');
fixture.metric = fakeAgg('agg_1', 'metric');
fixture.metric.getValue = function (b) { return _.has(b, this.id) ? b[this.id] : b.doc_count; };
fixture.aggData = {
buckets: [
{ key: 'foo', doc_count: 1 },
{ key: 'bar', doc_count: 2 }
{ key: 'foo', doc_count: 2, agg_3: { buckets: [ { key: 'win', doc_count: 1 }, { key: 'mac', doc_count: 1 }]}},
{ key: 'bar', doc_count: 4, agg_3: { buckets: [ { key: 'win', doc_count: 2 }, { key: 'mac', doc_count: 2 }]}}
]
};
var children = transform(agg, fixture.metric, aggData);
expect(children).to.be.an(Array);
expect(children).to.have.length(2);
expect(children[0]).to.have.property('size', 1);
expect(children[1]).to.have.property('size', 2);
});
it('should return an array of objects with the metric agg value as the size', function () {
var agg = { id: 'agg_2', name: 'test', schema: { group: 'buckets' }, getKey: function () {} };
it('relies on metricAgg#getValue() for the size of the children', function () {
var aggData = {
buckets: [
{ key: 'foo', doc_count: 1, agg_1: { value: 0 } },
{ key: 'bar', doc_count: 2, agg_1: { value: 4 } }
{ key: 'foo' },
{ key: 'bar' }
]
};
var children = transform(agg, fixture.metric, aggData);
var football = {};
fixture.metric.getValue = _.constant(football);
var children = transform(fixture.agg, fixture.metric, aggData);
expect(children).to.be.an(Array);
expect(children).to.have.length(2);
expect(children[0]).to.have.property('size', 0);
expect(children[1]).to.have.property('size', 4);
expect(children[0]).to.have.property('size', football);
expect(children[1]).to.have.property('size', football);
});
it('should create two levels of metrics', function () {
var children = transform(fixture.agg, fixture.metric, fixture.aggData);
fixture.metric.getValue = function (b) { return b.doc_count; };
expect(children).to.be.an(Array);
expect(children).to.have.length(2);
expect(children[0]).to.have.property('children');

View file

@ -1,15 +1,14 @@
define(function (require) {
describe('Point Series Agg Response', function () {
run(require('specs/components/agg_response/point_series/_main'));
run(require('specs/components/agg_response/point_series/_add_to_siri'));
run(require('specs/components/agg_response/point_series/_fake_x_aspect'));
run(require('specs/components/agg_response/point_series/_get_aspects'));
run(require('specs/components/agg_response/point_series/_get_point'));
run(require('specs/components/agg_response/point_series/_get_series'));
run(require('specs/components/agg_response/point_series/_init_x_axis'));
run(require('specs/components/agg_response/point_series/_init_y_axis'));
run(require('specs/components/agg_response/point_series/_ordered_date_axis'));
run(require('specs/components/agg_response/point_series/_tooltip_formatter'));
function run(module) { describe(module[0], module[1]); }
describe(require('specs/components/agg_response/point_series/_main'));
describe(require('specs/components/agg_response/point_series/_add_to_siri'));
describe(require('specs/components/agg_response/point_series/_fake_x_aspect'));
describe(require('specs/components/agg_response/point_series/_get_aspects'));
describe(require('specs/components/agg_response/point_series/_get_point'));
describe(require('specs/components/agg_response/point_series/_get_series'));
describe(require('specs/components/agg_response/point_series/_init_x_axis'));
describe(require('specs/components/agg_response/point_series/_init_y_axis'));
describe(require('specs/components/agg_response/point_series/_ordered_date_axis'));
describe(require('specs/components/agg_response/point_series/_tooltip_formatter'));
});
});
});

View file

@ -1,11 +1,10 @@
define(function (require) {
describe('Tabify Agg Response', function () {
run(require('specs/components/agg_response/tabify/_get_columns'));
run(require('specs/components/agg_response/tabify/_buckets'));
run(require('specs/components/agg_response/tabify/_table'));
run(require('specs/components/agg_response/tabify/_table_group'));
run(require('specs/components/agg_response/tabify/_response_writer'));
run(require('specs/components/agg_response/tabify/_integration'));
function run(module) { describe(module[0], module[1]); }
describe(require('specs/components/agg_response/tabify/_get_columns'));
describe(require('specs/components/agg_response/tabify/_buckets'));
describe(require('specs/components/agg_response/tabify/_table'));
describe(require('specs/components/agg_response/tabify/_table_group'));
describe(require('specs/components/agg_response/tabify/_response_writer'));
describe(require('specs/components/agg_response/tabify/_integration'));
});
});
});

View file

@ -1,7 +1,6 @@
define(function (require) {
describe('AggTable Component', function () {
run(require('specs/components/agg_table/_group'));
run(require('specs/components/agg_table/_table'));
function run(mod) { describe(mod[0], mod[1]); }
describe(require('specs/components/agg_table/_group'));
describe(require('specs/components/agg_table/_table'));
});
});
});

View file

@ -1,14 +1,10 @@
define(function (require) {
describe('AggTypesComponent', function () {
var childSuites = [
require('specs/components/agg_types/_agg_type'),
require('specs/components/agg_types/_agg_params'),
require('specs/components/agg_types/_bucket_count_between'),
require('specs/components/agg_types/buckets/_histogram'),
require('specs/components/agg_types/buckets/_date_histogram')
].forEach(function (s) {
describe(s[0], s[1]);
});
describe(require('specs/components/agg_types/_agg_type'));
describe(require('specs/components/agg_types/_agg_params'));
describe(require('specs/components/agg_types/_bucket_count_between'));
describe(require('specs/components/agg_types/buckets/_histogram'));
describe(require('specs/components/agg_types/buckets/date_histogram/_date_histogram'));
describe('bucket aggs', function () {
var bucketAggs;
@ -44,4 +40,4 @@ define(function (require) {
});
});
});
});
});

View file

@ -1,13 +1,9 @@
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'),
require('specs/components/agg_types/param_types/_string'),
require('specs/components/agg_types/param_types/_raw_json')
].forEach(function (s) {
describe(s[0], s[1]);
});
describe(require('specs/components/agg_types/param_types/_field'));
describe(require('specs/components/agg_types/param_types/_optioned'));
describe(require('specs/components/agg_types/param_types/_regex'));
describe(require('specs/components/agg_types/param_types/_string'));
describe(require('specs/components/agg_types/param_types/_raw_json'));
});
});
});

View file

@ -113,6 +113,16 @@ define(function (require) {
expect(filter.meta.negate).to.be(false);
});
});
it('should work without global state filters', function () {
// remove global filters
delete globalState.filters;
queryFilter.invertAll();
_.each(appState.filters, function (filter) {
expect(filter.meta.negate).to.be(true);
});
});
});
}];
});

View file

@ -44,16 +44,12 @@ define(function (require) {
});
describe('Actions', function () {
var childSuites = [
require('specs/components/filter_bar/_getFilters'),
require('specs/components/filter_bar/_addFilters'),
require('specs/components/filter_bar/_removeFilters'),
require('specs/components/filter_bar/_toggleFilters'),
require('specs/components/filter_bar/_invertFilters'),
require('specs/components/filter_bar/_pinFilters'),
].forEach(function (s) {
describe(s[0], s[1]);
});
describe(require('specs/components/filter_bar/_getFilters'));
describe(require('specs/components/filter_bar/_addFilters'));
describe(require('specs/components/filter_bar/_removeFilters'));
describe(require('specs/components/filter_bar/_toggleFilters'));
describe(require('specs/components/filter_bar/_invertFilters'));
describe(require('specs/components/filter_bar/_pinFilters'));
});
});
});

View file

@ -1,12 +1,10 @@
define(function (require) {
describe('Index Patterns', function () {
run(require('specs/components/index_pattern/_index_pattern'));
run(require('specs/components/index_pattern/_cast_mapping_type'));
run(require('specs/components/index_pattern/_map_field'));
run(require('specs/components/index_pattern/_pattern_to_wildcard'));
run(require('specs/components/index_pattern/_get_computed_fields'));
run(require('specs/components/index_pattern/_FieldFormat'));
function run(mod) { describe(mod[0], mod[1]); }
describe(require('specs/components/index_pattern/_index_pattern'));
describe(require('specs/components/index_pattern/_cast_mapping_type'));
describe(require('specs/components/index_pattern/_map_field'));
describe(require('specs/components/index_pattern/_pattern_to_wildcard'));
describe(require('specs/components/index_pattern/_get_computed_fields'));
describe(require('specs/components/index_pattern/_FieldFormat'));
});
});

View file

@ -1,12 +1,8 @@
define(function (require) {
describe('Stringify Component', function () {
run(require('specs/components/stringify/_conformance'));
run(require('specs/components/stringify/_ip'));
run(require('specs/components/stringify/_source'));
run(require('specs/components/stringify/_url'));
function run(suite) {
describe(suite[0], suite[1]);
}
describe(require('specs/components/stringify/_conformance'));
describe(require('specs/components/stringify/_ip'));
describe(require('specs/components/stringify/_source'));
describe(require('specs/components/stringify/_url'));
});
});

View file

@ -1,10 +1,6 @@
define(function (require) {
describe('Vis Component', function () {
var childSuites = [
require('specs/components/vis/_agg_config'),
require('specs/components/vis/_agg_configs')
].forEach(function (s) {
describe(s[0], s[1]);
});
describe(require('specs/components/vis/_agg_config'));
describe(require('specs/components/vis/_agg_configs'));
});
});
});

View file

@ -1,7 +1,6 @@
define(function (require) {
describe('Table Vis', function () {
function run(m) { describe(m[0], m[1]); }
run(require('specs/plugins/table_vis/_table_vis_controller'));
run(require('specs/plugins/table_vis/_table_vis'));
describe(require('specs/plugins/table_vis/_table_vis_controller'));
describe(require('specs/plugins/table_vis/_table_vis'));
});
});
});

View file

@ -1,10 +1,6 @@
define(function (require) {
describe('Vis Type', function () {
var childSuites = [
require('specs/plugins/vis_types/_renderbot'),
require('specs/plugins/vis_types/vislib/_index')
].forEach(function (s) {
describe(s[0], s[1]);
});
describe(require('specs/plugins/vis_types/_renderbot'));
describe(require('specs/plugins/vis_types/vislib/_index'));
});
});
});

View file

@ -1,9 +1,6 @@
define(function (require) {
return ['Vislib', exportWrapper];
function exportWrapper() {
run(require('specs/plugins/vis_types/vislib/_renderbot'));
run(require('specs/plugins/vis_types/vislib/_build_chart_data'));
function run(m) { describe(m[0], m[1]); }
}
});
return ['Vislib', function () {
describe(require('specs/plugins/vis_types/vislib/_renderbot'));
describe(require('specs/plugins/vis_types/vislib/_build_chart_data'));
}];
});

View file

@ -1,8 +1,7 @@
define(function (require) {
describe('lodash mixins', function () {
run(require('specs/utils/mixins/_move'));
run(require('specs/utils/mixins/_organize_by'));
run(require('specs/utils/mixins/_push_all'));
function run(m) { describe(m[0], m[1]); }
describe(require('specs/utils/mixins/_move'));
describe(require('specs/utils/mixins/_organize_by'));
describe(require('specs/utils/mixins/_push_all'));
});
});

View file

@ -65,16 +65,11 @@ define(function (require) {
var items = vis.handler.legend.labels;
items.forEach(function (label) {
var path = _(paths)
.map(function (path) {
return path.getAttribute('data-label');
})
.filter(function (dataLabel) {
return dataLabel === label;
})
.value();
var path = _.find(paths, function (path) {
return path.getAttribute('data-label') === String(label);
});
expect(path.length).to.be.greaterThan(0);
expect(path).to.be.ok();
});
});
});