mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(export): progress on dashboard export
This commit is contained in:
parent
79a8017fe9
commit
5b42753b8b
@ -26,7 +26,7 @@ module.exports = function(config) {
|
|||||||
browsers: ['PhantomJS'],
|
browsers: ['PhantomJS'],
|
||||||
captureTimeout: 20000,
|
captureTimeout: 20000,
|
||||||
singleRun: true,
|
singleRun: true,
|
||||||
autoWatchBatchDelay: 10000,
|
autoWatchBatchDelay: 1000,
|
||||||
browserNoActivityTimeout: 60000,
|
browserNoActivityTimeout: 60000,
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -36,10 +36,20 @@ export class DashboardExporter {
|
|||||||
type: 'datasource',
|
type: 'datasource',
|
||||||
id: ds.meta.id,
|
id: ds.meta.id,
|
||||||
name: ds.meta.name,
|
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;
|
dash["__requires"] = requires;
|
||||||
|
|
||||||
return dash;
|
return dash;
|
||||||
|
}).catch(err => {
|
||||||
|
console.log('Export failed:', err);
|
||||||
|
return {};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export(dashboard) {
|
export(dashboard) {
|
||||||
return this.makeExportable(dashboard).then(clean => {
|
return this.makeExportable(dashboard).then(clean => {
|
||||||
var blob = new Blob([angular.toJson(clean, true)], { type: "application/json;charset=utf-8" });
|
var html = angular.toJson(clean, true);
|
||||||
var wnd: any = window;
|
var uri = "data:application/json," + encodeURIComponent(html);
|
||||||
wnd.saveAs(blob, clean.title + '-' + new Date().getTime() + '.json');
|
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');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/common';
|
import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/common';
|
||||||
|
|
||||||
|
import _ from 'lodash';
|
||||||
|
import config from 'app/core/config';
|
||||||
import {DashboardExporter} from '../exporter';
|
import {DashboardExporter} from '../exporter';
|
||||||
|
|
||||||
describe.only('given dashboard with repeated panels', function() {
|
describe.only('given dashboard with repeated panels', function() {
|
||||||
var dash, exported;
|
var dash, exported;
|
||||||
|
|
||||||
beforeEach((done) => {
|
beforeEach(done => {
|
||||||
dash = {
|
dash = {
|
||||||
rows: [],
|
rows: [],
|
||||||
templating: { list: [] }
|
templating: { list: [] }
|
||||||
@ -19,7 +21,7 @@ describe.only('given dashboard with repeated panels', function() {
|
|||||||
dash.rows.push({
|
dash.rows.push({
|
||||||
repeat: 'test',
|
repeat: 'test',
|
||||||
panels: [
|
panels: [
|
||||||
{id: 2, repeat: 'apps', datasource: 'gfdb'},
|
{id: 2, repeat: 'apps', datasource: 'gfdb', type: 'graph'},
|
||||||
{id: 2, repeat: null, repeatPanelId: 2},
|
{id: 2, repeat: null, repeatPanelId: 2},
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
@ -31,19 +33,23 @@ describe.only('given dashboard with repeated panels', function() {
|
|||||||
var datasourceSrvStub = {
|
var datasourceSrvStub = {
|
||||||
get: sinon.stub().returns(Promise.resolve({
|
get: sinon.stub().returns(Promise.resolve({
|
||||||
name: 'gfdb',
|
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);
|
var exporter = new DashboardExporter(datasourceSrvStub);
|
||||||
exporter.makeExportable(dash).then(clean => {
|
exporter.makeExportable(dash).then(clean => {
|
||||||
exported = clean;
|
exported = clean;
|
||||||
done();
|
done();
|
||||||
console.log('done');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('exported dashboard should not contain repeated panels', function() {
|
it('exported dashboard should not contain repeated panels', function() {
|
||||||
expect(exported.rows[0].panels.length).to.be(1);
|
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");
|
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");
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user