Commit 83e49660 by Torkel Ödegaard

fixed dashboard sorting

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