export_modal.ts 1.4 KB

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