|
|
|
@ -55,6 +55,8 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState(
|
|
|
|
|
|
|
|
|
|
const selectedImage = ref() |
|
|
|
|
|
|
|
|
|
const selectedImages = ref<boolean[]>([]) |
|
|
|
|
|
|
|
|
|
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<any[]>(() => { |
|
|
|
|
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<string, any>) { |
|
|
|
|
;(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<any[]>(() => (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', |
|
|
|
|