فهرست منبع

feat(templating): refactoring template variable handling for variables that change on time refresh, closes #5021

Torkel Ödegaard 9 سال پیش
والد
کامیت
7c7e26bc18

+ 1 - 0
CHANGELOG.md

@@ -4,6 +4,7 @@
 * **Login**: Adds option to disable username/password logins, closes [#4674](https://github.com/grafana/grafana/issues/4674)
 * **Login**: Adds option to disable username/password logins, closes [#4674](https://github.com/grafana/grafana/issues/4674)
 * **SingleStat**: Add seriename as option in singlestat panel, closes [#4740](https://github.com/grafana/grafana/issues/4740)
 * **SingleStat**: Add seriename as option in singlestat panel, closes [#4740](https://github.com/grafana/grafana/issues/4740)
 * **Localization**: Week start day now dependant on browser locale setting, closes [#3003](https://github.com/grafana/grafana/issues/3003)
 * **Localization**: Week start day now dependant on browser locale setting, closes [#3003](https://github.com/grafana/grafana/issues/3003)
+* **Templating**: Update panel repeats for variables that change on time refresh, closes [#5021](https://github.com/grafana/grafana/issues/5021)
 
 
 # 3.1.0 stable (unreleased)
 # 3.1.0 stable (unreleased)
 
 

+ 1 - 0
public/app/features/dashboard/dashboard_ctrl.ts

@@ -87,6 +87,7 @@ export class DashboardCtrl {
       };
       };
 
 
       $scope.templateVariableUpdated = function() {
       $scope.templateVariableUpdated = function() {
+        console.log('dynamic update');
         dynamicDashboardSrv.update($scope.dashboard);
         dynamicDashboardSrv.update($scope.dashboard);
       };
       };
 
 

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

@@ -20,7 +20,7 @@
 			</li>
 			</li>
 		</ul>
 		</ul>
 
 
-		<button class="tabbed-view-close-btn" ng-click="dismiss();dashboard.refresh();">
+		<button class="tabbed-view-close-btn" ng-click="dismiss();">
 			<i class="fa fa-remove"></i>
 			<i class="fa fa-remove"></i>
 		</button>
 		</button>
 	</div>
 	</div>

+ 8 - 8
public/app/features/templating/templateValuesSrv.js

@@ -1,14 +1,15 @@
 define([
 define([
   'angular',
   'angular',
   'lodash',
   'lodash',
+  'jquery',
   'app/core/utils/kbn',
   'app/core/utils/kbn',
 ],
 ],
-function (angular, _, kbn) {
+function (angular, _, $, kbn) {
   'use strict';
   'use strict';
 
 
   var module = angular.module('grafana.services');
   var module = angular.module('grafana.services');
 
 
-  module.service('templateValuesSrv', function($q, $rootScope, datasourceSrv, $location, templateSrv, timeSrv, dynamicDashboardSrv) {
+  module.service('templateValuesSrv', function($q, $rootScope, datasourceSrv, $location, templateSrv, timeSrv) {
     var self = this;
     var self = this;
 
 
     function getNoneOption() { return { text: 'None', value: '', isNone: true }; }
     function getNoneOption() { return { text: 'None', value: '', isNone: true }; }
@@ -27,14 +28,13 @@ function (angular, _, kbn) {
         .filter(function(variable) {
         .filter(function(variable) {
           return variable.refresh === 2;
           return variable.refresh === 2;
         }).map(function(variable) {
         }).map(function(variable) {
-          var previousVariable = angular.copy(variable);
+          var previousOptions = variable.options.slice();
+
           return self.updateOptions(variable).then(function () {
           return self.updateOptions(variable).then(function () {
             return self.variableUpdated(variable).then(function () {
             return self.variableUpdated(variable).then(function () {
-              var updatedVariable = angular.copy(variable);
-              delete(updatedVariable.$$hashKey);
-              if (JSON.stringify(previousVariable) !== JSON.stringify(updatedVariable)) {
-                dynamicDashboardSrv.update(self.dashboard);
-                $rootScope.$emit('template-variable-value-updated');
+              // check if current options changed due to refresh
+              if (angular.toJson(previousOptions) !== angular.toJson(variable.options)) {
+                $rootScope.appEvent('template-variable-value-updated');
               }
               }
             });
             });
           });
           });