mirror of
https://github.com/grafana/grafana.git
synced 2025-09-29 01:34:36 +08:00
Merge branch '12918-only-arrow-functions3'
This commit is contained in:
@ -23,36 +23,36 @@ export class ElasticBucketAggCtrl {
|
||||
|
||||
$scope.orderByOptions = [];
|
||||
|
||||
$scope.getBucketAggTypes = function() {
|
||||
$scope.getBucketAggTypes = () => {
|
||||
return queryDef.bucketAggTypes;
|
||||
};
|
||||
|
||||
$scope.getOrderOptions = function() {
|
||||
$scope.getOrderOptions = () => {
|
||||
return queryDef.orderOptions;
|
||||
};
|
||||
|
||||
$scope.getSizeOptions = function() {
|
||||
$scope.getSizeOptions = () => {
|
||||
return queryDef.sizeOptions;
|
||||
};
|
||||
|
||||
$rootScope.onAppEvent(
|
||||
'elastic-query-updated',
|
||||
function() {
|
||||
() => {
|
||||
$scope.validateModel();
|
||||
},
|
||||
$scope
|
||||
);
|
||||
|
||||
$scope.init = function() {
|
||||
$scope.init = () => {
|
||||
$scope.agg = bucketAggs[$scope.index];
|
||||
$scope.validateModel();
|
||||
};
|
||||
|
||||
$scope.onChangeInternal = function() {
|
||||
$scope.onChangeInternal = () => {
|
||||
$scope.onChange();
|
||||
};
|
||||
|
||||
$scope.onTypeChanged = function() {
|
||||
$scope.onTypeChanged = () => {
|
||||
$scope.agg.settings = {};
|
||||
$scope.showOptions = false;
|
||||
|
||||
@ -79,7 +79,7 @@ export class ElasticBucketAggCtrl {
|
||||
$scope.onChange();
|
||||
};
|
||||
|
||||
$scope.validateModel = function() {
|
||||
$scope.validateModel = () => {
|
||||
$scope.index = _.indexOf(bucketAggs, $scope.agg);
|
||||
$scope.isFirst = $scope.index === 0;
|
||||
$scope.bucketAggCount = bucketAggs.length;
|
||||
@ -114,7 +114,7 @@ export class ElasticBucketAggCtrl {
|
||||
settings.filters = settings.filters || [{ query: '*' }];
|
||||
settingsLinkText = _.reduce(
|
||||
settings.filters,
|
||||
function(memo, value, index) {
|
||||
(memo, value, index) => {
|
||||
memo += 'Q' + (index + 1) + ' = ' + value.query + ' ';
|
||||
return memo;
|
||||
},
|
||||
@ -168,23 +168,23 @@ export class ElasticBucketAggCtrl {
|
||||
return true;
|
||||
};
|
||||
|
||||
$scope.addFiltersQuery = function() {
|
||||
$scope.addFiltersQuery = () => {
|
||||
$scope.agg.settings.filters.push({ query: '*' });
|
||||
};
|
||||
|
||||
$scope.removeFiltersQuery = function(filter) {
|
||||
$scope.removeFiltersQuery = filter => {
|
||||
$scope.agg.settings.filters = _.without($scope.agg.settings.filters, filter);
|
||||
};
|
||||
|
||||
$scope.toggleOptions = function() {
|
||||
$scope.toggleOptions = () => {
|
||||
$scope.showOptions = !$scope.showOptions;
|
||||
};
|
||||
|
||||
$scope.getOrderByOptions = function() {
|
||||
$scope.getOrderByOptions = () => {
|
||||
return queryDef.getOrderByOptions($scope.target);
|
||||
};
|
||||
|
||||
$scope.getFieldsInternal = function() {
|
||||
$scope.getFieldsInternal = () => {
|
||||
if ($scope.agg.type === 'date_histogram') {
|
||||
return $scope.getFields({ $fieldType: 'date' });
|
||||
} else {
|
||||
@ -192,11 +192,11 @@ export class ElasticBucketAggCtrl {
|
||||
}
|
||||
};
|
||||
|
||||
$scope.getIntervalOptions = function() {
|
||||
$scope.getIntervalOptions = () => {
|
||||
return $q.when(uiSegmentSrv.transformToSegments(true, 'interval')(queryDef.intervalOptions));
|
||||
};
|
||||
|
||||
$scope.addBucketAgg = function() {
|
||||
$scope.addBucketAgg = () => {
|
||||
// if last is date histogram add it before
|
||||
const lastBucket = bucketAggs[bucketAggs.length - 1];
|
||||
let addIndex = bucketAggs.length - 1;
|
||||
@ -207,7 +207,7 @@ export class ElasticBucketAggCtrl {
|
||||
|
||||
const id = _.reduce(
|
||||
$scope.target.bucketAggs.concat($scope.target.metrics),
|
||||
function(max, val) {
|
||||
(max, val) => {
|
||||
return parseInt(val.id) > max ? parseInt(val.id) : max;
|
||||
},
|
||||
0
|
||||
@ -217,7 +217,7 @@ export class ElasticBucketAggCtrl {
|
||||
$scope.onChange();
|
||||
};
|
||||
|
||||
$scope.removeBucketAgg = function() {
|
||||
$scope.removeBucketAgg = () => {
|
||||
bucketAggs.splice($scope.index, 1);
|
||||
$scope.onChange();
|
||||
};
|
||||
|
@ -59,12 +59,12 @@ export class ElasticDatasource {
|
||||
const range = this.timeSrv.timeRange();
|
||||
const indexList = this.indexPattern.getIndexList(range.from.valueOf(), range.to.valueOf());
|
||||
if (_.isArray(indexList) && indexList.length) {
|
||||
return this.request('GET', indexList[0] + url).then(function(results) {
|
||||
return this.request('GET', indexList[0] + url).then(results => {
|
||||
results.data.$$config = results.config;
|
||||
return results.data;
|
||||
});
|
||||
} else {
|
||||
return this.request('GET', this.indexPattern.getIndexForToday() + url).then(function(results) {
|
||||
return this.request('GET', this.indexPattern.getIndexForToday() + url).then(results => {
|
||||
results.data.$$config = results.config;
|
||||
return results.data;
|
||||
});
|
||||
@ -73,7 +73,7 @@ export class ElasticDatasource {
|
||||
|
||||
private post(url, data) {
|
||||
return this.request('POST', url, data)
|
||||
.then(function(results) {
|
||||
.then(results => {
|
||||
results.data.$$config = results.config;
|
||||
return results.data;
|
||||
})
|
||||
@ -145,7 +145,7 @@ export class ElasticDatasource {
|
||||
const list = [];
|
||||
const hits = res.responses[0].hits.hits;
|
||||
|
||||
const getFieldFromSource = function(source, fieldName) {
|
||||
const getFieldFromSource = (source, fieldName) => {
|
||||
if (!fieldName) {
|
||||
return;
|
||||
}
|
||||
@ -213,7 +213,7 @@ export class ElasticDatasource {
|
||||
}
|
||||
return { status: 'success', message: 'Index OK. Time field name OK.' };
|
||||
},
|
||||
function(err) {
|
||||
err => {
|
||||
console.log(err);
|
||||
if (err.data && err.data.error) {
|
||||
let message = angular.toJson(err.data.error);
|
||||
@ -274,13 +274,13 @@ export class ElasticDatasource {
|
||||
payload = payload.replace(/\$timeTo/g, options.range.to.valueOf());
|
||||
payload = this.templateSrv.replace(payload, options.scopedVars);
|
||||
|
||||
return this.post('_msearch', payload).then(function(res) {
|
||||
return this.post('_msearch', payload).then(res => {
|
||||
return new ElasticResponse(sentTargets, res).getTimeSeries();
|
||||
});
|
||||
}
|
||||
|
||||
getFields(query) {
|
||||
return this.get('/_mapping').then(function(result) {
|
||||
return this.get('/_mapping').then(result => {
|
||||
const typeMap = {
|
||||
float: 'number',
|
||||
double: 'number',
|
||||
@ -352,7 +352,7 @@ export class ElasticDatasource {
|
||||
}
|
||||
|
||||
// transform to array
|
||||
return _.map(fields, function(value) {
|
||||
return _.map(fields, value => {
|
||||
return value;
|
||||
});
|
||||
});
|
||||
@ -368,13 +368,13 @@ export class ElasticDatasource {
|
||||
esQuery = esQuery.replace(/\$timeTo/g, range.to.valueOf());
|
||||
esQuery = header + '\n' + esQuery + '\n';
|
||||
|
||||
return this.post('_msearch?search_type=' + searchType, esQuery).then(function(res) {
|
||||
return this.post('_msearch?search_type=' + searchType, esQuery).then(res => {
|
||||
if (!res.responses[0].aggregations) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const buckets = res.responses[0].aggregations['1'].buckets;
|
||||
return _.map(buckets, function(bucket) {
|
||||
return _.map(buckets, bucket => {
|
||||
return {
|
||||
text: bucket.key_as_string || bucket.key,
|
||||
value: bucket.key,
|
||||
|
@ -227,7 +227,7 @@ export class ElasticResponse {
|
||||
if (target.alias) {
|
||||
const regex = /\{\{([\s\S]+?)\}\}/g;
|
||||
|
||||
return target.alias.replace(regex, function(match, g1, g2) {
|
||||
return target.alias.replace(regex, (match, g1, g2) => {
|
||||
const group = g1 || g2;
|
||||
|
||||
if (group.indexOf('term ') === 0) {
|
||||
|
@ -25,19 +25,19 @@ export class ElasticMetricAggCtrl {
|
||||
$scope.pipelineAggOptions = [];
|
||||
$scope.modelSettingsValues = {};
|
||||
|
||||
$scope.init = function() {
|
||||
$scope.init = () => {
|
||||
$scope.agg = metricAggs[$scope.index];
|
||||
$scope.validateModel();
|
||||
$scope.updatePipelineAggOptions();
|
||||
};
|
||||
|
||||
$scope.updatePipelineAggOptions = function() {
|
||||
$scope.updatePipelineAggOptions = () => {
|
||||
$scope.pipelineAggOptions = queryDef.getPipelineAggOptions($scope.target);
|
||||
};
|
||||
|
||||
$rootScope.onAppEvent(
|
||||
'elastic-query-updated',
|
||||
function() {
|
||||
() => {
|
||||
$scope.index = _.indexOf(metricAggs, $scope.agg);
|
||||
$scope.updatePipelineAggOptions();
|
||||
$scope.validateModel();
|
||||
@ -45,7 +45,7 @@ export class ElasticMetricAggCtrl {
|
||||
$scope
|
||||
);
|
||||
|
||||
$scope.validateModel = function() {
|
||||
$scope.validateModel = () => {
|
||||
$scope.isFirst = $scope.index === 0;
|
||||
$scope.isSingle = metricAggs.length === 1;
|
||||
$scope.settingsLinkText = '';
|
||||
@ -57,7 +57,7 @@ export class ElasticMetricAggCtrl {
|
||||
|
||||
const pipelineOptions = queryDef.getPipelineOptions($scope.agg);
|
||||
if (pipelineOptions.length > 0) {
|
||||
_.each(pipelineOptions, function(opt) {
|
||||
_.each(pipelineOptions, opt => {
|
||||
$scope.agg.settings[opt.text] = $scope.agg.settings[opt.text] || opt.default;
|
||||
});
|
||||
$scope.settingsLinkText = 'Options';
|
||||
@ -84,7 +84,7 @@ export class ElasticMetricAggCtrl {
|
||||
|
||||
const stats = _.reduce(
|
||||
$scope.agg.meta,
|
||||
function(memo, val, key) {
|
||||
(memo, val, key) => {
|
||||
if (val) {
|
||||
const def = _.find($scope.extendedStats, { value: key });
|
||||
memo.push(def.text);
|
||||
@ -128,16 +128,16 @@ export class ElasticMetricAggCtrl {
|
||||
}
|
||||
};
|
||||
|
||||
$scope.toggleOptions = function() {
|
||||
$scope.toggleOptions = () => {
|
||||
$scope.showOptions = !$scope.showOptions;
|
||||
$scope.updatePipelineAggOptions();
|
||||
};
|
||||
|
||||
$scope.onChangeInternal = function() {
|
||||
$scope.onChangeInternal = () => {
|
||||
$scope.onChange();
|
||||
};
|
||||
|
||||
$scope.updateMovingAvgModelSettings = function() {
|
||||
$scope.updateMovingAvgModelSettings = () => {
|
||||
const modelSettingsKeys = [];
|
||||
const modelSettings = queryDef.getMovingAvgSettings($scope.agg.settings.model, false);
|
||||
for (let i = 0; i < modelSettings.length; i++) {
|
||||
@ -151,12 +151,12 @@ export class ElasticMetricAggCtrl {
|
||||
}
|
||||
};
|
||||
|
||||
$scope.onChangeClearInternal = function() {
|
||||
$scope.onChangeClearInternal = () => {
|
||||
delete $scope.agg.settings.minimize;
|
||||
$scope.onChange();
|
||||
};
|
||||
|
||||
$scope.onTypeChange = function() {
|
||||
$scope.onTypeChange = () => {
|
||||
$scope.agg.settings = {};
|
||||
$scope.agg.meta = {};
|
||||
$scope.showOptions = false;
|
||||
@ -164,19 +164,19 @@ export class ElasticMetricAggCtrl {
|
||||
$scope.onChange();
|
||||
};
|
||||
|
||||
$scope.getFieldsInternal = function() {
|
||||
$scope.getFieldsInternal = () => {
|
||||
if ($scope.agg.type === 'cardinality') {
|
||||
return $scope.getFields();
|
||||
}
|
||||
return $scope.getFields({ $fieldType: 'number' });
|
||||
};
|
||||
|
||||
$scope.addMetricAgg = function() {
|
||||
$scope.addMetricAgg = () => {
|
||||
const addIndex = metricAggs.length;
|
||||
|
||||
const id = _.reduce(
|
||||
$scope.target.bucketAggs.concat($scope.target.metrics),
|
||||
function(max, val) {
|
||||
(max, val) => {
|
||||
return parseInt(val.id) > max ? parseInt(val.id) : max;
|
||||
},
|
||||
0
|
||||
@ -186,12 +186,12 @@ export class ElasticMetricAggCtrl {
|
||||
$scope.onChange();
|
||||
};
|
||||
|
||||
$scope.removeMetricAgg = function() {
|
||||
$scope.removeMetricAgg = () => {
|
||||
metricAggs.splice($scope.index, 1);
|
||||
$scope.onChange();
|
||||
};
|
||||
|
||||
$scope.toggleShowMetric = function() {
|
||||
$scope.toggleShowMetric = () => {
|
||||
$scope.agg.hide = !$scope.agg.hide;
|
||||
if (!$scope.agg.hide) {
|
||||
delete $scope.agg.hide;
|
||||
|
@ -145,7 +145,7 @@ export const movingAvgModelSettings = {
|
||||
};
|
||||
|
||||
export function getMetricAggTypes(esVersion) {
|
||||
return _.filter(metricAggTypes, function(f) {
|
||||
return _.filter(metricAggTypes, f => {
|
||||
if (f.minVersion) {
|
||||
return f.minVersion <= esVersion;
|
||||
} else {
|
||||
@ -173,7 +173,7 @@ export function isPipelineAgg(metricType) {
|
||||
|
||||
export function getPipelineAggOptions(targets) {
|
||||
const result = [];
|
||||
_.each(targets.metrics, function(metric) {
|
||||
_.each(targets.metrics, metric => {
|
||||
if (!isPipelineAgg(metric.type)) {
|
||||
result.push({ text: describeMetric(metric), value: metric.id });
|
||||
}
|
||||
@ -185,7 +185,7 @@ export function getPipelineAggOptions(targets) {
|
||||
export function getMovingAvgSettings(model, filtered) {
|
||||
const filteredResult = [];
|
||||
if (filtered) {
|
||||
_.each(movingAvgModelSettings[model], function(setting) {
|
||||
_.each(movingAvgModelSettings[model], setting => {
|
||||
if (!setting.isCheckbox) {
|
||||
filteredResult.push(setting);
|
||||
}
|
||||
@ -197,7 +197,7 @@ export function getMovingAvgSettings(model, filtered) {
|
||||
|
||||
export function getOrderByOptions(target) {
|
||||
const metricRefs = [];
|
||||
_.each(target.metrics, function(metric) {
|
||||
_.each(target.metrics, metric => {
|
||||
if (metric.type !== 'count') {
|
||||
metricRefs.push({ text: describeMetric(metric), value: metric.id });
|
||||
}
|
||||
|
Reference in New Issue
Block a user