| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import _ from 'lodash';
- class TestDataDatasource {
- id: any;
- /** @ngInject */
- constructor(instanceSettings, private backendSrv, private $q) {
- this.id = instanceSettings.id;
- }
- query(options) {
- const queries = _.filter(options.targets, item => {
- return item.hide !== true;
- }).map(item => {
- return {
- refId: item.refId,
- scenarioId: item.scenarioId,
- intervalMs: options.intervalMs,
- maxDataPoints: options.maxDataPoints,
- stringInput: item.stringInput,
- points: item.points,
- alias: item.alias,
- datasourceId: this.id,
- };
- });
- if (queries.length === 0) {
- return this.$q.when({ data: [] });
- }
- return this.backendSrv
- .post('/api/tsdb/query', {
- from: options.range.from.valueOf().toString(),
- to: options.range.to.valueOf().toString(),
- queries: queries,
- })
- .then(res => {
- const data = [];
- if (res.results) {
- _.forEach(res.results, queryRes => {
- for (const series of queryRes.series) {
- data.push({
- target: series.name,
- datapoints: series.points,
- });
- }
- });
- }
- return { data: data };
- });
- }
- annotationQuery(options) {
- return this.backendSrv.get('/api/annotations', {
- from: options.range.from.valueOf(),
- to: options.range.to.valueOf(),
- limit: options.limit,
- type: options.type,
- });
- }
- }
- export { TestDataDatasource };
|