feat(export): progress on dashboard export

This commit is contained in:
Torkel Ödegaard 2016-05-10 21:09:15 +02:00
parent 79a8017fe9
commit 5b42753b8b
3 changed files with 48 additions and 10 deletions

View File

@ -26,7 +26,7 @@ module.exports = function(config) {
browsers: ['PhantomJS'],
captureTimeout: 20000,
singleRun: true,
autoWatchBatchDelay: 10000,
autoWatchBatchDelay: 1000,
browserNoActivityTimeout: 60000,
});

View File

@ -36,10 +36,20 @@ export class DashboardExporter {
type: 'datasource',
id: ds.meta.id,
name: ds.meta.name,
version: ds.meta.info.version
version: ds.meta.info.version || "1.0.0",
};
}));
}
var panelDef = config.panels[panel.type];
if (panelDef) {
requires['panel' + panelDef.id] = {
type: 'panel',
id: panelDef.id,
name: panelDef.name,
version: panelDef.info.version,
};
}
});
}
@ -56,14 +66,21 @@ export class DashboardExporter {
dash["__requires"] = requires;
return dash;
}).catch(err => {
console.log('Export failed:', err);
return {};
});
}
export(dashboard) {
return this.makeExportable(dashboard).then(clean => {
var blob = new Blob([angular.toJson(clean, true)], { type: "application/json;charset=utf-8" });
var wnd: any = window;
wnd.saveAs(blob, clean.title + '-' + new Date().getTime() + '.json');
var html = angular.toJson(clean, true);
var uri = "data:application/json," + encodeURIComponent(html);
var newWindow = window.open(uri);
// var blob = new Blob([angular.toJson(clean, true)], { type: "application/json;charset=utf-8" });
// var wnd: any = window;
// wnd.saveAs(blob, clean.title + '-' + new Date().getTime() + '.json');
});
}

View File

@ -1,11 +1,13 @@
import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/common';
import _ from 'lodash';
import config from 'app/core/config';
import {DashboardExporter} from '../exporter';
describe.only('given dashboard with repeated panels', function() {
var dash, exported;
beforeEach((done) => {
beforeEach(done => {
dash = {
rows: [],
templating: { list: [] }
@ -19,7 +21,7 @@ describe.only('given dashboard with repeated panels', function() {
dash.rows.push({
repeat: 'test',
panels: [
{id: 2, repeat: 'apps', datasource: 'gfdb'},
{id: 2, repeat: 'apps', datasource: 'gfdb', type: 'graph'},
{id: 2, repeat: null, repeatPanelId: 2},
]
});
@ -31,19 +33,23 @@ describe.only('given dashboard with repeated panels', function() {
var datasourceSrvStub = {
get: sinon.stub().returns(Promise.resolve({
name: 'gfdb',
meta: {id: "testdb"}
meta: {id: "testdb", info: {version: "1.2.1"}, name: "TestDB"}
}))
};
config.panels['graph'] = {
id: "graph",
name: "Graph",
info: {version: "1.1.0"}
};
var exporter = new DashboardExporter(datasourceSrvStub);
exporter.makeExportable(dash).then(clean => {
exported = clean;
done();
console.log('done');
});
});
it('exported dashboard should not contain repeated panels', function() {
expect(exported.rows[0].panels.length).to.be(1);
});
@ -63,5 +69,20 @@ describe.only('given dashboard with repeated panels', function() {
expect(exported.__inputs[0].type).to.be("datasource");
});
it('should add datasource to required', function() {
var require = _.findWhere(exported.__requires, {name: 'TestDB'});
expect(require.name).to.be("TestDB");
expect(require.id).to.be("testdb");
expect(require.type).to.be("datasource");
expect(require.version).to.be("1.2.1");
});
it('should add panel to required', function() {
var require = _.findWhere(exported.__requires, {name: 'Graph'});
expect(require.name).to.be("Graph");
expect(require.id).to.be("graph");
expect(require.version).to.be("1.1.0");
});
});