diff --git a/src/api/ADempiere/file-management/resources.ts b/src/api/ADempiere/file-management/resources.ts new file mode 100644 index 0000000000..f0bf1c3c39 --- /dev/null +++ b/src/api/ADempiere/file-management/resources.ts @@ -0,0 +1,45 @@ +/** + * ADempiere-Vue (Frontend) for ADempiere ERP & CRM Smart Business Solution + * Copyright (C) 2018-Present E.R.P. Consultores y Asociados, C.A. www.erpya.com + * Contributor(s): Elsio Sanchez elsiosanchez15@outlook.com https://github.com/elsiosanchez + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// Get Instance for connection +import { request } from '@/utils/ADempiere/request' + +// Utils and Helper Methods +import { isEmptyValue } from '@/utils/ADempiere/valueUtils' + +/** + * Get resource + * @param {number} id + * @param {string} resourceName as fileName + * @returns {promise} + */ +export function requestGetResource({ + id, + // + resourceName +}) { + let path = `/file-management/resources/${id}` + if (isEmptyValue(resourceName)) { + path = `/file-management/resources/file-name/${resourceName}` + } + + return request({ + url: path, + method: 'get' + }) +} diff --git a/src/api/ADempiere/user-interface/component/resource.js b/src/api/ADempiere/user-interface/component/resource.js index c51dea6ba4..ff073db141 100644 --- a/src/api/ADempiere/user-interface/component/resource.js +++ b/src/api/ADempiere/user-interface/component/resource.js @@ -22,37 +22,6 @@ import { request } from '@/utils/ADempiere/request' // Constants import { config } from '@/utils/ADempiere/config' -// Download a resource from file name -export function requestResource({ resourceUuid, resourceName }, callBack = { - onData: () => {}, - onStatus: () => {}, - onEnd: () => {} -}) { - const { getResoursePath } = require('@/utils/ADempiere/resource.js') - const { urn } = getResoursePath({ - resourceUuid, - resourceName - }) - return request({ - url: urn, - method: 'get', - // responseType: 'arraybuffer', - baseURL: config.adempiere.resource.url - }) -} - -export function requestDownloadResource({ resourceUuid, resourceName }) { - return request({ - url: '/user-interface/component/resource/download', - method: 'get', - // responseType: 'arraybuffer', - params: { - resource_uuid: resourceUuid, - resource_name: resourceName - } - }) -} - /** * Get image with uri request * @param {string} file diff --git a/src/components/ADempiere/PanelInfo/Component/AttachmentManager/attachment.js b/src/components/ADempiere/PanelInfo/Component/AttachmentManager/attachment.js index 8573dd4844..a66b23e648 100644 --- a/src/components/ADempiere/PanelInfo/Component/AttachmentManager/attachment.js +++ b/src/components/ADempiere/PanelInfo/Component/AttachmentManager/attachment.js @@ -22,16 +22,19 @@ import store from '@/store' // API Request Methods import { - requestResource, sendAttachmentDescription, sendAttachmentDescriptionHeader } from '@/api/ADempiere/user-interface/component/resource' import { requestDeleteResourceReference } from '@/api/ADempiere/file-management/resource-reference.ts' +import { + requestGetResource +} from '@/api/ADempiere/file-management/resources.ts' // Components and Mixins import FileRender from '@/components/ADempiere/FileRender/index.vue' +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' @@ -42,7 +45,6 @@ import { showMessage } from '@/utils/ADempiere/notification.js' import { buildLinkHref, formatFileSize, - getImagePath, getImageFromContentType } from '@/utils/ADempiere/resource.js' @@ -51,6 +53,7 @@ export default defineComponent({ components: { FileRender, + ListView, LoadingView, PanelFooter, UploadResource @@ -115,9 +118,10 @@ export default defineComponent({ return [] } return storedResourcesList.map(element => { + const sourceFile = getSurceFile(element) return { ...element, - src: getSurceFile(element), + src: sourceFile, isShowMessage: false } }) @@ -178,21 +182,20 @@ export default defineComponent({ * @param {Boolean} isDownload */ const handleDownload = async(file, isDownload = true) => { - let link - 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 - } - - requestResource({ - resourceUuid: file.uuid, - resourceName: file.file_name + // let link + // 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, @@ -209,7 +212,7 @@ export default defineComponent({ */ function getSurceFile(file) { if (file.content_type.includes('image')) { - return getImageFromSource(file).uri + return getImageFromSource(file) } return getImageFromContentType({ contentType: file.content_type, @@ -221,13 +224,16 @@ export default defineComponent({ * Image From Source * @param {Object} file */ - const getImageFromSource = (file) => { - const image = getImagePath({ - file: file.file_name, - width: 900, - height: 500 + const getImageFromSource = async(file) => { + const bytes = await requestGetResource({ + id: file.id, + resourceName: file.valid_file_name }) - return image + + const base64_array = bytes.map(part => part.data) + const base64_string = base64_array.join('') + + return 'data:' + file.content_type + ';base64,' + base64_string } /** diff --git a/src/components/ADempiere/PanelInfo/Component/AttachmentManager/listView.vue b/src/components/ADempiere/PanelInfo/Component/AttachmentManager/listView.vue new file mode 100644 index 0000000000..5789adc641 --- /dev/null +++ b/src/components/ADempiere/PanelInfo/Component/AttachmentManager/listView.vue @@ -0,0 +1,165 @@ + + + + + diff --git a/src/components/ADempiere/PanelInfo/Component/AttachmentManager/modeDesktop.vue b/src/components/ADempiere/PanelInfo/Component/AttachmentManager/modeDesktop.vue index c9400ced31..4800c888c2 100644 --- a/src/components/ADempiere/PanelInfo/Component/AttachmentManager/modeDesktop.vue +++ b/src/components/ADempiere/PanelInfo/Component/AttachmentManager/modeDesktop.vue @@ -193,47 +193,14 @@ - - - -
- -
-
- - {{ file.name }} - -

- {{ file.name }} -
- {{ formatFileSize(file.file_size) }} -

- -
- -
-
-
-
+ +
+