Skip to content

Commit

Permalink
feat: add download all PDFs
Browse files Browse the repository at this point in the history
  • Loading branch information
tmilost committed Jun 21, 2024
1 parent 38b8019 commit 2c24125
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/components/DownloadPDFButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,28 +136,29 @@ function downloadPdf () {
}
async function downloadAllFiles () {
const zipName = "negotiation_" + props.negotiationPdfData?.payload?.project?.title
const pdfName = "negotiation" + ".pdf"
await store.dispatch("downloadAllAttachment", { id: props.negotiationPdfData.id, name: props.negotiationPdfData?.payload?.project?.title})
// const zipName = "negotiation_" + props.negotiationPdfData?.payload?.project?.title
// const pdfName = "negotiation" + ".pdf"
const doc = createPDF()
//@ignore-ts
const zip = JSZip()
// const doc = createPDF()
// //@ignore-ts
// const zip = JSZip()
zip.file(pdfName, doc.output("blob"), { binary: true })
// zip.file(pdfName, doc.output("blob"), { binary: true })
if (props.attachments.length > 0) {
const file = zip.folder("Attachments")
// if (props.attachments.length > 0) {
// const file = zip.folder("Attachments")
for (const attachment of props.attachments) {
await store.dispatch("getAttachmentData", { id: attachment.id }).then((response) => {
file.file(attachment.name, response, { binary: true })
})
}
}
// for (const attachment of props.attachments) {
// await store.dispatch("getAttachmentData", { id: attachment.id }).then((response) => {
// file.file(attachment.name, response, { binary: true })
// })
// }
// }
zip.generateAsync({ type: "blob" }).then(function (content) {
FileSaver.saveAs(content, zipName.toString())
})
// zip.generateAsync({ type: "blob" }).then(function (content) {
// FileSaver.saveAs(content, zipName.toString())
// })
}
</script>
Expand Down
17 changes: 17 additions & 0 deletions src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,23 @@ export default {
window.URL.revokeObjectURL(href)
})
},
downloadAllAttachment ({ state }, { id, name }) {
const data = []
axios.post(`${NEGOTIATION_PATH}/${id}/attachments/merge-to-pdf`, data, { headers: getBearerHeaders(state.oidc.access_token), responseType: "blob" })
.then((response) => {
const href = window.URL.createObjectURL(response.data)

const anchorElement = document.createElement("a")
anchorElement.href = href
anchorElement.download = name

document.body.appendChild(anchorElement)
anchorElement.click()

document.body.removeChild(anchorElement)
window.URL.revokeObjectURL(href)
})
},
async getAttachmentData ({ state, commit }, { id }) {
return await axios.get(`${ATTACHMENTS_PATH}/${id}`, { headers: getBearerHeaders(state.oidc.access_token), responseType: "blob" })
.then((response) => {
Expand Down

0 comments on commit 2c24125

Please sign in to comment.