Skip to content

Commit

Permalink
Support Attachment (PanJiaChen#1933)
Browse files Browse the repository at this point in the history
* Support Attachment

* minimal changes
  • Loading branch information
elsiosanchez authored Feb 19, 2024
1 parent 584903a commit 3135fdd
Show file tree
Hide file tree
Showing 7 changed files with 371 additions and 185 deletions.
45 changes: 25 additions & 20 deletions src/components/ADempiere/FieldDefinition/FieldImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
:image-id="value"
:resource-name="displayedValue"
:file="fileResource"
:file-name="displayedValue"
class="popover-info"
/>

Expand Down Expand Up @@ -162,6 +163,7 @@ import { RESOURCE_TYPE_IMAGE } from '@/utils/ADempiere/resource'
// API Request Methods
import {
requestPresignedUrl,
requestShareResources,
requestDeleteResources,
requestSetResourceReference,
requestDeleteResourceReference
Expand Down Expand Up @@ -408,27 +410,30 @@ export default {
* Handle Download image
*/
async handleDownload() {
if (!this.isDownload) {
return
}
const link = document.createElement('a')
link.target = '_blank'
link.href = this.urlDownload({ fileName: this.displayedValue })
link.download = this.displayedValue
link.style.display = 'none'
link.click()
return
},

// const link = await getImagePath({
// file: this.displayedValue
// })
// const imagen = await fetch(this.imageSourceSmall)
// const imagenblob = await imagen.blob()
// const imageURL = URL.createObjectURL(imagenblob)
// const link = document.createElement('a')
// let link
// link.href = ``
// link.download = `http://192.168.5.101:7879/api/resources/${this.displayedValue}`
// link.click()
// const imagen = document.querySelector(`[src="http://192.168.5.101:7879/api/resources/${this.displayedValue}"]`)
// const link = document.createElement('a')
// link.setAttribute('href', imagen.src)
// link.setAttribute('download', `${this.displayedValue}`)
// document.body.appendChild(link)
// link.click()
urlDownload({
fileName
}) {
return new Promise((resolve, reject) => {
requestShareResources({
fileName,
seconds: 3600
})
.then(response => {
resolve(response)
})
.catch(() => {
reject('')
})
})
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ along with this program. If not, see <https:www.gnu.org/licenses/>.
<template>
<el-popover
v-model="isShowed"
:title="$t('component.attachment.share.title') + ' ' + resourceName"
:title="$t('component.attachment.share.title') + ' ' + fileName"
placement="bottom"
trigger="click"
width="550"
Expand All @@ -32,19 +32,20 @@ along with this program. If not, see <https:www.gnu.org/licenses/>.
{{ $t('component.attachment.share.timeText') }}
</b>
</p>
<el-radio-group
v-model="validTime"
@change="changeTIme"
>
<el-radio :label="3600">1 {{ ' ' + $t('component.attachment.share.time.hour') }}</el-radio>
<el-radio :label="21600">6 {{ ' ' + $t('component.attachment.share.time.hours') }}</el-radio>
<el-radio :label="86400">1 {{ ' ' + $t('component.attachment.share.time.day') }}</el-radio>
<el-radio :label="259200">3 {{ ' ' + $t('component.attachment.share.time.days') }}</el-radio>
<el-radio :label="604800">7 {{ ' ' + $t('component.attachment.share.time.days') }}</el-radio>
</el-radio-group>
<p>
<el-radio-group
v-model="validTime"
@change="changeTIme"
>
<el-radio :label="3600">1 {{ ' ' + $t('component.attachment.share.time.hour') }}</el-radio>
<el-radio :label="21600">6 {{ ' ' + $t('component.attachment.share.time.hours') }}</el-radio>
<el-radio :label="86400">1 {{ ' ' + $t('component.attachment.share.time.day') }}</el-radio>
<el-radio :label="259200">3 {{ ' ' + $t('component.attachment.share.time.days') }}</el-radio>
<el-radio :label="604800">7 {{ ' ' + $t('component.attachment.share.time.days') }}</el-radio>
</el-radio-group>
</p>
<el-input
v-model="linkShare"
size="small"
disabled
>
<!-- <template slot="prepend"> -->
Expand Down Expand Up @@ -140,16 +141,12 @@ export default defineComponent({
const isShowed = ref(false)
const validTime = ref(3600)
function loadData() {
console.log({
file: props.file
})
isLoading.value = true
requestShareResources({
fileName: props.resourceName,
seconds: validTime.value
})
.then(response => {
console.log({ response })
linkShare.value = response
})
.finally(() => {
Expand All @@ -169,7 +166,6 @@ export default defineComponent({
}

function changeTIme(params) {
console.log({ params })
loadData()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import {
sendAttachmentDescriptionHeader
} from '@/api/ADempiere/user-interface/component/resource'
import {
requestDeleteResourceReference
requestDeleteResourceReference,
requestDeleteResources,
requestShareResources
} from '@/api/ADempiere/file-management/resource-reference.ts'
import {
requestGetResource
Expand All @@ -38,25 +40,30 @@ import ListView from './listView.vue'
import LoadingView from '@/components/ADempiere/LoadingView/index.vue'
import UploadResource from './uploadResource.vue'
import PanelFooter from '@/components/ADempiere/PanelFooter/index.vue'
import FileInfo from '@/components/ADempiere/PanelInfo/Component/AttachmentManager/fileInfo'
import FileShare from '@/components/ADempiere/PanelInfo/Component/AttachmentManager/FileShare'

// Utils and Helper Methods
import { isEmptyValue } from '@/utils/ADempiere/valueUtils'
import { showMessage } from '@/utils/ADempiere/notification.js'
import {
buildLinkHref,
// buildLinkHref,
formatFileSize,
getImageFromContentType
} from '@/utils/ADempiere/resource.js'
import { config } from '@/utils/ADempiere/config'

export default defineComponent({
name: 'AttachmentManager',

components: {
FileRender,
ListView,
UploadResource,
LoadingView,
PanelFooter,
UploadResource
FileRender,
FileShare,
FileInfo,
ListView
},

props: {
Expand All @@ -68,6 +75,14 @@ export default defineComponent({
type: Object,
default: () => {}
},
containerUuid: {
type: String,
default: ''
},
parentUuid: {
type: String,
default: ''
},
recordId: {
type: Number,
default: 0
Expand Down Expand Up @@ -154,12 +169,16 @@ export default defineComponent({
const handleRemove = (file) => {
requestDeleteResourceReference({
id: file.id,
attachmenId: file.id,
resourceName: file.file_name
}).then(() => {
const resourceReferencesList = attachmentList.value.filter(resourceReference => {
return resourceReference.uuid !== file.uuid ||
resourceReference.file_name !== file.file_name
})
requestDeleteResources({
fileName: file.file_name
})
attachmentList.value = resourceReferencesList
})
}
Expand All @@ -182,27 +201,41 @@ export default defineComponent({
* @param {Boolean} isDownload
*/
const handleDownload = async(file, isDownload = true) => {
// let link
if (file.content_type.includes('image')) {
const link = document.createElement('a')
link.target = '_blank'
link.href = urlDownload({ fileName: file.name })
link.download = this.displayedValue
link.style.display = 'none'
link.click()
return
}
// if (file.content_type.includes('image')) {
// const imagen = await fetch(file.src)
// const imagenblob = await imagen.blob()
// const imageURL = URL.createObjectURL(imagenblob)
// link = document.createElement('a')
// link.href = imageURL
// link.download = file.name
// link.click()
// return
// }
requestGetResource({
id: file.id,
resourceName: file.valid_file_name
}).then(response => {
buildLinkHref({
fileName: file.name,
mimeType: file.content_type,
outputStream: response, // response.data
isDownload: true
const link = document.createElement('a')
const imageURL = config.adempiere.resource.url + '/' + file.file_name
link.href = imageURL
link.download = file.name
link.click()
return
}

function urlDownload({
fileName
}) {
return new Promise((resolve, reject) => {
requestShareResources({
fileName,
seconds: 3600
})
.then(response => {
resolve(response)
})
.catch(() => {
reject('')
})
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
:is-selectable="isSelectable"
:is-loading="isLoading"
:container-manager="containerManager"
:container-uuid="containerUuid"
:parent-uuid="parentUuid"
/>
</template>

Expand All @@ -50,6 +52,14 @@ export default defineComponent({
type: Object,
default: () => {}
},
containerUuid: {
type: String,
default: ''
},
parentUuid: {
type: String,
default: ''
},
recordUuid: {
type: String,
default: ''
Expand Down
Loading

0 comments on commit 3135fdd

Please sign in to comment.