ExportDataModalCtrl.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import angular from 'angular';
  2. import * as fileExport from 'app/core/utils/file_export';
  3. import appEvents from 'app/core/app_events';
  4. import { DashboardSrv } from 'app/features/dashboard/services/DashboardSrv';
  5. export class ExportDataModalCtrl {
  6. private data: any;
  7. private panel: string;
  8. asRows = true;
  9. dateTimeFormat = 'YYYY-MM-DDTHH:mm:ssZ';
  10. excel = false;
  11. /** @ngInject */
  12. constructor(private dashboardSrv: DashboardSrv) {}
  13. export() {
  14. const timezone = this.dashboardSrv.getCurrent().timezone;
  15. const options = {
  16. excel: this.excel,
  17. dateTimeFormat: this.dateTimeFormat,
  18. timezone,
  19. };
  20. if (this.panel === 'table') {
  21. fileExport.exportTableDataToCsv(this.data, this.excel);
  22. } else {
  23. if (this.asRows) {
  24. fileExport.exportSeriesListToCsv(this.data, options);
  25. } else {
  26. fileExport.exportSeriesListToCsvColumns(this.data, options);
  27. }
  28. }
  29. this.dismiss();
  30. }
  31. dismiss() {
  32. appEvents.emit('hide-modal');
  33. }
  34. }
  35. export function exportDataModal() {
  36. return {
  37. restrict: 'E',
  38. templateUrl: 'public/app/features/dashboard/components/ExportDataModal/template.html',
  39. controller: ExportDataModalCtrl,
  40. controllerAs: 'ctrl',
  41. scope: {
  42. panel: '<',
  43. data: '<', // The difference to '=' is that the bound properties are not watched
  44. },
  45. bindToController: true,
  46. };
  47. }
  48. angular.module('grafana.directives').directive('exportDataModal', exportDataModal);