mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
prettier: ran on all files again, sorry. now settings are defined in package.json
This commit is contained in:
@@ -9,12 +9,7 @@ export class PostgresDatasource {
|
||||
responseParser: ResponseParser;
|
||||
|
||||
/** @ngInject **/
|
||||
constructor(
|
||||
instanceSettings,
|
||||
private backendSrv,
|
||||
private $q,
|
||||
private templateSrv
|
||||
) {
|
||||
constructor(instanceSettings, private backendSrv, private $q, private templateSrv) {
|
||||
this.name = instanceSettings.name;
|
||||
this.id = instanceSettings.id;
|
||||
this.responseParser = new ResponseParser(this.$q);
|
||||
@@ -48,11 +43,7 @@ export class PostgresDatasource {
|
||||
intervalMs: options.intervalMs,
|
||||
maxDataPoints: options.maxDataPoints,
|
||||
datasourceId: this.id,
|
||||
rawSql: this.templateSrv.replace(
|
||||
item.rawSql,
|
||||
options.scopedVars,
|
||||
this.interpolateVariable
|
||||
),
|
||||
rawSql: this.templateSrv.replace(item.rawSql, options.scopedVars, this.interpolateVariable),
|
||||
format: item.format,
|
||||
};
|
||||
});
|
||||
@@ -84,11 +75,7 @@ export class PostgresDatasource {
|
||||
const query = {
|
||||
refId: options.annotation.name,
|
||||
datasourceId: this.id,
|
||||
rawSql: this.templateSrv.replace(
|
||||
options.annotation.rawQuery,
|
||||
options.scopedVars,
|
||||
this.interpolateVariable
|
||||
),
|
||||
rawSql: this.templateSrv.replace(options.annotation.rawQuery, options.scopedVars, this.interpolateVariable),
|
||||
format: 'table',
|
||||
};
|
||||
|
||||
@@ -102,18 +89,12 @@ export class PostgresDatasource {
|
||||
queries: [query],
|
||||
},
|
||||
})
|
||||
.then(data =>
|
||||
this.responseParser.transformAnnotationResponse(options, data)
|
||||
);
|
||||
.then(data => this.responseParser.transformAnnotationResponse(options, data));
|
||||
}
|
||||
|
||||
metricFindQuery(query, optionalOptions) {
|
||||
let refId = 'tempvar';
|
||||
if (
|
||||
optionalOptions &&
|
||||
optionalOptions.variable &&
|
||||
optionalOptions.variable.name
|
||||
) {
|
||||
if (optionalOptions && optionalOptions.variable && optionalOptions.variable.name) {
|
||||
refId = optionalOptions.variable.name;
|
||||
}
|
||||
|
||||
@@ -128,11 +109,7 @@ export class PostgresDatasource {
|
||||
queries: [interpolatedQuery],
|
||||
};
|
||||
|
||||
if (
|
||||
optionalOptions &&
|
||||
optionalOptions.range &&
|
||||
optionalOptions.range.from
|
||||
) {
|
||||
if (optionalOptions && optionalOptions.range && optionalOptions.range.from) {
|
||||
data['from'] = optionalOptions.range.from.valueOf().toString();
|
||||
}
|
||||
if (optionalOptions && optionalOptions.range && optionalOptions.range.to) {
|
||||
@@ -145,9 +122,7 @@ export class PostgresDatasource {
|
||||
method: 'POST',
|
||||
data: data,
|
||||
})
|
||||
.then(data =>
|
||||
this.responseParser.parseMetricFindQueryResult(refId, data)
|
||||
);
|
||||
.then(data => this.responseParser.parseMetricFindQueryResult(refId, data));
|
||||
}
|
||||
|
||||
testDatasource() {
|
||||
|
||||
@@ -39,10 +39,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
|
||||
this.target.format = this.target.format || 'time_series';
|
||||
this.target.alias = '';
|
||||
this.formats = [
|
||||
{ text: 'Time series', value: 'time_series' },
|
||||
{ text: 'Table', value: 'table' },
|
||||
];
|
||||
this.formats = [{ text: 'Time series', value: 'time_series' }, { text: 'Table', value: 'table' }];
|
||||
|
||||
if (!this.target.rawSql) {
|
||||
// special handling when in table panel
|
||||
@@ -54,11 +51,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
|
||||
}
|
||||
}
|
||||
|
||||
this.panelCtrl.events.on(
|
||||
'data-received',
|
||||
this.onDataReceived.bind(this),
|
||||
$scope
|
||||
);
|
||||
this.panelCtrl.events.on('data-received', this.onDataReceived.bind(this), $scope);
|
||||
this.panelCtrl.events.on('data-error', this.onDataError.bind(this), $scope);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,11 +40,7 @@ export default class ResponseParser {
|
||||
}
|
||||
|
||||
parseMetricFindQueryResult(refId, results) {
|
||||
if (
|
||||
!results ||
|
||||
results.data.length === 0 ||
|
||||
results.data.results[refId].meta.rowCount === 0
|
||||
) {
|
||||
if (!results || results.data.length === 0 || results.data.results[refId].meta.rowCount === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -143,9 +139,7 @@ export default class ResponseParser {
|
||||
time: Math.floor(row[timeColumnIndex]) * 1000,
|
||||
title: row[titleColumnIndex],
|
||||
text: row[textColumnIndex],
|
||||
tags: row[tagsColumnIndex]
|
||||
? row[tagsColumnIndex].trim().split(/\s*,\s*/)
|
||||
: [],
|
||||
tags: row[tagsColumnIndex] ? row[tagsColumnIndex].trim().split(/\s*,\s*/) : [],
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
import {
|
||||
describe,
|
||||
beforeEach,
|
||||
it,
|
||||
expect,
|
||||
angularMocks,
|
||||
} from 'test/lib/common';
|
||||
import { describe, beforeEach, it, expect, angularMocks } from 'test/lib/common';
|
||||
import moment from 'moment';
|
||||
import helpers from 'test/specs/helpers';
|
||||
import { PostgresDatasource } from '../datasource';
|
||||
@@ -101,11 +95,7 @@ describe('PostgreSQLDatasource', function() {
|
||||
tables: [
|
||||
{
|
||||
columns: [{ text: 'title' }, { text: 'text' }],
|
||||
rows: [
|
||||
['aTitle', 'some text'],
|
||||
['aTitle2', 'some text2'],
|
||||
['aTitle3', 'some text3'],
|
||||
],
|
||||
rows: [['aTitle', 'some text'], ['aTitle2', 'some text2'], ['aTitle3', 'some text3']],
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -142,11 +132,7 @@ describe('PostgreSQLDatasource', function() {
|
||||
tables: [
|
||||
{
|
||||
columns: [{ text: '__value' }, { text: '__text' }],
|
||||
rows: [
|
||||
['value1', 'aTitle'],
|
||||
['value2', 'aTitle2'],
|
||||
['value3', 'aTitle3'],
|
||||
],
|
||||
rows: [['value1', 'aTitle'], ['value2', 'aTitle2'], ['value3', 'aTitle3']],
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -185,11 +171,7 @@ describe('PostgreSQLDatasource', function() {
|
||||
tables: [
|
||||
{
|
||||
columns: [{ text: '__text' }, { text: '__value' }],
|
||||
rows: [
|
||||
['aTitle', 'same'],
|
||||
['aTitle', 'same'],
|
||||
['aTitle', 'diff'],
|
||||
],
|
||||
rows: [['aTitle', 'same'], ['aTitle', 'same'], ['aTitle', 'diff']],
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -232,9 +214,7 @@ describe('PostgreSQLDatasource', function() {
|
||||
|
||||
describe('and value is an array of strings', () => {
|
||||
it('should return comma separated quoted values', () => {
|
||||
expect(
|
||||
ctx.ds.interpolateVariable(['a', 'b', 'c'], ctx.variable)
|
||||
).to.eql("'a','b','c'");
|
||||
expect(ctx.ds.interpolateVariable(['a', 'b', 'c'], ctx.variable)).to.eql("'a','b','c'");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user