From ad7a1e15b4d0830c0589aad7bdc406f2339f9078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 17 May 2016 10:29:57 +0200 Subject: [PATCH] feat(export): began working on export modal --- pkg/plugins/dashboard_importer.go | 2 +- public/app/features/dashboard/all.js | 1 + .../features/dashboard/dashnav/dashnav.html | 5 ++ .../app/features/dashboard/dashnav/dashnav.ts | 10 ++- .../dashboard/export/export_modal.html | 74 +++++++++++++++++++ .../features/dashboard/export/export_modal.ts | 40 ++++++++++ .../dashboard/{ => export}/exporter.ts | 4 +- public/app/features/dashboard/keybindings.js | 4 - .../dashboard/specs/exporter_specs.ts | 2 +- public/app/partials/help_modal.html | 4 - 10 files changed, 131 insertions(+), 15 deletions(-) create mode 100644 public/app/features/dashboard/export/export_modal.html create mode 100644 public/app/features/dashboard/export/export_modal.ts rename public/app/features/dashboard/{ => export}/exporter.ts (95%) diff --git a/pkg/plugins/dashboard_importer.go b/pkg/plugins/dashboard_importer.go index aa489fcdaaf..8f6998d344d 100644 --- a/pkg/plugins/dashboard_importer.go +++ b/pkg/plugins/dashboard_importer.go @@ -109,7 +109,7 @@ func (this *DashTemplateEvaluator) findInput(varName string, varType string) *Im func (this *DashTemplateEvaluator) Eval() (*simplejson.Json, error) { this.result = simplejson.New() this.variables = make(map[string]string) - this.varRegex, _ = regexp.Compile(`(\$\{\w+\})`) + this.varRegex, _ = regexp.Compile(`(\$\{.+\})`) // check that we have all inputs we need for _, inputDef := range this.template.Get("__inputs").MustArray() { diff --git a/public/app/features/dashboard/all.js b/public/app/features/dashboard/all.js index 51a2b806e19..a7b40b14b58 100644 --- a/public/app/features/dashboard/all.js +++ b/public/app/features/dashboard/all.js @@ -18,4 +18,5 @@ define([ './impression_store', './upload', './import/import', + './export/export_modal', ], function () {}); diff --git a/public/app/features/dashboard/dashnav/dashnav.html b/public/app/features/dashboard/dashnav/dashnav.html index 9afd152d8aa..1a0c8a56e21 100644 --- a/public/app/features/dashboard/dashnav/dashnav.html +++ b/public/app/features/dashboard/dashnav/dashnav.html @@ -33,6 +33,11 @@ Snapshot sharing +
  • + + Export + +
  • diff --git a/public/app/features/dashboard/dashnav/dashnav.ts b/public/app/features/dashboard/dashnav/dashnav.ts index e9ef96408ad..81f2d9ea8c6 100644 --- a/public/app/features/dashboard/dashnav/dashnav.ts +++ b/public/app/features/dashboard/dashnav/dashnav.ts @@ -4,7 +4,7 @@ import _ from 'lodash'; import moment from 'moment'; import angular from 'angular'; -import {DashboardExporter} from '../exporter'; +import {DashboardExporter} from '../export/exporter'; export class DashNavCtrl { @@ -14,7 +14,6 @@ export class DashNavCtrl { $scope.init = function() { $scope.onAppEvent('save-dashboard', $scope.saveDashboard); $scope.onAppEvent('delete-dashboard', $scope.deleteDashboard); - $scope.onAppEvent('export-dashboard', $scope.snapshot); $scope.onAppEvent('quick-snapshot', $scope.quickSnapshot); $scope.showSettingsMenu = $scope.dashboardMeta.canEdit || $scope.contextSrv.isEditor; @@ -60,6 +59,12 @@ export class DashNavCtrl { $scope.shareDashboard(1); }; + $scope.shareExport = function() { + $scope.appEvent('show-modal', { + templateHtml: '', + }); + }; + $scope.openSearch = function() { $scope.appEvent('show-dash-search'); }; @@ -181,7 +186,6 @@ export class DashNavCtrl { $rootScope.$broadcast('refresh'); $timeout(function() { - $scope.exportDashboard(); $scope.dashboard.snapshot = false; $scope.appEvent('dashboard-snapshot-cleanup'); }, 1000); diff --git a/public/app/features/dashboard/export/export_modal.html b/public/app/features/dashboard/export/export_modal.html new file mode 100644 index 00000000000..fe821887ca4 --- /dev/null +++ b/public/app/features/dashboard/export/export_modal.html @@ -0,0 +1,74 @@ + + + diff --git a/public/app/features/dashboard/export/export_modal.ts b/public/app/features/dashboard/export/export_modal.ts new file mode 100644 index 00000000000..3857d8a1330 --- /dev/null +++ b/public/app/features/dashboard/export/export_modal.ts @@ -0,0 +1,40 @@ +/// + +import kbn from 'app/core/utils/kbn'; +import coreModule from 'app/core/core_module'; +import appEvents from 'app/core/app_events'; +import config from 'app/core/config'; +import _ from 'lodash'; + +import {DashboardExporter} from './exporter'; + +export class DashExportCtrl { + dash: any; + exporter: DashboardExporter; + + /** @ngInject */ + constructor(private backendSrv, dashboardSrv, datasourceSrv, $scope) { + this.exporter = new DashboardExporter(datasourceSrv); + + var current = dashboardSrv.getCurrent().getSaveModelClone(); + + this.exporter.makeExportable(current).then(dash => { + $scope.$apply(() => { + this.dash = dash; + }); + }); + } + +} + +export function dashExportDirective() { + return { + restrict: 'E', + templateUrl: 'public/app/features/dashboard/export/export_modal.html', + controller: DashExportCtrl, + bindToController: true, + controllerAs: 'ctrl', + }; +} + +coreModule.directive('dashExportModal', dashExportDirective); diff --git a/public/app/features/dashboard/exporter.ts b/public/app/features/dashboard/export/exporter.ts similarity index 95% rename from public/app/features/dashboard/exporter.ts rename to public/app/features/dashboard/export/exporter.ts index 63067502605..0e73cbcf038 100644 --- a/public/app/features/dashboard/exporter.ts +++ b/public/app/features/dashboard/export/exporter.ts @@ -1,10 +1,10 @@ -/// +/// import config from 'app/core/config'; import angular from 'angular'; import _ from 'lodash'; -import {DynamicDashboardSrv} from './dynamic_dashboard_srv'; +import {DynamicDashboardSrv} from '../dynamic_dashboard_srv'; export class DashboardExporter { diff --git a/public/app/features/dashboard/keybindings.js b/public/app/features/dashboard/keybindings.js index b07dd2fd848..429e5f5d667 100644 --- a/public/app/features/dashboard/keybindings.js +++ b/public/app/features/dashboard/keybindings.js @@ -68,10 +68,6 @@ function(angular, $) { scope.appEvent('shift-time-forward', evt); }, { inputDisabled: true }); - keyboardManager.bind('ctrl+e', function(evt) { - scope.appEvent('export-dashboard', evt); - }, { inputDisabled: true }); - keyboardManager.bind('ctrl+i', function(evt) { scope.appEvent('quick-snapshot', evt); }, { inputDisabled: true }); diff --git a/public/app/features/dashboard/specs/exporter_specs.ts b/public/app/features/dashboard/specs/exporter_specs.ts index 62403efae7c..408d8cc5bb3 100644 --- a/public/app/features/dashboard/specs/exporter_specs.ts +++ b/public/app/features/dashboard/specs/exporter_specs.ts @@ -2,7 +2,7 @@ import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/co import _ from 'lodash'; import config from 'app/core/config'; -import {DashboardExporter} from '../exporter'; +import {DashboardExporter} from '../export/exporter'; describe.only('given dashboard with repeated panels', function() { var dash, exported; diff --git a/public/app/partials/help_modal.html b/public/app/partials/help_modal.html index 6a8c888bda3..e6601001433 100644 --- a/public/app/partials/help_modal.html +++ b/public/app/partials/help_modal.html @@ -40,10 +40,6 @@ CTRL+S Save dashboard - - CTRL+E - Export dashboard - CTRL+H Hide row controls