export_modal.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ///<reference path="../../../headers/common.d.ts" />
  2. import kbn from 'app/core/utils/kbn';
  3. import angular from 'angular';
  4. import coreModule from 'app/core/core_module';
  5. import appEvents from 'app/core/app_events';
  6. import config from 'app/core/config';
  7. import _ from 'lodash';
  8. import {DashboardExporter} from './exporter';
  9. export class DashExportCtrl {
  10. dash: any;
  11. exporter: DashboardExporter;
  12. dismiss: () => void;
  13. /** @ngInject */
  14. constructor(private backendSrv, private dashboardSrv, datasourceSrv, private $scope) {
  15. this.exporter = new DashboardExporter(datasourceSrv);
  16. this.exporter.makeExportable(this.dashboardSrv.getCurrent()).then(dash => {
  17. this.$scope.$apply(() => {
  18. this.dash = dash;
  19. });
  20. });
  21. }
  22. save() {
  23. var blob = new Blob([angular.toJson(this.dash, true)], { type: "application/json;charset=utf-8" });
  24. var wnd: any = window;
  25. wnd.saveAs(blob, this.dash.title + '-' + new Date().getTime() + '.json');
  26. }
  27. saveJson() {
  28. var clone = this.dashboardSrv.getCurrent().getSaveModelClone();
  29. this.$scope.$root.appEvent('show-json-editor', {
  30. object: clone,
  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);