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) {
attributesList = rootGetters.getParametersToServer({
containerUuid, containerUuid,
row 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,17 +127,30 @@ 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,
isEdit = true,
isNew = true,
fieldList,
row
}) {
const dataStore = getters.getDataRecordsList(containerUuid)
let values = {}
const currentNewRow = dataStore.find(itemData => {
return isEmptyValue(itemData.UUID) && itemData.isNew
})
if (!isEmptyValue(currentNewRow)) {
values = currentNewRow
return values
} if (isEmptyValue(row)) {
const tabPanel = rootGetters.getPanel(containerUuid) const tabPanel = rootGetters.getPanel(containerUuid)
if (!fieldList.length) { if (isEmptyValue(fieldList)) {
fieldList = tabPanel.fieldList fieldList = tabPanel.fieldList
} }
let values = {}
// add row with default values to create new record // add row with default values to create new record
if (isPanelValues) { if (isPanelValues) {
// add row with values used from record in panel // add row with values used from record in panel
@ -160,13 +173,13 @@ const data = {
values.isSendServer = false values.isSendServer = false
// get the link column name from the tab // get the link column name from the tab
var linkColumnName = tabPanel.linkColumnName let linkColumnName = tabPanel.linkColumnName
if (isEmptyValue(linkColumnName)) { if (isEmptyValue(linkColumnName)) {
// get the link column name from field list // get the link column name from field list
linkColumnName = tabPanel.fieldLinkColumnName linkColumnName = tabPanel.fieldLinkColumnName
} }
var valueLink let valueLink
// get context value if link column exists and does not exist in row // get context value if link column exists and does not exist in row
if (!isEmptyValue(linkColumnName)) { if (!isEmptyValue(linkColumnName)) {
valueLink = rootGetters.getContext({ valueLink = rootGetters.getContext({
@ -174,10 +187,10 @@ const data = {
containerUuid, containerUuid,
columnName: linkColumnName columnName: linkColumnName
}) })
}
if (!isEmptyValue(valueLink)) { if (!isEmptyValue(valueLink)) {
valueLink = parseInt(valueLink, 10) valueLink = parseInt(valueLink, 10)
} }
}
// get display column // get display column
if (fieldList.length) { if (fieldList.length) {
@ -185,13 +198,15 @@ const data = {
// TODO: Evaluate if is field is read only and FieldSelect // TODO: Evaluate if is field is read only and FieldSelect
.filter(itemField => itemField.componentPath === 'FieldSelect' || String(values[itemField.columnName]) === '[object Object]') .filter(itemField => itemField.componentPath === 'FieldSelect' || String(values[itemField.columnName]) === '[object Object]')
.forEach(itemField => { .forEach(itemField => {
var valueGetDisplayColumn = values[itemField.columnName] let valueGetDisplayColumn = values[itemField.columnName]
if (String(values[itemField.columnName]) === '[object Object]' && itemField.componentPath === 'FieldSelect') { if (String(values[itemField.columnName]) === '[object Object]') {
if (itemField.componentPath === 'FieldSelect') {
values[itemField.columnName] = ' ' values[itemField.columnName] = ' '
values[`DisplayColumn_${itemField.columnName}`] = ' ' values[`DisplayColumn_${itemField.columnName}`] = ' '
} else if (String(values[itemField.columnName]) === '[object Object]' && itemField.componentPath === 'FieldNumber') { } else if (itemField.componentPath === 'FieldNumber') {
values[itemField.columnName] = 0 values[itemField.columnName] = 0
} }
}
// overwrite value with column link // overwrite value with column link
if (!isEmptyValue(linkColumnName) && linkColumnName === itemField.columnName) { if (!isEmptyValue(linkColumnName) && linkColumnName === itemField.columnName) {
valueGetDisplayColumn = valueLink valueGetDisplayColumn = valueLink
@ -288,8 +303,10 @@ const data = {
if (isEmptyValue(values[linkColumnName])) { if (isEmptyValue(values[linkColumnName])) {
values[linkColumnName] = valueLink values[linkColumnName] = valueLink
} }
} else {
values = row
}
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 = '',
columnName,
value,
criteria,
isAddRecord = false,
isLoadAllRecords = false,
isRefreshPanel = false,
isReference = false,
isShowNotification = true isShowNotification = true
} = parameters }) {
let { isAddRecord = false } = parameters
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