export_modal.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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(
  11. private dashboardSrv,
  12. datasourceSrv,
  13. private $scope,
  14. private $rootScope
  15. ) {
  16. this.exporter = new DashboardExporter(datasourceSrv);
  17. this.exporter.makeExportable(this.dashboardSrv.getCurrent()).then(dash => {
  18. this.$scope.$apply(() => {
  19. this.dash = dash;
  20. });
  21. });
  22. }
  23. save() {
  24. var blob = new Blob([angular.toJson(this.dash, true)], {
  25. type: 'application/json;charset=utf-8',
  26. });
  27. saveAs(blob, this.dash.title + '-' + new Date().getTime() + '.json');
  28. }
  29. saveJson() {
  30. var clone = this.dash;
  31. let editScope = this.$rootScope.$new();
  32. editScope.object = clone;
  33. this.$rootScope.appEvent('show-modal', {
  34. src: 'public/app/partials/edit_json.html',
  35. scope: editScope,
  36. });
  37. this.dismiss();
  38. }
  39. }
  40. export function dashExportDirective() {
  41. return {
  42. restrict: 'E',
  43. templateUrl: 'public/app/features/dashboard/export/export_modal.html',
  44. controller: DashExportCtrl,
  45. bindToController: true,
  46. controllerAs: 'ctrl',
  47. scope: { dismiss: '&' },
  48. };
  49. }
  50. coreModule.directive('dashExportModal', dashExportDirective);