export_modal.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. /** @ngInject */
  13. constructor(private backendSrv, dashboardSrv, datasourceSrv, $scope) {
  14. this.exporter = new DashboardExporter(datasourceSrv);
  15. var current = dashboardSrv.getCurrent().getSaveModelClone();
  16. this.exporter.makeExportable(current).then(dash => {
  17. $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 html = angular.toJson(this.dash, true);
  29. var uri = "data:application/json," + encodeURIComponent(html);
  30. var newWindow = window.open(uri);
  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. };
  41. }
  42. coreModule.directive('dashExportModal', dashExportDirective);