Fix tslint errors

This commit is contained in:
Sven Klemm
2018-10-18 20:01:40 +02:00
parent 5d8826d034
commit c4452ba335
6 changed files with 49 additions and 49 deletions

View File

@ -9,7 +9,7 @@ export class MysqlDatasource {
queryModel: MysqlQuery; queryModel: MysqlQuery;
interval: string; interval: string;
/** @ngInject **/ /** @ngInject */
constructor(instanceSettings, private backendSrv, private $q, private templateSrv, private timeSrv) { constructor(instanceSettings, private backendSrv, private $q, private templateSrv, private timeSrv) {
this.name = instanceSettings.name; this.name = instanceSettings.name;
this.id = instanceSettings.id; this.id = instanceSettings.id;
@ -41,7 +41,7 @@ export class MysqlDatasource {
const queries = _.filter(options.targets, target => { const queries = _.filter(options.targets, target => {
return target.hide !== true; return target.hide !== true;
}).map(target => { }).map(target => {
let queryModel = new MysqlQuery(target, this.templateSrv, options.scopedVars); const queryModel = new MysqlQuery(target, this.templateSrv, options.scopedVars);
return { return {
refId: target.refId, refId: target.refId,

View File

@ -25,7 +25,7 @@ export class MysqlMetaQuery {
findMetricTable() { findMetricTable() {
// query that returns first table found that has a timestamp(tz) column and a float column // query that returns first table found that has a timestamp(tz) column and a float column
let query = ` const query = `
SELECT SELECT
table_name as table_name, table_name as table_name,
( SELECT ( SELECT
@ -74,7 +74,7 @@ export class MysqlMetaQuery {
// check for schema qualified table // check for schema qualified table
if (table.includes('.')) { if (table.includes('.')) {
let parts = table.split('.'); const parts = table.split('.');
query = 'table_schema = ' + this.quoteIdentAsLiteral(parts[0]); query = 'table_schema = ' + this.quoteIdentAsLiteral(parts[0]);
query += ' AND table_name = ' + this.quoteIdentAsLiteral(parts[1]); query += ' AND table_name = ' + this.quoteIdentAsLiteral(parts[1]);
return query; return query;

View File

@ -73,12 +73,12 @@ export default class MysqlQuery {
return this.quoteLiteral(value); return this.quoteLiteral(value);
} }
let escapedValues = _.map(value, this.quoteLiteral); const escapedValues = _.map(value, this.quoteLiteral);
return escapedValues.join(','); return escapedValues.join(',');
} }
render(interpolate?) { render(interpolate?) {
let target = this.target; const target = this.target;
// new query with no table set yet // new query with no table set yet
if (!this.target.rawQuery && !('table' in this.target)) { if (!this.target.rawQuery && !('table' in this.target)) {
@ -101,7 +101,7 @@ export default class MysqlQuery {
} }
buildTimeColumn(alias = true) { buildTimeColumn(alias = true) {
let timeGroup = this.hasTimeGroup(); const timeGroup = this.hasTimeGroup();
let query; let query;
let macro = '$__timeGroup'; let macro = '$__timeGroup';
@ -139,7 +139,7 @@ export default class MysqlQuery {
buildValueColumns() { buildValueColumns() {
let query = ''; let query = '';
for (let column of this.target.select) { for (const column of this.target.select) {
query += ',\n ' + this.buildValueColumn(column); query += ',\n ' + this.buildValueColumn(column);
} }
@ -149,14 +149,14 @@ export default class MysqlQuery {
buildValueColumn(column) { buildValueColumn(column) {
let query = ''; let query = '';
let columnName = _.find(column, (g: any) => g.type === 'column'); const columnName = _.find(column, (g: any) => g.type === 'column');
query = columnName.params[0]; query = columnName.params[0];
let aggregate = _.find(column, (g: any) => g.type === 'aggregate' || g.type === 'percentile'); const aggregate = _.find(column, (g: any) => g.type === 'aggregate' || g.type === 'percentile');
let windows = _.find(column, (g: any) => g.type === 'window' || g.type === 'moving_window'); const windows = _.find(column, (g: any) => g.type === 'window' || g.type === 'moving_window');
if (aggregate) { if (aggregate) {
let func = aggregate.params[0]; const func = aggregate.params[0];
switch (aggregate.type) { switch (aggregate.type) {
case 'aggregate': case 'aggregate':
if (func === 'first' || func === 'last') { if (func === 'first' || func === 'last') {
@ -172,13 +172,13 @@ export default class MysqlQuery {
} }
if (windows) { if (windows) {
let overParts = []; const overParts = [];
if (this.hasMetricColumn()) { if (this.hasMetricColumn()) {
overParts.push('PARTITION BY ' + this.target.metricColumn); overParts.push('PARTITION BY ' + this.target.metricColumn);
} }
overParts.push('ORDER BY ' + this.buildTimeColumn(false)); overParts.push('ORDER BY ' + this.buildTimeColumn(false));
let over = overParts.join(' '); const over = overParts.join(' ');
let curr: string; let curr: string;
let prev: string; let prev: string;
switch (windows.type) { switch (windows.type) {
@ -211,7 +211,7 @@ export default class MysqlQuery {
} }
} }
let alias = _.find(column, (g: any) => g.type === 'alias'); const alias = _.find(column, (g: any) => g.type === 'alias');
if (alias) { if (alias) {
query += ' AS ' + this.quoteIdentifier(alias.params[0]); query += ' AS ' + this.quoteIdentifier(alias.params[0]);
} }
@ -221,7 +221,7 @@ export default class MysqlQuery {
buildWhereClause() { buildWhereClause() {
let query = ''; let query = '';
let conditions = _.map(this.target.where, (tag, index) => { const conditions = _.map(this.target.where, (tag, index) => {
switch (tag.type) { switch (tag.type) {
case 'macro': case 'macro':
return tag.name + '(' + this.target.timeColumn + ')'; return tag.name + '(' + this.target.timeColumn + ')';
@ -244,7 +244,7 @@ export default class MysqlQuery {
let groupSection = ''; let groupSection = '';
for (let i = 0; i < this.target.group.length; i++) { for (let i = 0; i < this.target.group.length; i++) {
let part = this.target.group[i]; const part = this.target.group[i];
if (i > 0) { if (i > 0) {
groupSection += ', '; groupSection += ', ';
} }

View File

@ -40,7 +40,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
whereParts: SqlPart[]; whereParts: SqlPart[];
groupAdd: any; groupAdd: any;
/** @ngInject **/ /** @ngInject */
constructor($scope, $injector, private templateSrv, private $q, private uiSegmentSrv) { constructor($scope, $injector, private templateSrv, private $q, private uiSegmentSrv) {
super($scope, $injector); super($scope, $injector);
@ -98,7 +98,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
} }
updateProjection() { updateProjection() {
this.selectParts = _.map(this.target.select, function(parts: any) { this.selectParts = _.map(this.target.select, (parts: any) => {
return _.map(parts, sqlPart.create).filter(n => n); return _.map(parts, sqlPart.create).filter(n => n);
}); });
this.whereParts = _.map(this.target.where, sqlPart.create).filter(n => n); this.whereParts = _.map(this.target.where, sqlPart.create).filter(n => n);
@ -106,22 +106,22 @@ export class MysqlQueryCtrl extends QueryCtrl {
} }
updatePersistedParts() { updatePersistedParts() {
this.target.select = _.map(this.selectParts, function(selectParts) { this.target.select = _.map(this.selectParts, selectParts => {
return _.map(selectParts, function(part: any) { return _.map(selectParts, (part: any) => {
return { type: part.def.type, datatype: part.datatype, params: part.params }; return { type: part.def.type, datatype: part.datatype, params: part.params };
}); });
}); });
this.target.where = _.map(this.whereParts, function(part: any) { this.target.where = _.map(this.whereParts, (part: any) => {
return { type: part.def.type, datatype: part.datatype, name: part.name, params: part.params }; return { type: part.def.type, datatype: part.datatype, name: part.name, params: part.params };
}); });
this.target.group = _.map(this.groupParts, function(part: any) { this.target.group = _.map(this.groupParts, (part: any) => {
return { type: part.def.type, datatype: part.datatype, params: part.params }; return { type: part.def.type, datatype: part.datatype, params: part.params };
}); });
} }
buildSelectMenu() { buildSelectMenu() {
this.selectMenu = []; this.selectMenu = [];
let aggregates = { const aggregates = {
text: 'Aggregate Functions', text: 'Aggregate Functions',
value: 'aggregate', value: 'aggregate',
submenu: [ submenu: [
@ -157,7 +157,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
} }
resetPlusButton(button) { resetPlusButton(button) {
let plusButton = this.uiSegmentSrv.newPlusButton(); const plusButton = this.uiSegmentSrv.newPlusButton();
button.html = plusButton.html; button.html = plusButton.html;
button.value = plusButton.value; button.value = plusButton.value;
} }
@ -175,21 +175,21 @@ export class MysqlQueryCtrl extends QueryCtrl {
this.target.group = []; this.target.group = [];
this.updateProjection(); this.updateProjection();
let segment = this.uiSegmentSrv.newSegment('none'); const segment = this.uiSegmentSrv.newSegment('none');
this.metricColumnSegment.html = segment.html; this.metricColumnSegment.html = segment.html;
this.metricColumnSegment.value = segment.value; this.metricColumnSegment.value = segment.value;
this.target.metricColumn = 'none'; 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 // check if time column is still valid
if (result.length > 0 && !_.find(result, (r: any) => r.text === this.target.timeColumn)) { 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.html = segment.html;
this.timeColumnSegment.value = segment.value; this.timeColumnSegment.value = segment.value;
} }
return this.timeColumnChanged(false); 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) { if (result.length > 0) {
this.target.select = [[{ type: 'column', params: [result[0].text] }]]; this.target.select = [[{ type: 'column', params: [result[0].text] }]];
this.updateProjection(); this.updateProjection();
@ -271,7 +271,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
transformToSegments(config) { transformToSegments(config) {
return results => { return results => {
let segments = _.map(results, segment => { const segments = _.map(results, segment => {
return this.uiSegmentSrv.newSegment({ return this.uiSegmentSrv.newSegment({
value: segment.text, value: segment.text,
expandable: segment.expandable, expandable: segment.expandable,
@ -279,7 +279,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
}); });
if (config.addTemplateVars) { if (config.addTemplateVars) {
for (let variable of this.templateSrv.variables) { for (const variable of this.templateSrv.variables) {
let value; let value;
value = '$' + variable.name; value = '$' + variable.name;
if (config.templateQuoter && variable.multi === false) { if (config.templateQuoter && variable.multi === false) {
@ -325,7 +325,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
switch (partType) { switch (partType) {
case 'column': case 'column':
let parts = _.map(selectParts, function(part: any) { const parts = _.map(selectParts, (part: any) => {
return sqlPart.create({ type: part.def.type, params: _.clone(part.params) }); return sqlPart.create({ type: part.def.type, params: _.clone(part.params) });
}); });
this.selectParts.push(parts); this.selectParts.push(parts);
@ -336,7 +336,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
if (this.target.group.length === 0) { if (this.target.group.length === 0) {
this.addGroup('time', '$__interval'); this.addGroup('time', '$__interval');
} }
let aggIndex = this.findAggregateIndex(selectParts); const aggIndex = this.findAggregateIndex(selectParts);
if (aggIndex !== -1) { if (aggIndex !== -1) {
// replace current aggregation // replace current aggregation
selectParts[aggIndex] = partModel; selectParts[aggIndex] = partModel;
@ -349,12 +349,12 @@ export class MysqlQueryCtrl extends QueryCtrl {
break; break;
case 'moving_window': case 'moving_window':
case 'window': case 'window':
let windowIndex = this.findWindowIndex(selectParts); const windowIndex = this.findWindowIndex(selectParts);
if (windowIndex !== -1) { if (windowIndex !== -1) {
// replace current window function // replace current window function
selectParts[windowIndex] = partModel; selectParts[windowIndex] = partModel;
} else { } else {
let aggIndex = this.findAggregateIndex(selectParts); const aggIndex = this.findAggregateIndex(selectParts);
if (aggIndex !== -1) { if (aggIndex !== -1) {
selectParts.splice(aggIndex + 1, 0, partModel); selectParts.splice(aggIndex + 1, 0, partModel);
} else { } else {
@ -388,11 +388,11 @@ export class MysqlQueryCtrl extends QueryCtrl {
if (part.def.type === 'column') { if (part.def.type === 'column') {
// remove all parts of column unless its last column // remove all parts of column unless its last column
if (this.selectParts.length > 1) { if (this.selectParts.length > 1) {
let modelsIndex = _.indexOf(this.selectParts, selectParts); const modelsIndex = _.indexOf(this.selectParts, selectParts);
this.selectParts.splice(modelsIndex, 1); this.selectParts.splice(modelsIndex, 1);
} }
} else { } else {
let partIndex = _.indexOf(selectParts, part); const partIndex = _.indexOf(selectParts, part);
selectParts.splice(partIndex, 1); selectParts.splice(partIndex, 1);
} }
@ -460,7 +460,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
if (partType === 'time') { if (partType === 'time') {
params = ['$__interval', 'none']; params = ['$__interval', 'none'];
} }
let partModel = sqlPart.create({ type: partType, params: params }); const partModel = sqlPart.create({ type: partType, params: params });
if (partType === 'time') { if (partType === 'time') {
// put timeGroup at start // put timeGroup at start
@ -470,12 +470,12 @@ export class MysqlQueryCtrl extends QueryCtrl {
} }
// add aggregates when adding group by // 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')) { 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); selectParts.splice(1, 0, aggregate);
if (!selectParts.some(part => part.def.type === 'alias')) { 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); selectParts.push(alias);
} }
} }
@ -557,7 +557,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
} }
getWhereOptions() { getWhereOptions() {
var options = []; const options = [];
if (this.queryModel.hasUnixEpochTimecolumn()) { if (this.queryModel.hasUnixEpochTimecolumn()) {
options.push(this.uiSegmentSrv.newSegment({ type: 'macro', value: '$__unixEpochFilter' })); options.push(this.uiSegmentSrv.newSegment({ type: 'macro', value: '$__unixEpochFilter' }));
} else { } else {
@ -570,7 +570,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
addWhereAction(part, index) { addWhereAction(part, index) {
switch (this.whereAdd.type) { switch (this.whereAdd.type) {
case 'macro': { 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') { if (this.whereParts.length >= 1 && this.whereParts[0].def.type === 'macro') {
// replace current macro // replace current macro
this.whereParts[0] = partModel; this.whereParts[0] = partModel;
@ -593,11 +593,11 @@ export class MysqlQueryCtrl extends QueryCtrl {
return this.datasource return this.datasource
.metricFindQuery(this.metaBuilder.buildColumnQuery('group')) .metricFindQuery(this.metaBuilder.buildColumnQuery('group'))
.then(tags => { .then(tags => {
var options = []; const options = [];
if (!this.queryModel.hasTimeGroup()) { if (!this.queryModel.hasTimeGroup()) {
options.push(this.uiSegmentSrv.newSegment({ type: 'time', value: 'time($__interval,none)' })); 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 })); options.push(this.uiSegmentSrv.newSegment({ type: 'column', value: tag.text }));
} }
return options; return options;

View File

@ -13,7 +13,7 @@ describe('MySQLDatasource', () => {
from: moment.utc('2018-04-25 10:00'), from: moment.utc('2018-04-25 10:00'),
to: moment.utc('2018-04-25 11:00'), to: moment.utc('2018-04-25 11:00'),
}; };
const ctx = <any>{ const ctx = {
backendSrv, backendSrv,
timeSrvMock: { timeSrvMock: {
timeRange: () => ({ timeRange: () => ({
@ -22,7 +22,7 @@ describe('MySQLDatasource', () => {
raw: raw, raw: raw,
}), }),
}, },
}; } as any;
beforeEach(() => { beforeEach(() => {
ctx.ds = new MysqlDatasource(instanceSettings, backendSrv, {}, templateSrv, ctx.timeSrvMock); ctx.ds = new MysqlDatasource(instanceSettings, backendSrv, {}, templateSrv, ctx.timeSrvMock);

View File

@ -1,9 +1,9 @@
import { SqlPartDef, SqlPart } from 'app/core/components/sql_part/sql_part'; import { SqlPartDef, SqlPart } from 'app/core/components/sql_part/sql_part';
let index = []; const index = [];
function createPart(part): any { function createPart(part): any {
let def = index[part.type]; const def = index[part.type];
if (!def) { if (!def) {
return null; return null;
} }