From 45e6187c1aaf202062fb6e6da87e4c616fd45aaf Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Fri, 26 Feb 2016 00:43:48 +0900 Subject: [PATCH 1/9] add hide template variable option --- public/app/features/dashboard/submenu/submenu.html | 2 +- public/app/features/templating/partials/editor.html | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/public/app/features/dashboard/submenu/submenu.html b/public/app/features/dashboard/submenu/submenu.html index eb8de17676c..21a9744b359 100644 --- a/public/app/features/dashboard/submenu/submenu.html +++ b/public/app/features/dashboard/submenu/submenu.html @@ -1,6 +1,6 @@ From 09dfaf98755bbb30aed53074537aba1393d08a95 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Mon, 29 Feb 2016 17:42:38 +0900 Subject: [PATCH 2/9] timeFrom and timeShift templating --- public/app/core/directives/ng_model_on_blur.js | 3 +++ public/app/features/panel/metrics_panel_ctrl.ts | 10 +++++++--- public/app/plugins/panel/singlestat/module.ts | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/public/app/core/directives/ng_model_on_blur.js b/public/app/core/directives/ng_model_on_blur.js index 1e3ebc38a25..6f4a55b53f0 100644 --- a/public/app/core/directives/ng_model_on_blur.js +++ b/public/app/core/directives/ng_model_on_blur.js @@ -47,6 +47,9 @@ function (coreModule, kbn, rangeUtil) { if (ctrl.$isEmpty(modelValue)) { return true; } + if (viewValue.indexOf('$') === 0) { + return true; // allow template variable + } var info = rangeUtil.describeTextRange(viewValue); return info.invalid !== true; }; diff --git a/public/app/features/panel/metrics_panel_ctrl.ts b/public/app/features/panel/metrics_panel_ctrl.ts index 537bdbbcbdb..e1ad782fa74 100644 --- a/public/app/features/panel/metrics_panel_ctrl.ts +++ b/public/app/features/panel/metrics_panel_ctrl.ts @@ -17,6 +17,7 @@ class MetricsPanelCtrl extends PanelCtrl { $timeout: any; datasourceSrv: any; timeSrv: any; + templateSrv: any; timing: any; range: any; rangeRaw: any; @@ -34,6 +35,7 @@ class MetricsPanelCtrl extends PanelCtrl { this.$q = $injector.get('$q'); this.datasourceSrv = $injector.get('datasourceSrv'); this.timeSrv = $injector.get('timeSrv'); + this.templateSrv = $injector.get('templateSrv'); if (!this.panel.targets) { this.panel.targets = [{}]; @@ -119,7 +121,8 @@ class MetricsPanelCtrl extends PanelCtrl { // check panel time overrrides if (this.panel.timeFrom) { - var timeFromInfo = rangeUtil.describeTextRange(this.panel.timeFrom); + var timeFromInterpolated = this.templateSrv.replace(this.panel.timeFrom, this.panel.scopedVars); + var timeFromInfo = rangeUtil.describeTextRange(timeFromInterpolated); if (timeFromInfo.invalid) { this.timeInfo = 'invalid time override'; return; @@ -136,13 +139,14 @@ class MetricsPanelCtrl extends PanelCtrl { } if (this.panel.timeShift) { - var timeShiftInfo = rangeUtil.describeTextRange(this.panel.timeShift); + var timeShiftInterpolated = this.templateSrv.replace(this.panel.timeShift, this.panel.scopedVars); + var timeShiftInfo = rangeUtil.describeTextRange(timeShiftInterpolated); if (timeShiftInfo.invalid) { this.timeInfo = 'invalid timeshift'; return; } - var timeShift = '-' + this.panel.timeShift; + var timeShift = '-' + timeShiftInterpolated; this.timeInfo += ' timeshift ' + timeShift; this.range.from = dateMath.parseDateMath(timeShift, this.range.from, false); this.range.to = dateMath.parseDateMath(timeShift, this.range.to, true); diff --git a/public/app/plugins/panel/singlestat/module.ts b/public/app/plugins/panel/singlestat/module.ts index 7f576cc3f2d..6f692c700de 100644 --- a/public/app/plugins/panel/singlestat/module.ts +++ b/public/app/plugins/panel/singlestat/module.ts @@ -50,7 +50,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { unitFormats: any[]; /** @ngInject */ - constructor($scope, $injector, private $location, private linkSrv, private templateSrv) { + constructor($scope, $injector, private $location, private linkSrv) { super($scope, $injector); _.defaults(this.panel, panelDefaults); } From c30c12d36950fc9a21b0f5a8b5423454bab33721 Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 29 Feb 2016 10:05:00 +0100 Subject: [PATCH 3/9] fix(single_stat): rounding bug in value => text --- public/app/plugins/panel/singlestat/editor.html | 4 ++-- public/app/plugins/panel/singlestat/module.ts | 2 +- .../panel/singlestat/specs/singlestat-specs.ts | 14 ++++++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/public/app/plugins/panel/singlestat/editor.html b/public/app/plugins/panel/singlestat/editor.html index bf3227f7582..6b0806133b8 100644 --- a/public/app/plugins/panel/singlestat/editor.html +++ b/public/app/plugins/panel/singlestat/editor.html @@ -167,13 +167,13 @@
  • - +
  • - +
  • diff --git a/public/app/plugins/panel/singlestat/module.ts b/public/app/plugins/panel/singlestat/module.ts index 7f576cc3f2d..88e09937186 100644 --- a/public/app/plugins/panel/singlestat/module.ts +++ b/public/app/plugins/panel/singlestat/module.ts @@ -213,7 +213,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { // value/number to text mapping var value = parseFloat(map.value); - if (value === data.value) { + if (value === data.valueRounded) { data.valueFormated = map.text; return; } diff --git a/public/app/plugins/panel/singlestat/specs/singlestat-specs.ts b/public/app/plugins/panel/singlestat/specs/singlestat-specs.ts index 283389ee400..90bd5339737 100644 --- a/public/app/plugins/panel/singlestat/specs/singlestat-specs.ts +++ b/public/app/plugins/panel/singlestat/specs/singlestat-specs.ts @@ -69,14 +69,20 @@ describe('SingleStatCtrl', function() { singleStatScenario('When value to text mapping is specified', function(ctx) { ctx.setup(function() { - ctx.datapoints = [[10,1]]; + ctx.datapoints = [[9.9,1]]; ctx.ctrl.panel.valueMaps = [{value: '10', text: 'OK'}]; }); - it('Should replace value with text', function() { - expect(ctx.data.value).to.be(10); - expect(ctx.data.valueFormated).to.be('OK'); + it('value should remain', function() { + expect(ctx.data.value).to.be(9.9); }); + it('round should be rounded up', function() { + expect(ctx.data.valueRounded).to.be(10); + }); + + it('Should replace value with text', function() { + expect(ctx.data.valueFormated).to.be('OK'); + }); }); }); From 05ba32b55292d8643659cd6e300e7fb91b48971f Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 29 Feb 2016 10:18:50 +0100 Subject: [PATCH 4/9] feat(datasource): add type to datasource list closes #4183 --- public/app/features/datasources/partials/list.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/public/app/features/datasources/partials/list.html b/public/app/features/datasources/partials/list.html index 6ad9c18bc53..940927df688 100644 --- a/public/app/features/datasources/partials/list.html +++ b/public/app/features/datasources/partials/list.html @@ -23,6 +23,7 @@ name + type url @@ -37,7 +38,10 @@ - {{ds.url}} + {{ds.type}} + + + {{ds.url}} From 86b1906798f61c97abde151779a4e412fc117ba1 Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 29 Feb 2016 10:29:40 +0100 Subject: [PATCH 5/9] fix(templating): make checkboxes a new row --- .../app/features/templating/partials/editor.html | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/public/app/features/templating/partials/editor.html b/public/app/features/templating/partials/editor.html index 1ea99617f1d..aab5f048465 100644 --- a/public/app/features/templating/partials/editor.html +++ b/public/app/features/templating/partials/editor.html @@ -91,12 +91,17 @@ -
    - Label - - - +
    +
    + Label + +
    +
    + + +
    +
    Value Options
    From 4299feee3799402119972083696194f7ab6984cc Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 29 Feb 2016 10:49:11 +0100 Subject: [PATCH 6/9] feat(templates): collapse submenu if none visable templates --- public/app/features/dashboard/dashboardSrv.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/public/app/features/dashboard/dashboardSrv.js b/public/app/features/dashboard/dashboardSrv.js index be404dd1ce1..01c5787481b 100644 --- a/public/app/features/dashboard/dashboardSrv.js +++ b/public/app/features/dashboard/dashboardSrv.js @@ -140,7 +140,11 @@ function (angular, $, _, moment) { }; p.isSubmenuFeaturesEnabled = function() { - return this.templating.list.length > 0 || this.annotations.list.length > 0 || this.links.length > 0; + var visableTemplates = _.filter(this.templating.list, function(template) { + return template.hideVariable === undefined || template.hideVariable === false; + }); + + return visableTemplates.length > 0 || this.annotations.list.length > 0 || this.links.length > 0; }; p.getPanelInfoById = function(panelId) { From fb33cf4576a329c6f6a3f7aab1c7ba0b6e20fde3 Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 29 Feb 2016 11:14:24 +0100 Subject: [PATCH 7/9] docs(changelog): add info about templated timeshift --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8f4fbef587..dcdc838115c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ * **Admin**: Admin can now have global overview of Grafana setup, closes [#3812](https://github.com/grafana/grafana/issues/3812) * **graph**: Right side legend height is now fixed at row height, closes [#1277](https://github.com/grafana/grafana/issues/1277) * **Table**: All content in table panel is now html escaped, closes [#3673](https://github.com/grafana/grafana/issues/3673) +* **graph**: Template variables can now be used in TimeShift and TimeFrom, closes[#1960](https://github.com/grafana/grafana/issues/1960) ### Bug fixes * **Playlist**: Fix for memory leak when running a playlist, closes [#3794](https://github.com/grafana/grafana/pull/3794) From 4741152f0526b1998e786558798cb0b67b14ba3d Mon Sep 17 00:00:00 2001 From: Anthony Woods Date: Mon, 29 Feb 2016 19:37:35 +0800 Subject: [PATCH 8/9] correct path for app page links. --- pkg/api/index.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/api/index.go b/pkg/api/index.go index df752109530..a5199fa79ae 100644 --- a/pkg/api/index.go +++ b/pkg/api/index.go @@ -85,13 +85,13 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) { if plugin.Pinned { pageLink := &dtos.NavLink{ Text: plugin.Name, - Url: setting.AppSubUrl + "/apps/" + plugin.Id + "/edit", + Url: setting.AppSubUrl + "/plugins/" + plugin.Id + "/edit", Img: plugin.Info.Logos.Small, } for _, page := range plugin.Pages { pageLink.Children = append(pageLink.Children, &dtos.NavLink{ - Url: setting.AppSubUrl + "/apps/" + plugin.Id + "/page/" + page.Slug, + Url: setting.AppSubUrl + "/plugins/" + plugin.Id + "/page/" + page.Slug, Text: page.Name, }) } From 35f7a71f9a2a70f873db475044330b0e75af0376 Mon Sep 17 00:00:00 2001 From: Anthony Woods Date: Mon, 29 Feb 2016 19:54:36 +0800 Subject: [PATCH 9/9] fix app->plugin renamin in more places --- pkg/api/api.go | 5 +++-- public/app/features/plugins/partials/page.html | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/api/api.go b/pkg/api/api.go index 90d613e46e0..ed029a5171a 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -43,8 +43,9 @@ func Register(r *macaron.Macaron) { r.Get("/admin/orgs/edit/:id", reqGrafanaAdmin, Index) r.Get("/admin/stats", reqGrafanaAdmin, Index) - r.Get("/apps", reqSignedIn, Index) - r.Get("/apps/edit/*", reqSignedIn, Index) + r.Get("/plugins", reqSignedIn, Index) + r.Get("/plugins/:id/edit", reqSignedIn, Index) + r.Get("/plugins/:id/page/:page", reqSignedIn, Index) r.Get("/dashboard/*", reqSignedIn, Index) r.Get("/dashboard-solo/*", reqSignedIn, Index) diff --git a/public/app/features/plugins/partials/page.html b/public/app/features/plugins/partials/page.html index db6d64457bf..949175419ac 100644 --- a/public/app/features/plugins/partials/page.html +++ b/public/app/features/plugins/partials/page.html @@ -1,4 +1,4 @@ - +