Просмотр исходного кода

Merge branch 'refresh_temp_value_by_time_range_changes' of https://github.com/mtanda/grafana into mtanda-refresh_temp_value_by_time_range_changes

bergquist 9 лет назад
Родитель
Сommit
7224728ab8

+ 9 - 1
public/app/features/dashboard/dashboardSrv.js

@@ -212,7 +212,7 @@ function (angular, $, _, moment) {
       var i, j, k;
       var oldVersion = this.schemaVersion;
       var panelUpgrades = [];
-      this.schemaVersion = 10;
+      this.schemaVersion = 11;
 
       if (oldVersion === this.schemaVersion) {
         return;
@@ -401,6 +401,14 @@ function (angular, $, _, moment) {
         });
       }
 
+      if (oldVersion < 11) {
+        // update template variables
+        _.each(this.templating.list, function(templateVariable) {
+          if (templateVariable.refresh) { templateVariable.refresh = 'On Dashboard Load'; }
+          if (!templateVariable.refresh) { templateVariable.refresh = 'Never'; }
+        });
+      }
+
       if (panelUpgrades.length === 0) {
         return;
       }

+ 1 - 1
public/app/features/templating/editorCtrl.js

@@ -12,7 +12,7 @@ function (angular, _) {
     var replacementDefaults = {
       type: 'query',
       datasource: null,
-      refresh: false,
+      refresh: 'Never',
       name: '',
       options: [],
       includeAll: false,

+ 3 - 3
public/app/features/templating/partials/editor.html

@@ -170,9 +170,9 @@
 					<input type="text" class="gf-form-input" ng-model='current.regex' placeholder="/.*-(.*)-.*/" ng-model-onblur ng-change="runQuery()"></input>
 				</div>
 				<div class="gf-form">
-					<span class="gf-form-label width-7">Update</span>
-					<editor-checkbox text="On Dashboard Load" model="current.refresh"></editor-checkbox>
-					<tip>Check if you want values to be updated on dashboard load, will slow down dashboard load time</tip>
+					<span class="gf-form-label width-7">Refresh</span>
+					<select class="input-large tight-form-input" ng-model="current.refresh" ng-options="f for f in ['Never', 'On Dashboard Load', 'On Time Change and Dashboard Load']"></select>
+					<tip>When to update the values of this template, will slow down dashboard load / time change</tip>
 				</div>
 			</div>
 

+ 12 - 1
public/app/features/templating/templateValuesSrv.js

@@ -20,6 +20,17 @@ function (angular, _, kbn) {
       }
     }, $rootScope);
 
+    $rootScope.onAppEvent('refresh', function() {
+      var promises = _.chain(self.variables)
+      .filter(function(variable) {
+        return variable.refresh === 'On Time Change and Dashboard Load';
+      })
+      .map(function(variable) {
+        return self.updateOptions(variable);
+      }).value();
+      return $q.all(promises);
+    }, $rootScope);
+
     this.init = function(dashboard) {
       this.variables = dashboard.templating.list;
       templateSrv.init(this.variables);
@@ -60,7 +71,7 @@ function (angular, _, kbn) {
         if (urlValue !== void 0) {
           return self.setVariableFromUrl(variable, urlValue).then(lock.resolve);
         }
-        else if (variable.refresh) {
+        else if (variable.refresh === 'On Dashboard Load' || variable.refresh === 'On Time Change and Dashboard Load') {
           return self.updateOptions(variable).then(function() {
             if (_.isEmpty(variable.current) && variable.options.length) {
               console.log("setting current for %s", variable.name);

+ 1 - 1
public/dashboards/template_vars.json

@@ -258,6 +258,6 @@
   "annotations": {
     "enable": false
   },
-  "refresh": false,
+  "refresh": "Never",
   "version": 6
 }

+ 1 - 1
public/test/specs/dashboardSrv-specs.js

@@ -194,7 +194,7 @@ define([
       });
 
       it('dashboard schema version should be set to latest', function() {
-        expect(model.schemaVersion).to.be(10);
+        expect(model.schemaVersion).to.be(11);
       });
 
     });