export_modal.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import angular from 'angular';
  2. import {saveAs} from 'file-saver';
  3. import coreModule from 'app/core/core_module';
  4. import {DashboardExporter} from './exporter';
  5. export class DashExportCtrl {
  6. dash: any;
  7. exporter: DashboardExporter;
  8. dismiss: () => void;
  9. /** @ngInject */
  10. constructor(private dashboardSrv, datasourceSrv, private $scope) {
  11. this.exporter = new DashboardExporter(datasourceSrv);
  12. this.exporter.makeExportable(this.dashboardSrv.getCurrent()).then(dash => {
  13. this.$scope.$apply(() => {
  14. this.dash = dash;
  15. });
  16. });
  17. }
  18. save() {
  19. var blob = new Blob([angular.toJson(this.dash, true)], {type: 'application/json;charset=utf-8'});
  20. saveAs(blob, this.dash.title + '-' + new Date().getTime() + '.json');
  21. }
  22. saveJson() {
  23. var clone = this.dash;
  24. this.$scope.$root.appEvent('show-json-editor', {
  25. object: clone,
  26. });
  27. this.dismiss();
  28. }
  29. }
  30. export function dashExportDirective() {
  31. return {
  32. restrict: 'E',
  33. templateUrl: 'public/app/features/dashboard/export/export_modal.html',
  34. controller: DashExportCtrl,
  35. bindToController: true,
  36. controllerAs: 'ctrl',
  37. scope: {dismiss: '&'},
  38. };
  39. }
  40. coreModule.directive('dashExportModal', dashExportDirective);