From b6b48d2f1cfe79aed731e46df08bbb3330b4b72f Mon Sep 17 00:00:00 2001
From: Elsio Sanchez <45974454+elsiosanchez@users.noreply.github.com>
Date: Wed, 31 Jul 2024 19:42:10 -0400
Subject: [PATCH] Support Attachment Resource (#2549)
---
.../ADempiere/FieldDefinition/FieldImage.vue | 85 ++++++++++---------
.../Component/AttachmentManager/FileShare.vue | 22 ++---
.../Component/AttachmentManager/attachment.js | 65 +++++++-------
.../Component/AttachmentManager/fileInfo.vue | 18 ++--
.../AttachmentManager/modeDesktop.vue | 9 +-
src/components/ADempiere/TabManager/index.vue | 11 ++-
.../modules/ADempiere/attachmentManager.js | 3 +-
.../ADempiere/dictionary/window/index.js | 4 +-
src/utils/ADempiere/resource.js | 2 +-
9 files changed, 110 insertions(+), 109 deletions(-)
diff --git a/src/components/ADempiere/FieldDefinition/FieldImage.vue b/src/components/ADempiere/FieldDefinition/FieldImage.vue
index 32da669420..661c0d3661 100644
--- a/src/components/ADempiere/FieldDefinition/FieldImage.vue
+++ b/src/components/ADempiere/FieldDefinition/FieldImage.vue
@@ -66,6 +66,7 @@
@@ -74,6 +75,7 @@
:resource-name="displayedValue"
:file="fileResource"
:file-name="displayedValue"
+ :file-url="infoImage.name"
class="popover-info"
/>
@@ -92,7 +94,7 @@
icon="el-icon-delete"
class="button-manage-file"
plain
- :disabled="isDisabled || isEmptyValue(value)"
+ :disabled="isEmptyValue(infoImage)"
@click="handleRemove()"
/>
@@ -124,7 +126,7 @@
{
this.isLoadImageUpload = true
requestPresignedUrl({
- clientId: this.clientId,
- containerType: 'window',
+ clientId: this.clientUuid,
+ containerType: 'attachment',
columnName: this.columnNameImage,
fileName: this.nameImage,
recordId: this.recordId,
@@ -433,6 +437,7 @@ export default {
method: 'PUT',
body: file
}).then(() => {
+ this.getListResources()
setTimeout(() => {
this.imageSourceSmall = this.pathImage
this.valideImage(file)
@@ -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
},
@@ -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)
})
diff --git a/src/components/ADempiere/PanelInfo/Component/AttachmentManager/FileShare.vue b/src/components/ADempiere/PanelInfo/Component/AttachmentManager/FileShare.vue
index c60d4d6d15..a98211ba77 100644
--- a/src/components/ADempiere/PanelInfo/Component/AttachmentManager/FileShare.vue
+++ b/src/components/ADempiere/PanelInfo/Component/AttachmentManager/FileShare.vue
@@ -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',
@@ -132,6 +128,10 @@ export default defineComponent({
fileName: {
type: String,
default: undefined
+ },
+ fileUrl: {
+ type: String,
+ default: undefined
}
},
@@ -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() {
diff --git a/src/components/ADempiere/PanelInfo/Component/AttachmentManager/attachment.js b/src/components/ADempiere/PanelInfo/Component/AttachmentManager/attachment.js
index 81aaa4598b..bc2e4cbf8e 100644
--- a/src/components/ADempiere/PanelInfo/Component/AttachmentManager/attachment.js
+++ b/src/components/ADempiere/PanelInfo/Component/AttachmentManager/attachment.js
@@ -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
@@ -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
@@ -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
})
@@ -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
diff --git a/src/components/ADempiere/PanelInfo/Component/AttachmentManager/fileInfo.vue b/src/components/ADempiere/PanelInfo/Component/AttachmentManager/fileInfo.vue
index ba52e51646..797defa871 100644
--- a/src/components/ADempiere/PanelInfo/Component/AttachmentManager/fileInfo.vue
+++ b/src/components/ADempiere/PanelInfo/Component/AttachmentManager/fileInfo.vue
@@ -26,21 +26,21 @@
- {{ resourceReference.name }}
+ {{ infoImage.name }}
- {{ formatFileSize(resourceReference.file_size) }}
+ {{ formatFileSize(infoImage.size) }}
- {{ resourceReference.content_type }}
+ {{ infoImage.content_type }}
-
+
+
- {{ formatFileSize(file.file_size) }}
+ {{ formatFileSize(file.size) }}
{{ file.content_type }}
-
- {{ file.description }}
-
-
- {{ file.text_message }}
-
{
+ const { client } = store.getters['user/getRole']
+ return client.uuid
+ })
+
const isShowedTabs = computed(() => {
const storedWindow = store.getters.getStoredWindow(props.parentUuid)
return storedWindow.isShowedTabsParent
@@ -815,9 +820,8 @@ export default defineComponent({
requestListResources({
recordId: currentRecordId.value,
tableName: currentTabTableName.value,
- containerId: router.app._route.meta.action_id,
- clientId: store.getters.getSessionContextClientId,
- containerType: 'window'
+ clientId: clientUuid.value,
+ containerType: 'attachment'
})
.then(response => {
countAttachment.value = response.resources.length
@@ -929,6 +933,7 @@ export default defineComponent({
tableHeaders,
recordsList,
drawer,
+ clientUuid,
currentRecordLogs,
openPanelInfo,
showChatAvailable,
diff --git a/src/store/modules/ADempiere/attachmentManager.js b/src/store/modules/ADempiere/attachmentManager.js
index 89e0ae41eb..9dcc7035d6 100644
--- a/src/store/modules/ADempiere/attachmentManager.js
+++ b/src/store/modules/ADempiere/attachmentManager.js
@@ -57,6 +57,7 @@ const attachment = {
// if (isEmptyValue(tableName) && (isEmptyValue(recordId))) {
// return
// }
+ const { client } = getters['user/getRole']
if (isEmptyValue(clientId)) {
clientId = getters.getSessionContextClientId
}
@@ -64,7 +65,7 @@ const attachment = {
return requestListResources({
recordId,
tableName,
- clientId,
+ clientId: client.uuid,
containerId,
containerType
})
diff --git a/src/utils/ADempiere/dictionary/window/index.js b/src/utils/ADempiere/dictionary/window/index.js
index c4772d8ff8..562324044b 100644
--- a/src/utils/ADempiere/dictionary/window/index.js
+++ b/src/utils/ADempiere/dictionary/window/index.js
@@ -2043,8 +2043,8 @@ export const containerManager = {
recordId,
tableName,
clientId,
- containerId,
- containerType: 'window'
+ // containerId,
+ containerType: 'attachment'
})
},
searchWorkflowHistory({ tableName, recordId, recordUuid, containerUuid }) {
diff --git a/src/utils/ADempiere/resource.js b/src/utils/ADempiere/resource.js
index 71f3d5bef2..4a7f06eb5e 100644
--- a/src/utils/ADempiere/resource.js
+++ b/src/utils/ADempiere/resource.js
@@ -442,5 +442,5 @@ export function pathImageWindows({
resourceName
}) {
const url = config.adempiere.resource.url
- return `${url}${clientId}/client/window/${tableName}/${recordId}/${columnName}/${resourceName}`
+ return `${url}${clientId}/client/attachment/${tableName}/${recordId}/${columnName}/${resourceName}`
}