Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Fix: Download Legacy Report (#2832)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricargame authored Oct 17, 2024
1 parent b3bc0df commit 94f00cf
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions src/store/modules/ADempiere/reportManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ import { listPrintFormatsRequest, listPrintFormatsTableRequest } from '@/api/ADe
import { listReportViewsRequest } from '@/api/ADempiere/reportManagement/reportView.ts'
import { listDrillTablesRequest } from '@/api/ADempiere/reportManagement/drillTable.ts'
import {
requestPresignedUrl,
requestUploadFile
requestPresignedUrl
} from '@/api/ADempiere/file-management/resource-reference.ts'

// Constants
Expand Down Expand Up @@ -851,6 +850,8 @@ const reportManager = {
containerUuid,
reportName,
isDownload
}).then(fileName => {
resolve(fileName)
})
} else {
runExport({
Expand Down Expand Up @@ -962,6 +963,7 @@ const reportManager = {
isDownload
}) {
return new Promise(resolve => {
const { url, file_name, mime_type } = reportOutput
requestPresignedUrl({
clientId: rootGetters['user/getRole'].uuid,
containerType: 'resource',
Expand All @@ -971,21 +973,27 @@ const reportManager = {
recordId: reportOutput.id
})
.then(response => {
const { file_name, url } = response
requestUploadFile({
url,
file: reportOutput.output_stream
})
if (!isEmptyValue(file_name)) {
if (isDownload) {
const file = document.createElement('a')
file.href = `${config.adempiere.api.url}/resource/${file_name}`
file.download = `${reportName}`
file.target = '_blank'
file.click()
}
resolve(file_name)
}
fetch(url)
.then(responseBlob => responseBlob.blob())
.then(blob => {
const file = new File([blob], file_name, { type: mime_type })
const fileUrl = URL.createObjectURL(file)
fetch(response.url, {
method: 'PUT',
body: file
})
if (!isEmptyValue(response.file_name)) {
if (isDownload) {
const fileLink = document.createElement('a')
fileLink.href = fileUrl
fileLink.download = reportName
document.body.appendChild(fileLink)
fileLink.click()
document.body.removeChild(fileLink)
}
resolve(response.file_name)
}
})
})
.catch(error => {
showNotification({
Expand Down

0 comments on commit 94f00cf

Please sign in to comment.