1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-11 05:11:59 +08:00

fix: #347 Loses values when create entity using callout generate error or warning. (#348)

* fix loses values when using callout or generate error create entity.

* fix undefined method.

* Remover comments un data table component

* Delete comments in dictionary utils
This commit is contained in:
Edwin Betancourt 2020-02-25 09:05:02 -04:00 committed by GitHub
parent 02c634e56d
commit 1126c00c1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 250 additions and 210 deletions

View File

@ -2,6 +2,7 @@ import { supportedTypes, exportFileFromJson, exportFileZip } from '@/utils/ADemp
import { showNotification } from '@/utils/ADempiere/notification' import { showNotification } from '@/utils/ADempiere/notification'
import { recursiveTreeSearch } from '@/utils/ADempiere/valueUtils' import { recursiveTreeSearch } from '@/utils/ADempiere/valueUtils'
import { FIELDS_QUANTITY } from '@/components/ADempiere/Field/references' import { FIELDS_QUANTITY } from '@/components/ADempiere/Field/references'
import { sortFields } from '@/utils/ADempiere/dictionaryUtils'
export const menuTableMixin = { export const menuTableMixin = {
props: { props: {
@ -84,6 +85,8 @@ export const menuTableMixin = {
if (this.panelType === 'browser') { if (this.panelType === 'browser') {
sortAttribute = 'seqNoGrid' sortAttribute = 'seqNoGrid'
} }
// TODO: Change to destructuring and add isParent attribure to change
// orderBy sequence value to seqNoGrid value if isParent is false
return this.sortFields( return this.sortFields(
this.panelMetadata.fieldList, this.panelMetadata.fieldList,
sortAttribute sortAttribute
@ -164,6 +167,7 @@ export const menuTableMixin = {
}, },
methods: { methods: {
showNotification, showNotification,
sortFields,
closeMenu() { closeMenu() {
// TODO: Validate to dispatch one action // TODO: Validate to dispatch one action
this.$store.dispatch('showMenuTable', { this.$store.dispatch('showMenuTable', {

View File

@ -16,17 +16,10 @@ const callOutControl = {
oldValue oldValue
}) { }) {
const window = rootGetters.getWindow(parentUuid) const window = rootGetters.getWindow(parentUuid)
let attributesList = [] const attributesList = rootGetters.getParametersToServer({
if (inTable) { containerUuid,
attributesList = rootGetters.getParametersToServer({ row
containerUuid, })
row
})
} else {
attributesList = rootGetters.getParametersToServer({
containerUuid
})
}
return runCallOutRequest({ return runCallOutRequest({
windowUuid: parentUuid, windowUuid: parentUuid,
@ -40,13 +33,11 @@ const callOutControl = {
windowNo: window.windowIndex windowNo: window.windowIndex
}) })
.then(calloutResponse => { .then(calloutResponse => {
const newValues = {}
Object.keys(calloutResponse.values).forEach(key => {
if (calloutResponse.values[key] !== undefined) {
newValues[key] = calloutResponse.values[key]
}
})
if (inTable) { if (inTable) {
const newValues = {
...row,
...calloutResponse.values
}
dispatch('notifyRowTableChange', { dispatch('notifyRowTableChange', {
parentUuid, parentUuid,
containerUuid, containerUuid,
@ -58,7 +49,7 @@ const callOutControl = {
parentUuid, parentUuid,
containerUuid, containerUuid,
panelType: 'window', panelType: 'window',
newValues, newValues: calloutResponse.values,
isSendToServer: false, isSendToServer: false,
withOutColumnNames, withOutColumnNames,
isSendCallout: false, isSendCallout: false,

View File

@ -127,169 +127,186 @@ const data = {
* @param {boolean} isPanelValues, define if used values form panel * @param {boolean} isPanelValues, define if used values form panel
* @param {boolean} isEdit, define if used values form panel * @param {boolean} isEdit, define if used values form panel
*/ */
addNewRow({ commit, getters, rootGetters, dispatch }, parameters) { addNewRow({ commit, getters, rootGetters, dispatch }, {
const { parentUuid, containerUuid, isPanelValues = false, isEdit = true, isNew = true } = parameters parentUuid,
let { fieldList = [] } = parameters containerUuid,
isPanelValues = false,
const tabPanel = rootGetters.getPanel(containerUuid) isEdit = true,
isNew = true,
if (!fieldList.length) { fieldList,
fieldList = tabPanel.fieldList row
} }) {
const dataStore = getters.getDataRecordsList(containerUuid)
let values = {} let values = {}
// add row with default values to create new record const currentNewRow = dataStore.find(itemData => {
if (isPanelValues) { return isEmptyValue(itemData.UUID) && itemData.isNew
// add row with values used from record in panel })
values = rootGetters.getColumnNamesAndValues({
containerUuid, if (!isEmptyValue(currentNewRow)) {
propertyName: 'value', values = currentNewRow
isObjectReturn: true, return values
isAddDisplayColumn: true, } if (isEmptyValue(row)) {
const tabPanel = rootGetters.getPanel(containerUuid)
if (isEmptyValue(fieldList)) {
fieldList = tabPanel.fieldList
}
// add row with default values to create new record
if (isPanelValues) {
// add row with values used from record in panel
values = rootGetters.getColumnNamesAndValues({
containerUuid,
propertyName: 'value',
isObjectReturn: true,
isAddDisplayColumn: true,
fieldList
})
} else {
values = rootGetters.getParsedDefaultValues({
parentUuid,
containerUuid,
fieldList
})
}
values.isNew = isNew
values.isEdit = isEdit
values.isSendServer = false
// get the link column name from the tab
let linkColumnName = tabPanel.linkColumnName
if (isEmptyValue(linkColumnName)) {
// get the link column name from field list
linkColumnName = tabPanel.fieldLinkColumnName
}
let valueLink
// get context value if link column exists and does not exist in row
if (!isEmptyValue(linkColumnName)) {
valueLink = rootGetters.getContext({
parentUuid,
containerUuid,
columnName: linkColumnName
})
if (!isEmptyValue(valueLink)) {
valueLink = parseInt(valueLink, 10)
}
}
// get display column
if (fieldList.length) {
fieldList fieldList
}) // TODO: Evaluate if is field is read only and FieldSelect
} else { .filter(itemField => itemField.componentPath === 'FieldSelect' || String(values[itemField.columnName]) === '[object Object]')
values = rootGetters.getParsedDefaultValues({ .forEach(itemField => {
parentUuid, let valueGetDisplayColumn = values[itemField.columnName]
containerUuid, if (String(values[itemField.columnName]) === '[object Object]') {
fieldList if (itemField.componentPath === 'FieldSelect') {
}) values[itemField.columnName] = ' '
} values[`DisplayColumn_${itemField.columnName}`] = ' '
values.isNew = isNew } else if (itemField.componentPath === 'FieldNumber') {
values.isEdit = isEdit values[itemField.columnName] = 0
values.isSendServer = false }
// get the link column name from the tab
var linkColumnName = tabPanel.linkColumnName
if (isEmptyValue(linkColumnName)) {
// get the link column name from field list
linkColumnName = tabPanel.fieldLinkColumnName
}
var valueLink
// get context value if link column exists and does not exist in row
if (!isEmptyValue(linkColumnName)) {
valueLink = rootGetters.getContext({
parentUuid,
containerUuid,
columnName: linkColumnName
})
}
if (!isEmptyValue(valueLink)) {
valueLink = parseInt(valueLink, 10)
}
// get display column
if (fieldList.length) {
fieldList
// TODO: Evaluate if is field is read only and FieldSelect
.filter(itemField => itemField.componentPath === 'FieldSelect' || String(values[itemField.columnName]) === '[object Object]')
.forEach(itemField => {
var valueGetDisplayColumn = values[itemField.columnName]
if (String(values[itemField.columnName]) === '[object Object]' && itemField.componentPath === 'FieldSelect') {
values[itemField.columnName] = ' '
values[`DisplayColumn_${itemField.columnName}`] = ' '
} else if (String(values[itemField.columnName]) === '[object Object]' && itemField.componentPath === 'FieldNumber') {
values[itemField.columnName] = 0
}
// overwrite value with column link
if (!isEmptyValue(linkColumnName) && linkColumnName === itemField.columnName) {
valueGetDisplayColumn = valueLink
if (isEmptyValue(values[itemField.columnName])) {
values[itemField.columnName] = valueGetDisplayColumn
} }
} // overwrite value with column link
if (!isEmptyValue(linkColumnName) && linkColumnName === itemField.columnName) {
// break this itineration if is empty valueGetDisplayColumn = valueLink
if (isEmptyValue(valueGetDisplayColumn)) { if (isEmptyValue(values[itemField.columnName])) {
return values[itemField.columnName] = valueGetDisplayColumn
} }
// always the values for these types of fields are integers
if (['TableDirect'].includes(itemField.referenceType)) {
valueGetDisplayColumn = parseInt(valueGetDisplayColumn, 10)
} else {
if (!isNaN(valueGetDisplayColumn)) {
valueGetDisplayColumn = parseInt(valueGetDisplayColumn, 10)
} }
}
if (!isEmptyValue(valueGetDisplayColumn) && String(valueGetDisplayColumn) === '[object Object]' && valueGetDisplayColumn.isSQL) {
// get value from direct Query
dispatch('getRecordBySQL', {
query: valueGetDisplayColumn.query,
field: itemField
})
.then(defaultValue => {
if (itemField.componentPath === 'FieldSelect') {
values[itemField.columnName] = defaultValue.key
values[`DisplayColumn_${itemField.columnName}`] = defaultValue.label
} else {
values[itemField.columnName] = defaultValue.key
dispatch('notifyRowTableChange', {
parentUuid,
containerUuid,
isNew,
isEdit,
row: values
})
}
})
return
}
// get label (DisplayColumn) from vuex store
const options = rootGetters.getLookupAll({
parentUuid,
containerUuid,
tableName: itemField.reference.tableName,
query: itemField.reference.query,
directQuery: itemField.reference.directQuery,
value: valueGetDisplayColumn
})
const option = options.find(itemOption => itemOption.key === valueGetDisplayColumn) // break this itineration if is empty
// if there is a lookup option, assign the display column with the label if (isEmptyValue(valueGetDisplayColumn)) {
if (option) {
values[`DisplayColumn_${itemField.columnName}`] = option.label
if (isEmptyValue(option.label) && !itemField.isMandatory) {
values[itemField.columnName] = undefined
}
return
}
if (linkColumnName === itemField.columnName) {
// get context value if link column exists and does not exist in row
const nameParent = rootGetters.getContext({
parentUuid,
containerUuid,
columnName: 'Name'
})
if (nameParent) {
values[`DisplayColumn_${itemField.columnName}`] = nameParent
return return
} }
} // always the values for these types of fields are integers
// get from server if (['TableDirect'].includes(itemField.referenceType)) {
dispatch('getLookupItemFromServer', { valueGetDisplayColumn = parseInt(valueGetDisplayColumn, 10)
parentUuid, } else {
containerUuid, if (!isNaN(valueGetDisplayColumn)) {
tableName: itemField.reference.tableName, valueGetDisplayColumn = parseInt(valueGetDisplayColumn, 10)
directQuery: itemField.reference.directQuery, }
value: valueGetDisplayColumn }
}) if (!isEmptyValue(valueGetDisplayColumn) && String(valueGetDisplayColumn) === '[object Object]' && valueGetDisplayColumn.isSQL) {
.then(responseLookup => { // get value from direct Query
dispatch('addDisplayColumn', { dispatch('getRecordBySQL', {
containerUuid, query: valueGetDisplayColumn.query,
columnName: itemField.columnName, field: itemField
displayColumn: responseLookup.label
}) })
.then(defaultValue => {
if (itemField.componentPath === 'FieldSelect') {
values[itemField.columnName] = defaultValue.key
values[`DisplayColumn_${itemField.columnName}`] = defaultValue.label
} else {
values[itemField.columnName] = defaultValue.key
dispatch('notifyRowTableChange', {
parentUuid,
containerUuid,
isNew,
isEdit,
row: values
})
}
})
return
}
// get label (DisplayColumn) from vuex store
const options = rootGetters.getLookupAll({
parentUuid,
containerUuid,
tableName: itemField.reference.tableName,
query: itemField.reference.query,
directQuery: itemField.reference.directQuery,
value: valueGetDisplayColumn
}) })
})
const option = options.find(itemOption => itemOption.key === valueGetDisplayColumn)
// if there is a lookup option, assign the display column with the label
if (option) {
values[`DisplayColumn_${itemField.columnName}`] = option.label
if (isEmptyValue(option.label) && !itemField.isMandatory) {
values[itemField.columnName] = undefined
}
return
}
if (linkColumnName === itemField.columnName) {
// get context value if link column exists and does not exist in row
const nameParent = rootGetters.getContext({
parentUuid,
containerUuid,
columnName: 'Name'
})
if (nameParent) {
values[`DisplayColumn_${itemField.columnName}`] = nameParent
return
}
}
// get from server
dispatch('getLookupItemFromServer', {
parentUuid,
containerUuid,
tableName: itemField.reference.tableName,
directQuery: itemField.reference.directQuery,
value: valueGetDisplayColumn
})
.then(responseLookup => {
dispatch('addDisplayColumn', {
containerUuid,
columnName: itemField.columnName,
displayColumn: responseLookup.label
})
})
})
}
// overwrite value with column link
if (isEmptyValue(values[linkColumnName])) {
values[linkColumnName] = valueLink
}
} else {
values = row
} }
// overwrite value with column link
if (isEmptyValue(values[linkColumnName])) {
values[linkColumnName] = valueLink
}
const dataStore = getters.getDataRecordsList(containerUuid)
commit('addNewRow', { commit('addNewRow', {
values, values,
data: dataStore data: dataStore
@ -395,7 +412,7 @@ const data = {
withOut = [], withOut = [],
isNew = false isNew = false
}) { }) {
var setNews = [] const setNews = []
const record = state.recordSelection.filter(itemRecord => { const record = state.recordSelection.filter(itemRecord => {
// ignore this uuid // ignore this uuid
if (withOut.includes(itemRecord.containerUuid)) { if (withOut.includes(itemRecord.containerUuid)) {
@ -632,13 +649,18 @@ const data = {
* @param {objec} objectParams.isEdit, if the row displayed to edit mode * @param {objec} objectParams.isEdit, if the row displayed to edit mode
* @param {objec} objectParams.isNew, if insert data to new row * @param {objec} objectParams.isNew, if insert data to new row
*/ */
notifyRowTableChange({ commit, getters, rootGetters }, objectParams) { notifyRowTableChange({ commit, getters, rootGetters }, {
const { parentUuid, containerUuid, isEdit = true } = objectParams parentUuid,
var currentValues = {} containerUuid,
if (objectParams.hasOwnProperty('row')) { isEdit = true,
currentValues = objectParams.row isNew,
row
}) {
let values = {}
if (row) {
values = row
} else { } else {
currentValues = rootGetters.getColumnNamesAndValues({ values = rootGetters.getColumnNamesAndValues({
parentUuid, parentUuid,
containerUuid, containerUuid,
propertyName: 'value', propertyName: 'value',
@ -647,27 +669,34 @@ const data = {
}) })
} }
var row = getters.getRowData(objectParams.containerUuid, currentValues.UUID) const currentRow = getters.getRowData(containerUuid, values.UUID)
var newRow = { const newRow = {
...currentValues, ...values,
// ...objectParams.row, // ...objectParams.row,
isEdit isEdit
} }
commit('notifyRowTableChange', { commit('notifyRowTableChange', {
isNew: objectParams.isNew, isNew,
newRow, newRow,
row row: currentRow
}) })
}, },
notifyCellTableChange({ commit, state, dispatch, rootGetters }, parameters) { notifyCellTableChange({ commit, state, dispatch, rootGetters }, {
const { parentUuid,
parentUuid, containerUuid, field, panelType = 'window', containerUuid,
isSendToServer = true, columnName, rowKey, keyColumn, newValue, field,
displayColumn, withOutColumnNames = [], isSendCallout = true columnName,
} = parameters rowKey,
keyColumn,
panelType = 'window',
isSendToServer = true,
isSendCallout = true,
newValue,
displayColumn,
withOutColumnNames = []
}) {
const recordSelection = state.recordSelection.find(recordItem => { const recordSelection = state.recordSelection.find(recordItem => {
return recordItem.containerUuid === containerUuid return recordItem.containerUuid === containerUuid
}) })
@ -730,13 +759,6 @@ const data = {
containerUuid, containerUuid,
row row
}) })
.then(() => {
// refresh record list
dispatch('getDataListTab', {
parentUuid,
containerUuid
})
})
} }
} else { } else {
const fieldsEmpty = rootGetters.getFieldListEmptyMandatory({ const fieldsEmpty = rootGetters.getFieldListEmptyMandatory({

View File

@ -172,7 +172,7 @@ const windowControl = {
}) })
}) })
}, },
createEntityFromTable({ commit, getters, rootGetters }, { createEntityFromTable({ commit, dispatch, getters, rootGetters }, {
parentUuid, parentUuid,
containerUuid, containerUuid,
row row
@ -187,8 +187,9 @@ const windowControl = {
const { tableName, isParentTab } = rootGetters.getPanel(containerUuid) const { tableName, isParentTab } = rootGetters.getPanel(containerUuid)
// TODO: Add support to Binary columns (BinaryData) // TODO: Add support to Binary columns (BinaryData)
const columnsToDontSend = ['BinaryData', 'isSendServer', 'isEdit'] const columnsToDontSend = ['BinaryData', 'isEdit', 'isNew', 'isSendServer']
// TODO: Evaluate peformance without filter using delete(prop) before convert object to array
// attributes or fields // attributes or fields
let finalAttributes = convertObjectToArrayPairs(row) let finalAttributes = convertObjectToArrayPairs(row)
finalAttributes = finalAttributes.filter(itemAttribute => { finalAttributes = finalAttributes.filter(itemAttribute => {
@ -206,6 +207,8 @@ const windowControl = {
tableName, tableName,
attributesList: finalAttributes attributesList: finalAttributes
}) })
let isError = false
return createEntity({ return createEntity({
tableName, tableName,
attributesList: finalAttributes attributesList: finalAttributes
@ -239,9 +242,22 @@ const windowControl = {
message: error.message, message: error.message,
type: 'error' type: 'error'
}) })
console.warn(`Create Entity Table Error ${error.code}: ${error.message}`) console.warn(`Create Entity Table Error ${error.code}: ${error.message}.`)
isError = true
}) })
.finally(() => { .finally(() => {
if (isError) {
dispatch('addNewRow', {
containerUuid,
row
})
} else {
// refresh record list
dispatch('getDataListTab', {
parentUuid,
containerUuid
})
}
commit('deleteInCreate', { commit('deleteInCreate', {
containerUuid, containerUuid,
tableName, tableName,
@ -332,15 +348,15 @@ const windowControl = {
}) })
}, },
updateCurrentEntityFromTable({ rootGetters }, { updateCurrentEntityFromTable({ rootGetters }, {
parentUuid,
containerUuid, containerUuid,
row row
}) { }) {
const { tableName, fieldList } = rootGetters.getPanel(containerUuid) const { tableName, fieldList } = rootGetters.getPanel(containerUuid)
// TODO: Add support to Binary columns (BinaryData) // TODO: Add support to Binary columns (BinaryData)
const columnsToDontSend = ['BinaryData', 'isSendServer', 'isEdit'] const columnsToDontSend = ['BinaryData', 'isEdit', 'isNew', 'isSendServer']
// TODO: Evaluate peformance without filter using delete(prop) before convert object to array
// attributes or fields // attributes or fields
let finalAttributes = convertObjectToArrayPairs(row) let finalAttributes = convertObjectToArrayPairs(row)
finalAttributes = finalAttributes.filter(itemAttribute => { finalAttributes = finalAttributes.filter(itemAttribute => {
@ -367,7 +383,7 @@ const windowControl = {
message: error.message, message: error.message,
type: 'error' type: 'error'
}) })
console.warn(`Update Entity Table Error ${error.code}: ${error.message}`) console.warn(`Update Entity Table Error ${error.code}: ${error.message}.`)
}) })
}, },
/** /**
@ -596,14 +612,20 @@ const windowControl = {
* @param {boolean} isRefreshPanel, if main panel is updated with new response data * @param {boolean} isRefreshPanel, if main panel is updated with new response data
* @param {boolean} isLoadAllRecords, if main panel is updated with new response data * @param {boolean} isLoadAllRecords, if main panel is updated with new response data
*/ */
getDataListTab({ dispatch, rootGetters }, parameters) { getDataListTab({ dispatch, rootGetters }, {
const { parentUuid,
parentUuid, containerUuid, recordUuid, containerUuid,
referenceWhereClause = '', columnName, value, criteria, recordUuid,
isRefreshPanel = false, isLoadAllRecords = false, isReference = false, referenceWhereClause = '',
isShowNotification = true columnName,
} = parameters value,
let { isAddRecord = false } = parameters criteria,
isAddRecord = false,
isLoadAllRecords = false,
isRefreshPanel = false,
isReference = false,
isShowNotification = true
}) {
const tab = rootGetters.getTab(parentUuid, containerUuid) const tab = rootGetters.getTab(parentUuid, containerUuid)
let parsedQuery = tab.query let parsedQuery = tab.query

View File

@ -471,6 +471,7 @@ export function assignedGroup(fieldList, assignedGroup) {
if (fieldList === undefined || fieldList.length <= 0) { if (fieldList === undefined || fieldList.length <= 0) {
return fieldList return fieldList
} }
fieldList = sortFields(fieldList, 'sequence', 'asc', fieldList[0].panelType) fieldList = sortFields(fieldList, 'sequence', 'asc', fieldList[0].panelType)
let firstChangeGroup = false let firstChangeGroup = false