Skip to content

Commit

Permalink
Merge pull request #6934 from elastic/jasper/backport/6921/4.x
Browse files Browse the repository at this point in the history
[backport] PR #6921 to 4.x
  • Loading branch information
epixa committed Apr 14, 2016
2 parents b7cf34c + 7b9ed64 commit d654a7c
Show file tree
Hide file tree
Showing 15 changed files with 162 additions and 162 deletions.
68 changes: 34 additions & 34 deletions src/ui/public/Vis/AggConfig.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
define(function (require) {
return function AggConfigFactory(Private, fieldTypeFilter) {
var _ = require('lodash');
var fieldFormats = Private(require('ui/registry/field_formats'));
let _ = require('lodash');
let fieldFormats = Private(require('ui/registry/field_formats'));

function AggConfig(vis, opts) {
var self = this;
let self = this;

self.id = String(opts.id || AggConfig.nextId(vis.aggs));
self.vis = vis;
Expand All @@ -26,13 +26,13 @@ define(function (require) {
* @return {array} - the list that was passed in
*/
AggConfig.ensureIds = function (list) {
var have = [];
var haveNot = [];
let have = [];
let haveNot = [];
list.forEach(function (obj) {
(obj.id ? have : haveNot).push(obj);
});

var nextId = AggConfig.nextId(have);
let nextId = AggConfig.nextId(have);
haveNot.forEach(function (obj) {
obj.id = String(nextId++);
});
Expand Down Expand Up @@ -97,12 +97,12 @@ define(function (require) {
* @return {undefined}
*/
AggConfig.prototype.fillDefaults = function (from) {
var self = this;
let self = this;
from = from || self.params || {};
var to = self.params = {};
let to = self.params = {};

self.getAggParams().forEach(function (aggParam) {
var val = from[aggParam.name];
let val = from[aggParam.name];

if (val == null) {
if (aggParam.default == null) return;
Expand All @@ -116,11 +116,11 @@ define(function (require) {
}

if (aggParam.deserialize) {
var isTyped = _.isFunction(aggParam.type);
let isTyped = _.isFunction(aggParam.type);

var isType = isTyped && (val instanceof aggParam.type);
var isObject = !isTyped && _.isObject(val);
var isDeserialized = (isType || isObject);
let isType = isTyped && (val instanceof aggParam.type);
let isObject = !isTyped && _.isObject(val);
let isDeserialized = (isType || isObject);

if (!isDeserialized) {
val = aggParam.deserialize(val, self);
Expand All @@ -140,12 +140,12 @@ define(function (require) {
* @return {object} the new params object
*/
AggConfig.prototype.resetParams = function () {
var fieldParam = this.type && this.type.params.byName.field;
let fieldParam = this.type && this.type.params.byName.field;
let field;

if (fieldParam) {
var prevField = this.params.field;
var fieldOpts = fieldTypeFilter(this.vis.indexPattern.fields, fieldParam.filterFieldTypes);
let prevField = this.params.field;
let fieldOpts = fieldTypeFilter(this.vis.indexPattern.fields, fieldParam.filterFieldTypes);
field = _.contains(fieldOpts, prevField) ? prevField : null;
}

Expand All @@ -161,10 +161,10 @@ define(function (require) {
throw new TypeError('The "' + this.type.title + '" aggregation does not support filtering.');
}

var field = this.field();
var label = this.fieldDisplayName();
let field = this.field();
let label = this.fieldDisplayName();
if (field && !field.filterable) {
var message = 'The "' + label + '" field can not be used for filtering.';
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.';
}
Expand All @@ -181,7 +181,7 @@ define(function (require) {
* @return {[type]} [description]
*/
AggConfig.prototype.requesting = function () {
var self = this;
let self = this;
self.type && self.type.params.forEach(function (param) {
if (param.onRequest) param.onRequest(self);
});
Expand All @@ -198,14 +198,14 @@ define(function (require) {
*/
AggConfig.prototype.toDsl = function () {
if (this.type.hasNoDsl) return;
var output = this.write();
let output = this.write();

var configDsl = {};
let configDsl = {};
configDsl[this.type.dslName || this.type.name] = output.params;

// if the config requires subAggs, write them to the dsl as well
if (output.subAggs) {
var subDslLvl = configDsl.aggs || (configDsl.aggs = {});
let subDslLvl = configDsl.aggs || (configDsl.aggs = {});
output.subAggs.forEach(function nestAdhocSubAggs(subAggConfig) {
subDslLvl[subAggConfig.id] = subAggConfig.toDsl();
});
Expand All @@ -215,11 +215,11 @@ define(function (require) {
};

AggConfig.prototype.toJSON = function () {
var self = this;
var params = self.params;
let self = this;
let params = self.params;

var outParams = _.transform(self.getAggParams(), function (out, aggParam) {
var val = params[aggParam.name];
let outParams = _.transform(self.getAggParams(), function (out, aggParam) {
let val = params[aggParam.name];

// don't serialize undefined/null values
if (val == null) return;
Expand Down Expand Up @@ -264,7 +264,7 @@ define(function (require) {
}

if (!this.type) return '';
var pre = (_.get(this.vis, 'params.mode') === 'percentage') ? 'Percentage of ' : '';
let pre = (_.get(this.vis, 'params.mode') === 'percentage') ? 'Percentage of ' : '';
return pre += this.type.makeLabel(this);
};

Expand All @@ -273,31 +273,31 @@ define(function (require) {
};

AggConfig.prototype.fieldFormatter = function (contentType, defaultFormat) {
var format = this.type && this.type.getFormat(this);
let format = this.type && this.type.getFormat(this);
if (format) return format.getConverterFor(contentType);
return this.fieldOwnFormatter(contentType, defaultFormat);
};

AggConfig.prototype.fieldOwnFormatter = function (contentType, defaultFormat) {
var field = this.field();
var format = field && field.format;
let field = this.field();
let format = field && field.format;
if (!format) format = defaultFormat;
if (!format) format = fieldFormats.getDefaultInstance('string');
return format.getConverterFor(contentType);
};

AggConfig.prototype.fieldName = function () {
var field = this.field();
let field = this.field();
return field ? field.name : '';
};

AggConfig.prototype.fieldDisplayName = function () {
var field = this.field();
let field = this.field();
return field ? (field.displayName || this.fieldName()) : '';
};

AggConfig.prototype.fieldIsTimeField = function () {
var timeFieldName = this.vis.indexPattern.timeFieldName;
let timeFieldName = this.vis.indexPattern.timeFieldName;
return timeFieldName && this.fieldName() === timeFieldName;
};

Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/Vis/AggConfigResult.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
define(function () {
var i = 0;
let i = 0;

function AggConfigResult(aggConfig, parent, value, key) {
this.key = key;
Expand Down
24 changes: 12 additions & 12 deletions src/ui/public/Vis/AggConfigs.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
define(function (require) {
return function AggConfigsFactory(Private) {
var _ = require('lodash');
var AggConfig = Private(require('ui/Vis/AggConfig'));
var IndexedArray = require('ui/IndexedArray');
let _ = require('lodash');
let AggConfig = Private(require('ui/Vis/AggConfig'));
let IndexedArray = require('ui/IndexedArray');

AggConfig.aggTypes = Private(require('ui/agg_types/index'));

_.class(AggConfigs).inherits(IndexedArray);
function AggConfigs(vis, configStates) {
var self = this;
let self = this;
self.vis = vis;

configStates = AggConfig.ensureIds(configStates || []);
Expand All @@ -35,9 +35,9 @@ define(function (require) {
})
.each(function (schema) {
if (!self.bySchemaName[schema.name]) {
var defaults = schema.defaults.slice(0, schema.max);
let defaults = schema.defaults.slice(0, schema.max);
_.each(defaults, function (defaultState) {
var state = _.defaults({ id: AggConfig.nextId(self) }, defaultState);
let state = _.defaults({ id: AggConfig.nextId(self) }, defaultState);
self.push(new AggConfig(vis, state));
});
}
Expand All @@ -47,7 +47,7 @@ define(function (require) {
}

AggConfigs.prototype.toDsl = function () {
var dslTopLvl = {};
let dslTopLvl = {};
let dslLvlCursor;
let nestedMetrics;

Expand Down Expand Up @@ -75,16 +75,16 @@ define(function (require) {
// start at the top level
dslLvlCursor = dslTopLvl;
} else {
var prevConfig = list[i - 1];
var prevDsl = dslLvlCursor[prevConfig.id];
let prevConfig = list[i - 1];
let prevDsl = dslLvlCursor[prevConfig.id];

// advance the cursor and nest under the previous agg, or
// put it on the same level if the previous agg doesn't accept
// sub aggs
dslLvlCursor = prevDsl.aggs || dslLvlCursor;
}

var dsl = dslLvlCursor[config.id] = config.toDsl();
let dsl = dslLvlCursor[config.id] = config.toDsl();
let subAggs;

if (config.schema.group === 'buckets' && i < list.length - 1) {
Expand Down Expand Up @@ -121,7 +121,7 @@ define(function (require) {
*/
AggConfigs.prototype.getResponseAggs = function () {
return this.getRequestAggs().reduce(function (responseValuesAggs, agg) {
var aggs = agg.getResponseAggs();
let aggs = agg.getResponseAggs();
return aggs ? responseValuesAggs.concat(aggs) : responseValuesAggs;
}, []);
};
Expand All @@ -136,7 +136,7 @@ define(function (require) {
*/
AggConfigs.prototype.getResponseAggById = function (id) {
id = String(id);
var reqAgg = _.find(this.getRequestAggs(), function (agg) {
let reqAgg = _.find(this.getRequestAggs(), function (agg) {
return id.substr(0, String(agg.id).length) === agg.id;
});
if (!reqAgg) return;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/Vis/Renderbot.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
define(function (require) {
var _ = require('lodash');
let _ = require('lodash');

return function RenderbotFactory(Private) {

Expand Down
8 changes: 4 additions & 4 deletions src/ui/public/Vis/Schemas.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
define(function (require) {
return function VisTypeSchemasFactory(Private) {
var _ = require('lodash');
var IndexedArray = require('ui/IndexedArray');
var AggParams = Private(require('ui/agg_types/AggParams'));
let _ = require('lodash');
let IndexedArray = require('ui/IndexedArray');
let AggParams = Private(require('ui/agg_types/AggParams'));

function Schemas(schemas) {
var self = this;
let self = this;

_(schemas || [])
.map(function (schema) {
Expand Down
22 changes: 11 additions & 11 deletions src/ui/public/Vis/Vis.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
define(function (require) {
return function VisFactory(Notifier, Private) {
var _ = require('lodash');
var aggTypes = Private(require('ui/agg_types/index'));
var visTypes = Private(require('ui/registry/vis_types'));
var AggConfigs = Private(require('ui/Vis/AggConfigs'));
let _ = require('lodash');
let aggTypes = Private(require('ui/agg_types/index'));
let visTypes = Private(require('ui/registry/vis_types'));
let AggConfigs = Private(require('ui/Vis/AggConfigs'));

var notify = new Notifier({
let notify = new Notifier({
location: 'Vis'
});

Expand All @@ -29,23 +29,23 @@ define(function (require) {
type = visTypes.byName[type || 'histogram'];
}

var schemas = type.schemas;
let schemas = type.schemas;

var aggs = _.transform(oldState, function (newConfigs, oldConfigs, oldGroupName) {
var schema = schemas.all.byName[oldGroupName];
let aggs = _.transform(oldState, function (newConfigs, oldConfigs, oldGroupName) {
let schema = schemas.all.byName[oldGroupName];

if (!schema) {
notify.log('unable to match old schema', oldGroupName, 'to a new schema');
return;
}

oldConfigs.forEach(function (oldConfig) {
var agg = {
let agg = {
schema: schema.name,
type: oldConfig.agg,
};

var aggType = aggTypes.byName[agg.type];
let aggType = aggTypes.byName[agg.type];
if (!aggType) {
notify.log('unable to find an agg type for old confg', oldConfig);
return;
Expand Down Expand Up @@ -116,7 +116,7 @@ define(function (require) {
};

Vis.prototype.hasSchemaAgg = function (schemaName, aggTypeName) {
var aggs = this.aggs.bySchemaName[schemaName] || [];
let aggs = this.aggs.bySchemaName[schemaName] || [];
return aggs.some(function (agg) {
if (!agg.type || !agg.type.name) return false;
return agg.type.name === aggTypeName;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/Vis/VisType.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
define(function (require) {
return function VisTypeFactory(Private) {
var VisTypeSchemas = Private(require('ui/Vis/Schemas'));
let VisTypeSchemas = Private(require('ui/Vis/Schemas'));

function VisType(opts) {
opts = opts || {};
Expand Down
Loading

0 comments on commit d654a7c

Please sign in to comment.