Dashboard: fix for dashboard schema upgrade during load, ensure that annotation and templating object as a list array, Closes #890

This commit is contained in:
Torkel Ödegaard 2014-10-02 12:13:18 +02:00
parent 05cb97819c
commit bc8fd62cff
2 changed files with 32 additions and 4 deletions

View File

@ -30,8 +30,8 @@ function (angular, $, kbn, _, moment) {
this.rows = data.rows || [];
this.nav = data.nav || [];
this.time = data.time || { from: 'now-6h', to: 'now' };
this.templating = data.templating || { list: [], enable: false };
this.annotations = data.annotations || { list: [], enable: false};
this.templating = this._ensureListExist(data.templating);
this.annotations = this._ensureListExist(data.annotations);
this.refresh = data.refresh;
this.version = data.version || 0;
@ -39,11 +39,17 @@ function (angular, $, kbn, _, moment) {
this.nav.push({ type: 'timepicker' });
}
this.updateSchema(data);
this._updateSchema(data);
}
var p = DashboardModel.prototype;
p._ensureListExist = function (data) {
if (!data) { data = {}; }
if (!data.list) { data.list = []; }
return data;
};
p.getNextPanelId = function() {
var i, j, row, panel, max = 0;
for (i = 0; i < this.rows.length; i++) {
@ -115,7 +121,7 @@ function (angular, $, kbn, _, moment) {
$rootScope.$broadcast('refresh');
};
p.updateSchema = function(old) {
p._updateSchema = function(old) {
var i, j, k;
var oldVersion = this.version;
var panelUpgrades = [];

View File

@ -178,4 +178,26 @@ define([
});
describe('when creating dashboard model with missing list for annoations or templating', function() {
var model;
beforeEach(module('grafana.services'));
beforeEach(inject(function(dashboardSrv) {
model = dashboardSrv.create({
annotations: {
enable: true,
},
templating: {
enable: true
}
});
}));
it('should add empty list', function() {
expect(model.annotations.list.length).to.be(0);
expect(model.templating.list.length).to.be(1);
});
});
});