1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-13 07:04:21 +08:00

fix: Run callout's after change values in all field's. (#418)

* fix: Run callout's after change values in all field's.

* change to pomisse getCalloyut and await getContextInfoValueFromServer
This commit is contained in:
Edwin Betancourt 2020-03-24 21:42:34 -04:00 committed by GitHub
parent e6fd209d2b
commit f47dea22df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 445 additions and 383 deletions

View File

@ -280,6 +280,9 @@ export default {
timeElapsed: 'Time Elapsed', timeElapsed: 'Time Elapsed',
addNote: 'Add Note' addNote: 'Add Note'
} }
},
callout: {
error: 'Error In Callout'
} }
}, },
data: { data: {

View File

@ -255,6 +255,9 @@ export default {
timeElapsed: 'Tiempo transcurrido', timeElapsed: 'Tiempo transcurrido',
addNote: 'Agregar Nota' addNote: 'Agregar Nota'
} }
},
callout: {
error: 'Error En Callout'
} }
}, },
data: { data: {

View File

@ -1,8 +1,23 @@
import { runCallOutRequest } from '@/api/ADempiere/data' import { runCallOutRequest } from '@/api/ADempiere/data'
import { showMessage } from '@/utils/ADempiere/notification' import { showMessage } from '@/utils/ADempiere/notification'
import language from '@/lang'
const callOutControl = { const callOutControl = {
actions: { actions: {
/**
* Run or execute callout to get values
* @param {String} parentUuid
* @param {String} containerUuid
* @param {String} callout, path of callout to execute
* @param {String} tableName
* @param {String} columnName
* @param {Array<String>} withOutColumnNames
* @param {Boolean} inTable, indicate if is activate from table
* @param {Object} row, if callout is activate in table
* @param {Mixed} value
* @param {Mixed} oldValue
* @return {Promise} values
*/
getCallout({ rootGetters, dispatch }, { getCallout({ rootGetters, dispatch }, {
parentUuid, parentUuid,
containerUuid, containerUuid,
@ -15,13 +30,13 @@ const callOutControl = {
value, value,
oldValue oldValue
}) { }) {
return new Promise((resolve, reject) => {
const window = rootGetters.getWindow(parentUuid) const window = rootGetters.getWindow(parentUuid)
const attributesList = rootGetters.getParametersToServer({ const attributesList = rootGetters.getParametersToServer({
containerUuid, containerUuid,
row row
}) })
runCallOutRequest({
return runCallOutRequest({
windowUuid: parentUuid, windowUuid: parentUuid,
tabUuid: containerUuid, tabUuid: containerUuid,
tableName, tableName,
@ -56,13 +71,16 @@ const callOutControl = {
isChangeFromCallout: true isChangeFromCallout: true
}) })
} }
resolve(calloutResponse.values)
}) })
.catch(error => { .catch(error => {
reject(error)
showMessage({ showMessage({
message: error.message, message: error.message || language.t('window.callout.error'),
type: 'error' type: 'error'
}) })
console.warn(`Field ${columnName} error callout`, error.message) console.warn(`Field ${columnName} error callout. Code ${error.code}: ${error.message}`)
})
}) })
} }
} }

View File

@ -375,13 +375,16 @@ const panel = {
isAdvancedQuery = false, isAdvancedQuery = false,
isPrivateAccess = false, isPrivateAccess = false,
fieldList = [], fieldList = [],
isChangeFromCallout = false isChangeFromCallout = false,
isChangeMultipleFields = true
}) { }) {
return new Promise(resolve => {
if (!fieldList.length) { if (!fieldList.length) {
fieldList = getters.getFieldsListFromPanel(containerUuid, isAdvancedQuery) fieldList = getters.getFieldsListFromPanel(containerUuid, isAdvancedQuery)
} }
let fieldsShowed = [] let fieldsShowed = []
fieldList.forEach(actionField => { const promisessList = []
fieldList.map(async actionField => {
if (actionField.isShowedFromUser) { if (actionField.isShowedFromUser) {
fieldsShowed.push(actionField.columnName) fieldsShowed.push(actionField.columnName)
} }
@ -391,48 +394,32 @@ const panel = {
return return
} }
if (isChangeFromCallout && actionField.componentPath === 'FieldSelect' && !newValues.hasOwnProperty(`DisplayColumn_${actionField.columnName}`)) { if (isChangeFromCallout &&
const lookup = getters.getLookupItem({ actionField.componentPath === 'FieldSelect' &&
parentUuid: parentUuid, !newValues.hasOwnProperty(`DisplayColumn_${actionField.columnName}`)) {
containerUuid: containerUuid, let lookup = rootGetters.getLookupItem({
parentUuid,
containerUuid,
directQuery: actionField.reference.directQuery, directQuery: actionField.reference.directQuery,
tableName: actionField.reference.tableName, tableName: actionField.reference.tableName,
value: newValues[actionField.columnName] value: newValues[actionField.columnName]
}) })
if (isEmptyValue(lookup)) { if (isEmptyValue(lookup) && !isEmptyValue(newValues[actionField.columnName])) {
dispatch('getLookupItemFromServer', { lookup = await dispatch('getLookupItemFromServer', {
parentUuid: parentUuid, parentUuid,
containerUuid: containerUuid, containerUuid,
tableName: actionField.reference.tableName, tableName: actionField.reference.tableName,
directQuery: actionField.reference.parsedDirectQuery, directQuery: actionField.reference.parsedDirectQuery,
value: newValues[actionField.columnName] value: newValues[actionField.columnName]
}) })
.then(response => {
if (!isEmptyValue(response)) {
dispatch('notifyFieldChange', {
isSendToServer,
isSendCallout,
isAdvancedQuery,
panelType,
parentUuid,
containerUuid,
columnName: actionField.columnName,
displayColumn: response.label,
newValue: newValues[actionField.columnName],
valueTo: newValues[`${actionField.columnName}_To`],
fieldList,
field: actionField,
withOutColumnNames,
isChangedOldValue: true // defines if set oldValue with newValue instead of current value
})
} }
}) if (!isEmptyValue(lookup)) {
} else {
newValues[`DisplayColumn_${actionField.columnName}`] = lookup.label newValues[`DisplayColumn_${actionField.columnName}`] = lookup.label
} }
} }
dispatch('notifyFieldChange', {
promisessList.push(dispatch('notifyFieldChange', {
isSendToServer, isSendToServer,
isSendCallout, isSendCallout,
isAdvancedQuery, isAdvancedQuery,
@ -446,7 +433,37 @@ const panel = {
fieldList, fieldList,
field: actionField, field: actionField,
withOutColumnNames, withOutColumnNames,
isChangedOldValue: true // defines if set oldValue with newValue instead of current value isChangedOldValue: true, // defines if set oldValue with newValue instead of current value
isChangeMultipleFields
}))
})
Promise.all(promisessList)
.then(response => {
const calloutsToExecute = []
if (isSendCallout) {
response.forEach(item => {
if (item && !isEmptyValue(item.field.callout) &&
!withOutColumnNames.includes(item.field.columnName)) {
withOutColumnNames.push(item.field.columnName)
calloutsToExecute.push({
parentUuid,
containerUuid,
tableName: item.tableName,
columnName: item.field.columnName,
callout: item.field.callout,
value: item.newValue,
oldValue: item.field.oldValue,
withOutColumnNames
})
}
})
}
calloutsToExecute.map(async executeCallout => {
await dispatch('getCallout', {
...executeCallout
})
}) })
}) })
@ -481,6 +498,7 @@ const panel = {
} }
} }
} }
})
}, },
/** /**
* TODO: Add fieldAttributes * TODO: Add fieldAttributes
@ -501,12 +519,14 @@ const panel = {
parentUuid, containerUuid, panelType = 'window', isAdvancedQuery = false, parentUuid, containerUuid, panelType = 'window', isAdvancedQuery = false,
columnName, newValue, valueTo, displayColumn, columnName, newValue, valueTo, displayColumn,
isSendToServer = true, isSendCallout = true, isSendToServer = true, isSendCallout = true,
isChangedOldValue = false, withOutColumnNames = [] isChangedOldValue = false, withOutColumnNames = [],
isChangeMultipleFields = false
}) { }) {
return new Promise(async resolve => {
const panel = getters.getPanel(containerUuid, isAdvancedQuery) const panel = getters.getPanel(containerUuid, isAdvancedQuery)
const { fieldList } = panel const { fieldList: fieldsList, tableName } = panel
// get field // get field
const field = fieldList.find(fieldItem => fieldItem.columnName === columnName) const field = fieldsList.find(fieldItem => fieldItem.columnName === columnName)
if (!(panelType === 'table' || isAdvancedQuery)) { if (!(panelType === 'table' || isAdvancedQuery)) {
if (!['IN', 'NOT_IN'].includes(field.operator)) { if (!['IN', 'NOT_IN'].includes(field.operator)) {
@ -536,8 +556,8 @@ const panel = {
// request context info field // request context info field
if ((!isEmptyValue(field.value) || !isEmptyValue(newValue)) && !isEmptyValue(field.contextInfo) && !isEmptyValue(field.contextInfo.sqlStatement)) { if ((!isEmptyValue(field.value) || !isEmptyValue(newValue)) && !isEmptyValue(field.contextInfo) && !isEmptyValue(field.contextInfo.sqlStatement)) {
var isSQL = false let isSQL = false
var sqlStatement = field.contextInfo.sqlStatement let sqlStatement = field.contextInfo.sqlStatement
if (sqlStatement.includes('@')) { if (sqlStatement.includes('@')) {
if (sqlStatement.includes('@SQL=')) { if (sqlStatement.includes('@SQL=')) {
isSQL = true isSQL = true
@ -547,26 +567,24 @@ const panel = {
containerUuid, containerUuid,
columnName, columnName,
value: sqlStatement, value: sqlStatement,
isSQL: isSQL isSQL
}).value }).value
if (isSQL && String(sqlStatement) === '[object Object]') { if (isSQL && String(sqlStatement) === '[object Object]') {
sqlStatement = sqlStatement.query sqlStatement = sqlStatement.query
} }
} }
dispatch('getContextInfoValueFromServer', { const contextInfo = await dispatch('getContextInfoValueFromServer', {
parentUuid, parentUuid,
containerUuid, containerUuid,
contextInfoUuid: field.contextInfo.uuid, contextInfoUuid: field.contextInfo.uuid,
columnName: columnName, columnName,
sqlStatement: sqlStatement sqlStatement
}) })
.then(response => { if (!isEmptyValue(contextInfo) && !isEmptyValue(contextInfo.messageText)) {
if (!isEmptyValue(response) && !isEmptyValue(response.messageText)) {
field.contextInfo.isActive = true field.contextInfo.isActive = true
field.contextInfo.messageText.msgText = response.messageText field.contextInfo.messageText.msgText = contextInfo.messageText
field.contextInfo.messageText.msgTip = response.messageTip field.contextInfo.messageText.msgTip = contextInfo.messageTip
} }
})
} }
// Change Dependents // Change Dependents
@ -574,13 +592,14 @@ const panel = {
parentUuid, parentUuid,
containerUuid, containerUuid,
dependentFieldsList: field.dependentFieldsList, dependentFieldsList: field.dependentFieldsList,
fieldsList: fieldList, fieldsList,
isSendToServer isSendToServer
}) })
} }
// the field has not changed, then the action is broken // the field has not changed, then the action is broken
if (newValue === field.value && isEmptyValue(displayColumn) && !isAdvancedQuery) { if (newValue === field.value && isEmptyValue(displayColumn) && !isAdvancedQuery) {
resolve()
return return
} }
@ -591,15 +610,22 @@ const panel = {
displayColumn, displayColumn,
isChangedOldValue isChangedOldValue
}) })
resolve({
field,
newValue,
valueTo,
displayColumn,
tableName
})
// request callouts // request callouts
if (field.panelType === 'window' && isSendCallout) { if (field.panelType === 'window' && isSendCallout && !isChangeMultipleFields) {
if (!withOutColumnNames.includes(field.columnName) && !isEmptyValue(newValue) && !isEmptyValue(field.callout)) { if (!withOutColumnNames.includes(field.columnName) && !isEmptyValue(newValue) && !isEmptyValue(field.callout)) {
withOutColumnNames.push(field.columnName) withOutColumnNames.push(field.columnName)
dispatch('getCallout', { dispatch('getCallout', {
parentUuid, parentUuid,
containerUuid, containerUuid,
tableName: panel.tableName, tableName,
columnName: field.columnName, columnName: field.columnName,
callout: field.callout, callout: field.callout,
value: newValue, value: newValue,
@ -746,7 +772,7 @@ const panel = {
} else { } else {
const fieldsEmpty = getters.getFieldListEmptyMandatory({ const fieldsEmpty = getters.getFieldListEmptyMandatory({
containerUuid, containerUuid,
fieldsList: fieldList fieldsList
}) })
showMessage({ showMessage({
message: language.t('notifications.mandatoryFieldMissing') + fieldsEmpty, message: language.t('notifications.mandatoryFieldMissing') + fieldsEmpty,
@ -754,6 +780,7 @@ const panel = {
}) })
} }
} }
})
}, },
changeDependentFieldsList({ commit, dispatch, getters }, { changeDependentFieldsList({ commit, dispatch, getters }, {
parentUuid, parentUuid,
@ -975,7 +1002,7 @@ const panel = {
isNotReadyForSubmit: (state, getters) => (containerUuid, row) => { isNotReadyForSubmit: (state, getters) => (containerUuid, row) => {
const field = getters.getFieldsListFromPanel(containerUuid).find(fieldItem => { const field = getters.getFieldsListFromPanel(containerUuid).find(fieldItem => {
const isMandatory = fieldItem.isMandatory || fieldItem.isMandatoryFromLogic const isMandatory = fieldItem.isMandatory || fieldItem.isMandatoryFromLogic
var value = fieldItem.value let value = fieldItem.value
// used when evaluate data in table // used when evaluate data in table
if (row) { if (row) {
value = row[fieldItem.columnName] value = row[fieldItem.columnName]
@ -1142,7 +1169,7 @@ const panel = {
isGetServer = true, isGetServer = true,
fieldsList = [] fieldsList = []
}) => { }) => {
if (!fieldsList.length) { if (isEmptyValue(fieldsList)) {
fieldsList = getters.getFieldsListFromPanel(containerUuid) fieldsList = getters.getFieldsListFromPanel(containerUuid)
} }
const attributesObject = {} const attributesObject = {}
@ -1194,8 +1221,8 @@ const panel = {
}, },
getFieldsIsDisplayed: (state, getters) => (containerUuid) => { getFieldsIsDisplayed: (state, getters) => (containerUuid) => {
const fieldList = getters.getFieldsListFromPanel(containerUuid) const fieldList = getters.getFieldsListFromPanel(containerUuid)
var fieldsIsDisplayed = [] let fieldsIsDisplayed = []
var fieldsNotDisplayed = [] const fieldsNotDisplayed = []
if (fieldList.length) { if (fieldList.length) {
fieldsIsDisplayed = fieldList.filter(itemField => { fieldsIsDisplayed = fieldList.filter(itemField => {
const isMandatory = itemField.isMandatory && itemField.isMandatoryFromLogic const isMandatory = itemField.isMandatory && itemField.isMandatoryFromLogic
@ -1206,8 +1233,8 @@ const panel = {
}) })
} }
return { return {
fieldIsDisplayed: fieldsIsDisplayed, fieldIsDisplayed,
fieldsNotDisplayed: fieldsNotDisplayed, fieldsNotDisplayed,
totalField: fieldList.length, totalField: fieldList.length,
isDisplayed: Boolean(fieldsIsDisplayed.length) isDisplayed: Boolean(fieldsIsDisplayed.length)
} }
@ -1243,8 +1270,8 @@ const panel = {
fieldList.map(fieldItem => { fieldList.map(fieldItem => {
// assign values // assign values
var value = fieldItem.value let value = fieldItem.value
var valueTo = fieldItem.valueTo let valueTo = fieldItem.valueTo
if (!isEmptyValue(value)) { if (!isEmptyValue(value)) {
if (['FieldDate', 'FieldTime'].includes(fieldItem.componentPath)) { if (['FieldDate', 'FieldTime'].includes(fieldItem.componentPath)) {
@ -1265,7 +1292,14 @@ const panel = {
}, },
/** /**
* Getter converter selection params with value format * Getter converter selection params with value format
* [{ columname: name key, value: value to send, operator }] * @param {String} containerUuid
* @param {Object} row
* @param {Array<Object>} fieldList
* @param {Array<String>} withOutColumnNames
* @param {Boolean} isEvaluateDisplayed, default value is true
* @param {Boolean} isEvaluateMandatory, default value is true
* @param {Boolean} isAdvancedQuery, default value is false
* @returns {Array<Object>} [{ columname: name key, value: value to send, operator }]
*/ */
getParametersToServer: (state, getters) => ({ getParametersToServer: (state, getters) => ({
containerUuid, containerUuid,
@ -1276,7 +1310,7 @@ const panel = {
isEvaluateMandatory = true, isEvaluateMandatory = true,
isAdvancedQuery = false isAdvancedQuery = false
}) => { }) => {
if (fieldList.length <= 0) { if (isEmptyValue(fieldList)) {
fieldList = getters.getFieldsListFromPanel(containerUuid, isAdvancedQuery) fieldList = getters.getFieldsListFromPanel(containerUuid, isAdvancedQuery)
} }
const parametersRange = [] const parametersRange = []
@ -1329,10 +1363,14 @@ const panel = {
// conever parameters // conever parameters
parametersList = parametersList parametersList = parametersList
.map(parameterItem => { .map(parameterItem => {
let value = row ? row[parameterItem.columnName] : parameterItem.value let value = parameterItem.value
const valueTo = row ? row[`${parameterItem.columnName}_To`] : parameterItem.valueTo let valueTo = parameterItem.valueTo
let values = [] if (row) {
value = row[parameterItem.columnName]
valueTo = row[`${parameterItem.columnName}_To`]
}
let values = []
if (isAdvancedQuery && ['IN', 'NOT_IN'].includes(parameterItem.operator)) { if (isAdvancedQuery && ['IN', 'NOT_IN'].includes(parameterItem.operator)) {
if (Array.isArray(value)) { if (Array.isArray(value)) {
values = value.map(itemValue => { values = value.map(itemValue => {