mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
More optimizations and unit tests for panel repeats #1888
This commit is contained in:
parent
bcb80eb38f
commit
5768f10769
@ -64,30 +64,35 @@ function (angular, _) {
|
|||||||
return sourceRow;
|
return sourceRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
var i, panel, row;
|
var i, panel, row, copy;
|
||||||
var sourceRowId = _.indexOf(this.dashboard.rows, sourceRow) + 1;
|
var sourceRowId = _.indexOf(this.dashboard.rows, sourceRow) + 1;
|
||||||
|
|
||||||
// look for row to reuse
|
// look for row to reuse
|
||||||
for (i = 0; i < this.dashboard.rows.length; i++) {
|
for (i = 0; i < this.dashboard.rows.length; i++) {
|
||||||
row = this.dashboard.rows[i];
|
row = this.dashboard.rows[i];
|
||||||
if (row.repeatRowId === sourceRowId && row.repeatIteration !== this.iteration) {
|
if (row.repeatRowId === sourceRowId && row.repeatIteration !== this.iteration) {
|
||||||
row.repeatIteration = this.iteration;
|
copy = row;
|
||||||
return row;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var copy = angular.copy(sourceRow);
|
if (!copy) {
|
||||||
|
copy = angular.copy(sourceRow);
|
||||||
|
this.dashboard.rows.push(copy);
|
||||||
|
|
||||||
|
// set new panel ids
|
||||||
|
for (i = 0; i < copy.panels.length; i++) {
|
||||||
|
panel = copy.panels[i];
|
||||||
|
panel.id = this.dashboard.getNextPanelId();
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// update reused instance
|
||||||
|
}
|
||||||
|
|
||||||
copy.repeat = null;
|
copy.repeat = null;
|
||||||
copy.repeatRowId = sourceRowId;
|
copy.repeatRowId = sourceRowId;
|
||||||
copy.repeatIteration = this.iteration;
|
copy.repeatIteration = this.iteration;
|
||||||
this.dashboard.rows.push(copy);
|
|
||||||
|
|
||||||
// set new panel ids
|
|
||||||
for (i = 0; i < copy.panels.length; i++) {
|
|
||||||
panel = copy.panels[i];
|
|
||||||
panel.id = this.dashboard.getNextPanelId();
|
|
||||||
}
|
|
||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -122,16 +127,28 @@ function (angular, _) {
|
|||||||
return sourcePanel;
|
return sourcePanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var i, tmpId, panel, clone;
|
||||||
|
|
||||||
// first try finding an existing clone to use
|
// first try finding an existing clone to use
|
||||||
for (var i = 0; i < row.panels.length; i++) {
|
for (i = 0; i < row.panels.length; i++) {
|
||||||
var panel = row.panels[i];
|
panel = row.panels[i];
|
||||||
if (panel.repeatIteration !== this.iteration && panel.repeatPanelId === sourcePanel.id) {
|
if (panel.repeatIteration !== this.iteration && panel.repeatPanelId === sourcePanel.id) {
|
||||||
panel.repeatIteration = this.iteration;
|
clone = panel;
|
||||||
return panel;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var clone = this.dashboard.duplicatePanel(sourcePanel, row);
|
if (!clone) {
|
||||||
|
clone = { id: this.dashboard.getNextPanelId() };
|
||||||
|
row.panels.push(clone);
|
||||||
|
}
|
||||||
|
|
||||||
|
// save id
|
||||||
|
tmpId = clone.id;
|
||||||
|
// copy properties from source
|
||||||
|
angular.extend(clone, sourcePanel);
|
||||||
|
// restore id
|
||||||
|
clone.id = tmpId;
|
||||||
clone.repeatIteration = this.iteration;
|
clone.repeatIteration = this.iteration;
|
||||||
clone.repeatPanelId = sourcePanel.id;
|
clone.repeatPanelId = sourcePanel.id;
|
||||||
clone.repeat = null;
|
clone.repeat = null;
|
||||||
|
@ -70,6 +70,7 @@ define([
|
|||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
repeatedPanelAfterIteration1 = ctx.rows[0].panels[1];
|
repeatedPanelAfterIteration1 = ctx.rows[0].panels[1];
|
||||||
|
ctx.rows[0].panels[0].fill = 10;
|
||||||
ctx.dynamicDashboardSrv.update(ctx.dash);
|
ctx.dynamicDashboardSrv.update(ctx.dash);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -77,6 +78,10 @@ define([
|
|||||||
expect(ctx.rows[0].panels[1]).to.be(repeatedPanelAfterIteration1);
|
expect(ctx.rows[0].panels[1]).to.be(repeatedPanelAfterIteration1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('reused panel should copy properties from source', function() {
|
||||||
|
expect(ctx.rows[0].panels[1].fill).to.be(10);
|
||||||
|
});
|
||||||
|
|
||||||
it('should have same panel count', function() {
|
it('should have same panel count', function() {
|
||||||
expect(ctx.rows[0].panels.length).to.be(2);
|
expect(ctx.rows[0].panels.length).to.be(2);
|
||||||
});
|
});
|
||||||
@ -144,6 +149,7 @@ define([
|
|||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
repeatedRowAfterFirstIteration = ctx.rows[1];
|
repeatedRowAfterFirstIteration = ctx.rows[1];
|
||||||
|
ctx.rows[0].height = 500;
|
||||||
ctx.dynamicDashboardSrv.update(ctx.dash);
|
ctx.dynamicDashboardSrv.update(ctx.dash);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -151,6 +157,10 @@ define([
|
|||||||
expect(ctx.rows.length).to.be(2);
|
expect(ctx.rows.length).to.be(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.skip('should have updated props from source', function() {
|
||||||
|
expect(ctx.rows[1].height).to.be(500);
|
||||||
|
});
|
||||||
|
|
||||||
it('should reuse row instance', function() {
|
it('should reuse row instance', function() {
|
||||||
expect(ctx.rows[1]).to.be(repeatedRowAfterFirstIteration);
|
expect(ctx.rows[1]).to.be(repeatedRowAfterFirstIteration);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user