mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 23:53:20 +08:00
Merge branch 'master' into postgres-query-builder
This commit is contained in:
@ -39,7 +39,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
whereParts: SqlPart[];
|
||||
groupAdd: any;
|
||||
|
||||
/** @ngInject **/
|
||||
/** @ngInject */
|
||||
constructor($scope, $injector, private templateSrv, private $q, private uiSegmentSrv) {
|
||||
super($scope, $injector);
|
||||
this.target = this.target;
|
||||
@ -119,7 +119,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
|
||||
buildSelectMenu() {
|
||||
this.selectMenu = [];
|
||||
let aggregates = {
|
||||
const aggregates = {
|
||||
text: 'Aggregate Functions',
|
||||
value: 'aggregate',
|
||||
submenu: [
|
||||
@ -143,7 +143,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
|
||||
// ordered set aggregates require postgres 9.4+
|
||||
if (this.datasource.jsonData.postgresVersion >= 904) {
|
||||
let aggregates2 = {
|
||||
const aggregates2 = {
|
||||
text: 'Ordered-Set Aggregate Functions',
|
||||
value: 'percentile',
|
||||
submenu: [
|
||||
@ -154,7 +154,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
this.selectMenu.push(aggregates2);
|
||||
}
|
||||
|
||||
let windows = {
|
||||
const windows = {
|
||||
text: 'Window Functions',
|
||||
value: 'window',
|
||||
submenu: [
|
||||
@ -187,7 +187,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
}
|
||||
|
||||
resetPlusButton(button) {
|
||||
let plusButton = this.uiSegmentSrv.newPlusButton();
|
||||
const plusButton = this.uiSegmentSrv.newPlusButton();
|
||||
button.html = plusButton.html;
|
||||
button.value = plusButton.value;
|
||||
}
|
||||
@ -205,21 +205,21 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
this.target.group = [];
|
||||
this.updateProjection();
|
||||
|
||||
let segment = this.uiSegmentSrv.newSegment('none');
|
||||
const segment = this.uiSegmentSrv.newSegment('none');
|
||||
this.metricColumnSegment.html = segment.html;
|
||||
this.metricColumnSegment.value = segment.value;
|
||||
this.target.metricColumn = 'none';
|
||||
|
||||
let task1 = this.datasource.metricFindQuery(this.metaBuilder.buildColumnQuery('time')).then(result => {
|
||||
const task1 = this.datasource.metricFindQuery(this.metaBuilder.buildColumnQuery('time')).then(result => {
|
||||
// check if time column is still valid
|
||||
if (result.length > 0 && !_.find(result, (r: any) => r.text === this.target.timeColumn)) {
|
||||
let segment = this.uiSegmentSrv.newSegment(result[0].text);
|
||||
const segment = this.uiSegmentSrv.newSegment(result[0].text);
|
||||
this.timeColumnSegment.html = segment.html;
|
||||
this.timeColumnSegment.value = segment.value;
|
||||
}
|
||||
return this.timeColumnChanged(false);
|
||||
});
|
||||
let task2 = this.datasource.metricFindQuery(this.metaBuilder.buildColumnQuery('value')).then(result => {
|
||||
const task2 = this.datasource.metricFindQuery(this.metaBuilder.buildColumnQuery('value')).then(result => {
|
||||
if (result.length > 0) {
|
||||
this.target.select = [[{ type: 'column', params: [result[0].text] }]];
|
||||
this.updateProjection();
|
||||
@ -301,7 +301,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
|
||||
transformToSegments(config) {
|
||||
return results => {
|
||||
let segments = _.map(results, segment => {
|
||||
const segments = _.map(results, segment => {
|
||||
return this.uiSegmentSrv.newSegment({
|
||||
value: segment.text,
|
||||
expandable: segment.expandable,
|
||||
@ -309,7 +309,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
});
|
||||
|
||||
if (config.addTemplateVars) {
|
||||
for (let variable of this.templateSrv.variables) {
|
||||
for (const variable of this.templateSrv.variables) {
|
||||
let value;
|
||||
value = '$' + variable.name;
|
||||
if (config.templateQuoter && variable.multi === false) {
|
||||
@ -355,7 +355,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
|
||||
switch (partType) {
|
||||
case 'column':
|
||||
let parts = _.map(selectParts, function(part: any) {
|
||||
const parts = _.map(selectParts, function(part: any) {
|
||||
return sqlPart.create({ type: part.def.type, params: _.clone(part.params) });
|
||||
});
|
||||
this.selectParts.push(parts);
|
||||
@ -366,7 +366,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
if (this.target.group.length === 0) {
|
||||
this.addGroup('time', '$__interval');
|
||||
}
|
||||
let aggIndex = this.findAggregateIndex(selectParts);
|
||||
const aggIndex = this.findAggregateIndex(selectParts);
|
||||
if (aggIndex !== -1) {
|
||||
// replace current aggregation
|
||||
selectParts[aggIndex] = partModel;
|
||||
@ -379,12 +379,12 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
break;
|
||||
case 'moving_window':
|
||||
case 'window':
|
||||
let windowIndex = this.findWindowIndex(selectParts);
|
||||
const windowIndex = this.findWindowIndex(selectParts);
|
||||
if (windowIndex !== -1) {
|
||||
// replace current window function
|
||||
selectParts[windowIndex] = partModel;
|
||||
} else {
|
||||
let aggIndex = this.findAggregateIndex(selectParts);
|
||||
const aggIndex = this.findAggregateIndex(selectParts);
|
||||
if (aggIndex !== -1) {
|
||||
selectParts.splice(aggIndex + 1, 0, partModel);
|
||||
} else {
|
||||
@ -418,11 +418,11 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
if (part.def.type === 'column') {
|
||||
// remove all parts of column unless its last column
|
||||
if (this.selectParts.length > 1) {
|
||||
let modelsIndex = _.indexOf(this.selectParts, selectParts);
|
||||
const modelsIndex = _.indexOf(this.selectParts, selectParts);
|
||||
this.selectParts.splice(modelsIndex, 1);
|
||||
}
|
||||
} else {
|
||||
let partIndex = _.indexOf(selectParts, part);
|
||||
const partIndex = _.indexOf(selectParts, part);
|
||||
selectParts.splice(partIndex, 1);
|
||||
}
|
||||
|
||||
@ -490,7 +490,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
if (partType === 'time') {
|
||||
params = ['$__interval', 'none'];
|
||||
}
|
||||
let partModel = sqlPart.create({ type: partType, params: params });
|
||||
const partModel = sqlPart.create({ type: partType, params: params });
|
||||
|
||||
if (partType === 'time') {
|
||||
// put timeGroup at start
|
||||
@ -500,12 +500,12 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
}
|
||||
|
||||
// add aggregates when adding group by
|
||||
for (let selectParts of this.selectParts) {
|
||||
for (const selectParts of this.selectParts) {
|
||||
if (!selectParts.some(part => part.def.type === 'aggregate')) {
|
||||
let aggregate = sqlPart.create({ type: 'aggregate', params: ['avg'] });
|
||||
const aggregate = sqlPart.create({ type: 'aggregate', params: ['avg'] });
|
||||
selectParts.splice(1, 0, aggregate);
|
||||
if (!selectParts.some(part => part.def.type === 'alias')) {
|
||||
let alias = sqlPart.create({ type: 'alias', params: [selectParts[0].part.params[0]] });
|
||||
const alias = sqlPart.create({ type: 'alias', params: [selectParts[0].part.params[0]] });
|
||||
selectParts.push(alias);
|
||||
}
|
||||
}
|
||||
@ -587,7 +587,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
}
|
||||
|
||||
getWhereOptions() {
|
||||
var options = [];
|
||||
const options = [];
|
||||
if (this.queryModel.hasUnixEpochTimecolumn()) {
|
||||
options.push(this.uiSegmentSrv.newSegment({ type: 'macro', value: '$__unixEpochFilter' }));
|
||||
} else {
|
||||
@ -600,7 +600,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
addWhereAction(part, index) {
|
||||
switch (this.whereAdd.type) {
|
||||
case 'macro': {
|
||||
let partModel = sqlPart.create({ type: 'macro', name: this.whereAdd.value, params: [] });
|
||||
const partModel = sqlPart.create({ type: 'macro', name: this.whereAdd.value, params: [] });
|
||||
if (this.whereParts.length >= 1 && this.whereParts[0].def.type === 'macro') {
|
||||
// replace current macro
|
||||
this.whereParts[0] = partModel;
|
||||
@ -623,11 +623,11 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
return this.datasource
|
||||
.metricFindQuery(this.metaBuilder.buildColumnQuery('group'))
|
||||
.then(tags => {
|
||||
var options = [];
|
||||
const options = [];
|
||||
if (!this.queryModel.hasTimeGroup()) {
|
||||
options.push(this.uiSegmentSrv.newSegment({ type: 'time', value: 'time($__interval,none)' }));
|
||||
}
|
||||
for (let tag of tags) {
|
||||
for (const tag of tags) {
|
||||
options.push(this.uiSegmentSrv.newSegment({ type: 'column', value: tag.text }));
|
||||
}
|
||||
return options;
|
||||
|
Reference in New Issue
Block a user