mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
parent
01e97b87ed
commit
2045c93438
27 changed files with 490 additions and 515 deletions
|
@ -6,7 +6,7 @@ import $ from 'jquery';
|
|||
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
|
||||
import LineVisTypeProvider from 'plugins/kbn_vislib_vis_types/line';
|
||||
import { VisProvider } from 'ui/vis';
|
||||
import { VisAggConfigProvider } from 'ui/vis/agg_config';
|
||||
import { AggConfig } from 'ui/vis/agg_config';
|
||||
|
||||
describe('point series editor', function () {
|
||||
let $parentScope;
|
||||
|
@ -15,7 +15,6 @@ describe('point series editor', function () {
|
|||
let lineVisType;
|
||||
let Vis;
|
||||
let indexPattern;
|
||||
let AggConfig;
|
||||
|
||||
function makeConfig() {
|
||||
return {
|
||||
|
@ -31,7 +30,6 @@ describe('point series editor', function () {
|
|||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function ($rootScope, $compile, Private) {
|
||||
AggConfig = Private(VisAggConfigProvider);
|
||||
lineVisType = Private(LineVisTypeProvider);
|
||||
Vis = Private(VisProvider);
|
||||
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
import _ from 'lodash';
|
||||
import { GeohashLayer } from './geohash_layer';
|
||||
import { BaseMapsVisualizationProvider } from './base_maps_visualization';
|
||||
import { VisAggConfigProvider } from 'ui/vis/agg_config';
|
||||
import { AggConfig } from 'ui/vis/agg_config';
|
||||
import './styles/_tilemap.less';
|
||||
|
||||
export function CoordinateMapsVisualizationProvider(Notifier, Private) {
|
||||
|
||||
const AggConfig = Private(VisAggConfigProvider);
|
||||
const BaseMapsVisualization = Private(BaseMapsVisualizationProvider);
|
||||
|
||||
class CoordinateMapsVisualization extends BaseMapsVisualization {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import expect from 'expect.js';
|
||||
import ngMock from 'ng_mock';
|
||||
import { VisProvider } from 'ui/vis';
|
||||
import { VisAggConfigProvider } from 'ui/vis/agg_config';
|
||||
import { AggConfig } from 'ui/vis/agg_config';
|
||||
import { AggTypesAggTypeProvider } from 'ui/agg_types/agg_type';
|
||||
import { PointSeriesFakeXAxisProvider } from 'ui/agg_response/point_series/_fake_x_aspect';
|
||||
|
||||
|
@ -10,13 +10,11 @@ describe('makeFakeXAspect', function () {
|
|||
let makeFakeXAspect;
|
||||
let Vis;
|
||||
let AggType;
|
||||
let AggConfig;
|
||||
let indexPattern;
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
Vis = Private(VisProvider);
|
||||
AggConfig = Private(VisAggConfigProvider);
|
||||
AggType = Private(AggTypesAggTypeProvider);
|
||||
indexPattern = Private(VisProvider);
|
||||
makeFakeXAspect = Private(PointSeriesFakeXAxisProvider);
|
||||
|
|
|
@ -3,20 +3,18 @@ import moment from 'moment';
|
|||
import expect from 'expect.js';
|
||||
import ngMock from 'ng_mock';
|
||||
import { VisProvider } from 'ui/vis';
|
||||
import { VisAggConfigProvider } from 'ui/vis/agg_config';
|
||||
import { AggConfig } from 'ui/vis/agg_config';
|
||||
import { PointSeriesGetAspectsProvider } from 'ui/agg_response/point_series/_get_aspects';
|
||||
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
|
||||
|
||||
describe('getAspects', function () {
|
||||
let Vis;
|
||||
let AggConfig;
|
||||
let indexPattern;
|
||||
let getAspects;
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
Vis = Private(VisProvider);
|
||||
AggConfig = Private(VisAggConfigProvider);
|
||||
getAspects = Private(PointSeriesGetAspectsProvider);
|
||||
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
|
||||
}));
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import { VisAggConfigProvider } from 'ui/vis/agg_config';
|
||||
import { AggConfig } from 'ui/vis/agg_config';
|
||||
import { AggTypesAggTypeProvider } from 'ui/agg_types/agg_type';
|
||||
|
||||
export function PointSeriesFakeXAxisProvider(Private) {
|
||||
const AggConfig = Private(VisAggConfigProvider);
|
||||
const AggType = Private(AggTypesAggTypeProvider);
|
||||
|
||||
const allAgg = new AggType({
|
||||
|
|
|
@ -3,7 +3,7 @@ import { VisProvider } from 'ui/vis';
|
|||
import { AggTypesIndexProvider } from 'ui/agg_types/index';
|
||||
import { VisTypesRegistryProvider } from 'ui/registry/vis_types';
|
||||
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
|
||||
import { VisAggConfigProvider } from 'ui/vis/agg_config';
|
||||
import { AggConfig } from 'ui/vis/agg_config';
|
||||
|
||||
// eslint-disable-next-line @elastic/kibana-custom/no-default-export
|
||||
export default function AggParamWriterHelper(Private) {
|
||||
|
@ -11,7 +11,6 @@ export default function AggParamWriterHelper(Private) {
|
|||
const aggTypes = Private(AggTypesIndexProvider);
|
||||
const visTypes = Private(VisTypesRegistryProvider);
|
||||
const stubbedLogstashIndexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
|
||||
const AggConfig = Private(VisAggConfigProvider);
|
||||
|
||||
/**
|
||||
* Helper object for writing aggParams. Specify an aggType and it will find a vis & schema, and
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
import expect from 'expect.js';
|
||||
import sinon from 'sinon';
|
||||
import ngMock from 'ng_mock';
|
||||
import { AggTypesBucketsGeoHashProvider } from 'ui/agg_types/buckets/geo_hash';
|
||||
import * as AggConfigModule from 'ui/vis/agg_config';
|
||||
import { AggTypesIndexProvider } from 'ui/agg_types/index';
|
||||
|
||||
describe('Geohash Agg', () => {
|
||||
|
||||
|
@ -25,7 +29,8 @@ describe('Geohash Agg', () => {
|
|||
params: {
|
||||
mapZoom: intialZoom
|
||||
},
|
||||
sessionState: {}
|
||||
sessionState: {},
|
||||
aggs: []
|
||||
},
|
||||
type: 'geohash_grid',
|
||||
};
|
||||
|
@ -40,9 +45,6 @@ describe('Geohash Agg', () => {
|
|||
case 'AggTypesBucketsBucketAggTypeProvider':
|
||||
return BucketAggTypeMock;
|
||||
break;
|
||||
case 'VisAggConfigProvider':
|
||||
return AggConfigMock;
|
||||
break;
|
||||
default:
|
||||
return () => {};
|
||||
}
|
||||
|
@ -53,6 +55,15 @@ describe('Geohash Agg', () => {
|
|||
}
|
||||
};
|
||||
|
||||
before(function () {
|
||||
sinon.stub(AggConfigModule, 'AggConfig', AggConfigMock);
|
||||
});
|
||||
|
||||
after(function () {
|
||||
AggConfigModule.AggConfig.restore();
|
||||
});
|
||||
|
||||
|
||||
function initVisSessionState() {
|
||||
aggMock.vis.sessionState = {
|
||||
mapBounds: initialMapBounds
|
||||
|
@ -82,11 +93,17 @@ describe('Geohash Agg', () => {
|
|||
};
|
||||
}
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
AggConfigModule.AggConfig.aggTypes = Private(AggTypesIndexProvider);
|
||||
}));
|
||||
|
||||
let geohashAgg;
|
||||
beforeEach(() => {
|
||||
geohashAgg = AggTypesBucketsGeoHashProvider(PrivateMock, configMock); // eslint-disable-line new-cap
|
||||
});
|
||||
|
||||
|
||||
describe('precision parameter', () => {
|
||||
|
||||
const PRECISION_PARAM_INDEX = 6;
|
||||
|
|
|
@ -5,7 +5,7 @@ import ngMock from 'ng_mock';
|
|||
import AggParamWriterProvider from '../../agg_param_writer';
|
||||
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
|
||||
import { AggTypesIndexProvider } from 'ui/agg_types/index';
|
||||
import { VisAggConfigProvider } from 'ui/vis/agg_config';
|
||||
import { AggConfig } from 'ui/vis/agg_config';
|
||||
|
||||
describe('params', function () {
|
||||
|
||||
|
@ -13,7 +13,6 @@ describe('params', function () {
|
|||
let writeInterval;
|
||||
|
||||
let aggTypes;
|
||||
let AggConfig;
|
||||
let setTimeBounds;
|
||||
let timeField;
|
||||
|
||||
|
@ -25,7 +24,6 @@ describe('params', function () {
|
|||
|
||||
timeField = indexPattern.timeFieldName;
|
||||
aggTypes = Private(AggTypesIndexProvider);
|
||||
AggConfig = Private(VisAggConfigProvider);
|
||||
|
||||
paramWriter = new AggParamWriter({ aggType: 'date_histogram' });
|
||||
writeInterval = function (interval) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import _ from 'lodash';
|
||||
import { VisAggConfigProvider } from 'ui/vis/agg_config';
|
||||
import { AggConfig } from 'ui/vis/agg_config';
|
||||
import { buildPhrasesFilter } from 'ui/filter_manager/lib/phrases';
|
||||
import { buildExistsFilter } from 'ui/filter_manager/lib/exists';
|
||||
import { buildQueryFromFilters } from 'ui/courier/data_source/build_query/from_filters';
|
||||
|
@ -84,8 +84,7 @@ const getOtherAggTerms = (requestAgg, key, otherAgg) => {
|
|||
};
|
||||
|
||||
|
||||
export const OtherBucketHelperProvider = (Private) => {
|
||||
const AggConfig = Private(VisAggConfigProvider);
|
||||
export const OtherBucketHelperProvider = () => {
|
||||
|
||||
const buildOtherBucketAgg = (aggConfigs, aggWithOtherBucket, response) => {
|
||||
const bucketAggs = aggConfigs.filter(agg => agg.type.type === 'buckets');
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
import _ from 'lodash';
|
||||
import { AggTypesBucketsBucketAggTypeProvider } from 'ui/agg_types/buckets/_bucket_agg_type';
|
||||
import { VisAggConfigProvider } from 'ui/vis/agg_config';
|
||||
import { AggConfig } from 'ui/vis/agg_config';
|
||||
import precisionTemplate from 'ui/agg_types/controls/precision.html';
|
||||
import { geohashColumns } from 'ui/utils/decode_geo_hash';
|
||||
import { geoContains, scaleBounds } from 'ui/utils/geo_utils';
|
||||
|
||||
export function AggTypesBucketsGeoHashProvider(Private, config) {
|
||||
const BucketAggType = Private(AggTypesBucketsBucketAggTypeProvider);
|
||||
const AggConfig = Private(VisAggConfigProvider);
|
||||
|
||||
const defaultPrecision = 2;
|
||||
const maxPrecision = parseInt(config.get('visualization:tileMap:maxPrecision'), 10) || 12;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import _ from 'lodash';
|
||||
import { AggTypesBucketsBucketAggTypeProvider } from 'ui/agg_types/buckets/_bucket_agg_type';
|
||||
import { VisAggConfigProvider } from 'ui/vis/agg_config';
|
||||
import { AggConfig } from 'ui/vis/agg_config';
|
||||
import { Schemas } from 'ui/vis/editors/default/schemas';
|
||||
import { AggTypesBucketsCreateFilterTermsProvider } from 'ui/agg_types/buckets/create_filter/terms';
|
||||
import orderAggTemplate from 'ui/agg_types/controls/order_agg.html';
|
||||
|
@ -10,7 +10,6 @@ import { OtherBucketHelperProvider } from './_terms_other_bucket_helper';
|
|||
|
||||
export function AggTypesBucketsTermsProvider(Private) {
|
||||
const BucketAggType = Private(AggTypesBucketsBucketAggTypeProvider);
|
||||
const AggConfig = Private(VisAggConfigProvider);
|
||||
const createFilter = Private(AggTypesBucketsCreateFilterTermsProvider);
|
||||
const routeBasedNotifier = Private(RouteBasedNotifierProvider);
|
||||
const { buildOtherBucketAgg, mergeOtherBucketAggResponse, updateMissingBucket } = Private(OtherBucketHelperProvider);
|
||||
|
|
|
@ -1,21 +1,20 @@
|
|||
import { get } from 'lodash';
|
||||
import { AggTypesMetricsMetricAggTypeProvider } from 'ui/agg_types/metrics/metric_agg_type';
|
||||
import { makeNestedLabel } from './lib/make_nested_label';
|
||||
import { SiblingPipelineAggHelperProvider } from './lib/sibling_pipeline_agg_helper';
|
||||
import { siblingPipelineAggHelper } from './lib/sibling_pipeline_agg_helper';
|
||||
|
||||
export function AggTypesMetricsBucketAvgProvider(Private) {
|
||||
const MetricAggType = Private(AggTypesMetricsMetricAggTypeProvider);
|
||||
const siblingPipelineHelper = Private(SiblingPipelineAggHelperProvider);
|
||||
|
||||
return new MetricAggType({
|
||||
name: 'avg_bucket',
|
||||
title: 'Average Bucket',
|
||||
makeLabel: agg => makeNestedLabel(agg, 'overall average'),
|
||||
subtype: siblingPipelineHelper.subtype,
|
||||
subtype: siblingPipelineAggHelper.subtype,
|
||||
params: [
|
||||
...siblingPipelineHelper.params()
|
||||
...siblingPipelineAggHelper.params()
|
||||
],
|
||||
getFormat: siblingPipelineHelper.getFormat,
|
||||
getFormat: siblingPipelineAggHelper.getFormat,
|
||||
getValue: function (agg, bucket) {
|
||||
const customMetric = agg.params.customMetric;
|
||||
const scaleMetrics = customMetric.type && customMetric.type.isScalable();
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
import { AggTypesMetricsMetricAggTypeProvider } from 'ui/agg_types/metrics/metric_agg_type';
|
||||
import { makeNestedLabel } from './lib/make_nested_label';
|
||||
import { SiblingPipelineAggHelperProvider } from './lib/sibling_pipeline_agg_helper';
|
||||
import { siblingPipelineAggHelper } from './lib/sibling_pipeline_agg_helper';
|
||||
|
||||
export function AggTypesMetricsBucketMaxProvider(Private) {
|
||||
const MetricAggType = Private(AggTypesMetricsMetricAggTypeProvider);
|
||||
const siblingPipelineHelper = Private(SiblingPipelineAggHelperProvider);
|
||||
|
||||
return new MetricAggType({
|
||||
name: 'max_bucket',
|
||||
title: 'Max Bucket',
|
||||
makeLabel: agg => makeNestedLabel(agg, 'overall max'),
|
||||
subtype: siblingPipelineHelper.subtype,
|
||||
subtype: siblingPipelineAggHelper.subtype,
|
||||
params: [
|
||||
...siblingPipelineHelper.params()
|
||||
...siblingPipelineAggHelper.params()
|
||||
],
|
||||
getFormat: siblingPipelineHelper.getFormat
|
||||
getFormat: siblingPipelineAggHelper.getFormat
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
import { AggTypesMetricsMetricAggTypeProvider } from 'ui/agg_types/metrics/metric_agg_type';
|
||||
import { makeNestedLabel } from './lib/make_nested_label';
|
||||
import { SiblingPipelineAggHelperProvider } from './lib/sibling_pipeline_agg_helper';
|
||||
import { siblingPipelineAggHelper } from './lib/sibling_pipeline_agg_helper';
|
||||
|
||||
export function AggTypesMetricsBucketMinProvider(Private) {
|
||||
const MetricAggType = Private(AggTypesMetricsMetricAggTypeProvider);
|
||||
const siblingPipelineHelper = Private(SiblingPipelineAggHelperProvider);
|
||||
|
||||
return new MetricAggType({
|
||||
name: 'min_bucket',
|
||||
title: 'Min Bucket',
|
||||
makeLabel: agg => makeNestedLabel(agg, 'overall min'),
|
||||
subtype: siblingPipelineHelper.subtype,
|
||||
subtype: siblingPipelineAggHelper.subtype,
|
||||
params: [
|
||||
...siblingPipelineHelper.params()
|
||||
...siblingPipelineAggHelper.params()
|
||||
],
|
||||
getFormat: siblingPipelineHelper.getFormat
|
||||
getFormat: siblingPipelineAggHelper.getFormat
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
import { AggTypesMetricsMetricAggTypeProvider } from 'ui/agg_types/metrics/metric_agg_type';
|
||||
import { makeNestedLabel } from './lib/make_nested_label';
|
||||
import { SiblingPipelineAggHelperProvider } from './lib/sibling_pipeline_agg_helper';
|
||||
import { siblingPipelineAggHelper } from './lib/sibling_pipeline_agg_helper';
|
||||
|
||||
export function AggTypesMetricsBucketSumProvider(Private) {
|
||||
const MetricAggType = Private(AggTypesMetricsMetricAggTypeProvider);
|
||||
const siblingPipelineHelper = Private(SiblingPipelineAggHelperProvider);
|
||||
|
||||
return new MetricAggType({
|
||||
name: 'sum_bucket',
|
||||
title: 'Sum Bucket',
|
||||
makeLabel: agg => makeNestedLabel(agg, 'overall sum'),
|
||||
subtype: siblingPipelineHelper.subtype,
|
||||
subtype: siblingPipelineAggHelper.subtype,
|
||||
params: [
|
||||
...siblingPipelineHelper.params()
|
||||
...siblingPipelineAggHelper.params()
|
||||
],
|
||||
getFormat: siblingPipelineHelper.getFormat
|
||||
getFormat: siblingPipelineAggHelper.getFormat
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import { AggTypesMetricsMetricAggTypeProvider } from 'ui/agg_types/metrics/metric_agg_type';
|
||||
import { ParentPipelineAggHelperProvider } from './lib/parent_pipeline_agg_helper';
|
||||
import { parentPipelineAggHelper } from './lib/parent_pipeline_agg_helper';
|
||||
import { makeNestedLabel } from './lib/make_nested_label';
|
||||
|
||||
export function AggTypesMetricsCumulativeSumProvider(Private) {
|
||||
const MetricAggType = Private(AggTypesMetricsMetricAggTypeProvider);
|
||||
const parentPipelineAggHelper = Private(ParentPipelineAggHelperProvider);
|
||||
|
||||
return new MetricAggType({
|
||||
name: 'cumulative_sum',
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import { AggTypesMetricsMetricAggTypeProvider } from 'ui/agg_types/metrics/metric_agg_type';
|
||||
import { ParentPipelineAggHelperProvider } from './lib/parent_pipeline_agg_helper';
|
||||
import { parentPipelineAggHelper } from './lib/parent_pipeline_agg_helper';
|
||||
import { makeNestedLabel } from './lib/make_nested_label';
|
||||
|
||||
export function AggTypesMetricsDerivativeProvider(Private) {
|
||||
const MetricAggType = Private(AggTypesMetricsMetricAggTypeProvider);
|
||||
const parentPipelineAggHelper = Private(ParentPipelineAggHelperProvider);
|
||||
|
||||
return new MetricAggType({
|
||||
name: 'derivative',
|
||||
|
|
|
@ -1,69 +1,66 @@
|
|||
import metricAggTemplate from 'ui/agg_types/controls/sub_agg.html';
|
||||
import _ from 'lodash';
|
||||
import { VisAggConfigProvider } from 'ui/vis/agg_config';
|
||||
import { AggConfig } from 'ui/vis/agg_config';
|
||||
import { Schemas } from 'ui/vis/editors/default/schemas';
|
||||
import { parentPipelineAggController } from './parent_pipeline_agg_controller';
|
||||
import { parentPipelineAggWritter } from './parent_pipeline_agg_writter';
|
||||
|
||||
export const ParentPipelineAggHelperProvider = function (Private) {
|
||||
|
||||
const AggConfig = Private(VisAggConfigProvider);
|
||||
const metricAggFilter = ['!top_hits', '!percentiles', '!percentile_ranks', '!median', '!std_dev'];
|
||||
const metricAggSchema = (new Schemas([
|
||||
{
|
||||
group: 'none',
|
||||
name: 'metricAgg',
|
||||
title: 'Metric Agg',
|
||||
hideCustomLabel: true,
|
||||
aggFilter: metricAggFilter
|
||||
}
|
||||
])).all[0];
|
||||
|
||||
const metricAggFilter = ['!top_hits', '!percentiles', '!percentile_ranks', '!median', '!std_dev'];
|
||||
const metricAggSchema = (new Schemas([
|
||||
{
|
||||
group: 'none',
|
||||
name: 'metricAgg',
|
||||
title: 'Metric Agg',
|
||||
hideCustomLabel: true,
|
||||
aggFilter: metricAggFilter
|
||||
}
|
||||
])).all[0];
|
||||
|
||||
return {
|
||||
subtype: 'Parent Pipeline Aggregations',
|
||||
params: function () {
|
||||
return [
|
||||
{
|
||||
name: 'customMetric',
|
||||
type: AggConfig,
|
||||
default: null,
|
||||
serialize: function (customMetric) {
|
||||
return customMetric.toJSON();
|
||||
},
|
||||
deserialize: function (state, agg) {
|
||||
return this.makeAgg(agg, state);
|
||||
},
|
||||
makeAgg: function (termsAgg, state) {
|
||||
state = state || { type: 'count' };
|
||||
state.schema = metricAggSchema;
|
||||
const metricAgg = new AggConfig(termsAgg.vis, state);
|
||||
metricAgg.id = termsAgg.id + '-metric';
|
||||
return metricAgg;
|
||||
},
|
||||
write: _.noop
|
||||
const parentPipelineAggHelper = {
|
||||
subtype: 'Parent Pipeline Aggregations',
|
||||
params: function () {
|
||||
return [
|
||||
{
|
||||
name: 'customMetric',
|
||||
type: AggConfig,
|
||||
default: null,
|
||||
serialize: function (customMetric) {
|
||||
return customMetric.toJSON();
|
||||
},
|
||||
{
|
||||
name: 'buckets_path',
|
||||
write: _.noop
|
||||
deserialize: function (state, agg) {
|
||||
return this.makeAgg(agg, state);
|
||||
},
|
||||
{
|
||||
name: 'metricAgg',
|
||||
editor: metricAggTemplate,
|
||||
default: 'custom',
|
||||
controller: parentPipelineAggController,
|
||||
write: parentPipelineAggWritter
|
||||
}
|
||||
];
|
||||
},
|
||||
getFormat: function (agg) {
|
||||
let subAgg;
|
||||
if (agg.params.customMetric) {
|
||||
subAgg = agg.params.customMetric;
|
||||
} else {
|
||||
subAgg = agg.vis.getAggConfig().byId[agg.params.metricAgg];
|
||||
makeAgg: function (termsAgg, state) {
|
||||
state = state || { type: 'count' };
|
||||
state.schema = metricAggSchema;
|
||||
const metricAgg = new AggConfig(termsAgg.vis, state);
|
||||
metricAgg.id = termsAgg.id + '-metric';
|
||||
return metricAgg;
|
||||
},
|
||||
write: _.noop
|
||||
},
|
||||
{
|
||||
name: 'buckets_path',
|
||||
write: _.noop
|
||||
},
|
||||
{
|
||||
name: 'metricAgg',
|
||||
editor: metricAggTemplate,
|
||||
default: 'custom',
|
||||
controller: parentPipelineAggController,
|
||||
write: parentPipelineAggWritter
|
||||
}
|
||||
return subAgg.type.getFormat(subAgg);
|
||||
];
|
||||
},
|
||||
getFormat: function (agg) {
|
||||
let subAgg;
|
||||
if (agg.params.customMetric) {
|
||||
subAgg = agg.params.customMetric;
|
||||
} else {
|
||||
subAgg = agg.vis.getAggConfig().byId[agg.params.metricAgg];
|
||||
}
|
||||
};
|
||||
return subAgg.type.getFormat(subAgg);
|
||||
}
|
||||
};
|
||||
export { parentPipelineAggHelper };
|
||||
|
|
|
@ -1,93 +1,90 @@
|
|||
import _ from 'lodash';
|
||||
import { VisAggConfigProvider } from 'ui/vis/agg_config';
|
||||
import { AggConfig } from 'ui/vis/agg_config';
|
||||
import { Schemas } from 'ui/vis/editors/default/schemas';
|
||||
|
||||
import { siblingPipelineAggController } from './sibling_pipeline_agg_controller';
|
||||
import { siblingPipelineAggWritter } from './sibling_pipeline_agg_writter';
|
||||
import metricAggTemplate from 'ui/agg_types/controls/sub_metric.html';
|
||||
|
||||
export const SiblingPipelineAggHelperProvider = function (Private) {
|
||||
|
||||
const AggConfig = Private(VisAggConfigProvider);
|
||||
const metricAggFilter = [
|
||||
'!top_hits', '!percentiles', '!percentile_ranks', '!median', '!std_dev',
|
||||
'!sum_bucket', '!avg_bucket', '!min_bucket', '!max_bucket',
|
||||
'!derivative', '!moving_avg', '!serial_diff', '!cumulative_sum'
|
||||
];
|
||||
|
||||
const metricAggFilter = [
|
||||
'!top_hits', '!percentiles', '!percentile_ranks', '!median', '!std_dev',
|
||||
'!sum_bucket', '!avg_bucket', '!min_bucket', '!max_bucket',
|
||||
'!derivative', '!moving_avg', '!serial_diff', '!cumulative_sum'
|
||||
];
|
||||
const metricAggSchema = (new Schemas([
|
||||
{
|
||||
group: 'none',
|
||||
name: 'metricAgg',
|
||||
title: 'Metric Agg',
|
||||
aggFilter: metricAggFilter
|
||||
}
|
||||
])).all[0];
|
||||
|
||||
const metricAggSchema = (new Schemas([
|
||||
{
|
||||
group: 'none',
|
||||
name: 'metricAgg',
|
||||
title: 'Metric Agg',
|
||||
aggFilter: metricAggFilter
|
||||
}
|
||||
])).all[0];
|
||||
const bucketAggFilter = [];
|
||||
const bucketAggSchema = (new Schemas([
|
||||
{
|
||||
group: 'none',
|
||||
title: 'Bucket Agg',
|
||||
name: 'bucketAgg',
|
||||
aggFilter: bucketAggFilter
|
||||
}
|
||||
])).all[0];
|
||||
|
||||
const bucketAggFilter = [];
|
||||
const bucketAggSchema = (new Schemas([
|
||||
{
|
||||
group: 'none',
|
||||
title: 'Bucket Agg',
|
||||
name: 'bucketAgg',
|
||||
aggFilter: bucketAggFilter
|
||||
}
|
||||
])).all[0];
|
||||
|
||||
return {
|
||||
subtype: 'Sibling Pipeline Aggregations',
|
||||
params: function () {
|
||||
return [
|
||||
{
|
||||
name: 'customBucket',
|
||||
type: AggConfig,
|
||||
default: null,
|
||||
serialize: function (customMetric) {
|
||||
return customMetric.toJSON();
|
||||
},
|
||||
deserialize: function (state, agg) {
|
||||
return this.makeAgg(agg, state);
|
||||
},
|
||||
makeAgg: function (agg, state) {
|
||||
state = state || { type: 'date_histogram' };
|
||||
state.schema = bucketAggSchema;
|
||||
const orderAgg = new AggConfig(agg.vis, state);
|
||||
orderAgg.id = agg.id + '-bucket';
|
||||
return orderAgg;
|
||||
},
|
||||
editor: metricAggTemplate,
|
||||
controller: siblingPipelineAggController('customBucket'),
|
||||
write: _.noop
|
||||
const siblingPipelineAggHelper = {
|
||||
subtype: 'Sibling Pipeline Aggregations',
|
||||
params: function () {
|
||||
return [
|
||||
{
|
||||
name: 'customBucket',
|
||||
type: AggConfig,
|
||||
default: null,
|
||||
serialize: function (customMetric) {
|
||||
return customMetric.toJSON();
|
||||
},
|
||||
{
|
||||
name: 'customMetric',
|
||||
type: AggConfig,
|
||||
default: null,
|
||||
serialize: function (customMetric) {
|
||||
return customMetric.toJSON();
|
||||
},
|
||||
deserialize: function (state, agg) {
|
||||
return this.makeAgg(agg, state);
|
||||
},
|
||||
makeAgg: function (agg, state) {
|
||||
state = state || { type: 'count' };
|
||||
state.schema = metricAggSchema;
|
||||
const orderAgg = new AggConfig(agg.vis, state);
|
||||
orderAgg.id = agg.id + '-metric';
|
||||
return orderAgg;
|
||||
},
|
||||
editor: metricAggTemplate,
|
||||
controller: siblingPipelineAggController('customMetric'),
|
||||
write: siblingPipelineAggWritter
|
||||
}
|
||||
];
|
||||
},
|
||||
getFormat: function (agg) {
|
||||
return agg.params.customMetric.type.getFormat(agg.params.customMetric);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
deserialize: function (state, agg) {
|
||||
return this.makeAgg(agg, state);
|
||||
},
|
||||
makeAgg: function (agg, state) {
|
||||
state = state || { type: 'date_histogram' };
|
||||
state.schema = bucketAggSchema;
|
||||
const orderAgg = new AggConfig(agg.vis, state);
|
||||
orderAgg.id = agg.id + '-bucket';
|
||||
return orderAgg;
|
||||
},
|
||||
editor: metricAggTemplate,
|
||||
controller: siblingPipelineAggController('customBucket'),
|
||||
write: _.noop
|
||||
},
|
||||
{
|
||||
name: 'customMetric',
|
||||
type: AggConfig,
|
||||
default: null,
|
||||
serialize: function (customMetric) {
|
||||
return customMetric.toJSON();
|
||||
},
|
||||
deserialize: function (state, agg) {
|
||||
return this.makeAgg(agg, state);
|
||||
},
|
||||
makeAgg: function (agg, state) {
|
||||
state = state || { type: 'count' };
|
||||
state.schema = metricAggSchema;
|
||||
const orderAgg = new AggConfig(agg.vis, state);
|
||||
orderAgg.id = agg.id + '-metric';
|
||||
return orderAgg;
|
||||
},
|
||||
editor: metricAggTemplate,
|
||||
controller: siblingPipelineAggController('customMetric'),
|
||||
write: siblingPipelineAggWritter
|
||||
}
|
||||
];
|
||||
},
|
||||
getFormat: function (agg) {
|
||||
return agg.params.customMetric.type.getFormat(agg.params.customMetric);
|
||||
}
|
||||
};
|
||||
|
||||
export { siblingPipelineAggHelper };
|
||||
|
||||
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import { AggTypesMetricsMetricAggTypeProvider } from 'ui/agg_types/metrics/metric_agg_type';
|
||||
import { ParentPipelineAggHelperProvider } from './lib/parent_pipeline_agg_helper';
|
||||
import { parentPipelineAggHelper } from './lib/parent_pipeline_agg_helper';
|
||||
import { makeNestedLabel } from './lib/make_nested_label';
|
||||
|
||||
export function AggTypesMetricsMovingAvgProvider(Private) {
|
||||
const MetricAggType = Private(AggTypesMetricsMetricAggTypeProvider);
|
||||
const parentPipelineAggHelper = Private(ParentPipelineAggHelperProvider);
|
||||
|
||||
return new MetricAggType({
|
||||
name: 'moving_avg',
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import { AggTypesMetricsMetricAggTypeProvider } from 'ui/agg_types/metrics/metric_agg_type';
|
||||
import { ParentPipelineAggHelperProvider } from './lib/parent_pipeline_agg_helper';
|
||||
import { parentPipelineAggHelper } from './lib/parent_pipeline_agg_helper';
|
||||
import { makeNestedLabel } from './lib/make_nested_label';
|
||||
|
||||
export function AggTypesMetricsSerialDiffProvider(Private) {
|
||||
const MetricAggType = Private(AggTypesMetricsMetricAggTypeProvider);
|
||||
const parentPipelineAggHelper = Private(ParentPipelineAggHelperProvider);
|
||||
|
||||
return new MetricAggType({
|
||||
name: 'serial_diff',
|
||||
|
|
|
@ -3,7 +3,7 @@ import expect from 'expect.js';
|
|||
import ngMock from 'ng_mock';
|
||||
import { VisProvider } from 'ui/vis';
|
||||
import { AggTypesAggTypeProvider } from 'ui/agg_types/agg_type';
|
||||
import { VisAggConfigProvider } from 'ui/vis/agg_config';
|
||||
import { AggConfig } from 'ui/vis/agg_config';
|
||||
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
|
||||
import { fieldFormats } from 'ui/registry/field_formats';
|
||||
|
||||
|
@ -11,14 +11,12 @@ describe('AggConfig', function () {
|
|||
|
||||
let Vis;
|
||||
let AggType;
|
||||
let AggConfig;
|
||||
let indexPattern;
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
Vis = Private(VisProvider);
|
||||
AggType = Private(AggTypesAggTypeProvider);
|
||||
AggConfig = Private(VisAggConfigProvider);
|
||||
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
|
||||
}));
|
||||
|
||||
|
@ -155,6 +153,7 @@ describe('AggConfig', function () {
|
|||
it('uses ::nextId to get the starting value', function () {
|
||||
sinon.stub(AggConfig, 'nextId').returns(534);
|
||||
const objs = AggConfig.ensureIds([{}]);
|
||||
AggConfig.nextId.restore();
|
||||
expect(objs[0]).to.have.property('id', '534');
|
||||
});
|
||||
|
||||
|
@ -164,6 +163,8 @@ describe('AggConfig', function () {
|
|||
const objs = AggConfig.ensureIds([{}, {}, {}, {}, {}, {}, {}]);
|
||||
|
||||
expect(AggConfig.nextId).to.have.property('callCount', 1);
|
||||
|
||||
AggConfig.nextId.restore();
|
||||
objs.forEach(function (obj, i) {
|
||||
expect(obj).to.have.property('id', String(start + i));
|
||||
});
|
||||
|
|
|
@ -2,7 +2,7 @@ import _ from 'lodash';
|
|||
import sinon from 'sinon';
|
||||
import expect from 'expect.js';
|
||||
import ngMock from 'ng_mock';
|
||||
import { VisAggConfigProvider } from 'ui/vis/agg_config';
|
||||
import { AggConfig } from 'ui/vis/agg_config';
|
||||
import { VisProvider } from 'ui/vis';
|
||||
import { VisAggConfigsProvider } from 'ui/vis/agg_configs';
|
||||
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
|
||||
|
@ -12,27 +12,22 @@ import { IndexedArray } from 'ui/indexed_array';
|
|||
describe('AggConfigs', function () {
|
||||
|
||||
let Vis;
|
||||
let AggConfig;
|
||||
let AggConfigs;
|
||||
let SpiedAggConfig;
|
||||
let indexPattern;
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
AggConfigs = Private(VisAggConfigsProvider);
|
||||
// replace the AggConfig module with a spy
|
||||
AggConfig = Private(VisAggConfigProvider);
|
||||
|
||||
const spy = sinon.spy(AggConfig);
|
||||
Object.defineProperty(spy, 'aggTypes', {
|
||||
get: function () { return AggConfig.aggTypes; },
|
||||
set: function (val) { AggConfig.aggTypes = val; }
|
||||
});
|
||||
|
||||
Private.stub(VisAggConfigProvider, spy);
|
||||
|
||||
// load main deps
|
||||
Vis = Private(VisProvider);
|
||||
SpiedAggConfig = Private(VisAggConfigProvider);
|
||||
AggConfigs = Private(VisAggConfigsProvider);
|
||||
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
|
||||
}));
|
||||
|
||||
|
@ -70,7 +65,6 @@ describe('AggConfigs', function () {
|
|||
]);
|
||||
|
||||
expect(ac).to.have.length(3);
|
||||
expect(SpiedAggConfig).to.have.property('callCount', 3);
|
||||
});
|
||||
|
||||
it('attemps to ensure that all states have an id', function () {
|
||||
|
@ -90,10 +84,11 @@ describe('AggConfigs', function () {
|
|||
}
|
||||
];
|
||||
|
||||
const spy = sinon.spy(SpiedAggConfig, 'ensureIds');
|
||||
const spy = sinon.spy(AggConfig, 'ensureIds');
|
||||
new AggConfigs(vis, states);
|
||||
expect(spy.callCount).to.be(1);
|
||||
expect(spy.firstCall.args[0]).to.be(states);
|
||||
AggConfig.ensureIds.restore();
|
||||
});
|
||||
|
||||
describe('defaults', function () {
|
||||
|
|
|
@ -8,338 +8,334 @@
|
|||
import _ from 'lodash';
|
||||
import { fieldFormats } from 'ui/registry/field_formats';
|
||||
|
||||
export function VisAggConfigProvider(Promise) {
|
||||
|
||||
function AggConfig(vis, opts) {
|
||||
const self = this;
|
||||
|
||||
function AggConfig(vis, opts) {
|
||||
const self = this;
|
||||
self.id = String(opts.id || AggConfig.nextId(vis.aggs));
|
||||
self.vis = vis;
|
||||
self._opts = opts = (opts || {});
|
||||
self.enabled = typeof opts.enabled === 'boolean' ? opts.enabled : true;
|
||||
|
||||
self.id = String(opts.id || AggConfig.nextId(vis.aggs));
|
||||
self.vis = vis;
|
||||
self._opts = opts = (opts || {});
|
||||
self.enabled = typeof opts.enabled === 'boolean' ? opts.enabled : true;
|
||||
// start with empty params so that checks in type/schema setters don't freak
|
||||
// because self.params is undefined
|
||||
self.params = {};
|
||||
|
||||
// start with empty params so that checks in type/schema setters don't freak
|
||||
// because self.params is undefined
|
||||
self.params = {};
|
||||
// setters
|
||||
self.type = opts.type;
|
||||
self.schema = opts.schema;
|
||||
|
||||
// setters
|
||||
self.type = opts.type;
|
||||
self.schema = opts.schema;
|
||||
// set the params to the values from opts, or just to the defaults
|
||||
self.setParams(opts.params || {});
|
||||
}
|
||||
|
||||
// set the params to the values from opts, or just to the defaults
|
||||
self.setParams(opts.params || {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that all of the objects in the list have ids, the objects
|
||||
* and list are modified by reference.
|
||||
*
|
||||
* @param {array[object]} list - a list of objects, objects can be anything really
|
||||
* @return {array} - the list that was passed in
|
||||
*/
|
||||
AggConfig.ensureIds = function (list) {
|
||||
const have = [];
|
||||
const haveNot = [];
|
||||
list.forEach(function (obj) {
|
||||
(obj.id ? have : haveNot).push(obj);
|
||||
});
|
||||
|
||||
let nextId = AggConfig.nextId(have);
|
||||
haveNot.forEach(function (obj) {
|
||||
obj.id = String(nextId++);
|
||||
});
|
||||
|
||||
return list;
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculate the next id based on the ids in this list
|
||||
*
|
||||
* @return {array} list - a list of objects with id properties
|
||||
*/
|
||||
AggConfig.nextId = function (list) {
|
||||
return 1 + list.reduce(function (max, obj) {
|
||||
return Math.max(max, +obj.id || 0);
|
||||
}, 0);
|
||||
};
|
||||
|
||||
Object.defineProperties(AggConfig.prototype, {
|
||||
type: {
|
||||
get: function () {
|
||||
return this.__type;
|
||||
},
|
||||
set: function (type) {
|
||||
if (this.__typeDecorations) {
|
||||
_.forOwn(this.__typeDecorations, function (prop, name) {
|
||||
delete this[name];
|
||||
}, this);
|
||||
}
|
||||
|
||||
if (_.isString(type)) {
|
||||
type = AggConfig.aggTypes.byName[type];
|
||||
}
|
||||
|
||||
if (type && _.isFunction(type.decorateAggConfig)) {
|
||||
this.__typeDecorations = type.decorateAggConfig();
|
||||
Object.defineProperties(this, this.__typeDecorations);
|
||||
}
|
||||
|
||||
this.__type = type;
|
||||
|
||||
// clear out the previous params except for a few special ones
|
||||
this.setParams({
|
||||
// split row/columns is "outside" of the agg, so don't reset it
|
||||
row: this.params.row,
|
||||
|
||||
// almost every agg has fields, so we try to persist that when type changes
|
||||
field: _.get(this.getFieldOptions(), ['byName', this.getField()])
|
||||
});
|
||||
}
|
||||
},
|
||||
schema: {
|
||||
get: function () {
|
||||
return this.__schema;
|
||||
},
|
||||
set: function (schema) {
|
||||
if (_.isString(schema)) {
|
||||
schema = this.vis.type.schemas.all.byName[schema];
|
||||
}
|
||||
|
||||
this.__schema = schema;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Ensure that all of the objects in the list have ids, the objects
|
||||
* and list are modified by reference.
|
||||
*
|
||||
* @param {array[object]} list - a list of objects, objects can be anything really
|
||||
* @return {array} - the list that was passed in
|
||||
*/
|
||||
AggConfig.ensureIds = function (list) {
|
||||
const have = [];
|
||||
const haveNot = [];
|
||||
list.forEach(function (obj) {
|
||||
(obj.id ? have : haveNot).push(obj);
|
||||
});
|
||||
|
||||
/**
|
||||
* Write the current values to this.params, filling in the defaults as we go
|
||||
*
|
||||
* @param {object} [from] - optional object to read values from,
|
||||
* used when initializing
|
||||
* @return {undefined}
|
||||
*/
|
||||
AggConfig.prototype.setParams = function (from) {
|
||||
const self = this;
|
||||
from = from || self.params || {};
|
||||
const to = self.params = {};
|
||||
let nextId = AggConfig.nextId(have);
|
||||
haveNot.forEach(function (obj) {
|
||||
obj.id = String(nextId++);
|
||||
});
|
||||
|
||||
self.getAggParams().forEach(function (aggParam) {
|
||||
let val = from[aggParam.name];
|
||||
return list;
|
||||
};
|
||||
|
||||
if (val == null) {
|
||||
if (aggParam.default == null) return;
|
||||
/**
|
||||
* Calculate the next id based on the ids in this list
|
||||
*
|
||||
* @return {array} list - a list of objects with id properties
|
||||
*/
|
||||
AggConfig.nextId = function (list) {
|
||||
return 1 + list.reduce(function (max, obj) {
|
||||
return Math.max(max, +obj.id || 0);
|
||||
}, 0);
|
||||
};
|
||||
|
||||
if (!_.isFunction(aggParam.default)) {
|
||||
val = aggParam.default;
|
||||
} else {
|
||||
val = aggParam.default(self);
|
||||
if (val == null) return;
|
||||
}
|
||||
Object.defineProperties(AggConfig.prototype, {
|
||||
type: {
|
||||
get: function () {
|
||||
return this.__type;
|
||||
},
|
||||
set: function (type) {
|
||||
if (this.__typeDecorations) {
|
||||
_.forOwn(this.__typeDecorations, function (prop, name) {
|
||||
delete this[name];
|
||||
}, this);
|
||||
}
|
||||
|
||||
if (aggParam.deserialize) {
|
||||
const isTyped = _.isFunction(aggParam.type);
|
||||
|
||||
const isType = isTyped && (val instanceof aggParam.type);
|
||||
const isObject = !isTyped && _.isObject(val);
|
||||
const isDeserialized = (isType || isObject);
|
||||
|
||||
if (!isDeserialized) {
|
||||
val = aggParam.deserialize(val, self);
|
||||
}
|
||||
|
||||
to[aggParam.name] = val;
|
||||
return;
|
||||
if (_.isString(type)) {
|
||||
type = AggConfig.aggTypes.byName[type];
|
||||
}
|
||||
|
||||
to[aggParam.name] = _.cloneDeep(val);
|
||||
if (type && _.isFunction(type.decorateAggConfig)) {
|
||||
this.__typeDecorations = type.decorateAggConfig();
|
||||
Object.defineProperties(this, this.__typeDecorations);
|
||||
}
|
||||
|
||||
this.__type = type;
|
||||
|
||||
// clear out the previous params except for a few special ones
|
||||
this.setParams({
|
||||
// split row/columns is "outside" of the agg, so don't reset it
|
||||
row: this.params.row,
|
||||
|
||||
// almost every agg has fields, so we try to persist that when type changes
|
||||
field: _.get(this.getFieldOptions(), ['byName', this.getField()])
|
||||
});
|
||||
}
|
||||
},
|
||||
schema: {
|
||||
get: function () {
|
||||
return this.__schema;
|
||||
},
|
||||
set: function (schema) {
|
||||
if (_.isString(schema)) {
|
||||
schema = this.vis.type.schemas.all.byName[schema];
|
||||
}
|
||||
|
||||
this.__schema = schema;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Write the current values to this.params, filling in the defaults as we go
|
||||
*
|
||||
* @param {object} [from] - optional object to read values from,
|
||||
* used when initializing
|
||||
* @return {undefined}
|
||||
*/
|
||||
AggConfig.prototype.setParams = function (from) {
|
||||
const self = this;
|
||||
from = from || self.params || {};
|
||||
const to = self.params = {};
|
||||
|
||||
self.getAggParams().forEach(function (aggParam) {
|
||||
let val = from[aggParam.name];
|
||||
|
||||
if (val == null) {
|
||||
if (aggParam.default == null) return;
|
||||
|
||||
if (!_.isFunction(aggParam.default)) {
|
||||
val = aggParam.default;
|
||||
} else {
|
||||
val = aggParam.default(self);
|
||||
if (val == null) return;
|
||||
}
|
||||
}
|
||||
|
||||
if (aggParam.deserialize) {
|
||||
const isTyped = _.isFunction(aggParam.type);
|
||||
|
||||
const isType = isTyped && (val instanceof aggParam.type);
|
||||
const isObject = !isTyped && _.isObject(val);
|
||||
const isDeserialized = (isType || isObject);
|
||||
|
||||
if (!isDeserialized) {
|
||||
val = aggParam.deserialize(val, self);
|
||||
}
|
||||
|
||||
to[aggParam.name] = val;
|
||||
return;
|
||||
}
|
||||
|
||||
to[aggParam.name] = _.cloneDeep(val);
|
||||
});
|
||||
};
|
||||
|
||||
AggConfig.prototype.write = function () {
|
||||
return this.type.params.write(this);
|
||||
};
|
||||
|
||||
AggConfig.prototype.isFilterable = function () {
|
||||
return _.isFunction(this.type.createFilter);
|
||||
};
|
||||
|
||||
AggConfig.prototype.createFilter = function (key) {
|
||||
if (!this.isFilterable()) {
|
||||
throw new TypeError('The "' + this.type.title + '" aggregation does not support filtering.');
|
||||
}
|
||||
|
||||
const field = this.getField();
|
||||
const label = this.getFieldDisplayName();
|
||||
if (field && !field.filterable) {
|
||||
let message = 'The "' + label + '" field can not be used for filtering.';
|
||||
if (field.scripted) {
|
||||
message = 'The "' + label + '" field is scripted and can not be used for filtering.';
|
||||
}
|
||||
throw new TypeError(message);
|
||||
}
|
||||
|
||||
return this.type.createFilter(this, key);
|
||||
};
|
||||
|
||||
/**
|
||||
* Hook for pre-flight logic, see AggType#onSearchRequestStart
|
||||
* @param {Courier.SearchSource} searchSource
|
||||
* @param {Courier.SearchRequest} searchRequest
|
||||
* @return {Promise<undefined>}
|
||||
*/
|
||||
AggConfig.prototype.onSearchRequestStart = function (searchSource, searchRequest) {
|
||||
if (!this.type) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return Promise.all(
|
||||
this.type.params.map(param => param.modifyAggConfigOnSearchRequestStart(this, searchSource, searchRequest))
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert this aggConfig to its dsl syntax.
|
||||
*
|
||||
* Adds params and adhoc subaggs to a pojo, then returns it
|
||||
*
|
||||
* @param {AggConfig} aggConfig - the config object to convert
|
||||
* @return {void|Object} - if the config has a dsl representation, it is
|
||||
* returned, else undefined is returned
|
||||
*/
|
||||
AggConfig.prototype.toDsl = function () {
|
||||
if (this.type.hasNoDsl) return;
|
||||
const output = this.write();
|
||||
|
||||
const configDsl = {};
|
||||
configDsl[this.type.dslName || this.type.name] = output.params;
|
||||
|
||||
// if the config requires subAggs, write them to the dsl as well
|
||||
if (this.subAggs && !output.subAggs) output.subAggs = this.subAggs;
|
||||
if (output.subAggs) {
|
||||
const subDslLvl = configDsl.aggs || (configDsl.aggs = {});
|
||||
output.subAggs.forEach(function nestAdhocSubAggs(subAggConfig) {
|
||||
subDslLvl[subAggConfig.id] = subAggConfig.toDsl();
|
||||
});
|
||||
}
|
||||
|
||||
if (output.parentAggs) {
|
||||
const subDslLvl = configDsl.parentAggs || (configDsl.parentAggs = {});
|
||||
output.parentAggs.forEach(function nestAdhocSubAggs(subAggConfig) {
|
||||
subDslLvl[subAggConfig.id] = subAggConfig.toDsl();
|
||||
});
|
||||
}
|
||||
|
||||
return configDsl;
|
||||
};
|
||||
|
||||
AggConfig.prototype.toJSON = function () {
|
||||
const self = this;
|
||||
const params = self.params;
|
||||
|
||||
const outParams = _.transform(self.getAggParams(), function (out, aggParam) {
|
||||
let val = params[aggParam.name];
|
||||
|
||||
// don't serialize undefined/null values
|
||||
if (val == null) return;
|
||||
if (aggParam.serialize) val = aggParam.serialize(val, self);
|
||||
if (val == null) return;
|
||||
|
||||
// to prevent accidental leaking, we will clone all complex values
|
||||
out[aggParam.name] = _.cloneDeep(val);
|
||||
}, {});
|
||||
|
||||
return {
|
||||
id: self.id,
|
||||
enabled: self.enabled,
|
||||
type: self.type && self.type.name,
|
||||
schema: self.schema && self.schema.name,
|
||||
params: outParams
|
||||
};
|
||||
};
|
||||
|
||||
AggConfig.prototype.write = function () {
|
||||
return this.type.params.write(this);
|
||||
};
|
||||
AggConfig.prototype.getAggParams = function () {
|
||||
return [].concat(
|
||||
(this.type) ? this.type.params.raw : [],
|
||||
(_.has(this, 'schema.params')) ? this.schema.params.raw : []
|
||||
);
|
||||
};
|
||||
|
||||
AggConfig.prototype.isFilterable = function () {
|
||||
return _.isFunction(this.type.createFilter);
|
||||
};
|
||||
AggConfig.prototype.getRequestAggs = function () {
|
||||
if (!this.type) return;
|
||||
return this.type.getRequestAggs(this) || [this];
|
||||
};
|
||||
|
||||
AggConfig.prototype.createFilter = function (key) {
|
||||
if (!this.isFilterable()) {
|
||||
throw new TypeError('The "' + this.type.title + '" aggregation does not support filtering.');
|
||||
}
|
||||
AggConfig.prototype.getResponseAggs = function () {
|
||||
if (!this.type) return;
|
||||
return this.type.getResponseAggs(this) || [this];
|
||||
};
|
||||
|
||||
const field = this.getField();
|
||||
const label = this.getFieldDisplayName();
|
||||
if (field && !field.filterable) {
|
||||
let message = 'The "' + label + '" field can not be used for filtering.';
|
||||
if (field.scripted) {
|
||||
message = 'The "' + label + '" field is scripted and can not be used for filtering.';
|
||||
}
|
||||
throw new TypeError(message);
|
||||
}
|
||||
AggConfig.prototype.getValue = function (bucket) {
|
||||
return this.type.getValue(this, bucket);
|
||||
};
|
||||
|
||||
return this.type.createFilter(this, key);
|
||||
};
|
||||
AggConfig.prototype.getKey = function (bucket, key) {
|
||||
return this.type.getKey(bucket, key, this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Hook for pre-flight logic, see AggType#onSearchRequestStart
|
||||
* @param {Courier.SearchSource} searchSource
|
||||
* @param {Courier.SearchRequest} searchRequest
|
||||
* @return {Promise<undefined>}
|
||||
*/
|
||||
AggConfig.prototype.onSearchRequestStart = function (searchSource, searchRequest) {
|
||||
if (!this.type) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
AggConfig.prototype.getFieldDisplayName = function () {
|
||||
const field = this.getField();
|
||||
return field ? (field.displayName || this.fieldName()) : '';
|
||||
};
|
||||
|
||||
return Promise.map(
|
||||
this.type.params,
|
||||
param => param.modifyAggConfigOnSearchRequestStart(this, searchSource, searchRequest)
|
||||
);
|
||||
};
|
||||
AggConfig.prototype.getField = function () {
|
||||
return this.params.field;
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert this aggConfig to its dsl syntax.
|
||||
*
|
||||
* Adds params and adhoc subaggs to a pojo, then returns it
|
||||
*
|
||||
* @param {AggConfig} aggConfig - the config object to convert
|
||||
* @return {void|Object} - if the config has a dsl representation, it is
|
||||
* returned, else undefined is returned
|
||||
*/
|
||||
AggConfig.prototype.toDsl = function () {
|
||||
if (this.type.hasNoDsl) return;
|
||||
const output = this.write();
|
||||
AggConfig.prototype.makeLabel = function () {
|
||||
if (this.params.customLabel) {
|
||||
return this.params.customLabel;
|
||||
}
|
||||
|
||||
const configDsl = {};
|
||||
configDsl[this.type.dslName || this.type.name] = output.params;
|
||||
if (!this.type) return '';
|
||||
let pre = (_.get(this.vis, 'params.mode') === 'percentage') ? 'Percentage of ' : '';
|
||||
return pre += this.type.makeLabel(this);
|
||||
};
|
||||
|
||||
// if the config requires subAggs, write them to the dsl as well
|
||||
if (this.subAggs && !output.subAggs) output.subAggs = this.subAggs;
|
||||
if (output.subAggs) {
|
||||
const subDslLvl = configDsl.aggs || (configDsl.aggs = {});
|
||||
output.subAggs.forEach(function nestAdhocSubAggs(subAggConfig) {
|
||||
subDslLvl[subAggConfig.id] = subAggConfig.toDsl();
|
||||
});
|
||||
}
|
||||
AggConfig.prototype.getIndexPattern = function () {
|
||||
return this.vis.indexPattern;
|
||||
};
|
||||
|
||||
if (output.parentAggs) {
|
||||
const subDslLvl = configDsl.parentAggs || (configDsl.parentAggs = {});
|
||||
output.parentAggs.forEach(function nestAdhocSubAggs(subAggConfig) {
|
||||
subDslLvl[subAggConfig.id] = subAggConfig.toDsl();
|
||||
});
|
||||
}
|
||||
AggConfig.prototype.getFieldOptions = function () {
|
||||
const fieldParamType = this.type && this.type.params.byName.field;
|
||||
|
||||
return configDsl;
|
||||
};
|
||||
if (!fieldParamType || !fieldParamType.getFieldOptions) {
|
||||
return null;
|
||||
}
|
||||
|
||||
AggConfig.prototype.toJSON = function () {
|
||||
const self = this;
|
||||
const params = self.params;
|
||||
return fieldParamType.getFieldOptions(this);
|
||||
};
|
||||
|
||||
const outParams = _.transform(self.getAggParams(), function (out, aggParam) {
|
||||
let val = params[aggParam.name];
|
||||
AggConfig.prototype.fieldFormatter = function (contentType, defaultFormat) {
|
||||
const format = this.type && this.type.getFormat(this);
|
||||
if (format) return format.getConverterFor(contentType);
|
||||
return this.fieldOwnFormatter(contentType, defaultFormat);
|
||||
};
|
||||
|
||||
// don't serialize undefined/null values
|
||||
if (val == null) return;
|
||||
if (aggParam.serialize) val = aggParam.serialize(val, self);
|
||||
if (val == null) return;
|
||||
AggConfig.prototype.fieldOwnFormatter = function (contentType, defaultFormat) {
|
||||
const field = this.getField();
|
||||
let format = field && field.format;
|
||||
if (!format) format = defaultFormat;
|
||||
if (!format) format = fieldFormats.getDefaultInstance('string');
|
||||
return format.getConverterFor(contentType);
|
||||
};
|
||||
|
||||
// to prevent accidental leaking, we will clone all complex values
|
||||
out[aggParam.name] = _.cloneDeep(val);
|
||||
}, {});
|
||||
AggConfig.prototype.fieldName = function () {
|
||||
const field = this.getField();
|
||||
return field ? field.name : '';
|
||||
};
|
||||
|
||||
return {
|
||||
id: self.id,
|
||||
enabled: self.enabled,
|
||||
type: self.type && self.type.name,
|
||||
schema: self.schema && self.schema.name,
|
||||
params: outParams
|
||||
};
|
||||
};
|
||||
AggConfig.prototype.fieldIsTimeField = function () {
|
||||
const timeFieldName = this.vis.indexPattern.timeFieldName;
|
||||
return timeFieldName && this.fieldName() === timeFieldName;
|
||||
};
|
||||
|
||||
AggConfig.prototype.getAggParams = function () {
|
||||
return [].concat(
|
||||
(this.type) ? this.type.params.raw : [],
|
||||
(_.has(this, 'schema.params')) ? this.schema.params.raw : []
|
||||
);
|
||||
};
|
||||
|
||||
AggConfig.prototype.getRequestAggs = function () {
|
||||
if (!this.type) return;
|
||||
return this.type.getRequestAggs(this) || [this];
|
||||
};
|
||||
|
||||
AggConfig.prototype.getResponseAggs = function () {
|
||||
if (!this.type) return;
|
||||
return this.type.getResponseAggs(this) || [this];
|
||||
};
|
||||
|
||||
AggConfig.prototype.getValue = function (bucket) {
|
||||
return this.type.getValue(this, bucket);
|
||||
};
|
||||
|
||||
AggConfig.prototype.getKey = function (bucket, key) {
|
||||
return this.type.getKey(bucket, key, this);
|
||||
};
|
||||
|
||||
AggConfig.prototype.getFieldDisplayName = function () {
|
||||
const field = this.getField();
|
||||
return field ? (field.displayName || this.fieldName()) : '';
|
||||
};
|
||||
|
||||
AggConfig.prototype.getField = function () {
|
||||
return this.params.field;
|
||||
};
|
||||
|
||||
AggConfig.prototype.makeLabel = function () {
|
||||
if (this.params.customLabel) {
|
||||
return this.params.customLabel;
|
||||
}
|
||||
|
||||
if (!this.type) return '';
|
||||
let pre = (_.get(this.vis, 'params.mode') === 'percentage') ? 'Percentage of ' : '';
|
||||
return pre += this.type.makeLabel(this);
|
||||
};
|
||||
|
||||
AggConfig.prototype.getIndexPattern = function () {
|
||||
return this.vis.indexPattern;
|
||||
};
|
||||
|
||||
AggConfig.prototype.getFieldOptions = function () {
|
||||
const fieldParamType = this.type && this.type.params.byName.field;
|
||||
|
||||
if (!fieldParamType || !fieldParamType.getFieldOptions) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return fieldParamType.getFieldOptions(this);
|
||||
};
|
||||
|
||||
AggConfig.prototype.fieldFormatter = function (contentType, defaultFormat) {
|
||||
const format = this.type && this.type.getFormat(this);
|
||||
if (format) return format.getConverterFor(contentType);
|
||||
return this.fieldOwnFormatter(contentType, defaultFormat);
|
||||
};
|
||||
|
||||
AggConfig.prototype.fieldOwnFormatter = function (contentType, defaultFormat) {
|
||||
const field = this.getField();
|
||||
let format = field && field.format;
|
||||
if (!format) format = defaultFormat;
|
||||
if (!format) format = fieldFormats.getDefaultInstance('string');
|
||||
return format.getConverterFor(contentType);
|
||||
};
|
||||
|
||||
AggConfig.prototype.fieldName = function () {
|
||||
const field = this.getField();
|
||||
return field ? field.name : '';
|
||||
};
|
||||
|
||||
AggConfig.prototype.fieldIsTimeField = function () {
|
||||
const timeFieldName = this.vis.indexPattern.timeFieldName;
|
||||
return timeFieldName && this.fieldName() === timeFieldName;
|
||||
};
|
||||
|
||||
return AggConfig;
|
||||
}
|
||||
export { AggConfig };
|
||||
|
|
|
@ -9,13 +9,11 @@
|
|||
|
||||
import _ from 'lodash';
|
||||
import { IndexedArray } from 'ui/indexed_array';
|
||||
import { VisAggConfigProvider } from 'ui/vis/agg_config';
|
||||
import { AggConfig } from 'ui/vis/agg_config';
|
||||
import { AggTypesIndexProvider } from 'ui/agg_types/index';
|
||||
import { createLegacyClass } from '../utils/legacy_class';
|
||||
|
||||
export function VisAggConfigsProvider(Private) {
|
||||
const AggConfig = Private(VisAggConfigProvider);
|
||||
|
||||
AggConfig.aggTypes = Private(AggTypesIndexProvider);
|
||||
|
||||
createLegacyClass(AggConfigs).inherits(IndexedArray);
|
||||
|
|
|
@ -5,7 +5,7 @@ import expect from 'expect.js';
|
|||
import ngMock from 'ng_mock';
|
||||
import '../agg_params';
|
||||
import { VisProvider } from 'ui/vis';
|
||||
import { VisAggConfigProvider } from 'ui/vis/agg_config';
|
||||
import { AggConfig } from 'ui/vis/agg_config';
|
||||
import { Schemas } from 'ui/vis/editors/default/schemas';
|
||||
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
|
||||
|
||||
|
@ -14,7 +14,6 @@ describe('Vis-Editor-Agg-Params plugin directive', function () {
|
|||
let $parentScope = {};
|
||||
let Vis;
|
||||
let vis;
|
||||
let AggConfig;
|
||||
let $elem;
|
||||
let compile;
|
||||
let rootScope;
|
||||
|
@ -34,7 +33,6 @@ describe('Vis-Editor-Agg-Params plugin directive', function () {
|
|||
|
||||
Vis = Private(VisProvider);
|
||||
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
|
||||
AggConfig = Private(VisAggConfigProvider);
|
||||
}));
|
||||
|
||||
function init(config) {
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
import { VisAggConfigProvider } from 'ui/vis/agg_config';
|
||||
import { AggConfig } from 'ui/vis/agg_config';
|
||||
import { uiModules } from 'ui/modules';
|
||||
import aggAddTemplate from './agg_add.html';
|
||||
|
||||
uiModules
|
||||
.get('kibana')
|
||||
.directive('visEditorAggAdd', function (Private) {
|
||||
const AggConfig = Private(VisAggConfigProvider);
|
||||
.directive('visEditorAggAdd', function () {
|
||||
|
||||
return {
|
||||
restrict: 'E',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue