From 57f91801056fed09c62737e843f001f4029a2a2d Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 17 Jan 2023 17:43:44 +0800 Subject: [PATCH] feat(nc-gui): selectedImages & bulk download --- .../components/cell/attachment/Modal.vue | 17 +++++++++++++++++ .../components/cell/attachment/utils.ts | 19 ++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/packages/nc-gui/components/cell/attachment/Modal.vue b/packages/nc-gui/components/cell/attachment/Modal.vue index cd9f6c0215..de9f4eec48 100644 --- a/packages/nc-gui/components/cell/attachment/Modal.vue +++ b/packages/nc-gui/components/cell/attachment/Modal.vue @@ -20,6 +20,8 @@ const { downloadFile, updateModelValue, selectedImage, + selectedImages, + bulkDownloadFiles, } = useAttachmentCell()! // todo: replace placeholder var @@ -97,6 +99,10 @@ function onRemoveFileClick(title: any, i: number) { Viewing Attachments of
{{ column?.title }}
+ +
+ Bulk Download +
@@ -115,6 +121,12 @@ function onRemoveFileClick(title: any, i: number) {
+ + ([]) + const { project } = useProject() const { api, isLoading } = useApi() @@ -63,6 +65,13 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( const { t } = useI18n() + /** our currently visible items, either the locally stored or the ones from db, depending on isPublic & isForm status */ + const visibleItems = computed(() => { + const items = isPublic.value && isForm.value ? storedFiles.value : attachments.value + selectedImages.value = Array.from({ length: items.length }, () => false) + return items + }) + /** remove a file from our stored attachments (either locally stored or saved ones) */ function removeFile(i: number) { if (isPublic.value) { @@ -198,6 +207,11 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( } } + /** bulk download selected files */ + async function bulkDownloadFiles() { + await Promise.all(selectedImages.value.map(async (v, i) => v && (await downloadFile(visibleItems.value[i])))) + } + /** download a file */ async function downloadFile(item: Record) { ;(await import('file-saver')).saveAs(item.url || item.data, item.title) @@ -218,9 +232,6 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( } } - /** our currently visible items, either the locally stored or the ones from db, depending on isPublic & isForm status */ - const visibleItems = computed(() => (isPublic.value && isForm.value ? storedFiles.value : attachments.value)) - watch(files, (nextFiles) => nextFiles && onFileSelect(nextFiles)) return { @@ -243,7 +254,9 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( downloadFile, updateModelValue, selectedImage, + selectedImages, storedFiles, + bulkDownloadFiles, } }, 'useAttachmentCell',