Skip to content

Instantly share code, notes, and snippets.

@spbnick
Created August 28, 2020 08:06
Show Gist options
  • Save spbnick/3cfee0eec89aca0b8d921ef6d73507ee to your computer and use it in GitHub Desktop.
Save spbnick/3cfee0eec89aca0b8d921ef6d73507ee to your computer and use it in GitHub Desktop.
diff --git a/plugin.json b/plugin.json
index 6fa6cba..5c8dd80 100644
--- a/plugin.json
+++ b/plugin.json
@@ -10,7 +10,7 @@
"url": "https://redhat.com"
},
"keywords": ["singlestat", "link", "panel"],
- "version": "1.0.0",
+ "version": "2.0.0",
"updated": "2020-03-05"
},
diff --git a/src/singlevalue_ctrl.js b/src/singlevalue_ctrl.js
index 05e96fb..a02b30a 100644
--- a/src/singlevalue_ctrl.js
+++ b/src/singlevalue_ctrl.js
@@ -2,7 +2,7 @@ import { MetricsPanelCtrl } from 'app/plugins/sdk';
import { PanelEvents } from '@grafana/data';
class SingleValueCtrl extends MetricsPanelCtrl {
- constructor($scope, $injector) {
+ constructor($scope, $injector, templateSrv) {
super($scope, $injector);
const panelDefaults = {
@@ -17,6 +17,7 @@ class SingleValueCtrl extends MetricsPanelCtrl {
}
}
+ this.templateSrv = templateSrv
this.events.on(PanelEvents.panelInitialized, this.adjustFontSize.bind(this));
this.events.on(PanelEvents.editModeInitialized, this.onInitEditMode.bind(this));
this.events.on(PanelEvents.dataReceived, this.onDataReceived.bind(this));
@@ -34,7 +35,7 @@ class SingleValueCtrl extends MetricsPanelCtrl {
const results = dataList[0];
const data = results && results.rows && results.rows[0];
- if (!data) {
+ if (!results) {
this.text = "No result rows. Make sure you are using 'Table' format and not 'Time series' format.";
this.url = null;
return;
@@ -47,7 +48,8 @@ class SingleValueCtrl extends MetricsPanelCtrl {
data[cellNumber]
)
);
- this.url = this.panel.urlTemplate.replace(
+ this.url = this.templateSrv.replace(this.panel.urlTemplate)
+ this.url = this.url.replace(
/\${__cell_(\d+)}/g,
(match, cellNumber) => (
data[cellNumber]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment