export_modal.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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, private $rootScope) {
  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. const blob = new Blob([angular.toJson(this.dash, true)], {
  20. type: 'application/json;charset=utf-8',
  21. });
  22. saveAs(blob, this.dash.title + '-' + new Date().getTime() + '.json');
  23. }
  24. saveJson() {
  25. const clone = this.dash;
  26. const model = {
  27. object: clone,
  28. enableCopy: true,
  29. };
  30. this.$rootScope.appEvent('show-modal', {
  31. src: 'public/app/partials/edit_json.html',
  32. model: model,
  33. });
  34. this.dismiss();
  35. }
  36. }
  37. export function dashExportDirective() {
  38. return {
  39. restrict: 'E',
  40. templateUrl: 'public/app/features/dashboard/export/export_modal.html',
  41. controller: DashExportCtrl,
  42. bindToController: true,
  43. controllerAs: 'ctrl',
  44. scope: { dismiss: '&' },
  45. };
  46. }
  47. coreModule.directive('dashExportModal', dashExportDirective);