export_modal.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 editScope = this.$rootScope.$new();
  27. editScope.object = clone;
  28. editScope.enableCopy = true;
  29. this.$rootScope.appEvent('show-modal', {
  30. src: 'public/app/partials/edit_json.html',
  31. scope: editScope,
  32. });
  33. this.dismiss();
  34. }
  35. }
  36. export function dashExportDirective() {
  37. return {
  38. restrict: 'E',
  39. templateUrl: 'public/app/features/dashboard/export/export_modal.html',
  40. controller: DashExportCtrl,
  41. bindToController: true,
  42. controllerAs: 'ctrl',
  43. scope: { dismiss: '&' },
  44. };
  45. }
  46. coreModule.directive('dashExportModal', dashExportDirective);