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

Commit

Permalink
Support Attachment Resource (#2549)
Browse files Browse the repository at this point in the history
  • Loading branch information
elsiosanchez authored Jul 31, 2024
1 parent de3e251 commit b6b48d2
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 109 deletions.
85 changes: 45 additions & 40 deletions src/components/ADempiere/FieldDefinition/FieldImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<file-info
:image-id="value"
:resource-name="displayedValue"
:info-image="infoImage"
class="popover-info"
/>

Expand All @@ -74,6 +75,7 @@
:resource-name="displayedValue"
:file="fileResource"
:file-name="displayedValue"
:file-url="infoImage.name"
class="popover-info"
/>

Expand All @@ -92,7 +94,7 @@
icon="el-icon-delete"
class="button-manage-file"
plain
:disabled="isDisabled || isEmptyValue(value)"
:disabled="isEmptyValue(infoImage)"
@click="handleRemove()"
/>

Expand Down Expand Up @@ -124,7 +126,7 @@
<el-button
class="button-manage-file-svg"
plain
:disabled="!isDownload"
:disabled="isEmptyValue(infoImage)"
@click="handleDownload()"
>
<svg-icon
Expand Down Expand Up @@ -178,15 +180,15 @@ import {
requestListResources,
requestShareResources,
requestDeleteResources,
requestSetResourceReference,
requestDeleteResourceReference
requestSetResourceReference
} from '@/api/ADempiere/file-management/resource-reference.ts'

// Utils and Helper Methods
import { isEmptyValue } from '@/utils/ADempiere/valueUtils'
import { getToken } from '@/utils/auth'
import { pathImageWindows } from '@/utils/ADempiere/resource'
import { showMessage } from '@/utils/ADempiere/notification'
import { refreshRecord } from '@/utils/ADempiere/dictionary/window'

export default {
name: 'FieldImage',
Expand Down Expand Up @@ -269,8 +271,9 @@ export default {
if (!isEmptyValue(key_columns)) return this.currentRecord[key_columns[0]]
return 1
},
clientId() {
return this.$store.getters.getSessionContextClientId
clientUuid() {
const { client } = this.$store.getters['user/getRole']
return client.uuid
},
tableNameImage() {
return this.currentTab.table_name.toLowerCase()
Expand All @@ -283,7 +286,7 @@ export default {
},
pathImage() {
return pathImageWindows({
clientId: this.clientId,
clientId: this.clientUuid,
tableName: this.tableNameImage,
recordId: this.recordId,
columnName: this.columnNameImage,
Expand All @@ -303,6 +306,7 @@ export default {
},

mounted() {
this.getListResources()
this.valideImage()
},
updated() {
Expand Down Expand Up @@ -420,8 +424,8 @@ export default {
return new Promise((resolve, reject) => {
this.isLoadImageUpload = true
requestPresignedUrl({
clientId: this.clientId,
containerType: 'window',
clientId: this.clientUuid,
containerType: 'attachment',
columnName: this.columnNameImage,
fileName: this.nameImage,
recordId: this.recordId,
Expand All @@ -433,6 +437,7 @@ export default {
method: 'PUT',
body: file
}).then(() => {
this.getListResources()
setTimeout(() => {
this.imageSourceSmall = this.pathImage
this.valideImage(file)
Expand All @@ -457,14 +462,14 @@ export default {
* Handle Download image
*/
async handleDownload() {
const link = document.createElement('a')
link.target = '_blank'
link.href = this.imageSourceSmall + '?f=' + Date.now()
link.download = this.displayedValue
link.style.display = 'none'
link.click()
document.body.appendChild(link)
document.body.removeChild(link)
const {
name
} = this.infoImage
const file = document.createElement('a')
file.href = `${config.adempiere.resource.url}${name}`
file.download = `${name}`
file.target = '_blank'
file.click()
return
},

Expand All @@ -489,48 +494,48 @@ export default {
* Handle Removeya esta actualizado solop
*/
handleRemove() {
if (this.isDisabled) {
return
}
const resourceName = this.displayedValue
if (isEmptyValue(resourceName)) {
const { name } = this.infoImage
if (isEmptyValue(name)) {
this.getListResources()
return
}
requestDeleteResourceReference({
resourceName,
imageId: this.value
}).then(() => {
this.clearValues()
})

const {
id,
parentUuid,
containerUuid
} = this.currentTab

requestDeleteResources({
fileName: resourceName
fileName: name
})
.then(() => {
this.clearValues()
refreshRecord.refreshRecord({
parentUuid,
containerUuid,
tabId: id,
recordId: this.recordId
})
})
},

getListResources() {
return new Promise((resolve, reject) => {
const clientId = this.$store.getters.getSessionContextClientId
const { action_id } = this.$route.meta
const { table_name } = this.currentTab
requestListResources({
clientId: clientId,
containerId: action_id,
containerType: 'resource',
clientId: this.clientUuid,
// containerId: action_id,
containerType: 'attachment',
columnName: this.metadata.columnName,
recordId: this.recordId,
tableName: table_name
})
.then(response => {
let resource
let image = ''
const resources = this.sortResource(response.resources)
const resources = response.resources.find(resource => resource.name.includes(this.columnNameImage))
if (!this.isEmptyValue(resources)) {
resource = resources[resources.length - 1]
image = resource.name
this.infoImage = resource
image = resources.name
this.infoImage = resources
}
resolve(image)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,13 @@ import {
ref
} from '@vue/composition-api'

// API Request Methods
import {
requestShareResources
} from '@/api/ADempiere/file-management/resource-reference.ts'

// Utils and Helper Methods
import {
isEmptyValue
} from '@/utils/ADempiere/valueUtils'
import { copyToClipboard } from '@/utils/ADempiere/coreUtils.js'
// import { formatFileSize } from '@/utils/ADempiere/resource.js'
import { config } from '@/utils/ADempiere/config'

export default defineComponent({
name: 'FileShare',
Expand Down Expand Up @@ -132,6 +128,10 @@ export default defineComponent({
fileName: {
type: String,
default: undefined
},
fileUrl: {
type: String,
default: undefined
}
},

Expand All @@ -141,17 +141,7 @@ export default defineComponent({
const isShowed = ref(false)
const validTime = ref(3600)
function loadData() {
isLoading.value = true
requestShareResources({
fileName: props.resourceName,
seconds: validTime.value
})
.then(response => {
linkShare.value = response
})
.finally(() => {
isLoading.value = false
})
linkShare.value = config.adempiere.resource.url + props.fileUrl
}

function copyValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import { defineComponent, computed, ref } from '@vue/composition-api'

import router from '@/router'
// import router from '@/router'
import store from '@/store'

// API Request Methods
Expand All @@ -28,8 +28,7 @@ import {
} from '@/api/ADempiere/user-interface/component/resource'
import {
requestDeleteResourceReference,
requestDeleteResources,
requestShareResources
requestDeleteResources
} from '@/api/ADempiere/file-management/resource-reference.ts'

// Components and Mixins
Expand Down Expand Up @@ -169,12 +168,10 @@ export default defineComponent({
fileName: file.fullName
})
.then(() => {
const clientId = store.getters.getSessionContextClientId
const { action_id, type } = router.app._route.meta
const { client } = store.getters['user/getRole']
store.dispatch('getAttachmentFromServer', {
containerType: type,
clientId: clientId,
containerId: action_id,
containerType: 'attachment',
clientId: client.uuid,
recordId: props.recordId,
tableName: props.tableName
})
Expand Down Expand Up @@ -210,39 +207,43 @@ export default defineComponent({
* @param {Boolean} isDownload
*/
const handleDownload = async(file, isDownload = true) => {
const imageURL = config.adempiere.resource.url + file.fullName
if (!isEmptyValue(file.content_type) && 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()
const linkImage = document.createElement('a')
linkImage.href = config.adempiere.resource.url + file.fullName
linkImage.download = `${file.fullName}`
linkImage.target = '_blank'
linkImage.click()
return
}
const link = document.createElement('a')
const imageURL = config.adempiere.resource.url + file.file_name
link.href = imageURL
link.download = file.name
link.download = file.fullName
link.click()
// const file = document.createElement('a')
// file.href = `${config.adempiere.resource.url}${file.fullName}`
// file.download = `${file.name}`
// file.target = '_blank'
// file.click()
return
}

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

/**
* Get Surce File
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@

<el-descriptions v-else class="margin-top" :column="1" border>
<el-descriptions-item :label="$t('component.attachment.fileName')">
{{ resourceReference.name }}
{{ infoImage.name }}
</el-descriptions-item>
<el-descriptions-item :label="$t('component.attachment.fileSize')">
{{ formatFileSize(resourceReference.file_size) }}
{{ formatFileSize(infoImage.size) }}
</el-descriptions-item>
<el-descriptions-item :label="$t('component.attachment.fileFormat')">
{{ resourceReference.content_type }}
{{ infoImage.content_type }}
</el-descriptions-item>

<el-descriptions-item :label="$t('component.attachment.description')">
<!-- <el-descriptions-item :label="$t('component.attachment.description')">
{{ resourceReference.description }}
</el-descriptions-item>
<el-descriptions-item :label="$t('component.attachment.message')">
</el-descriptions-item> -->
<!-- <el-descriptions-item :label="$t('component.attachment.message')">
{{ resourceReference.text_message }}
</el-descriptions-item>
</el-descriptions-item> -->
</el-descriptions>

<el-button
Expand Down Expand Up @@ -102,6 +102,10 @@ export default defineComponent({
isEditDescription: {
type: Boolean,
default: false
},
infoImage: {
type: Object,
default: undefined
}
},

Expand Down
Loading

0 comments on commit b6b48d2

Please sign in to comment.