From 77166793a1377ce92f2a5409e63306141ebdf6dd Mon Sep 17 00:00:00 2001 From: Anthony Tarlao Date: Wed, 2 Aug 2023 10:39:32 +0200 Subject: [PATCH] Export: add context menu and batch operation (#1) * Export: add context menu and batch operation * Export: add exclusion * Improve readibility * Improve readibility --- README.md | 2 +- i18n/en.json | 4 +++ index.js | 8 +++++ .../import-export-doc-type/index.js | 27 +++++++++++++++++ .../import-export-piece-type/index.js | 29 +++++++++++++++++++ 5 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 i18n/en.json create mode 100644 modules/@apostrophecms/import-export-doc-type/index.js create mode 100644 modules/@apostrophecms/import-export-piece-type/index.js diff --git a/README.md b/README.md index 5cf2d6b2..130142b4 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@
ApostropheCMS logo -

Apostrophe Module Template

+

Apostrophe Import Export Module

diff --git a/i18n/en.json b/i18n/en.json new file mode 100644 index 00000000..e4608824 --- /dev/null +++ b/i18n/en.json @@ -0,0 +1,4 @@ +{ + "export": "Export", + "exporting": "Exporting" +} diff --git a/index.js b/index.js index 688e3e06..d08bf2bd 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,14 @@ module.exports = { bundle: { directory: 'modules', modules: getBundleModuleNames() + }, + + options: { + name: '@apostrophecms/import-export', + i18n: { + ns: 'aposImportExport', + browser: true + } } }; diff --git a/modules/@apostrophecms/import-export-doc-type/index.js b/modules/@apostrophecms/import-export-doc-type/index.js new file mode 100644 index 00000000..1cd6a020 --- /dev/null +++ b/modules/@apostrophecms/import-export-doc-type/index.js @@ -0,0 +1,27 @@ +const excludedTypes = []; + +module.exports = { + improve: '@apostrophecms/doc-type', + + init(self) { + const criteria = { + action: 'export', + context: 'update', + label: 'aposImportExport:export', + modal: 'AposExportPiecesModal' + }; + + if (self.options.export === false) { + excludedTypes.push({ + type: { + $ne: self.__meta.name + } + }); + criteria.if = { + $and: excludedTypes + }; + } + + self.apos.doc.addContextOperation(self.__meta.name, criteria); + } +}; diff --git a/modules/@apostrophecms/import-export-piece-type/index.js b/modules/@apostrophecms/import-export-piece-type/index.js new file mode 100644 index 00000000..f1863255 --- /dev/null +++ b/modules/@apostrophecms/import-export-piece-type/index.js @@ -0,0 +1,29 @@ +module.exports = { + improve: '@apostrophecms/piece-type', + + cascades: [ 'batchOperations' ], + + batchOperations(self) { + if (self.options.export === false) { + return; + } + + return { + add: { + export: { + label: 'aposImportExport:export', + messages: { + progress: 'aposImportExport:exporting' + }, + modal: 'AposExportPiecesModal' + } + }, + group: { + more: { + icon: 'dots-vertical-icon', + operations: [ 'export' ] + } + } + }; + } +};