fix: Lookup with -1 as default value. (#435)
parent
6c62dec4ad
commit
78e2c19468
|
@ -49,10 +49,11 @@ export default {
|
||||||
label: ' ',
|
label: ' ',
|
||||||
key: undefined
|
key: undefined
|
||||||
}],
|
}],
|
||||||
|
blankValues: [null, undefined, -1],
|
||||||
blankOption: {
|
blankOption: {
|
||||||
// label with '' value is assumed to be undefined non-existent
|
// label with '' value is assumed to be undefined non-existent
|
||||||
label: ' ',
|
label: ' ',
|
||||||
key: undefined || -1
|
key: undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -73,21 +74,10 @@ export default {
|
||||||
}
|
}
|
||||||
return styleClass
|
return styleClass
|
||||||
},
|
},
|
||||||
getterLookupItem() {
|
|
||||||
if (this.isEmptyValue(this.metadata.reference.directQuery)) {
|
|
||||||
return this.blankOption
|
|
||||||
}
|
|
||||||
return this.$store.getters.getLookupItem({
|
|
||||||
parentUuid: this.metadata.parentUuid,
|
|
||||||
containerUuid: this.metadata.containerUuid,
|
|
||||||
directQuery: this.metadata.reference.directQuery,
|
|
||||||
tableName: this.metadata.reference.tableName,
|
|
||||||
value: this.value
|
|
||||||
})
|
|
||||||
},
|
|
||||||
getterLookupList() {
|
getterLookupList() {
|
||||||
if (this.isEmptyValue(this.metadata.reference.query)) {
|
if (this.isEmptyValue(this.metadata.reference.query) ||
|
||||||
return this.blankOption
|
!this.metadata.displayed) {
|
||||||
|
return [this.blankOption]
|
||||||
}
|
}
|
||||||
return this.$store.getters.getLookupList({
|
return this.$store.getters.getLookupList({
|
||||||
parentUuid: this.metadata.parentUuid,
|
parentUuid: this.metadata.parentUuid,
|
||||||
|
@ -106,17 +96,11 @@ export default {
|
||||||
value: this.value
|
value: this.value
|
||||||
})
|
})
|
||||||
|
|
||||||
if (this.isEmptyValue(allOptions) || !this.blankOptionInfo.hasBlankOption) {
|
if (this.isEmptyValue(allOptions) || (allOptions.length &&
|
||||||
|
(!this.blankValues.includes(allOptions[0].key)))) {
|
||||||
allOptions.unshift(this.blankOption)
|
allOptions.unshift(this.blankOption)
|
||||||
}
|
}
|
||||||
return allOptions
|
return allOptions
|
||||||
},
|
|
||||||
blankOptionInfo() {
|
|
||||||
return {
|
|
||||||
hasBlankOption: this.options.some(option => option.label === ' '),
|
|
||||||
index: this.options.findIndex(option => option.label === ' '),
|
|
||||||
option: this.options.find(option => option.label === ' ')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
@ -179,10 +163,17 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
'metadata.displayed'(value) {
|
||||||
|
if (value) {
|
||||||
|
this.changeBlankOption()
|
||||||
|
this.options = this.getterLookupAll
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeMount() {
|
beforeMount() {
|
||||||
if (this.metadata.displayed) {
|
if (this.metadata.displayed) {
|
||||||
|
this.changeBlankOption()
|
||||||
this.options = this.getterLookupAll
|
this.options = this.getterLookupAll
|
||||||
if (!this.isEmptyValue(this.value) && !this.metadata.isAdvancedQuery) {
|
if (!this.isEmptyValue(this.value) && !this.metadata.isAdvancedQuery) {
|
||||||
if (!this.findLabel(this.value)) {
|
if (!this.findLabel(this.value)) {
|
||||||
|
@ -194,7 +185,8 @@ export default {
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
if (!this.isPanelWindow || (this.isPanelWindow &&
|
if (!this.isPanelWindow || (this.isPanelWindow &&
|
||||||
(this.isEmptyValue(this.metadata.optionCRUD) || this.metadata.optionCRUD === 'create-new'))) {
|
(this.isEmptyValue(this.metadata.optionCRUD) ||
|
||||||
|
this.metadata.optionCRUD === 'create-new'))) {
|
||||||
this.getDataLookupItem()
|
this.getDataLookupItem()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,6 +195,20 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
changeBlankOption() {
|
||||||
|
if (Number(this.metadata.defaultValue) === -1) {
|
||||||
|
this.blankOption = {
|
||||||
|
label: ' ',
|
||||||
|
key: -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.value === undefined || this.value === null) {
|
||||||
|
this.blankOption = {
|
||||||
|
label: ' ',
|
||||||
|
key: undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
preHandleChange(value) {
|
preHandleChange(value) {
|
||||||
const label = this.findLabel(this.value)
|
const label = this.findLabel(this.value)
|
||||||
this.handleChange(value, undefined, label)
|
this.handleChange(value, undefined, label)
|
||||||
|
@ -237,10 +243,8 @@ export default {
|
||||||
attributeValue: responseLookupItem.label
|
attributeValue: responseLookupItem.label
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
this.changeBlankOption()
|
||||||
this.options = this.getterLookupAll
|
this.options = this.getterLookupAll
|
||||||
if (this.options.length && !this.options[0].key) {
|
|
||||||
this.options.unshift(this.blankOption)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
this.isLoading = false
|
this.isLoading = false
|
||||||
|
@ -252,7 +256,8 @@ export default {
|
||||||
getDataLookupList(isShowList) {
|
getDataLookupList(isShowList) {
|
||||||
if (isShowList) {
|
if (isShowList) {
|
||||||
// TODO: Evaluate if length = 1 and this element key = blankOption
|
// TODO: Evaluate if length = 1 and this element key = blankOption
|
||||||
if (this.getterLookupList.length === 0) {
|
const list = this.getterLookupList
|
||||||
|
if (this.isEmptyValue(list) || (list.length === 1 && this.blankValues.includes(list[0]))) {
|
||||||
this.remoteMethod()
|
this.remoteMethod()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -269,6 +274,7 @@ export default {
|
||||||
query: this.metadata.reference.query
|
query: this.metadata.reference.query
|
||||||
})
|
})
|
||||||
.then(responseLookupList => {
|
.then(responseLookupList => {
|
||||||
|
this.changeBlankOption()
|
||||||
this.options = this.getterLookupAll
|
this.options = this.getterLookupAll
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
|
@ -282,10 +288,16 @@ export default {
|
||||||
tableName: this.metadata.reference.tableName,
|
tableName: this.metadata.reference.tableName,
|
||||||
query: this.metadata.reference.query,
|
query: this.metadata.reference.query,
|
||||||
directQuery: this.metadata.reference.directQuery,
|
directQuery: this.metadata.reference.directQuery,
|
||||||
value: this.metadata.value
|
value: this.value
|
||||||
})
|
})
|
||||||
// TODO: Evaluate if is number -1 or string '' (or default value)
|
|
||||||
this.options = this.getterLookupAll
|
// set empty list and empty option
|
||||||
|
this.changeBlankOption()
|
||||||
|
const list = []
|
||||||
|
list.push(this.blankOption)
|
||||||
|
this.options = list
|
||||||
|
|
||||||
|
// set empty value
|
||||||
this.value = this.blankOption.key
|
this.value = this.blankOption.key
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { getLookup, getLookupList } from '@/api/ADempiere/data'
|
import { getLookup, getLookupList } from '@/api/ADempiere/data'
|
||||||
import { getCurrentRole } from '@/utils/ADempiere/auth'
|
import { getToken as getSession } from '@/utils/auth'
|
||||||
import { isEmptyValue } from '@/utils/ADempiere/valueUtils'
|
import { isEmptyValue } from '@/utils/ADempiere/valueUtils'
|
||||||
import { parseContext } from '@/utils/ADempiere/contextUtils'
|
import { parseContext } from '@/utils/ADempiere/contextUtils'
|
||||||
|
|
||||||
|
@ -26,6 +26,14 @@ const lookup = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
/**
|
||||||
|
* Get display column from lookup
|
||||||
|
* @param {string} parentUuid
|
||||||
|
* @param {string} containerUuid
|
||||||
|
* @param {string} tableName
|
||||||
|
* @param {string} directQuery
|
||||||
|
* @param {string|number} value identifier or key
|
||||||
|
*/
|
||||||
getLookupItemFromServer({ commit, rootGetters }, {
|
getLookupItemFromServer({ commit, rootGetters }, {
|
||||||
parentUuid,
|
parentUuid,
|
||||||
containerUuid,
|
containerUuid,
|
||||||
|
@ -64,7 +72,7 @@ const lookup = {
|
||||||
value, // isNaN(objectParams.value) ? objectParams.value : parseInt(objectParams.value, 10),
|
value, // isNaN(objectParams.value) ? objectParams.value : parseInt(objectParams.value, 10),
|
||||||
parsedDirectQuery: directQuery,
|
parsedDirectQuery: directQuery,
|
||||||
tableName,
|
tableName,
|
||||||
roleUuid: getCurrentRole(),
|
sessionUuid: getSession(),
|
||||||
clientId: rootGetters.getContextClientId
|
clientId: rootGetters.getContextClientId
|
||||||
})
|
})
|
||||||
return option
|
return option
|
||||||
|
@ -74,9 +82,12 @@ const lookup = {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* tableName,
|
* Get display column's list from lookup
|
||||||
* query
|
* @param {string} parentUuid
|
||||||
*/
|
* @param {string} containerUuid
|
||||||
|
* @param {string} tableName
|
||||||
|
* @param {string} query
|
||||||
|
*/
|
||||||
getLookupListFromServer({ commit, rootGetters }, {
|
getLookupListFromServer({ commit, rootGetters }, {
|
||||||
parentUuid,
|
parentUuid,
|
||||||
containerUuid,
|
containerUuid,
|
||||||
|
@ -100,21 +111,25 @@ const lookup = {
|
||||||
query: parsedQuery
|
query: parsedQuery
|
||||||
})
|
})
|
||||||
.then(lookupListResponse => {
|
.then(lookupListResponse => {
|
||||||
const options = lookupListResponse.recordsList.map(itemLookup => {
|
const list = []
|
||||||
return {
|
lookupListResponse.recordsList.forEach(itemLookup => {
|
||||||
label: itemLookup.values.DisplayColumn,
|
const key = itemLookup.values.KeyColumn
|
||||||
key: itemLookup.values.KeyColumn
|
if (![null, -1, undefined].includes(key)) {
|
||||||
|
list.push({
|
||||||
|
label: itemLookup.values.DisplayColumn,
|
||||||
|
key
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
commit('addLoockupList', {
|
commit('addLoockupList', {
|
||||||
list: options,
|
list,
|
||||||
tableName,
|
tableName,
|
||||||
parsedQuery,
|
parsedQuery,
|
||||||
roleUuid: getCurrentRole(),
|
sessionUuid: getSession(),
|
||||||
clientId: rootGetters.getContextClientId
|
clientId: rootGetters.getContextClientId
|
||||||
})
|
})
|
||||||
return options
|
return list
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.warn(`Get Lookup List, Select Base - Error ${error.code}: ${error.message}.`)
|
console.warn(`Get Lookup List, Select Base - Error ${error.code}: ${error.message}.`)
|
||||||
|
@ -141,7 +156,7 @@ const lookup = {
|
||||||
return itemLookup.parsedDirectQuery !== parsedDirectQuery &&
|
return itemLookup.parsedDirectQuery !== parsedDirectQuery &&
|
||||||
itemLookup.tableName !== tableName &&
|
itemLookup.tableName !== tableName &&
|
||||||
itemLookup.value !== value &&
|
itemLookup.value !== value &&
|
||||||
itemLookup.roleUuid !== getCurrentRole()
|
itemLookup.sessionUuid !== getSession()
|
||||||
})
|
})
|
||||||
|
|
||||||
let parsedQuery = query
|
let parsedQuery = query
|
||||||
|
@ -156,7 +171,7 @@ const lookup = {
|
||||||
const lookupList = state.lookupList.filter(itemLookup => {
|
const lookupList = state.lookupList.filter(itemLookup => {
|
||||||
return itemLookup.parsedQuery !== parsedQuery &&
|
return itemLookup.parsedQuery !== parsedQuery &&
|
||||||
itemLookup.tableName !== tableName &&
|
itemLookup.tableName !== tableName &&
|
||||||
itemLookup.roleUuid !== getCurrentRole()
|
itemLookup.sessionUuid !== getSession()
|
||||||
})
|
})
|
||||||
commit('deleteLookupList', {
|
commit('deleteLookupList', {
|
||||||
lookupItem,
|
lookupItem,
|
||||||
|
@ -184,7 +199,7 @@ const lookup = {
|
||||||
const lookupItem = state.lookupItem.find(itemLookup => {
|
const lookupItem = state.lookupItem.find(itemLookup => {
|
||||||
return itemLookup.parsedDirectQuery === parsedDirectQuery &&
|
return itemLookup.parsedDirectQuery === parsedDirectQuery &&
|
||||||
itemLookup.tableName === tableName &&
|
itemLookup.tableName === tableName &&
|
||||||
itemLookup.roleUuid === getCurrentRole() &&
|
itemLookup.sessionUuid === getSession() &&
|
||||||
itemLookup.clientId === rootGetters.getContextClientId &&
|
itemLookup.clientId === rootGetters.getContextClientId &&
|
||||||
itemLookup.value === value
|
itemLookup.value === value
|
||||||
})
|
})
|
||||||
|
@ -211,16 +226,11 @@ const lookup = {
|
||||||
const lookupList = state.lookupList.find(itemLookup => {
|
const lookupList = state.lookupList.find(itemLookup => {
|
||||||
return itemLookup.parsedQuery === parsedQuery &&
|
return itemLookup.parsedQuery === parsedQuery &&
|
||||||
itemLookup.tableName === tableName &&
|
itemLookup.tableName === tableName &&
|
||||||
itemLookup.roleUuid === getCurrentRole() &&
|
itemLookup.sessionUuid === getSession() &&
|
||||||
itemLookup.clientId === rootGetters.getContextClientId
|
itemLookup.clientId === rootGetters.getContextClientId
|
||||||
})
|
})
|
||||||
if (lookupList) {
|
if (lookupList) {
|
||||||
const resultLookup = lookupList.list.filter(lookup => {
|
return lookupList.list
|
||||||
if (lookup.key !== undefined) {
|
|
||||||
return lookup
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return resultLookup
|
|
||||||
}
|
}
|
||||||
return []
|
return []
|
||||||
},
|
},
|
||||||
|
@ -235,13 +245,6 @@ const lookup = {
|
||||||
directQuery,
|
directQuery,
|
||||||
value
|
value
|
||||||
}) => {
|
}) => {
|
||||||
const item = getters.getLookupItem({
|
|
||||||
parentUuid,
|
|
||||||
containerUuid,
|
|
||||||
tableName,
|
|
||||||
directQuery,
|
|
||||||
value
|
|
||||||
})
|
|
||||||
const list = getters.getLookupList({
|
const list = getters.getLookupList({
|
||||||
parentUuid,
|
parentUuid,
|
||||||
containerUuid,
|
containerUuid,
|
||||||
|
@ -249,8 +252,18 @@ const lookup = {
|
||||||
query
|
query
|
||||||
})
|
})
|
||||||
const allList = list
|
const allList = list
|
||||||
if (item && !list.find(itemLookup => itemLookup.key === item.key)) {
|
// set item values getter from server into list
|
||||||
allList.push(item)
|
if (isEmptyValue(list)) {
|
||||||
|
const item = getters.getLookupItem({
|
||||||
|
parentUuid,
|
||||||
|
containerUuid,
|
||||||
|
tableName,
|
||||||
|
directQuery,
|
||||||
|
value
|
||||||
|
})
|
||||||
|
if (!isEmptyValue(item)) {
|
||||||
|
allList.push(item)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return allList
|
return allList
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue