fix: Error render lookups fields without reference. (#207)

* fix: Error render lookups without reference.

* fix: Query and DirectQuery empty values.

* Corrections when cleaning the lookup.
pull/3759/head
EdwinBetanc0urt 2019-12-13 20:37:43 -04:00 committed by Yamel Senih
parent 101de06515
commit 2e036e2034
2 changed files with 52 additions and 24 deletions

View File

@ -25,6 +25,17 @@
<script> <script>
import { fieldMixin } from '@/components/ADempiere/Field/FieldMixin' import { fieldMixin } from '@/components/ADempiere/Field/FieldMixin'
/**
* This component is a lookup type field, use as a replacement for fields:
* - Reference List
* - Table List
* - Table Direct
*
* TODO: ALL: Although in the future these will have different components, and
* are currently not supported is also displayed as a substitute for fields:
* - Locator (WH)
* - Search Field
*/
export default { export default {
name: 'FieldSelect', name: 'FieldSelect',
mixins: [fieldMixin], mixins: [fieldMixin],
@ -36,6 +47,7 @@ export default {
key: undefined key: undefined
}], }],
blanckOption: { blanckOption: {
// label with '' value is assumed to be undefined non-existent
label: ' ', label: ' ',
key: undefined key: undefined
} }
@ -49,6 +61,9 @@ export default {
return this.$store.state.app.device === 'mobile' return this.$store.state.app.device === 'mobile'
}, },
getterLookupItem() { getterLookupItem() {
if (this.isEmptyValue(this.metadata.reference.directQuery)) {
return this.blanckOption
}
return this.$store.getters.getLookupItem({ return this.$store.getters.getLookupItem({
parentUuid: this.metadata.parentUuid, parentUuid: this.metadata.parentUuid,
containerUuid: this.metadata.containerUuid, containerUuid: this.metadata.containerUuid,
@ -58,6 +73,9 @@ export default {
}) })
}, },
getterLookupList() { getterLookupList() {
if (this.isEmptyValue(this.metadata.reference.query)) {
return this.blanckOption
}
return this.$store.getters.getLookupList({ return this.$store.getters.getLookupList({
parentUuid: this.metadata.parentUuid, parentUuid: this.metadata.parentUuid,
containerUuid: this.metadata.containerUuid, containerUuid: this.metadata.containerUuid,
@ -66,7 +84,7 @@ export default {
}) })
}, },
getterLookupAll() { getterLookupAll() {
var allOptions = this.$store.getters.getLookupAll({ const allOptions = this.$store.getters.getLookupAll({
parentUuid: this.metadata.parentUuid, parentUuid: this.metadata.parentUuid,
containerUuid: this.metadata.containerUuid, containerUuid: this.metadata.containerUuid,
query: this.metadata.reference.query, query: this.metadata.reference.query,
@ -74,7 +92,7 @@ export default {
tableName: this.metadata.reference.tableName, tableName: this.metadata.reference.tableName,
value: this.value value: this.value
}) })
if (allOptions.length && !allOptions[0].key) { if (allOptions && ((allOptions.length && allOptions[0].key !== this.blanckOption.key) || !allOptions.length)) {
allOptions.unshift(this.blanckOption) allOptions.unshift(this.blanckOption)
} }
return allOptions return allOptions
@ -145,6 +163,9 @@ export default {
return selected return selected
}, },
async getDataLookupItem() { async getDataLookupItem() {
if (this.isEmptyValue(this.metadata.reference.directQuery)) {
return
}
this.isLoading = true this.isLoading = true
this.$store.dispatch('getLookupItemFromServer', { this.$store.dispatch('getLookupItemFromServer', {
parentUuid: this.metadata.parentUuid, parentUuid: this.metadata.parentUuid,
@ -153,12 +174,12 @@ export default {
directQuery: this.metadata.reference.directQuery, directQuery: this.metadata.reference.directQuery,
value: this.metadata.value value: this.metadata.value
}) })
.then(response => { .then(responseLookupItem => {
if (this.isPanelWindow) { if (this.isPanelWindow) {
this.$store.dispatch('notifyFieldChangeDisplayColumn', { this.$store.dispatch('notifyFieldChangeDisplayColumn', {
containerUuid: this.metadata.containerUuid, containerUuid: this.metadata.containerUuid,
columnName: this.metadata.columnName, columnName: this.metadata.columnName,
displayColumn: response.label displayColumn: responseLookupItem.label
}) })
} }
this.options = this.getterLookupAll this.options = this.getterLookupAll
@ -175,12 +196,16 @@ export default {
*/ */
getDataLookupList(showList) { getDataLookupList(showList) {
if (showList) { if (showList) {
// TODO: Evaluate if length = 1 and this element key = blanckOption
if (this.getterLookupList.length === 0) { if (this.getterLookupList.length === 0) {
this.remoteMethod() this.remoteMethod()
} }
} }
}, },
remoteMethod() { remoteMethod() {
if (this.isEmptyValue(this.metadata.reference.query)) {
return
}
this.isLoading = true this.isLoading = true
this.$store.dispatch('getLookupListFromServer', { this.$store.dispatch('getLookupListFromServer', {
parentUuid: this.metadata.parentUuid, parentUuid: this.metadata.parentUuid,
@ -188,13 +213,8 @@ export default {
tableName: this.metadata.reference.tableName, tableName: this.metadata.reference.tableName,
query: this.metadata.reference.query query: this.metadata.reference.query
}) })
.then(response => { .then(responseLookupList => {
const list = this.getterLookupAll.filter(options => { this.options = this.getterLookupAll
if (options.key !== undefined) {
return options
}
})
this.options = list
}) })
.finally(() => { .finally(() => {
this.isLoading = false this.isLoading = false
@ -210,6 +230,7 @@ export default {
value: this.metadata.value value: this.metadata.value
}) })
// TODO: Evaluate if is number -1 or string '' (or default value) // TODO: Evaluate if is number -1 or string '' (or default value)
this.options = this.getterLookupAll
this.value = this.blanckOption.key this.value = this.blanckOption.key
} }
} }

View File

@ -21,7 +21,11 @@ const lookup = {
actions: { actions: {
getLookupItemFromServer({ commit, rootGetters }, parameters) { getLookupItemFromServer({ commit, rootGetters }, parameters) {
const { parentUuid, containerUuid, value, tableName, directQuery } = parameters const { parentUuid, containerUuid, value, tableName, directQuery } = parameters
var parsedDirectQuery = directQuery if (isEmptyValue(directQuery)) {
return
}
let parsedDirectQuery = directQuery
if (parsedDirectQuery.includes('@')) { if (parsedDirectQuery.includes('@')) {
parsedDirectQuery = parseContext({ parsedDirectQuery = parseContext({
parentUuid: parentUuid, parentUuid: parentUuid,
@ -38,7 +42,7 @@ const lookup = {
.then(response => { .then(response => {
const map = response.getValuesMap() const map = response.getValuesMap()
const label = convertValueFromGRPC(map.get('DisplayColumn')) const label = convertValueFromGRPC(map.get('DisplayColumn'))
var option = { const option = {
label: isEmptyValue(label) ? ' ' : label, label: isEmptyValue(label) ? ' ' : label,
// key: convertValueFromGRPC(map.get('KeyColumn')) // key: convertValueFromGRPC(map.get('KeyColumn'))
key: value key: value
@ -64,7 +68,10 @@ const lookup = {
*/ */
getLookupListFromServer({ commit, rootGetters }, parameters) { getLookupListFromServer({ commit, rootGetters }, parameters) {
const { parentUuid, containerUuid, tableName, query } = parameters const { parentUuid, containerUuid, tableName, query } = parameters
var parsedQuery = query if (isEmptyValue(query)) {
return
}
let parsedQuery = query
if (parsedQuery.includes('@')) { if (parsedQuery.includes('@')) {
parsedQuery = parseContext({ parsedQuery = parseContext({
parentUuid: parentUuid, parentUuid: parentUuid,
@ -79,7 +86,7 @@ const lookup = {
}) })
.then(response => { .then(response => {
const recordList = response.getRecordsList() const recordList = response.getRecordsList()
var options = [] const options = []
recordList.forEach(element => { recordList.forEach(element => {
const map = element.getValuesMap() const map = element.getValuesMap()
const name = convertValueFromGRPC(map.get('DisplayColumn')) const name = convertValueFromGRPC(map.get('DisplayColumn'))
@ -106,8 +113,8 @@ const lookup = {
deleteLookupList({ commit, state }, params) { deleteLookupList({ commit, state }, params) {
const { parentUuid, containerUuid, tableName, query, directQuery, value } = params const { parentUuid, containerUuid, tableName, query, directQuery, value } = params
var parsedDirectQuery = directQuery let parsedDirectQuery = directQuery
if (parsedDirectQuery.includes('@')) { if (directQuery && parsedDirectQuery.includes('@')) {
parsedDirectQuery = parseContext({ parsedDirectQuery = parseContext({
parentUuid: parentUuid, parentUuid: parentUuid,
containerUuid: containerUuid, containerUuid: containerUuid,
@ -121,8 +128,8 @@ const lookup = {
itemLookup.roleUuid !== getCurrentRole() itemLookup.roleUuid !== getCurrentRole()
}) })
var parsedQuery = query let parsedQuery = query
if (parsedQuery.includes('@')) { if (parsedQuery && parsedQuery.includes('@')) {
parsedQuery = parseContext({ parsedQuery = parseContext({
parentUuid: parentUuid, parentUuid: parentUuid,
containerUuid: containerUuid, containerUuid: containerUuid,
@ -142,8 +149,8 @@ const lookup = {
}, },
getters: { getters: {
getLookupItem: (state, getters, rootState, rootGetters) => (params) => { getLookupItem: (state, getters, rootState, rootGetters) => (params) => {
var parsedDirectQuery = params.directQuery let parsedDirectQuery = params.directQuery
if (parsedDirectQuery.includes('@')) { if (parsedDirectQuery && parsedDirectQuery.includes('@')) {
parsedDirectQuery = parseContext({ parsedDirectQuery = parseContext({
parentUuid: params.parentUuid, parentUuid: params.parentUuid,
containerUuid: params.containerUuid, containerUuid: params.containerUuid,
@ -163,8 +170,8 @@ const lookup = {
return undefined return undefined
}, },
getLookupList: (state, getters, rootState, rootGetters) => (params) => { getLookupList: (state, getters, rootState, rootGetters) => (params) => {
var parsedQuery = params.query let parsedQuery = params.query
if (parsedQuery.includes('@')) { if (parsedQuery && parsedQuery.includes('@')) {
parsedQuery = parseContext({ parsedQuery = parseContext({
parentUuid: params.parentUuid, parentUuid: params.parentUuid,
containerUuid: params.containerUuid, containerUuid: params.containerUuid,
@ -192,7 +199,7 @@ const lookup = {
*/ */
getLookupAll: (state, getters, rootState, rootGetters) => (parameters) => { getLookupAll: (state, getters, rootState, rootGetters) => (parameters) => {
const item = getters.getLookupItem(parameters) const item = getters.getLookupItem(parameters)
var list = getters.getLookupList(parameters) const list = getters.getLookupList(parameters)
if (item && !list.find(itemLookup => itemLookup.key === item.key)) { if (item && !list.find(itemLookup => itemLookup.key === item.key)) {
list.push(item) list.push(item)
} }