Skip to content

Commit

Permalink
support key=>value template variables
Browse files Browse the repository at this point in the history
  • Loading branch information
r.khavronenko committed Dec 5, 2017
1 parent 3f4b28e commit c99570f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 52 deletions.
2 changes: 1 addition & 1 deletion dist/response_parser.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="../node_modules/grafana-sdk-mocks/app/headers/common.d.ts" />
export default class ResponseParser {
parse(query: any, results: any): any;
parse(query: any, results: any): any[];
}
29 changes: 13 additions & 16 deletions dist/response_parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/response_parser.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 13 additions & 17 deletions dist/response_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,24 @@
import _ from 'lodash';

export default class ResponseParser {

parse(query, results) {
if (!results || results.data.length === 0) { return []; }

var sqlResults = results.data;
var res = [], v;
_.each(sqlResults, row => {
_.each(row, value => {
if (_.isArray(value) || _.isObject(value)) {
v = value[0];
} else {
v = value;
}

if ( res.indexOf( v ) === -1 ) {
res.push(v);
}
});
var res = [];
_.each(sqlResults, r => {
if (r && r.text && r.value) {
res.push({ text: r.text, value: r.value });
return
}
if (_.isObject(r)) {
var key = Object.keys(r)[0];
res.push({ text: r[key]});
return
}
res.push({ text: r });
});

return _.map(res, value => {
return { text: value};
});
return res
}
}
30 changes: 13 additions & 17 deletions src/response_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,24 @@
import _ from 'lodash';

export default class ResponseParser {

parse(query, results) {
if (!results || results.data.length === 0) { return []; }

var sqlResults = results.data;
var res = [], v;
_.each(sqlResults, row => {
_.each(row, value => {
if (_.isArray(value) || _.isObject(value)) {
v = value[0];
} else {
v = value;
}

if ( res.indexOf( v ) === -1 ) {
res.push(v);
}
});
var res = [];
_.each(sqlResults, r => {
if (r && r.text && r.value) {
res.push({ text: r.text, value: r.value });
return
}
if (_.isObject(r)) {
var key = Object.keys(r)[0];
res.push({ text: r[key]});
return
}
res.push({ text: r });
});

return _.map(res, value => {
return { text: value};
});
return res
}
}

0 comments on commit c99570f

Please sign in to comment.