Skip to content

Support Binary #670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/api/ADempiere/field/binary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Get entity with binary by identifier
* @param {string} tableName
* @param {string} recordUuid
*/
export function getResource({
uuid,
tableName
}) {
const { requestGetEntity } = require('@/api/ADempiere/persistence.js')

return requestGetEntity({
recordUuid: uuid,
tableName
})
}

/**
* Update an existing binary by id or uuid
* @param {string} tableName
* @param {string} recordUuid
* @param {object} binaryFile
*/
export function updateResource({
uuid,
tableName,
binaryFile
}) {
const { requestUpdateEntity } = require('@/api/ADempiere/persistence.js')

return requestUpdateEntity({
recordUuid: uuid,
tableName,
attributesList: binaryFile
})
}
56 changes: 55 additions & 1 deletion src/components/ADempiere/Field/FieldImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
action="https://jsonplaceholder.typicode.com/posts/"
:show-file-list="false"
:on-success="handleAvatarSuccess"
:on-change="handleChange"
:before-upload="beforeAvatarUpload"
:disabled="isDisabled"
:class="cssClassStyle"
Expand All @@ -15,10 +16,27 @@

<script>
import fieldMixin from '@/components/ADempiere/Field/mixin/mixinField.js'
import { getResource, updateResource } from '@/api/ADempiere/field/binary.js'

export default {
name: 'FieldImage',
mixins: [fieldMixin],
props: {
// receives the property that is an object with all the attributes
binary: {
type: Array,
default: () => []
}
},
data() {
return {
valuesImage: [{
identifier: 'undefined',
value: '',
isLoaded: true
}]
}
},
computed: {
cssClassStyle() {
let styleClass = ' custom-field-image '
Expand All @@ -29,10 +47,46 @@ export default {
}
},
methods: {
updateResource,
getResource,
handleChange(file, fileList) {
let message, type
this.binary.push({
columnName: this.metadata.columnName,
value: file
})
switch (file.status) {
case 'success':
message = 'succesful'
type = file.status
break
case 'ready':
message = 'loading'
type = 'loading'
break
case 'error':
message = file.status
type = file.status
break
}
this.$message({
type: type,
showClose: true,
message: this.$t('notifications.' + message)
})
updateResource({
uuid: this.metadata.recordUuid,
tableName: this.$route.params.tableName,
binaryFile: this.binary
})
},
handleAvatarSuccess(res, file) {
this.value = URL.createObjectURL(file.raw)
// TODO: define one method to control change value
this.handleFieldChange({ value: this.value })
getResource({
uuid: this.metadata.recordUuid,
tableName: this.$route.params.tableName
})
},
beforeAvatarUpload(file) {
const isJPG = file.type === 'image/jpeg'
Expand Down