diff --git a/src/app/controllers/dashboardCtrl.js b/src/app/controllers/dashboardCtrl.js index 03cdddfbf7b..99b7a45a84f 100644 --- a/src/app/controllers/dashboardCtrl.js +++ b/src/app/controllers/dashboardCtrl.js @@ -15,7 +15,7 @@ function (angular, $, config, _) { $rootScope, dashboardKeybindings, timeSrv, - templateSrv, + templateValuesSrv, dashboardSrv, dashboardViewStateSrv, panelMoveSrv, @@ -51,7 +51,7 @@ function (angular, $, config, _) { $scope.grafana.style = $scope.dashboard.style; timeSrv.init($scope.dashboard); - templateSrv.init($scope.dashboard); + templateValuesSrv.init($scope.dashboard); $scope.submenuEnabled = $scope.dashboard.templating.enable || $scope.dashboard.annotations.enable; diff --git a/src/app/controllers/playlistCtrl.js b/src/app/controllers/playlistCtrl.js index ef605b48b7d..9e6a60013e2 100644 --- a/src/app/controllers/playlistCtrl.js +++ b/src/app/controllers/playlistCtrl.js @@ -13,7 +13,6 @@ function (angular, _, config) { $scope.init = function() { $scope.timespan = config.playlist_timespan; $scope.loadFavorites(); - $scope.$on('modal-opened', $scope.loadFavorites); }; $scope.loadFavorites = function() { diff --git a/src/app/controllers/templateEditorCtrl.js b/src/app/controllers/templateEditorCtrl.js index 85c7d81f669..ae5a85be687 100644 --- a/src/app/controllers/templateEditorCtrl.js +++ b/src/app/controllers/templateEditorCtrl.js @@ -7,7 +7,7 @@ function (angular, _) { var module = angular.module('grafana.controllers'); - module.controller('TemplateEditorCtrl', function($scope, datasourceSrv) { + module.controller('TemplateEditorCtrl', function($scope, datasourceSrv, templateSrv, templateValuesSrv) { var replacementDefaults = { type: 'query', @@ -21,7 +21,7 @@ function (angular, _) { $scope.editor = { index: 0 }; $scope.datasources = datasourceSrv.getMetricSources(); $scope.currentDatasource = _.findWhere($scope.datasources, { default: true }); - $scope.templateParameters = $scope.filter.templateParameters; + $scope.templateParameters = templateSrv.templateParameters; $scope.reset(); _.each($scope.templateParameters, function(param) { @@ -46,7 +46,7 @@ function (angular, _) { }; $scope.runQuery = function() { - $scope.filter.refreshTemplateParameter($scope.current); + templateValuesSrv.updateValuesFor($scope.current); }; $scope.edit = function(param) { @@ -71,6 +71,13 @@ function (angular, _) { $scope.current = angular.copy(replacementDefaults); }; + $scope.typeChanged = function () { + if ($scope.current.type === 'time period') { + $scope.current.options = ['auto', '1m', '10m', '30m', '1h', '6h', '12h', '1d', '7d', '14d', '30d']; + $scope.current.auto_count = 10; + } + }; + $scope.removeTemplateParam = function(templateParam) { var index = _.indexOf($scope.templateParameters, templateParam); $scope.templateParameters.splice(index, 1); diff --git a/src/app/dashboards/scripted_templated.js b/src/app/dashboards/scripted_templated.js new file mode 100644 index 00000000000..0ca4ea1fde8 --- /dev/null +++ b/src/app/dashboards/scripted_templated.js @@ -0,0 +1,96 @@ +/* global _ */ + +/* + * Complex scripted dashboard + * This script generates a dashboard object that Grafana can load. It also takes a number of user + * supplied URL parameters (int ARGS variable) + * + * Return a dashboard object, or a function + * + * For async scripts, return a function, this function must take a single callback function as argument, + * call this callback function with the dashboard object (look at scripted_async.js for an example) + */ + +'use strict'; + +// accessable variables in this scope +var window, document, ARGS, $, jQuery, moment, kbn; + +// Setup some variables +var dashboard, timspan; + +// All url parameters are available via the ARGS object +var ARGS; + +// Set a default timespan if one isn't specified +timspan = '1d'; + +// Intialize a skeleton with nothing but a rows array and service object +dashboard = { + rows : [], +}; + +// Set a title +dashboard.title = 'Scripted dash'; +dashboard.time = { + from: "now-" + (ARGS.from || timspan), + to: "now" +}; +dashboard.templating = { + enable: true, + list: [ + { + name: 'test', + query: 'apps.backend.*', + refresh: true, + options: [], + current: null, + }, + { + name: 'test2', + query: '*', + refresh: true, + options: [], + current: null, + } + ] +}; + +var rows = 1; +var seriesName = 'argName'; + +if(!_.isUndefined(ARGS.rows)) { + rows = parseInt(ARGS.rows, 10); +} + +if(!_.isUndefined(ARGS.name)) { + seriesName = ARGS.name; +} + +for (var i = 0; i < rows; i++) { + + dashboard.rows.push({ + title: 'Chart', + height: '300px', + panels: [ + { + title: 'Events', + type: 'graph', + span: 12, + fill: 1, + linewidth: 2, + targets: [ + { + 'target': "randomWalk('" + seriesName + "')" + }, + { + 'target': "randomWalk('[[test2]]')" + } + ], + } + ] + }); +} + + +return dashboard; diff --git a/src/app/partials/templating_editor.html b/src/app/partials/templating_editor.html index 57a1f6ad7a5..0b8a229f122 100644 --- a/src/app/partials/templating_editor.html +++ b/src/app/partials/templating_editor.html @@ -54,38 +54,61 @@
+
+
+ This special type of template replacement is useful as the auto word will be calculated depending on the time range divided by
+ the number of periods you wish.
+