mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Merge branch 'vislib/refactor' of https://github.com/elasticsearch/kibana4 into vislib/refactor
This commit is contained in:
commit
4d25913919
6 changed files with 94 additions and 12 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -5,4 +5,4 @@ bower_components
|
|||
trash
|
||||
build
|
||||
target
|
||||
.jruby
|
||||
.jruby
|
||||
|
|
|
@ -21,7 +21,8 @@ define(function (require) {
|
|||
toggle: '=',
|
||||
data: '=',
|
||||
state: '=',
|
||||
searchSource: '='
|
||||
searchSource: '=',
|
||||
updateFilterInQuery: '=filter'
|
||||
},
|
||||
template: html,
|
||||
controller: function ($scope) {
|
||||
|
|
|
@ -77,4 +77,4 @@ define(function (require) {
|
|||
|
||||
return AggParams;
|
||||
};
|
||||
});
|
||||
});
|
||||
|
|
|
@ -6,16 +6,40 @@ define(function (require) {
|
|||
|
||||
_(AggConfigs).inherits(Registry);
|
||||
function AggConfigs(vis, configStates) {
|
||||
var self = this;
|
||||
this.vis = vis;
|
||||
|
||||
|
||||
AggConfigs.Super.call(this, {
|
||||
index: ['id'],
|
||||
group: ['schema.group', 'type.name'],
|
||||
group: ['schema.group', 'type.name', 'schema.name'],
|
||||
initialSet: (configStates || []).map(function (aggConfigState) {
|
||||
if (aggConfigState instanceof AggConfig) return aggConfigState;
|
||||
return new AggConfig(vis, aggConfigState);
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
// Set the defaults for any schema which has them. If the defaults
|
||||
// for some reason has more then the max only set the max number
|
||||
// of defaults (not sure why a someone define more...
|
||||
// but whatever). Also if a schema.name is already set then don't
|
||||
// set anything.
|
||||
if (vis && vis.type && vis.type.schemas && vis.type.schemas.all) {
|
||||
_(vis.type.schemas.all)
|
||||
.filter(function (schema) {
|
||||
return _.isArray(schema.defaults) && schema.defaults.length > 0;
|
||||
})
|
||||
.each(function (schema) {
|
||||
if (!self.bySchemaName[schema.name]) {
|
||||
var defaults = schema.defaults.slice(0, schema.max);
|
||||
_.each(defaults, function (def) {
|
||||
self.push(new AggConfig(vis, def));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
AggConfigs.prototype.toDsl = function () {
|
||||
|
@ -52,4 +76,4 @@ define(function (require) {
|
|||
|
||||
return AggConfigs;
|
||||
};
|
||||
});
|
||||
});
|
||||
|
|
|
@ -18,7 +18,10 @@ define(function (require) {
|
|||
name: 'metric',
|
||||
title: 'Y-Axis',
|
||||
min: 1,
|
||||
max: 1
|
||||
max: 1,
|
||||
defaults: [
|
||||
{ schema: 'metric', type: 'count' }
|
||||
]
|
||||
},
|
||||
{
|
||||
group: 'buckets',
|
||||
|
@ -44,4 +47,4 @@ define(function (require) {
|
|||
])
|
||||
});
|
||||
};
|
||||
});
|
||||
});
|
||||
|
|
|
@ -9,6 +9,7 @@ define(function (require) {
|
|||
var AggConfigs;
|
||||
var SpiedAggConfig;
|
||||
var indexPattern;
|
||||
var Schemas;
|
||||
|
||||
beforeEach(module('kibana'));
|
||||
beforeEach(inject(function (Private) {
|
||||
|
@ -23,6 +24,7 @@ define(function (require) {
|
|||
AggConfigs = Private(require('components/vis/_agg_configs'));
|
||||
Registry = require('utils/registry/registry');
|
||||
indexPattern = Private(require('fixtures/stubbed_logstash_index_pattern'));
|
||||
Schemas = Private(require('components/vis_types/_schemas'));
|
||||
}));
|
||||
|
||||
it('extends Registry', function () {
|
||||
|
@ -38,7 +40,7 @@ define(function (require) {
|
|||
});
|
||||
|
||||
var ac = new AggConfigs(vis);
|
||||
expect(ac).to.have.length(0);
|
||||
expect(ac).to.have.length(1);
|
||||
});
|
||||
|
||||
it('converts configStates into AggConfig objects if they are not already', function () {
|
||||
|
@ -58,8 +60,60 @@ define(function (require) {
|
|||
})
|
||||
]);
|
||||
|
||||
expect(ac).to.have.length(2);
|
||||
expect(SpiedAggConfig).to.have.property('callCount', 1);
|
||||
expect(ac).to.have.length(3);
|
||||
expect(SpiedAggConfig).to.have.property('callCount', 3);
|
||||
});
|
||||
|
||||
describe('defaults', function () {
|
||||
var vis;
|
||||
beforeEach(function () {
|
||||
vis = {
|
||||
type: {
|
||||
schemas: new Schemas([
|
||||
{
|
||||
group: 'metrics',
|
||||
name: 'metric',
|
||||
title: 'Simple',
|
||||
min: 1,
|
||||
max: 2,
|
||||
defaults: [
|
||||
{ schema: 'metric', type: 'count' },
|
||||
{ schema: 'metric', type: 'avg' },
|
||||
{ schema: 'metric', type: 'sum' }
|
||||
]
|
||||
},
|
||||
{
|
||||
group: 'buckets',
|
||||
name: 'segment',
|
||||
title: 'Example',
|
||||
min: 0,
|
||||
max: 1,
|
||||
defaults: [
|
||||
{ schema: 'segment', type: 'terms' },
|
||||
{ schema: 'segment', type: 'filters' }
|
||||
]
|
||||
}
|
||||
])
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
it('should only set the number of defaults defined by the max', function () {
|
||||
var ac = new AggConfigs(vis);
|
||||
expect(ac.bySchemaName['metric']).to.have.length(2);
|
||||
});
|
||||
|
||||
it('should set the defaults defined in the schema when none exist', function () {
|
||||
var ac = new AggConfigs(vis);
|
||||
expect(ac).to.have.length(3);
|
||||
});
|
||||
|
||||
it('should NOT set the defaults defined in the schema when some exist', function () {
|
||||
var ac = new AggConfigs(vis, [{ schema: 'segment', type: 'date_histogram' }]);
|
||||
expect(ac).to.have.length(3);
|
||||
expect(ac.bySchemaName['segment'][0].type.name).to.equal('date_histogram');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -140,7 +194,7 @@ define(function (require) {
|
|||
}
|
||||
}(vis.aggs.toDsl()));
|
||||
|
||||
expect(aggInfos).to.have.length(0);
|
||||
expect(aggInfos).to.have.length(1);
|
||||
});
|
||||
|
||||
it('skips aggs that don\'t have a dsl representation', function () {
|
||||
|
@ -190,4 +244,4 @@ define(function (require) {
|
|||
});
|
||||
});
|
||||
}];
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue