diff --git a/public/app/features/dashboard/export/exporter.ts b/public/app/features/dashboard/export/exporter.ts index 7c076128ea8..958715b5cbb 100644 --- a/public/app/features/dashboard/export/exporter.ts +++ b/public/app/features/dashboard/export/exporter.ts @@ -91,6 +91,26 @@ export class DashboardExporter { inputs.push(value); }); + // templatize constants + for (let variable of dash.templating.list) { + if (variable.type === 'constant') { + var refName = 'VAR_' + variable.name.replace(' ', '_').toUpperCase(); + inputs.push({ + name: refName, + type: 'constant', + label: variable.label || variable.name, + value: variable.current.value, + description: '', + }); + // update current and option + variable.query = '${' + refName + '}'; + variable.options[0] = variable.current = { + value: variable.query, + text: variable.query, + }; + } + } + requires = _.map(requires, req => { return req; }); diff --git a/public/app/features/dashboard/import/dash_import.html b/public/app/features/dashboard/import/dash_import.html index 8343f262f88..64a4a91a3c8 100644 --- a/public/app/features/dashboard/import/dash_import.html +++ b/public/app/features/dashboard/import/dash_import.html @@ -49,12 +49,13 @@ -
-

- Importing Dashboard from - Grafana.net -

-
+
+
+

+ Importing Dashboard from + Grafana.net +

+
@@ -65,62 +66,65 @@
-

- Options -

+

+ Options +

-
-
-
- - - -
-
+
+
+
+ + + +
+
-
-
- -
-
+
+
+ +
+
-
-
-
+
+ + + +
+
+
-
- +
+ - Cancel - Back -
+ Overwrite & Open + + Cancel + Back +
-
-
+ + diff --git a/public/app/features/dashboard/import/dash_import.ts b/public/app/features/dashboard/import/dash_import.ts index be4ae744eca..264df3cd5a9 100644 --- a/public/app/features/dashboard/import/dash_import.ts +++ b/public/app/features/dashboard/import/dash_import.ts @@ -41,7 +41,8 @@ export class DashImportCtrl { var inputModel = { name: input.name, label: input.label, - description: input.description, + info: input.description, + value: input.value, type: input.type, pluginId: input.pluginId, options: [] @@ -49,6 +50,8 @@ export class DashImportCtrl { if (input.type === 'datasource') { this.setDatasourceOptions(input, inputModel); + } else if (!inputModel.info) { + inputModel.info = 'Specify a string constant'; } this.inputs.push(inputModel); @@ -65,7 +68,7 @@ export class DashImportCtrl { }); if (sources.length === 0) { - inputModel.error = "No data sources of type " + input.pluginName + " found"; + inputModel.info = "No data sources of type " + input.pluginName + " found"; } else if (inputModel.description) { inputModel.info = inputModel.description; } else { diff --git a/public/app/features/dashboard/specs/exporter_specs.ts b/public/app/features/dashboard/specs/exporter_specs.ts index da2faec962c..470fab57447 100644 --- a/public/app/features/dashboard/specs/exporter_specs.ts +++ b/public/app/features/dashboard/specs/exporter_specs.ts @@ -26,6 +26,13 @@ describe('given dashboard with repeated panels', function() { options: [{value: 'Asd', text: 'Asd'}] }); + dash.templating.list.push({ + name: 'prefix', + type: 'constant', + current: {value: 'collectd', text: 'collectd'}, + options: [] + }); + dash.annotations.list.push({ name: 'logs', datasource: 'gfdb', @@ -115,5 +122,21 @@ describe('given dashboard with repeated panels', function() { expect(require.version).to.be("3.0.2"); }); + it('should add constant template variables as inputs', function() { + var input = _.findWhere(exported.__inputs, {name: 'VAR_PREFIX'}); + expect(input.type).to.be("constant"); + expect(input.label).to.be("prefix"); + expect(input.value).to.be("collectd"); + }); + + it('should templatize constant variables', function() { + var variable = _.findWhere(exported.templating.list, {name: 'prefix'}); + expect(variable.query).to.be("${VAR_PREFIX}"); + expect(variable.current.text).to.be("${VAR_PREFIX}"); + expect(variable.current.value).to.be("${VAR_PREFIX}"); + expect(variable.options[0].text).to.be("${VAR_PREFIX}"); + expect(variable.options[0].value).to.be("${VAR_PREFIX}"); + }); + });