2017-12-20 12:33:33 +01:00
|
|
|
import _ from 'lodash';
|
2019-12-09 00:14:25 -08:00
|
|
|
import { dateMath, dateTime } from '@grafana/data';
|
|
|
|
|
import { e2e } from '@grafana/e2e';
|
2016-09-28 10:37:30 +02:00
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
import { QueryCtrl } from 'app/plugins/sdk';
|
2019-09-12 17:28:46 +02:00
|
|
|
import { defaultQuery } from './runStreams';
|
2019-04-25 14:01:02 -04:00
|
|
|
import { getBackendSrv } from 'app/core/services/backend_srv';
|
2016-09-27 14:39:51 +02:00
|
|
|
|
2019-07-17 15:48:08 -04:00
|
|
|
export const defaultPulse: any = {
|
|
|
|
|
timeStep: 60,
|
|
|
|
|
onCount: 3,
|
|
|
|
|
onValue: 2,
|
|
|
|
|
offCount: 3,
|
|
|
|
|
offValue: 1,
|
|
|
|
|
};
|
|
|
|
|
|
2019-07-18 13:36:22 -04:00
|
|
|
export const defaultCSVWave: any = {
|
|
|
|
|
timeStep: 60,
|
|
|
|
|
valuesCSV: '0,0,2,2,1,1',
|
|
|
|
|
};
|
|
|
|
|
|
2019-08-21 07:50:13 -07:00
|
|
|
const showLabelsFor = ['random_walk', 'predictable_pulse', 'predictable_csv_wave'];
|
|
|
|
|
|
2016-09-27 14:39:51 +02:00
|
|
|
export class TestDataQueryCtrl extends QueryCtrl {
|
2017-12-20 12:33:33 +01:00
|
|
|
static templateUrl = 'partials/query.editor.html';
|
2016-09-27 14:39:51 +02:00
|
|
|
|
2016-09-27 18:17:39 +02:00
|
|
|
scenarioList: any;
|
2016-09-28 10:37:30 +02:00
|
|
|
scenario: any;
|
2017-11-01 09:59:24 +01:00
|
|
|
newPointValue: number;
|
|
|
|
|
newPointTime: any;
|
|
|
|
|
selectedPoint: any;
|
2016-09-27 14:39:51 +02:00
|
|
|
|
2019-08-21 07:50:13 -07:00
|
|
|
showLabels = false;
|
2019-12-18 06:13:58 +01:00
|
|
|
selectors: typeof e2e.pages.Dashboard.Panels.DataSource.TestData.QueryTab.selectors;
|
2019-08-21 07:50:13 -07:00
|
|
|
|
2018-08-31 16:40:43 +02:00
|
|
|
/** @ngInject */
|
2019-04-25 14:01:02 -04:00
|
|
|
constructor($scope: any, $injector: any) {
|
2016-09-27 14:39:51 +02:00
|
|
|
super($scope, $injector);
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
this.target.scenarioId = this.target.scenarioId || 'random_walk';
|
2016-09-27 18:17:39 +02:00
|
|
|
this.scenarioList = [];
|
2019-05-08 13:51:44 +02:00
|
|
|
this.newPointTime = dateTime();
|
2017-12-20 12:33:33 +01:00
|
|
|
this.selectedPoint = { text: 'Select point', value: null };
|
2019-08-21 07:50:13 -07:00
|
|
|
this.showLabels = showLabelsFor.includes(this.target.scenarioId);
|
2019-12-18 06:13:58 +01:00
|
|
|
this.selectors = e2e.pages.Dashboard.Panels.DataSource.TestData.QueryTab.selectors;
|
2017-11-01 09:59:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getPoints() {
|
|
|
|
|
return _.map(this.target.points, (point, index) => {
|
|
|
|
|
return {
|
2019-05-08 13:51:44 +02:00
|
|
|
text: dateTime(point[1]).format('MMMM Do YYYY, H:mm:ss') + ' : ' + point[0],
|
2017-12-20 12:33:33 +01:00
|
|
|
value: index,
|
2017-11-01 09:59:24 +01:00
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-27 15:56:02 +02:00
|
|
|
pointSelected(option: any) {
|
2017-11-01 09:59:24 +01:00
|
|
|
this.selectedPoint = option;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deletePoint() {
|
|
|
|
|
this.target.points.splice(this.selectedPoint.value, 1);
|
2017-12-20 12:33:33 +01:00
|
|
|
this.selectedPoint = { text: 'Select point', value: null };
|
2017-11-01 09:59:24 +01:00
|
|
|
this.refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addPoint() {
|
|
|
|
|
this.target.points = this.target.points || [];
|
2019-09-27 16:18:24 +02:00
|
|
|
this.newPointTime = dateMath.parse(this.newPointTime);
|
2017-11-01 09:59:24 +01:00
|
|
|
this.target.points.push([this.newPointValue, this.newPointTime.valueOf()]);
|
|
|
|
|
this.target.points = _.sortBy(this.target.points, p => p[1]);
|
|
|
|
|
this.refresh();
|
2016-09-27 18:17:39 +02:00
|
|
|
}
|
2016-09-27 14:39:51 +02:00
|
|
|
|
2016-09-27 18:17:39 +02:00
|
|
|
$onInit() {
|
2019-04-25 14:01:02 -04:00
|
|
|
return getBackendSrv()
|
|
|
|
|
.get('/api/tsdb/testdata/scenarios')
|
2019-06-27 15:56:02 +02:00
|
|
|
.then((res: any) => {
|
2019-04-25 14:01:02 -04:00
|
|
|
this.scenarioList = res;
|
|
|
|
|
this.scenario = _.find(this.scenarioList, { id: this.target.scenarioId });
|
|
|
|
|
});
|
2016-09-27 14:39:51 +02:00
|
|
|
}
|
2016-09-28 10:37:30 +02:00
|
|
|
|
|
|
|
|
scenarioChanged() {
|
2017-11-01 09:59:24 +01:00
|
|
|
this.scenario = _.find(this.scenarioList, { id: this.target.scenarioId });
|
2016-09-28 10:37:30 +02:00
|
|
|
this.target.stringInput = this.scenario.stringInput;
|
2019-08-21 07:50:13 -07:00
|
|
|
this.showLabels = showLabelsFor.includes(this.target.scenarioId);
|
2017-11-01 09:59:24 +01:00
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
if (this.target.scenarioId === 'manual_entry') {
|
2017-11-01 09:59:24 +01:00
|
|
|
this.target.points = this.target.points || [];
|
|
|
|
|
} else {
|
|
|
|
|
delete this.target.points;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-25 14:01:02 -04:00
|
|
|
if (this.target.scenarioId === 'streaming_client') {
|
|
|
|
|
this.target.stream = _.defaults(this.target.stream || {}, defaultQuery);
|
|
|
|
|
} else {
|
|
|
|
|
delete this.target.stream;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-17 15:48:08 -04:00
|
|
|
if (this.target.scenarioId === 'predictable_pulse') {
|
|
|
|
|
this.target.pulseWave = _.defaults(this.target.pulseWave || {}, defaultPulse);
|
|
|
|
|
} else {
|
|
|
|
|
delete this.target.pulseWave;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-18 13:36:22 -04:00
|
|
|
if (this.target.scenarioId === 'predictable_csv_wave') {
|
|
|
|
|
this.target.csvWave = _.defaults(this.target.csvWave || {}, defaultCSVWave);
|
|
|
|
|
} else {
|
|
|
|
|
delete this.target.csvWave;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-25 14:01:02 -04:00
|
|
|
this.refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
streamChanged() {
|
2016-09-28 10:37:30 +02:00
|
|
|
this.refresh();
|
|
|
|
|
}
|
2016-09-27 14:39:51 +02:00
|
|
|
}
|