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:
parent
e6fd209d2b
commit
f47dea22df
@ -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: {
|
||||||
|
@ -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: {
|
||||||
|
@ -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,55 +30,58 @@ const callOutControl = {
|
|||||||
value,
|
value,
|
||||||
oldValue
|
oldValue
|
||||||
}) {
|
}) {
|
||||||
const window = rootGetters.getWindow(parentUuid)
|
return new Promise((resolve, reject) => {
|
||||||
const attributesList = rootGetters.getParametersToServer({
|
const window = rootGetters.getWindow(parentUuid)
|
||||||
containerUuid,
|
const attributesList = rootGetters.getParametersToServer({
|
||||||
row
|
containerUuid,
|
||||||
})
|
row
|
||||||
|
})
|
||||||
return runCallOutRequest({
|
runCallOutRequest({
|
||||||
windowUuid: parentUuid,
|
windowUuid: parentUuid,
|
||||||
tabUuid: containerUuid,
|
tabUuid: containerUuid,
|
||||||
tableName,
|
tableName,
|
||||||
columnName,
|
columnName,
|
||||||
value,
|
value,
|
||||||
oldValue,
|
oldValue,
|
||||||
callout,
|
callout,
|
||||||
attributesList,
|
attributesList,
|
||||||
windowNo: window.windowIndex
|
windowNo: window.windowIndex
|
||||||
})
|
})
|
||||||
.then(calloutResponse => {
|
.then(calloutResponse => {
|
||||||
if (inTable) {
|
if (inTable) {
|
||||||
const newValues = {
|
const newValues = {
|
||||||
...row,
|
...row,
|
||||||
...calloutResponse.values
|
...calloutResponse.values
|
||||||
|
}
|
||||||
|
dispatch('notifyRowTableChange', {
|
||||||
|
parentUuid,
|
||||||
|
containerUuid,
|
||||||
|
row: newValues,
|
||||||
|
isEdit: true
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
dispatch('notifyPanelChange', {
|
||||||
|
parentUuid,
|
||||||
|
containerUuid,
|
||||||
|
panelType: 'window',
|
||||||
|
newValues: calloutResponse.values,
|
||||||
|
isSendToServer: false,
|
||||||
|
withOutColumnNames,
|
||||||
|
isSendCallout: false,
|
||||||
|
isChangeFromCallout: true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
dispatch('notifyRowTableChange', {
|
resolve(calloutResponse.values)
|
||||||
parentUuid,
|
|
||||||
containerUuid,
|
|
||||||
row: newValues,
|
|
||||||
isEdit: true
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
dispatch('notifyPanelChange', {
|
|
||||||
parentUuid,
|
|
||||||
containerUuid,
|
|
||||||
panelType: 'window',
|
|
||||||
newValues: calloutResponse.values,
|
|
||||||
isSendToServer: false,
|
|
||||||
withOutColumnNames,
|
|
||||||
isSendCallout: false,
|
|
||||||
isChangeFromCallout: true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
showMessage({
|
|
||||||
message: error.message,
|
|
||||||
type: 'error'
|
|
||||||
})
|
})
|
||||||
console.warn(`Field ${columnName} error callout`, error.message)
|
.catch(error => {
|
||||||
})
|
reject(error)
|
||||||
|
showMessage({
|
||||||
|
message: error.message || language.t('window.callout.error'),
|
||||||
|
type: 'error'
|
||||||
|
})
|
||||||
|
console.warn(`Field ${columnName} error callout. Code ${error.code}: ${error.message}`)
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -375,112 +375,130 @@ const panel = {
|
|||||||
isAdvancedQuery = false,
|
isAdvancedQuery = false,
|
||||||
isPrivateAccess = false,
|
isPrivateAccess = false,
|
||||||
fieldList = [],
|
fieldList = [],
|
||||||
isChangeFromCallout = false
|
isChangeFromCallout = false,
|
||||||
|
isChangeMultipleFields = true
|
||||||
}) {
|
}) {
|
||||||
if (!fieldList.length) {
|
return new Promise(resolve => {
|
||||||
fieldList = getters.getFieldsListFromPanel(containerUuid, isAdvancedQuery)
|
if (!fieldList.length) {
|
||||||
}
|
fieldList = getters.getFieldsListFromPanel(containerUuid, isAdvancedQuery)
|
||||||
let fieldsShowed = []
|
|
||||||
fieldList.forEach(actionField => {
|
|
||||||
if (actionField.isShowedFromUser) {
|
|
||||||
fieldsShowed.push(actionField.columnName)
|
|
||||||
}
|
}
|
||||||
|
let fieldsShowed = []
|
||||||
|
const promisessList = []
|
||||||
|
fieldList.map(async actionField => {
|
||||||
|
if (actionField.isShowedFromUser) {
|
||||||
|
fieldsShowed.push(actionField.columnName)
|
||||||
|
}
|
||||||
|
|
||||||
// Evaluate with hasOwnProperty if exits this value
|
// Evaluate with hasOwnProperty if exits this value
|
||||||
if (!newValues.hasOwnProperty(actionField.columnName)) {
|
if (!newValues.hasOwnProperty(actionField.columnName)) {
|
||||||
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({
|
||||||
directQuery: actionField.reference.directQuery,
|
parentUuid,
|
||||||
tableName: actionField.reference.tableName,
|
containerUuid,
|
||||||
value: newValues[actionField.columnName]
|
directQuery: actionField.reference.directQuery,
|
||||||
})
|
|
||||||
|
|
||||||
if (isEmptyValue(lookup)) {
|
|
||||||
dispatch('getLookupItemFromServer', {
|
|
||||||
parentUuid: parentUuid,
|
|
||||||
containerUuid: containerUuid,
|
|
||||||
tableName: actionField.reference.tableName,
|
tableName: actionField.reference.tableName,
|
||||||
directQuery: actionField.reference.parsedDirectQuery,
|
|
||||||
value: newValues[actionField.columnName]
|
value: newValues[actionField.columnName]
|
||||||
})
|
})
|
||||||
.then(response => {
|
|
||||||
if (!isEmptyValue(response)) {
|
if (isEmptyValue(lookup) && !isEmptyValue(newValues[actionField.columnName])) {
|
||||||
dispatch('notifyFieldChange', {
|
lookup = await dispatch('getLookupItemFromServer', {
|
||||||
isSendToServer,
|
parentUuid,
|
||||||
isSendCallout,
|
containerUuid,
|
||||||
isAdvancedQuery,
|
tableName: actionField.reference.tableName,
|
||||||
panelType,
|
directQuery: actionField.reference.parsedDirectQuery,
|
||||||
|
value: newValues[actionField.columnName]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (!isEmptyValue(lookup)) {
|
||||||
|
newValues[`DisplayColumn_${actionField.columnName}`] = lookup.label
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
promisessList.push(dispatch('notifyFieldChange', {
|
||||||
|
isSendToServer,
|
||||||
|
isSendCallout,
|
||||||
|
isAdvancedQuery,
|
||||||
|
panelType,
|
||||||
|
parentUuid,
|
||||||
|
containerUuid,
|
||||||
|
columnName: actionField.columnName,
|
||||||
|
displayColumn: newValues[`DisplayColumn_${actionField.columnName}`],
|
||||||
|
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
|
||||||
|
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,
|
parentUuid,
|
||||||
containerUuid,
|
containerUuid,
|
||||||
columnName: actionField.columnName,
|
tableName: item.tableName,
|
||||||
displayColumn: response.label,
|
columnName: item.field.columnName,
|
||||||
newValue: newValues[actionField.columnName],
|
callout: item.field.callout,
|
||||||
valueTo: newValues[`${actionField.columnName}_To`],
|
value: item.newValue,
|
||||||
fieldList,
|
oldValue: item.field.oldValue,
|
||||||
field: actionField,
|
withOutColumnNames
|
||||||
withOutColumnNames,
|
|
||||||
isChangedOldValue: true // defines if set oldValue with newValue instead of current value
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
}
|
||||||
newValues[`DisplayColumn_${actionField.columnName}`] = lookup.label
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dispatch('notifyFieldChange', {
|
|
||||||
isSendToServer,
|
|
||||||
isSendCallout,
|
|
||||||
isAdvancedQuery,
|
|
||||||
panelType,
|
|
||||||
parentUuid,
|
|
||||||
containerUuid,
|
|
||||||
columnName: actionField.columnName,
|
|
||||||
displayColumn: newValues[`DisplayColumn_${actionField.columnName}`],
|
|
||||||
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
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
// show fields in query
|
calloutsToExecute.map(async executeCallout => {
|
||||||
if (isShowedField && !isEmptyValue(newValues)) {
|
await dispatch('getCallout', {
|
||||||
// join column names without duplicating it
|
...executeCallout
|
||||||
fieldsShowed = Array.from(new Set([
|
})
|
||||||
...fieldsShowed,
|
|
||||||
...Object.keys(newValues)
|
|
||||||
]))
|
|
||||||
|
|
||||||
dispatch('changeFieldAttributesBoolean', {
|
|
||||||
containerUuid,
|
|
||||||
attribute: 'isShowedFromUser',
|
|
||||||
valueAttribute: true,
|
|
||||||
fieldsIncludes: fieldsShowed
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if (panelType === 'window') {
|
|
||||||
dispatch('setIsloadContext', {
|
|
||||||
containerUuid
|
|
||||||
})
|
|
||||||
if (isPrivateAccess) {
|
|
||||||
const tableName = rootGetters.getTableNameFromTab(parentUuid, containerUuid)
|
|
||||||
// TODO: Add current id and new id to comparison
|
|
||||||
if (!isEmptyValue(newValues[`${tableName}_ID`])) {
|
|
||||||
dispatch('getPrivateAccessFromServer', {
|
|
||||||
tableName,
|
|
||||||
recordId: newValues[`${tableName}_ID`],
|
|
||||||
userUuid: rootGetters['user/getUserUuid']
|
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// show fields in query
|
||||||
|
if (isShowedField && !isEmptyValue(newValues)) {
|
||||||
|
// join column names without duplicating it
|
||||||
|
fieldsShowed = Array.from(new Set([
|
||||||
|
...fieldsShowed,
|
||||||
|
...Object.keys(newValues)
|
||||||
|
]))
|
||||||
|
|
||||||
|
dispatch('changeFieldAttributesBoolean', {
|
||||||
|
containerUuid,
|
||||||
|
attribute: 'isShowedFromUser',
|
||||||
|
valueAttribute: true,
|
||||||
|
fieldsIncludes: fieldsShowed
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (panelType === 'window') {
|
||||||
|
dispatch('setIsloadContext', {
|
||||||
|
containerUuid
|
||||||
|
})
|
||||||
|
if (isPrivateAccess) {
|
||||||
|
const tableName = rootGetters.getTableNameFromTab(parentUuid, containerUuid)
|
||||||
|
// TODO: Add current id and new id to comparison
|
||||||
|
if (!isEmptyValue(newValues[`${tableName}_ID`])) {
|
||||||
|
dispatch('getPrivateAccessFromServer', {
|
||||||
|
tableName,
|
||||||
|
recordId: newValues[`${tableName}_ID`],
|
||||||
|
userUuid: rootGetters['user/getUserUuid']
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* TODO: Add fieldAttributes
|
* TODO: Add fieldAttributes
|
||||||
@ -501,259 +519,268 @@ 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
|
||||||
}) {
|
}) {
|
||||||
const panel = getters.getPanel(containerUuid, isAdvancedQuery)
|
return new Promise(async resolve => {
|
||||||
const { fieldList } = panel
|
const panel = getters.getPanel(containerUuid, isAdvancedQuery)
|
||||||
// get field
|
const { fieldList: fieldsList, tableName } = panel
|
||||||
const field = fieldList.find(fieldItem => fieldItem.columnName === columnName)
|
// get field
|
||||||
|
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)) {
|
||||||
newValue = parsedValueComponent({
|
newValue = parsedValueComponent({
|
||||||
fieldType: field.componentPath,
|
|
||||||
referenceType: field.referenceType,
|
|
||||||
value: newValue,
|
|
||||||
isIdentifier: field.columnName.includes('_ID')
|
|
||||||
})
|
|
||||||
if (field.isRange) {
|
|
||||||
valueTo = parsedValueComponent({
|
|
||||||
fieldType: field.componentPath,
|
fieldType: field.componentPath,
|
||||||
referenceType: field.referenceType,
|
referenceType: field.referenceType,
|
||||||
value: valueTo,
|
value: newValue,
|
||||||
isIdentifier: field.columnName.includes('_ID')
|
isIdentifier: field.columnName.includes('_ID')
|
||||||
})
|
})
|
||||||
}
|
if (field.isRange) {
|
||||||
}
|
valueTo = parsedValueComponent({
|
||||||
|
fieldType: field.componentPath,
|
||||||
// Call context management
|
referenceType: field.referenceType,
|
||||||
dispatch('setContext', {
|
value: valueTo,
|
||||||
parentUuid,
|
isIdentifier: field.columnName.includes('_ID')
|
||||||
containerUuid,
|
})
|
||||||
columnName,
|
|
||||||
value: newValue
|
|
||||||
})
|
|
||||||
|
|
||||||
// request context info field
|
|
||||||
if ((!isEmptyValue(field.value) || !isEmptyValue(newValue)) && !isEmptyValue(field.contextInfo) && !isEmptyValue(field.contextInfo.sqlStatement)) {
|
|
||||||
var isSQL = false
|
|
||||||
var sqlStatement = field.contextInfo.sqlStatement
|
|
||||||
if (sqlStatement.includes('@')) {
|
|
||||||
if (sqlStatement.includes('@SQL=')) {
|
|
||||||
isSQL = true
|
|
||||||
}
|
|
||||||
sqlStatement = parseContext({
|
|
||||||
parentUuid,
|
|
||||||
containerUuid,
|
|
||||||
columnName,
|
|
||||||
value: sqlStatement,
|
|
||||||
isSQL: isSQL
|
|
||||||
}).value
|
|
||||||
if (isSQL && String(sqlStatement) === '[object Object]') {
|
|
||||||
sqlStatement = sqlStatement.query
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dispatch('getContextInfoValueFromServer', {
|
|
||||||
|
// Call context management
|
||||||
|
dispatch('setContext', {
|
||||||
parentUuid,
|
parentUuid,
|
||||||
containerUuid,
|
containerUuid,
|
||||||
contextInfoUuid: field.contextInfo.uuid,
|
columnName,
|
||||||
columnName: columnName,
|
value: newValue
|
||||||
sqlStatement: sqlStatement
|
|
||||||
})
|
})
|
||||||
.then(response => {
|
|
||||||
if (!isEmptyValue(response) && !isEmptyValue(response.messageText)) {
|
// request context info field
|
||||||
field.contextInfo.isActive = true
|
if ((!isEmptyValue(field.value) || !isEmptyValue(newValue)) && !isEmptyValue(field.contextInfo) && !isEmptyValue(field.contextInfo.sqlStatement)) {
|
||||||
field.contextInfo.messageText.msgText = response.messageText
|
let isSQL = false
|
||||||
field.contextInfo.messageText.msgTip = response.messageTip
|
let sqlStatement = field.contextInfo.sqlStatement
|
||||||
|
if (sqlStatement.includes('@')) {
|
||||||
|
if (sqlStatement.includes('@SQL=')) {
|
||||||
|
isSQL = true
|
||||||
}
|
}
|
||||||
})
|
sqlStatement = parseContext({
|
||||||
}
|
|
||||||
|
|
||||||
// Change Dependents
|
|
||||||
dispatch('changeDependentFieldsList', {
|
|
||||||
parentUuid,
|
|
||||||
containerUuid,
|
|
||||||
dependentFieldsList: field.dependentFieldsList,
|
|
||||||
fieldsList: fieldList,
|
|
||||||
isSendToServer
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// the field has not changed, then the action is broken
|
|
||||||
if (newValue === field.value && isEmptyValue(displayColumn) && !isAdvancedQuery) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
commit('changeFieldValue', {
|
|
||||||
field,
|
|
||||||
newValue,
|
|
||||||
valueTo,
|
|
||||||
displayColumn,
|
|
||||||
isChangedOldValue
|
|
||||||
})
|
|
||||||
|
|
||||||
// request callouts
|
|
||||||
if (field.panelType === 'window' && isSendCallout) {
|
|
||||||
if (!withOutColumnNames.includes(field.columnName) && !isEmptyValue(newValue) && !isEmptyValue(field.callout)) {
|
|
||||||
withOutColumnNames.push(field.columnName)
|
|
||||||
dispatch('getCallout', {
|
|
||||||
parentUuid,
|
|
||||||
containerUuid,
|
|
||||||
tableName: panel.tableName,
|
|
||||||
columnName: field.columnName,
|
|
||||||
callout: field.callout,
|
|
||||||
value: newValue,
|
|
||||||
oldValue: field.oldValue,
|
|
||||||
withOutColumnNames
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isSendToServer) {
|
|
||||||
if (panelType === 'table' || isAdvancedQuery) {
|
|
||||||
if (field.isShowedFromUser && (field.oldValue !== field.value ||
|
|
||||||
['NULL', 'NOT_NULL'].includes(field.operator) ||
|
|
||||||
field.operator !== field.oldOperator)) {
|
|
||||||
// change action to advanced query on field value is changed in this panel
|
|
||||||
if (router.currentRoute.query.action !== 'advancedQuery') {
|
|
||||||
router.push({
|
|
||||||
query: {
|
|
||||||
...router.currentRoute.query,
|
|
||||||
action: 'advancedQuery'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
commit('changeField', {
|
|
||||||
field,
|
|
||||||
newField: {
|
|
||||||
...field,
|
|
||||||
oldOperator: field.operator
|
|
||||||
}
|
|
||||||
})
|
|
||||||
dispatch('getObjectListFromCriteria', {
|
|
||||||
parentUuid,
|
|
||||||
containerUuid,
|
|
||||||
tableName: panel.tableName,
|
|
||||||
query: panel.query,
|
|
||||||
whereClause: panel.whereClause,
|
|
||||||
conditionsList: getters.getParametersToServer({
|
|
||||||
containerUuid,
|
|
||||||
isAdvancedQuery: true,
|
|
||||||
isEvaluateMandatory: false
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (response && response.length) {
|
|
||||||
dispatch('notifyPanelChange', {
|
|
||||||
parentUuid,
|
|
||||||
containerUuid,
|
|
||||||
isAdvancedQuery: false,
|
|
||||||
newValues: response[0],
|
|
||||||
isSendToServer: false,
|
|
||||||
isSendCallout: true,
|
|
||||||
panelType: 'window'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.warn(`Error getting Advanced Query (notifyFieldChange): ${error.message}. Code: ${error.code}.`)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else if (!getters.isNotReadyForSubmit(containerUuid)) {
|
|
||||||
// TODO: refactory for it and change for a standard method
|
|
||||||
if (field.panelType === 'browser' && fieldIsDisplayed(field)) {
|
|
||||||
let isReadyForQuery = true
|
|
||||||
if (field.isSQLValue) {
|
|
||||||
let awaitForValuesToQuery = panel.awaitForValuesToQuery
|
|
||||||
awaitForValuesToQuery--
|
|
||||||
dispatch('changeBrowserAttribute', {
|
|
||||||
containerUuid,
|
|
||||||
attributeName: 'awaitForValuesToQuery',
|
|
||||||
attributeValue: awaitForValuesToQuery
|
|
||||||
})
|
|
||||||
if (awaitForValuesToQuery === 0) {
|
|
||||||
if (panel.isShowedCriteria) {
|
|
||||||
dispatch('changeBrowserAttribute', {
|
|
||||||
containerUuid,
|
|
||||||
attributeName: 'isShowedCriteria',
|
|
||||||
attributeValue: false
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else if (awaitForValuesToQuery > 0) {
|
|
||||||
isReadyForQuery = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isReadyForQuery && !field.dependentFieldsList.length) {
|
|
||||||
dispatch('getBrowserSearch', {
|
|
||||||
containerUuid,
|
|
||||||
isClearSelection: true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (field.panelType === 'window' && fieldIsDisplayed(field)) {
|
|
||||||
const uuid = getters.getUuid(containerUuid)
|
|
||||||
if (isEmptyValue(uuid)) {
|
|
||||||
dispatch('createNewEntity', {
|
|
||||||
parentUuid,
|
parentUuid,
|
||||||
containerUuid
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
// change old value so that it is not send in the next update
|
|
||||||
commit('changeFieldValue', {
|
|
||||||
field,
|
|
||||||
newValue,
|
|
||||||
valueTo,
|
|
||||||
displayColumn,
|
|
||||||
isChangedOldValue: true
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
showMessage({
|
|
||||||
message: error.message,
|
|
||||||
type: 'error'
|
|
||||||
})
|
|
||||||
console.warn(`Create Entity Error ${error.code}: ${error.message}.`)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
dispatch('updateCurrentEntity', {
|
|
||||||
containerUuid,
|
containerUuid,
|
||||||
recordUuid: uuid
|
columnName,
|
||||||
|
value: sqlStatement,
|
||||||
|
isSQL
|
||||||
|
}).value
|
||||||
|
if (isSQL && String(sqlStatement) === '[object Object]') {
|
||||||
|
sqlStatement = sqlStatement.query
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const contextInfo = await dispatch('getContextInfoValueFromServer', {
|
||||||
|
parentUuid,
|
||||||
|
containerUuid,
|
||||||
|
contextInfoUuid: field.contextInfo.uuid,
|
||||||
|
columnName,
|
||||||
|
sqlStatement
|
||||||
|
})
|
||||||
|
if (!isEmptyValue(contextInfo) && !isEmptyValue(contextInfo.messageText)) {
|
||||||
|
field.contextInfo.isActive = true
|
||||||
|
field.contextInfo.messageText.msgText = contextInfo.messageText
|
||||||
|
field.contextInfo.messageText.msgTip = contextInfo.messageTip
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change Dependents
|
||||||
|
dispatch('changeDependentFieldsList', {
|
||||||
|
parentUuid,
|
||||||
|
containerUuid,
|
||||||
|
dependentFieldsList: field.dependentFieldsList,
|
||||||
|
fieldsList,
|
||||||
|
isSendToServer
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// the field has not changed, then the action is broken
|
||||||
|
if (newValue === field.value && isEmptyValue(displayColumn) && !isAdvancedQuery) {
|
||||||
|
resolve()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
commit('changeFieldValue', {
|
||||||
|
field,
|
||||||
|
newValue,
|
||||||
|
valueTo,
|
||||||
|
displayColumn,
|
||||||
|
isChangedOldValue
|
||||||
|
})
|
||||||
|
resolve({
|
||||||
|
field,
|
||||||
|
newValue,
|
||||||
|
valueTo,
|
||||||
|
displayColumn,
|
||||||
|
tableName
|
||||||
|
})
|
||||||
|
|
||||||
|
// request callouts
|
||||||
|
if (field.panelType === 'window' && isSendCallout && !isChangeMultipleFields) {
|
||||||
|
if (!withOutColumnNames.includes(field.columnName) && !isEmptyValue(newValue) && !isEmptyValue(field.callout)) {
|
||||||
|
withOutColumnNames.push(field.columnName)
|
||||||
|
dispatch('getCallout', {
|
||||||
|
parentUuid,
|
||||||
|
containerUuid,
|
||||||
|
tableName,
|
||||||
|
columnName: field.columnName,
|
||||||
|
callout: field.callout,
|
||||||
|
value: newValue,
|
||||||
|
oldValue: field.oldValue,
|
||||||
|
withOutColumnNames
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSendToServer) {
|
||||||
|
if (panelType === 'table' || isAdvancedQuery) {
|
||||||
|
if (field.isShowedFromUser && (field.oldValue !== field.value ||
|
||||||
|
['NULL', 'NOT_NULL'].includes(field.operator) ||
|
||||||
|
field.operator !== field.oldOperator)) {
|
||||||
|
// change action to advanced query on field value is changed in this panel
|
||||||
|
if (router.currentRoute.query.action !== 'advancedQuery') {
|
||||||
|
router.push({
|
||||||
|
query: {
|
||||||
|
...router.currentRoute.query,
|
||||||
|
action: 'advancedQuery'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
commit('changeField', {
|
||||||
|
field,
|
||||||
|
newField: {
|
||||||
|
...field,
|
||||||
|
oldOperator: field.operator
|
||||||
|
}
|
||||||
|
})
|
||||||
|
dispatch('getObjectListFromCriteria', {
|
||||||
|
parentUuid,
|
||||||
|
containerUuid,
|
||||||
|
tableName: panel.tableName,
|
||||||
|
query: panel.query,
|
||||||
|
whereClause: panel.whereClause,
|
||||||
|
conditionsList: getters.getParametersToServer({
|
||||||
|
containerUuid,
|
||||||
|
isAdvancedQuery: true,
|
||||||
|
isEvaluateMandatory: false
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
// change old value so that it is not send in the next update
|
if (response && response.length) {
|
||||||
showMessage({
|
dispatch('notifyPanelChange', {
|
||||||
message: language.t('notifications.updateFields') + field.name,
|
parentUuid,
|
||||||
type: 'success'
|
containerUuid,
|
||||||
})
|
isAdvancedQuery: false,
|
||||||
commit('changeFieldValue', {
|
newValues: response[0],
|
||||||
field,
|
isSendToServer: false,
|
||||||
newValue,
|
isSendCallout: true,
|
||||||
valueTo,
|
panelType: 'window'
|
||||||
displayColumn,
|
})
|
||||||
isChangedOldValue: true
|
}
|
||||||
})
|
})
|
||||||
|
.catch(error => {
|
||||||
// change value in table
|
console.warn(`Error getting Advanced Query (notifyFieldChange): ${error.message}. Code: ${error.code}.`)
|
||||||
dispatch('notifyRowTableChange', {
|
|
||||||
containerUuid,
|
|
||||||
row: response,
|
|
||||||
isEdit: false,
|
|
||||||
isParent: true
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
} else if (!getters.isNotReadyForSubmit(containerUuid)) {
|
||||||
|
// TODO: refactory for it and change for a standard method
|
||||||
|
if (field.panelType === 'browser' && fieldIsDisplayed(field)) {
|
||||||
|
let isReadyForQuery = true
|
||||||
|
if (field.isSQLValue) {
|
||||||
|
let awaitForValuesToQuery = panel.awaitForValuesToQuery
|
||||||
|
awaitForValuesToQuery--
|
||||||
|
dispatch('changeBrowserAttribute', {
|
||||||
|
containerUuid,
|
||||||
|
attributeName: 'awaitForValuesToQuery',
|
||||||
|
attributeValue: awaitForValuesToQuery
|
||||||
|
})
|
||||||
|
if (awaitForValuesToQuery === 0) {
|
||||||
|
if (panel.isShowedCriteria) {
|
||||||
|
dispatch('changeBrowserAttribute', {
|
||||||
|
containerUuid,
|
||||||
|
attributeName: 'isShowedCriteria',
|
||||||
|
attributeValue: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else if (awaitForValuesToQuery > 0) {
|
||||||
|
isReadyForQuery = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isReadyForQuery && !field.dependentFieldsList.length) {
|
||||||
|
dispatch('getBrowserSearch', {
|
||||||
|
containerUuid,
|
||||||
|
isClearSelection: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (field.panelType === 'window' && fieldIsDisplayed(field)) {
|
||||||
|
const uuid = getters.getUuid(containerUuid)
|
||||||
|
if (isEmptyValue(uuid)) {
|
||||||
|
dispatch('createNewEntity', {
|
||||||
|
parentUuid,
|
||||||
|
containerUuid
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
// change old value so that it is not send in the next update
|
||||||
|
commit('changeFieldValue', {
|
||||||
|
field,
|
||||||
|
newValue,
|
||||||
|
valueTo,
|
||||||
|
displayColumn,
|
||||||
|
isChangedOldValue: true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
showMessage({
|
||||||
|
message: error.message,
|
||||||
|
type: 'error'
|
||||||
|
})
|
||||||
|
console.warn(`Create Entity Error ${error.code}: ${error.message}.`)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
dispatch('updateCurrentEntity', {
|
||||||
|
containerUuid,
|
||||||
|
recordUuid: uuid
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
// change old value so that it is not send in the next update
|
||||||
|
showMessage({
|
||||||
|
message: language.t('notifications.updateFields') + field.name,
|
||||||
|
type: 'success'
|
||||||
|
})
|
||||||
|
commit('changeFieldValue', {
|
||||||
|
field,
|
||||||
|
newValue,
|
||||||
|
valueTo,
|
||||||
|
displayColumn,
|
||||||
|
isChangedOldValue: true
|
||||||
|
})
|
||||||
|
|
||||||
|
// change value in table
|
||||||
|
dispatch('notifyRowTableChange', {
|
||||||
|
containerUuid,
|
||||||
|
row: response,
|
||||||
|
isEdit: false,
|
||||||
|
isParent: true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const fieldsEmpty = getters.getFieldListEmptyMandatory({
|
||||||
|
containerUuid,
|
||||||
|
fieldsList
|
||||||
|
})
|
||||||
|
showMessage({
|
||||||
|
message: language.t('notifications.mandatoryFieldMissing') + fieldsEmpty,
|
||||||
|
type: 'info'
|
||||||
|
})
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
const fieldsEmpty = getters.getFieldListEmptyMandatory({
|
|
||||||
containerUuid,
|
|
||||||
fieldsList: fieldList
|
|
||||||
})
|
|
||||||
showMessage({
|
|
||||||
message: language.t('notifications.mandatoryFieldMissing') + fieldsEmpty,
|
|
||||||
type: 'info'
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
},
|
},
|
||||||
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 => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user