From d1819564d558d52afa2c43d294220bbc7b185bd9 Mon Sep 17 00:00:00 2001 From: Miro Yovchev <2827783+myovchev@users.noreply.github.com> Date: Thu, 5 Sep 2024 13:28:08 +0300 Subject: [PATCH] PRO-6436: Add export batch operation for pages (#78) --- CHANGELOG.md | 1 + lib/handlers.js | 4 ++ .../import-export-page/index.js | 36 +++++++++++++++++ ui/apos/components/AposExportModal.vue | 11 +++++- ui/apos/components/AposImportModal.vue | 39 ++++++++++++++++--- 5 files changed, 85 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea5503a8..16854d98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Adds * Singletons can now be imported through `contextOperations` since they have no manager modal and thus, no `utilityOperation` available. +* Pages can be exported via an Export batch operation. ### Fixes diff --git a/lib/handlers.js b/lib/handlers.js index 34b0e92c..38368e45 100644 --- a/lib/handlers.js +++ b/lib/handlers.js @@ -40,8 +40,12 @@ module.exports = (self) => { const importOperation = { action: 'import-export-import', context: 'update', + replaces: true, label: 'aposImportExport:import', modal: 'AposImportModal', + props: { + action: 'import-export-import' + }, if: { $and: excludedImportTypes }, conditions: [ 'canEdit' ] }; diff --git a/modules/@apostrophecms/import-export-page/index.js b/modules/@apostrophecms/import-export-page/index.js index 1598265e..a47c5610 100644 --- a/modules/@apostrophecms/import-export-page/index.js +++ b/modules/@apostrophecms/import-export-page/index.js @@ -21,7 +21,32 @@ module.exports = { } }; }, + batchOperations(self) { + if (self.options.importExport?.export === false) { + return {}; + } + return { + add: { + 'import-export-export-batch': { + label: 'aposImportExport:export', + messages: { + progress: 'aposImportExport:exporting', + completed: 'aposImportExport:exported', + icon: 'database-export-icon', + resultsEventName: 'import-export-export-download' + }, + modal: 'AposExportModal' + } + }, + group: { + more: { + icon: 'dots-vertical-icon', + operations: [ 'import-export-export-batch' ] + } + } + }; + }, apiRoutes(self) { return { post: { @@ -40,6 +65,17 @@ module.exports = { return self.apos.modules['@apostrophecms/import-export'].export(req, self); } + }, + importExportExportBatch(req) { + // Add the pages label to req.body for notifications. + // Should be done before calling the job's `run` method. + req.body.type = req.t('apostrophe:pages'); + + return self.apos.modules['@apostrophecms/job'].run( + req, + (req, reporting) => self.apos.modules['@apostrophecms/import-export'] + .export(req, self, reporting) + ); } } }; diff --git a/ui/apos/components/AposExportModal.vue b/ui/apos/components/AposExportModal.vue index 79be1687..65336438 100644 --- a/ui/apos/components/AposExportModal.vue +++ b/ui/apos/components/AposExportModal.vue @@ -149,6 +149,10 @@ export default { type: Array, default: () => [] }, + checkedTypes: { + type: Array, + default: () => [] + }, doc: { type: Object, default: null @@ -204,6 +208,11 @@ export default { label: format.label, value: format.name })); + }, + checkedTypesComputed() { + return this.moduleName === '@apostrophecms/page' && !this.type + ? [ ...new Set(this.checkedTypes) ] + : [ this.type ]; } }, @@ -229,7 +238,7 @@ export default { this.relatedTypes = await apos.http.get('/api/v1/@apostrophecms/import-export/related', { busy: true, qs: { - types: [ this.type ] + types: this.checkedTypesComputed } }); this.checkedRelatedTypes = this.relatedTypes; diff --git a/ui/apos/components/AposImportModal.vue b/ui/apos/components/AposImportModal.vue index c4cb7264..6c679d9e 100644 --- a/ui/apos/components/AposImportModal.vue +++ b/ui/apos/components/AposImportModal.vue @@ -12,7 +12,7 @@