Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #12 from akenza-io/load-more-on-search
Browse files Browse the repository at this point in the history
implements the same functionality as in the v3 connector which loads …
  • Loading branch information
Biglr authored Jul 23, 2021
2 parents 4cacd1a + 97b35a8 commit c9d9f2e
Show file tree
Hide file tree
Showing 8 changed files with 7,389 additions and 6,515 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Akenza Grafana Connector
---


## [1.0.0]

13,479 changes: 7,119 additions & 6,360 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"author": "David Giger",
"license": "Apache-2.0",
"dependencies": {
"@grafana/data": "^7.0.0",
"@grafana/runtime": "^7.0.0",
"@grafana/toolkit": "^7.0.0",
"@grafana/ui": "^7.0.0",
"@grafana/data": "7.5.3",
"@grafana/runtime": "7.5.3",
"@grafana/toolkit": "7.5.3",
"@grafana/ui": "7.5.3",
"@types/lodash": "^4.14.152",
"build-url": "^2.0.0"
},
Expand Down
25 changes: 15 additions & 10 deletions src/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '@grafana/data';
import { BackendSrvRequest, getBackendSrv } from '@grafana/runtime';
import buildUrl from 'build-url';
import { Asset, AssetData, AssetList, Environment, EnvironmentList, TimeSeriesData } from './types/AkenzaTypes';
import { DeviceData, DeviceList, Device, Environment, EnvironmentList, TimeSeriesData } from './types/AkenzaTypes';
import { AkenzaDataSourceConfig, AkenzaQuery } from './types/PluginTypes';
import { HttpErrorPromise, HttpPromise } from './types/Utils';

Expand Down Expand Up @@ -46,7 +46,7 @@ export class DataSource extends DataSourceApi<AkenzaQuery, AkenzaDataSourceConfi
const to: DateTime = options.range.to;
const panelData: MutableDataFrame[] = [];
for (let target of options.targets) {
if (target.assetId && target.topic && target.dataKey && !target.hide) {
if (target.deviceId && target.topic && target.dataKey && !target.hide) {
const timeSeriesData = await this.getTimeSeriesData(target, from.toISOString(), to.toISOString());
const data: number[] = [];
const time: number[] = [];
Expand All @@ -61,7 +61,11 @@ export class DataSource extends DataSourceApi<AkenzaQuery, AkenzaDataSourceConfi
refId: target.refId,
fields: [
{ name: 'Time', values: time, type: FieldType.time },
{ name: target.asset?.name + ' - ' + target.dataKey, values: data, type: FieldType.number },
{
name: target.device?.name + ' - ' + target.dataKey,
values: data,
type: FieldType.number,
},
],
})
);
Expand All @@ -81,7 +85,7 @@ export class DataSource extends DataSourceApi<AkenzaQuery, AkenzaDataSourceConfi
},
};

return this.doRequest('/v2/assets/' + query.assetId + '/query/time-series', 'POST', null, body).then(
return this.doRequest('/v2/assets/' + query.deviceId + '/query/time-series', 'POST', null, body).then(
(timeSeriesData: HttpPromise<TimeSeriesData>) => {
return timeSeriesData.data;
},
Expand All @@ -91,17 +95,18 @@ export class DataSource extends DataSourceApi<AkenzaQuery, AkenzaDataSourceConfi
);
}

async getAssets(): Promise<Asset[]> {
async getAssets(searchString?: string): Promise<Device[]> {
const params = {
limit: 1000,
limit: 25,
// has to be a string, since the backendSrv just calls toString() on it which results in [Object object] and an API error...
fields: '{"id": true, "name": true}',
search: searchString,
};

return this.getEnvironment().then(
environment => {
(environment) => {
return this.doRequest('/v2/environments/' + environment.id + '/devices', 'GET', params).then(
(assetListHttpPromise: HttpPromise<AssetList>) => {
(assetListHttpPromise: HttpPromise<DeviceList>) => {
return assetListHttpPromise.data.data;
},
(error: HttpErrorPromise) => {
Expand Down Expand Up @@ -134,9 +139,9 @@ export class DataSource extends DataSourceApi<AkenzaQuery, AkenzaDataSourceConfi
};

return this.doRequest('/v2/assets/' + assetId + '/query', 'POST', null, queryOptions).then(
(res: HttpPromise<AssetData[]>) => {
(res: HttpPromise<DeviceData[]>) => {
const keys: string[] = [];
Object.keys(res.data[0].data).forEach(key => keys.push(key));
Object.keys(res.data[0].data).forEach((key) => keys.push(key));
return keys;
},
(error: HttpErrorPromise) => {
Expand Down
Loading

0 comments on commit c9d9f2e

Please sign in to comment.