export_modal.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. ///<reference path="../../../headers/common.d.ts" />
  2. import kbn from 'app/core/utils/kbn';
  3. import angular from 'angular';
  4. import coreModule from 'app/core/core_module';
  5. import appEvents from 'app/core/app_events';
  6. import config from 'app/core/config';
  7. import _ from 'lodash';
  8. import {DashboardExporter} from './exporter';
  9. export class DashExportCtrl {
  10. dash: any;
  11. exporter: DashboardExporter;
  12. /** @ngInject */
  13. constructor(private backendSrv, dashboardSrv, datasourceSrv, $scope) {
  14. this.exporter = new DashboardExporter(datasourceSrv);
  15. this.exporter.makeExportable(dashboardSrv.getCurrent()).then(dash => {
  16. $scope.$apply(() => {
  17. this.dash = dash;
  18. });
  19. });
  20. }
  21. save() {
  22. var blob = new Blob([angular.toJson(this.dash, true)], { type: "application/json;charset=utf-8" });
  23. var wnd: any = window;
  24. wnd.saveAs(blob, this.dash.title + '-' + new Date().getTime() + '.json');
  25. }
  26. saveJson() {
  27. var html = angular.toJson(this.dash, true);
  28. var uri = "data:application/json," + encodeURIComponent(html);
  29. var newWindow = window.open(uri);
  30. }
  31. }
  32. export function dashExportDirective() {
  33. return {
  34. restrict: 'E',
  35. templateUrl: 'public/app/features/dashboard/export/export_modal.html',
  36. controller: DashExportCtrl,
  37. bindToController: true,
  38. controllerAs: 'ctrl',
  39. };
  40. }
  41. coreModule.directive('dashExportModal', dashExportDirective);