Browse Source

fix(): fix for cleaning up repeat panel scope for orphaned panels or duplicated panels

Torkel Ödegaard 10 years ago
parent
commit
775a805959

+ 5 - 0
public/app/features/dashboard/dashboardSrv.js

@@ -174,6 +174,11 @@ function (angular, $, kbn, _, moment) {
       var newPanel = angular.copy(panel);
       newPanel.id = this.getNextPanelId();
 
+      delete newPanel.repeat;
+      delete newPanel.repeatIteration;
+      delete newPanel.repeatPanelId;
+      delete newPanel.scopedVars;
+
       var currentRow = this.rows[rowIndex];
       currentRow.panels.push(newPanel);
       return newPanel;

+ 5 - 0
public/app/features/dashboard/dynamicDashboardSrv.js

@@ -53,6 +53,10 @@ function (angular, _) {
             row.panels = _.without(row.panels, panel);
             j = j - 1;
           }
+          // clean up left over scoped vars
+          else if (panel.scopedVars && panel.repeatIteration !== this.iteration) {
+            delete panel.scopedVars;
+          }
         }
       }
     };
@@ -116,6 +120,7 @@ function (angular, _) {
           panel = copy.panels[i];
           panel.scopedVars = {};
           panel.scopedVars[variable.name] = option;
+          panel.repeatIteration = self.iteration;
         }
       });
     };

+ 1 - 1
public/app/plugins/datasource/influxdb/queryCtrl.js

@@ -136,7 +136,7 @@ function (angular, _, InfluxQueryBuilder) {
 
     $scope.addTemplateVariableSegments = function(segments) {
       _.each(templateSrv.variables, function(variable) {
-        segments.unshift(new MetricSegment({ type: 'template', value: '$' + variable.name, expandable: true }));
+        segments.unshift(new MetricSegment({ type: 'template', value: '/$' + variable.name + '/', expandable: true }));
       });
       return segments;
     };

+ 9 - 0
public/test/specs/dashboardSrv-specs.js

@@ -81,6 +81,15 @@ define([
         expect(dashboard.rows[0].panels[1].id).to.be(11);
       });
 
+      it('duplicate panel should remove repeat data', function() {
+        var panel = { span: 4, attr: '123', id: 10, repeat: 'asd', scopedVars: { test: 'asd' }};
+        dashboard.rows = [{ panels: [panel] }];
+        dashboard.duplicatePanel(panel, dashboard.rows[0]);
+
+        expect(dashboard.rows[0].panels[1].repeat).to.be(null);
+        expect(dashboard.rows[0].panels[1].scopedVars.test).to.be(undefined);
+      });
+
     });
 
     describe('when creating dashboard with editable false', function() {