export_modal.ts 1.3 KB

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