From eafe0d6bfad219d04a7346c2454edb650e6362dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 17 Nov 2016 11:28:33 +0100 Subject: [PATCH] fix(templating): fixed issue when adding template variable, fixes #6622 --- CHANGELOG.md | 1 + public/app/features/dashboard/model.ts | 8 ++++++-- public/app/features/templating/adhoc_variable.ts | 2 +- public/app/features/templating/constant_variable.ts | 2 +- public/app/features/templating/custom_variable.ts | 2 +- public/app/features/templating/datasource_variable.ts | 2 +- public/app/features/templating/interval_variable.ts | 2 +- public/app/features/templating/partials/editor.html | 2 +- public/app/features/templating/query_variable.ts | 2 +- .../features/templating/specs/query_variable_specs.ts | 2 +- public/app/features/templating/variable.ts | 2 +- public/app/features/templating/variable_srv.ts | 11 +---------- 12 files changed, 17 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73d7aad8fb9..9e3f3766162 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * **Graph Panel**: Bar width if bars was only used in series override, [#6528](https://github.com/grafana/grafana/issues/6528) * **UI/Browser**: Fixed issue with page/view header gradient border not showing in Safari, [#6530](https://github.com/grafana/grafana/issues/6530) * **UX**: Panel Drop zone visible after duplicating panel, and when entering fullscreen/edit view, [#6598](https://github.com/grafana/grafana/issues/6598) +* **Templating**: Newly added variable was not visible directly only after dashboard reload, [#6622](https://github.com/grafana/grafana/issues/6622) ### Enhancements * **Singlestat**: Support repeated template variables in prefix/postfix [#6595](https://github.com/grafana/grafana/issues/6595) diff --git a/public/app/features/dashboard/model.ts b/public/app/features/dashboard/model.ts index 999c0470fdd..6b32004cfd5 100644 --- a/public/app/features/dashboard/model.ts +++ b/public/app/features/dashboard/model.ts @@ -98,12 +98,14 @@ export class DashboardModel { var events = this.events; var meta = this.meta; var rows = this.rows; + var variables = this.templating.list; + delete this.events; delete this.meta; // prepare save model - this.rows = _.map(this.rows, row => row.getSaveModel()); - events.emit('prepare-save-model'); + this.rows = _.map(rows, row => row.getSaveModel()); + this.templating.list = _.map(variables, variable => variable.getSaveModel()); var copy = $.extend(true, {}, this); @@ -111,6 +113,8 @@ export class DashboardModel { this.events = events; this.meta = meta; this.rows = rows; + this.templating.list = variables; + return copy; } diff --git a/public/app/features/templating/adhoc_variable.ts b/public/app/features/templating/adhoc_variable.ts index 5ebffb0b0e6..b3c9980c7c7 100644 --- a/public/app/features/templating/adhoc_variable.ts +++ b/public/app/features/templating/adhoc_variable.ts @@ -26,7 +26,7 @@ export class AdhocVariable implements Variable { return Promise.resolve(); } - getModel() { + getSaveModel() { assignModelProperties(this.model, this, this.defaults); return this.model; } diff --git a/public/app/features/templating/constant_variable.ts b/public/app/features/templating/constant_variable.ts index 59659459f85..1dcc473740f 100644 --- a/public/app/features/templating/constant_variable.ts +++ b/public/app/features/templating/constant_variable.ts @@ -24,7 +24,7 @@ export class ConstantVariable implements Variable { assignModelProperties(this, model, this.defaults); } - getModel() { + getSaveModel() { assignModelProperties(this.model, this, this.defaults); return this.model; } diff --git a/public/app/features/templating/custom_variable.ts b/public/app/features/templating/custom_variable.ts index 90ce08cf9e4..4fadcd26742 100644 --- a/public/app/features/templating/custom_variable.ts +++ b/public/app/features/templating/custom_variable.ts @@ -34,7 +34,7 @@ export class CustomVariable implements Variable { return this.variableSrv.setOptionAsCurrent(this, option); } - getModel() { + getSaveModel() { assignModelProperties(this.model, this, this.defaults); return this.model; } diff --git a/public/app/features/templating/datasource_variable.ts b/public/app/features/templating/datasource_variable.ts index d43c0dd486d..234c8c13fd5 100644 --- a/public/app/features/templating/datasource_variable.ts +++ b/public/app/features/templating/datasource_variable.ts @@ -30,7 +30,7 @@ export class DatasourceVariable implements Variable { this.refresh = 1; } - getModel() { + getSaveModel() { assignModelProperties(this.model, this, this.defaults); return this.model; } diff --git a/public/app/features/templating/interval_variable.ts b/public/app/features/templating/interval_variable.ts index a1cfbf324c0..ab1b0e59442 100644 --- a/public/app/features/templating/interval_variable.ts +++ b/public/app/features/templating/interval_variable.ts @@ -34,7 +34,7 @@ export class IntervalVariable implements Variable { this.refresh = 2; } - getModel() { + getSaveModel() { assignModelProperties(this.model, this, this.defaults); return this.model; } diff --git a/public/app/features/templating/partials/editor.html b/public/app/features/templating/partials/editor.html index e485072eed0..8006e356d85 100644 --- a/public/app/features/templating/partials/editor.html +++ b/public/app/features/templating/partials/editor.html @@ -136,7 +136,7 @@
Custom Options
- Values separated by comma + Values separated by comma
diff --git a/public/app/features/templating/query_variable.ts b/public/app/features/templating/query_variable.ts index c67a4d09209..baabc554b23 100644 --- a/public/app/features/templating/query_variable.ts +++ b/public/app/features/templating/query_variable.ts @@ -47,7 +47,7 @@ export class QueryVariable implements Variable { assignModelProperties(this, model, this.defaults); } - getModel() { + getSaveModel() { // copy back model properties to model assignModelProperties(this.model, this, this.defaults); return this.model; diff --git a/public/app/features/templating/specs/query_variable_specs.ts b/public/app/features/templating/specs/query_variable_specs.ts index 8a2aef65be2..6ddaaf3630f 100644 --- a/public/app/features/templating/specs/query_variable_specs.ts +++ b/public/app/features/templating/specs/query_variable_specs.ts @@ -25,7 +25,7 @@ describe('QueryVariable', function() { variable.regex = 'asd'; variable.sort = 50; - var model = variable.getModel(); + var model = variable.getSaveModel(); expect(model.options.length).to.be(1); expect(model.options[0].text).to.be('test'); expect(model.datasource).to.be('google'); diff --git a/public/app/features/templating/variable.ts b/public/app/features/templating/variable.ts index 0cd0cb9f847..381f1ea7a3c 100644 --- a/public/app/features/templating/variable.ts +++ b/public/app/features/templating/variable.ts @@ -10,7 +10,7 @@ export interface Variable { dependsOn(variable); setValueFromUrl(urlValue); getValueForUrl(); - getModel(); + getSaveModel(); } export var variableTypes = {}; diff --git a/public/app/features/templating/variable_srv.ts b/public/app/features/templating/variable_srv.ts index bb6f4f7cde3..ac2948dbd4b 100644 --- a/public/app/features/templating/variable_srv.ts +++ b/public/app/features/templating/variable_srv.ts @@ -20,12 +20,9 @@ export class VariableSrv { this.dashboard = dashboard; // create working class models representing variables - this.variables = dashboard.templating.list.map(this.createVariableFromModel.bind(this)); + this.variables = dashboard.templating.list = dashboard.templating.list.map(this.createVariableFromModel.bind(this)); this.templateSrv.init(this.variables); - // register event to sync back to persisted model - this.dashboard.events.on('prepare-save-model', this.syncToDashboardModel.bind(this)); - // init variables for (let variable of this.variables) { variable.initLock = this.$q.defer(); @@ -99,12 +96,6 @@ export class VariableSrv { return variable; } - syncToDashboardModel() { - this.dashboard.templating.list = this.variables.map(variable => { - return variable.getModel(); - }); - } - updateOptions(variable) { return variable.updateOptions(); }