Commit 83e49660 by Torkel Ödegaard

fixed dashboard sorting

parent 770a21b3
...@@ -40,6 +40,13 @@ export class DashboardModel { ...@@ -40,6 +40,13 @@ export class DashboardModel {
folderId: number; folderId: number;
panels: PanelModel[]; panels: PanelModel[];
static nonPersistedProperties: {[str: string]: boolean} = {
"events": true,
"meta": true,
"panels": true, // needs special handling
"templating": true, // needs special handling
};
constructor(data, meta?) { constructor(data, meta?) {
if (!data) { if (!data) {
data = {}; data = {};
...@@ -118,30 +125,26 @@ export class DashboardModel { ...@@ -118,30 +125,26 @@ export class DashboardModel {
// cleans meta data and other non peristent state // cleans meta data and other non peristent state
getSaveModelClone() { getSaveModelClone() {
// temp remove stuff // make clone
var events = this.events; var copy: any = {};
var meta = this.meta; for (var property in this) {
var variables = this.templating.list; if (DashboardModel.nonPersistedProperties[property] || !this.hasOwnProperty(property)) {
var panels = this.panels; continue;
}
delete this.events; copy[property] = _.cloneDeep(this[property]);
delete this.meta; }
delete this.panels;
// prepare save model // get variable save models
this.templating.list = _.map(variables, variable => variable.getSaveModel ? variable.getSaveModel() : variable); copy.templating = {
this.panels = _.map(panels, panel => panel.getSaveModel()); list: _.map(this.templating.list, variable => variable.getSaveModel ? variable.getSaveModel() : variable),
};
// make clone // get panel save models
var copy = _.cloneDeep(this); copy.panels = _.map(this.panels, panel => panel.getSaveModel());
// sort clone
copy = sortByKeys(copy);
// restore properties // sort by keys
this.events = events; copy = sortByKeys(copy);
this.meta = meta;
this.templating.list = variables;
this.panels = panels;
return copy; return copy;
} }
...@@ -188,7 +191,7 @@ export class DashboardModel { ...@@ -188,7 +191,7 @@ export class DashboardModel {
addPanel(panel) { addPanel(panel) {
panel.id = this.getNextPanelId(); panel.id = this.getNextPanelId();
this.panels.push(new PanelModel(panel)); this.panels.unshift(new PanelModel(panel));
// make sure it's sorted by pos // make sure it's sorted by pos
this.panels.sort(function(panelA, panelB) { this.panels.sort(function(panelA, panelB) {
......
...@@ -47,8 +47,8 @@ describe('DashboardModel', function() { ...@@ -47,8 +47,8 @@ describe('DashboardModel', function() {
var saveModel = model.getSaveModelClone(); var saveModel = model.getSaveModelClone();
var keys = _.keys(saveModel); var keys = _.keys(saveModel);
expect(keys[0]).to.be('autoUpdate'); expect(keys[0]).to.be('annotations');
expect(keys[1]).to.be('revision'); expect(keys[1]).to.be('autoUpdate');
}); });
}); });
......
...@@ -103,6 +103,7 @@ describe('given dashboard with repeated panels', function() { ...@@ -103,6 +103,7 @@ describe('given dashboard with repeated panels', function() {
}; };
dash = new DashboardModel(dash, {}); dash = new DashboardModel(dash, {});
dash.getSaveModelClone();
var exporter = new DashboardExporter(datasourceSrvStub); var exporter = new DashboardExporter(datasourceSrvStub);
exporter.makeExportable(dash).then(clean => { exporter.makeExportable(dash).then(clean => {
exported = clean; exported = clean;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment