UNPKG

@adaptabletools/adaptable

Version:

Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements

217 lines (216 loc) 8.87 kB
import { AdaptableModuleBase } from './AdaptableModuleBase'; import * as ModuleConstants from '../Utilities/Constants/ModuleConstants'; import * as ExportRedux from '../Redux/ActionsReducers/ExportRedux'; import { ExportPopupWizardRouter } from '../View/Export/Wizard/ExportPopupWizardRouter'; import { getExportColumnsViewItems } from './Utilities/Export/getExportColumnsViewItems'; import { getExportRowsViewItems } from './Utilities/Export/getExportRowsViewItems'; import { reportHasSchedules } from './Utilities/Export/getReportSchedulesViewItems'; import { ExportSchedulesTab } from '../View/Export/ExportSchedulesTab'; import { getObjectTagsViewItems } from '../Utilities/getObjectTagsViewItems'; import { ExportStatusBar } from '../View/Export/ExportStatusBar'; import { ReportListItem } from '../View/Export/ReportListItem'; import { exportStateNeedsScheduleUuids, getScheduledReports, } from '../Utilities/Helpers/Scheduling/ScheduledReportHelper'; import { createScheduleJobManager } from '../Utilities/Helpers/Scheduling/ScheduleJobManager'; export class ExportModule extends AdaptableModuleBase { scheduledReportJobManager; constructor(api) { super(ModuleConstants.ExportModuleId, ModuleConstants.ExportFriendlyName, 'export-data', 'ExportPopup', 'Export data from the Grid to numerous locations in numerous formatso', api); this.scheduledReportJobManager = createScheduleJobManager({ getActiveItems: () => getScheduledReports(this.api.exportApi.getExportState()), getSchedule: (reportSchedule) => reportSchedule.Schedule, onFire: (reportSchedule) => { this.api.exportApi.applyScheduledReport(reportSchedule); }, }); } onAdaptableReady() { const exportState = this.api.exportApi.getExportState(); if (exportStateNeedsScheduleUuids(exportState)) { this.api.exportApi.ensureScheduledReportUuids(); } this.setUpScheduledReportJobs(); } setUpScheduledReportJobs() { this.scheduledReportJobManager.setUpJobs(); } getModuleAdaptableObjects() { return this.api.exportApi.getAllReports(); } getExplicitlyReferencedColumnIds(report) { if (report.ReportColumnScope === 'ScopeColumns' && this.api.columnScopeApi.scopeHasColumns(report.Scope)) { return this.api.columnScopeApi .getColumnsInScope(report.Scope) .map((adaptableColumn) => adaptableColumn.columnId); } return []; } getReferencedNamedQueryNames(report) { if (!report.Query) { return []; } return this.api.namedQueryApi.internalApi.getReferencedNamedQueryNames(report.Query.BooleanExpression); } createContextMenuItems(menuContext) { const canExport = !menuContext.isRowGroupColumn && this.isModuleVisible(); if (!canExport) { return; } let returnMenuItems = []; const allReportNames = this.api.exportApi.internalApi.getAllAvailableReportNames(); const allReportFormats = this.api.exportApi.getAvailableSystemFormats(); allReportNames.forEach((reportName) => { const formatItems = allReportFormats.map((reportFormat) => { const supportedDestinations = this.api.exportApi.getSupportedExportDestinations(reportFormat); const exportDestinationItems = supportedDestinations.map((exportDestination) => this.createMenuItemClickFunction(this.getMenuItemName(reportName, reportFormat, exportDestination), exportDestination, this.getDestinationMenuItemIcon(exportDestination), () => this.api.exportApi.exportReport(reportName, reportFormat, exportDestination))); const formatMenuItemGroup = { name: this.getMenuItemName(reportName, reportFormat), label: reportFormat, isVisible: true, category: 'Export', icon: { name: this.getFormatMenuItemIcon(reportFormat), }, subItems: exportDestinationItems, }; return formatMenuItemGroup; }); const reportMenuItemGroup = { name: this.getMenuItemName(reportName), label: reportName, isVisible: true, category: 'Export', icon: { name: 'export-data', }, subItems: formatItems, }; returnMenuItems.push(reportMenuItemGroup); }); return returnMenuItems; } getMenuItemName(reportName, reportFormat, exportDestination) { const adjustName = (name = '') => { const result = name.replace(/ /g, '-'); return result.toLowerCase(); }; let name = `export-${adjustName(reportName)}`; if (reportFormat) { name += `-${adjustName(reportFormat)}`; } if (exportDestination) { name += `-${adjustName(exportDestination)}`; } return name; } getDestinationMenuItemIcon(exportDestination) { switch (exportDestination) { case 'Download': return 'downloaded'; case 'Clipboard': return 'clipboard'; default: return 'export-data'; } } getFormatMenuItemIcon(reportFormat) { switch (reportFormat) { case 'Excel': return 'excel'; case 'VisualExcel': return 'color-palette'; case 'CSV': return 'csv'; case 'JSON': return 'json'; default: return 'export'; } } getTeamSharingAction() { return { ModuleEntities: this.api.exportApi.getAllReports(), AddAction: ExportRedux.ReportAdd, EditAction: ExportRedux.ReportEdit, }; } toView(report) { const isSystemReport = this.api.exportApi.internalApi.isSystemReport(report.Name); const reportValues = [ report.Name, ...(reportHasSchedules(report, this.api) ? ['Scheduled'] : []), ]; if (isSystemReport) { return { items: [ { name: 'Report', values: reportValues, }, getObjectTagsViewItems(report, this.api), ].filter(Boolean), abObject: report, }; } return { items: [ { name: 'Report', values: reportValues, }, getExportColumnsViewItems(report, this.api), getExportRowsViewItems(report, this.api), getObjectTagsViewItems(report, this.api), ].filter(Boolean), abObject: report, }; } toViewAll() { return this.getModuleAdaptableObjects().map((report) => this.toView(report)); } getViewProperties() { return { settingsPanelTabs: [ { label: 'Reports' }, { label: 'Schedules', render: ExportSchedulesTab, }, ], abObjectTypes: [ { name: 'Report', label: 'New Report', accessLevel: this.AccessLevel, }, { name: 'Schedule', label: 'New Schedule', accessLevel: this.AccessLevel, }, ], newTooltipText: 'Create new Export item', actions: [ReportListItem], getDeleteAction: ExportRedux.ReportDelete, getDeleteConfirmationMsg: (abObject) => { const report = abObject; const scheduleCount = this.api.exportApi .getScheduledReports() .filter((d) => d.ReportName === report.Name).length; if (scheduleCount > 0) { return `Are you sure you want to delete '${report.Name}'? This will also delete ${scheduleCount} scheduled export(s).`; } return `Are you sure you want to delete '${report.Name}'?`; }, getEditWizard() { return ExportPopupWizardRouter; }, getStatusBarPanelProps: () => { return { content: ExportStatusBar, triggerActionOnWrapperClick: false, }; }, }; } }