From df50fa233255b88a28a8e17299f8160ca2d56e98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 17 May 2016 11:17:11 +0200 Subject: [PATCH] feat(export): export dashboard modal --- docs/sources/reference/dashboard.md | 2 - public/app/features/dashboard/dashboardSrv.js | 1 - .../features/dashboard/dashnav/dashnav.html | 2 +- .../dashboard/export/export_modal.html | 50 ++++++++----------- .../features/dashboard/export/export_modal.ts | 13 +++++ .../app/features/dashboard/export/exporter.ts | 12 +++-- public/dashboards/home.json | 1 - public/dashboards/template_vars.json | 1 - 8 files changed, 44 insertions(+), 38 deletions(-) diff --git a/docs/sources/reference/dashboard.md b/docs/sources/reference/dashboard.md index 93adf5cd789..831dbe3abdc 100644 --- a/docs/sources/reference/dashboard.md +++ b/docs/sources/reference/dashboard.md @@ -26,7 +26,6 @@ When a user creates a new dashboard, a new dashboard JSON object is initialized { "id": null, "title": "New dashboard", - "originalTitle": "New dashboard", "tags": [], "style": "dark", "timezone": "browser", @@ -59,7 +58,6 @@ Each field in the dashboard JSON is explained below with its usage: | ---- | ----- | | **id** | unique dashboard id, an integer | | **title** | current title of dashboard | -| **originalTitle** | title of dashboard when saved for the first time | | **tags** | tags associated with dashboard, an array of strings | | **style** | theme of dashboard, i.e. `dark` or `light` | | **timezone** | timezone of dashboard, i.e. `utc` or `browser` | diff --git a/public/app/features/dashboard/dashboardSrv.js b/public/app/features/dashboard/dashboardSrv.js index 2e1cd1acbf0..8181af4566f 100644 --- a/public/app/features/dashboard/dashboardSrv.js +++ b/public/app/features/dashboard/dashboardSrv.js @@ -22,7 +22,6 @@ function (angular, $, _, moment) { this.id = data.id || null; this.title = data.title || 'No Title'; - this.originalTitle = this.title; this.tags = data.tags || []; this.style = data.style || "dark"; this.timezone = data.timezone || ''; diff --git a/public/app/features/dashboard/dashnav/dashnav.html b/public/app/features/dashboard/dashnav/dashnav.html index 1a0c8a56e21..342612d12ce 100644 --- a/public/app/features/dashboard/dashnav/dashnav.html +++ b/public/app/features/dashboard/dashnav/dashnav.html @@ -35,7 +35,7 @@
  • - Export + Export for sharing
  • diff --git a/public/app/features/dashboard/export/export_modal.html b/public/app/features/dashboard/export/export_modal.html index fe821887ca4..a4c40cc6889 100644 --- a/public/app/features/dashboard/export/export_modal.html +++ b/public/app/features/dashboard/export/export_modal.html @@ -12,10 +12,10 @@ -

    - Dashboard data sources -

    - -
    -
    -
    - - - -
    -
    - - - -
    -
    -
    + + + + + + + + + + + +
    - + Cancel
    - diff --git a/public/app/features/dashboard/export/export_modal.ts b/public/app/features/dashboard/export/export_modal.ts index 3857d8a1330..57af9d9caf8 100644 --- a/public/app/features/dashboard/export/export_modal.ts +++ b/public/app/features/dashboard/export/export_modal.ts @@ -1,6 +1,7 @@ /// import kbn from 'app/core/utils/kbn'; +import angular from 'angular'; import coreModule from 'app/core/core_module'; import appEvents from 'app/core/app_events'; import config from 'app/core/config'; @@ -25,6 +26,18 @@ export class DashExportCtrl { }); } + save() { + var blob = new Blob([angular.toJson(this.dash, true)], { type: "application/json;charset=utf-8" }); + var wnd: any = window; + wnd.saveAs(blob, this.dash.title + '-' + new Date().getTime() + '.json'); + } + + saveJson() { + var html = angular.toJson(this.dash, true); + var uri = "data:application/json," + encodeURIComponent(html); + var newWindow = window.open(uri); + } + } export function dashExportDirective() { diff --git a/public/app/features/dashboard/export/exporter.ts b/public/app/features/dashboard/export/exporter.ts index 0e73cbcf038..d3b94d7fae7 100644 --- a/public/app/features/dashboard/export/exporter.ts +++ b/public/app/features/dashboard/export/exporter.ts @@ -15,6 +15,8 @@ export class DashboardExporter { var dynSrv = new DynamicDashboardSrv(); dynSrv.process(dash, {cleanUpOnly: true}); + dash.id = null; + var inputs = []; var requires = {}; var datasources = {}; @@ -63,10 +65,14 @@ export class DashboardExporter { return req; }); - dash["__inputs"] = inputs; - dash["__requires"] = requires; + // make inputs and requires a top thing + var newObj = {}; + newObj["__inputs"] = inputs; + newObj["__requires"] = requires; - return dash; + _.defaults(newObj, dash); + + return newObj; }).catch(err => { console.log('Export failed:', err); return {}; diff --git a/public/dashboards/home.json b/public/dashboards/home.json index c3ed1017bad..393cbc5865c 100644 --- a/public/dashboards/home.json +++ b/public/dashboards/home.json @@ -1,7 +1,6 @@ { "id": null, "title": "Home", - "originalTitle": "Home", "tags": [], "style": "dark", "timezone": "browser", diff --git a/public/dashboards/template_vars.json b/public/dashboards/template_vars.json index 8ca81fbdff5..a3c25d00371 100644 --- a/public/dashboards/template_vars.json +++ b/public/dashboards/template_vars.json @@ -1,7 +1,6 @@ { "id": null, "title": "Templated Graphs Nested", - "originalTitle": "Templated Graphs Nested", "tags": [ "showcase", "templated"