From 5b42753b8b135bcdc987ba6417b990c348106871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 10 May 2016 21:09:15 +0200 Subject: [PATCH] feat(export): progress on dashboard export --- karma.conf.js | 2 +- public/app/features/dashboard/exporter.ts | 25 ++++++++++++--- .../dashboard/specs/exporter_specs.ts | 31 ++++++++++++++++--- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index c803dda5eae..cdcea23a90b 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -26,7 +26,7 @@ module.exports = function(config) { browsers: ['PhantomJS'], captureTimeout: 20000, singleRun: true, - autoWatchBatchDelay: 10000, + autoWatchBatchDelay: 1000, browserNoActivityTimeout: 60000, }); diff --git a/public/app/features/dashboard/exporter.ts b/public/app/features/dashboard/exporter.ts index 8ed3f950c7f..9a8d5bae5b1 100644 --- a/public/app/features/dashboard/exporter.ts +++ b/public/app/features/dashboard/exporter.ts @@ -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'); }); } diff --git a/public/app/features/dashboard/specs/exporter_specs.ts b/public/app/features/dashboard/specs/exporter_specs.ts index 5b0576b729c..62403efae7c 100644 --- a/public/app/features/dashboard/specs/exporter_specs.ts +++ b/public/app/features/dashboard/specs/exporter_specs.ts @@ -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"); + }); + });