export_modal.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. ///<reference path="../../../headers/common.d.ts" />
  2. import angular from 'angular';
  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) {
  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. var wnd: any = window;
  21. wnd.saveAs(blob, this.dash.title + '-' + new Date().getTime() + '.json');
  22. }
  23. saveJson() {
  24. var clone = this.dashboardSrv.getCurrent().getSaveModelClone();
  25. this.$scope.$root.appEvent('show-json-editor', {
  26. object: clone,
  27. });
  28. this.dismiss();
  29. }
  30. }
  31. export function dashExportDirective() {
  32. return {
  33. restrict: 'E',
  34. templateUrl: 'public/app/features/dashboard/export/export_modal.html',
  35. controller: DashExportCtrl,
  36. bindToController: true,
  37. controllerAs: 'ctrl',
  38. scope: {dismiss: "&"}
  39. };
  40. }
  41. coreModule.directive('dashExportModal', dashExportDirective);