Fix tslint errors

pull/13758/head
Sven Klemm 7 years ago
parent 5d8826d034
commit c4452ba335
  1. 4
      public/app/plugins/datasource/mysql/datasource.ts
  2. 4
      public/app/plugins/datasource/mysql/meta_query.ts
  3. 26
      public/app/plugins/datasource/mysql/mysql_query.ts
  4. 56
      public/app/plugins/datasource/mysql/query_ctrl.ts
  5. 4
      public/app/plugins/datasource/mysql/specs/datasource.test.ts
  6. 4
      public/app/plugins/datasource/mysql/sql_part.ts

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

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

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

@ -40,7 +40,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
whereParts: SqlPart[];
groupAdd: any;
/** @ngInject **/
/** @ngInject */
constructor($scope, $injector, private templateSrv, private $q, private uiSegmentSrv) {
super($scope, $injector);
@ -98,7 +98,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
}
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);
});
this.whereParts = _.map(this.target.where, sqlPart.create).filter(n => n);
@ -106,22 +106,22 @@ export class MysqlQueryCtrl extends QueryCtrl {
}
updatePersistedParts() {
this.target.select = _.map(this.selectParts, function(selectParts) {
return _.map(selectParts, function(part: any) {
this.target.select = _.map(this.selectParts, selectParts => {
return _.map(selectParts, (part: any) => {
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 };
});
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 };
});
}
buildSelectMenu() {
this.selectMenu = [];
let aggregates = {
const aggregates = {
text: 'Aggregate Functions',
value: 'aggregate',
submenu: [
@ -157,7 +157,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
}
resetPlusButton(button) {
let plusButton = this.uiSegmentSrv.newPlusButton();
const plusButton = this.uiSegmentSrv.newPlusButton();
button.html = plusButton.html;
button.value = plusButton.value;
}
@ -175,21 +175,21 @@ export class MysqlQueryCtrl 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();
@ -271,7 +271,7 @@ export class MysqlQueryCtrl 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,
@ -279,7 +279,7 @@ export class MysqlQueryCtrl 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) {
@ -325,7 +325,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
switch (partType) {
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) });
});
this.selectParts.push(parts);
@ -336,7 +336,7 @@ export class MysqlQueryCtrl 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;
@ -349,12 +349,12 @@ export class MysqlQueryCtrl 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 {
@ -388,11 +388,11 @@ export class MysqlQueryCtrl 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);
}
@ -460,7 +460,7 @@ export class MysqlQueryCtrl 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
@ -470,12 +470,12 @@ export class MysqlQueryCtrl 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);
}
}
@ -557,7 +557,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
}
getWhereOptions() {
var options = [];
const options = [];
if (this.queryModel.hasUnixEpochTimecolumn()) {
options.push(this.uiSegmentSrv.newSegment({ type: 'macro', value: '$__unixEpochFilter' }));
} else {
@ -570,7 +570,7 @@ export class MysqlQueryCtrl 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;
@ -593,11 +593,11 @@ export class MysqlQueryCtrl 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;

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

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

Loading…
Cancel
Save