1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-10 20:39:48 +08:00

fix: Empty mandatory and read only fields. (#486)

This commit is contained in:
Edwin Betancourt 2020-05-06 14:46:20 -04:00 committed by GitHub
parent 50bac60614
commit 91f0e9805e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 163 additions and 158 deletions

View File

@ -45,7 +45,7 @@
},
"dependencies": {
"@adempiere/grpc-access-client": "^1.2.0",
"@adempiere/grpc-data-client": "^2.2.9",
"@adempiere/grpc-data-client": "^2.3.2",
"@adempiere/grpc-dictionary-client": "^1.4.1",
"@adempiere/grpc-enrollment-client": "^1.1.0",
"@adempiere/grpc-pos-client": "^1.1.0",
@ -104,7 +104,7 @@
"eslint": "^6.8.0",
"eslint-plugin-vue": "6.2.2",
"html-webpack-plugin": "4.2.1",
"husky": "4.2.5",
"husky": "^4.2.5",
"lint-staged": "10.2.0",
"mockjs": "1.1.0",
"node-sass": "^4.14.0",

View File

@ -16,6 +16,7 @@ const callOutControl = {
* @param {Object} row, if callout is activate in table
* @param {Mixed} value
* @param {Mixed} oldValue
* @param {String} valueType
* @return {Promise} values
*/
getCallout({ rootGetters, dispatch }, {
@ -40,11 +41,12 @@ const callOutControl = {
runCallOutRequest({
windowUuid: parentUuid,
tabUuid: containerUuid,
callout,
tableName,
columnName,
value,
oldValue,
callout,
valueType,
attributesList,
windowNo: window.windowIndex
})

View File

@ -249,16 +249,15 @@ const panel = {
containerUuid,
fieldsList = []
}) {
if (fieldsList.length <= 0) {
if (isEmptyValue(fieldsList)) {
fieldsList = getters.getFieldsListFromPanel(containerUuid)
}
const fieldsIncludes = fieldsList.filter(fieldItem => {
const fieldsIncludes = []
fieldsList.array.forEach(fieldItem => {
const isMandatory = fieldItem.isMandatory || fieldItem.isMandatoryFromLogic
if (isMandatory) {
return true
fieldsIncludes.push(fieldItem.columnName)
}
}).map(fieldItem => {
return fieldItem.columnName
})
dispatch('changeFieldAttributesBoolean', {
@ -276,15 +275,16 @@ const panel = {
containerUuid,
fieldsList = []
}) {
if (fieldsList.length <= 0) {
if (isEmptyValue(fieldsList)) {
fieldsList = getters.getFieldsListFromPanel(containerUuid)
}
const fieldsIncludes = fieldsList.filter(fieldItem => {
const fieldsIncludes = []
fieldsList.foreach(fieldItem => {
const isDisplayed = fieldItem.isDisplayed && fieldItem.isDisplayedFromLogic && !fieldItem.isKey
// Verify for displayed and is active
return fieldItem.isActive && isDisplayed
}).map(fieldItem => {
return fieldItem.columnName
// Verify for displayed and is active
if (fieldItem.isActive && isDisplayed) {
fieldsIncludes.push(fieldItem.columnName)
}
})
dispatch('changeFieldAttributesBoolean', {
@ -311,6 +311,10 @@ const panel = {
}) {
return new Promise(resolve => {
const panel = getters.getPanel(containerUuid)
if (isEmptyValue(panel)) {
resolve()
return
}
const defaultAttributes = getters.getParsedDefaultValues({
parentUuid,
containerUuid,
@ -409,7 +413,7 @@ const panel = {
isChangedAllValues = false
}) {
return new Promise(resolve => {
if (!fieldList.length) {
if (isEmptyValue(fieldList)) {
fieldList = getters.getFieldsListFromPanel(containerUuid, isAdvancedQuery)
}
let fieldsShowed = []
@ -682,10 +686,6 @@ const panel = {
}
if (isSendToServer) {
const fieldsEmpty = getters.getFieldListEmptyMandatory({
containerUuid,
fieldsList
})
if (panelType === 'table' || isAdvancedQuery) {
if (field.isShowedFromUser && (field.oldValue !== field.value ||
['NULL', 'NOT_NULL'].includes(field.operator) ||
@ -735,95 +735,101 @@ const panel = {
console.warn(`Error getting Advanced Query (notifyFieldChange): ${error.message}. Code: ${error.code}.`)
})
}
} else if (isEmptyValue(fieldsEmpty)) {
// 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 {
const fieldsEmpty = getters.getFieldListEmptyMandatory({
containerUuid,
fieldsList
})
if (isEmptyValue(fieldsEmpty)) {
// 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
}
} else if (awaitForValuesToQuery > 0) {
isReadyForQuery = false
}
if (isReadyForQuery && !field.dependentFieldsList.length) {
dispatch('getBrowserSearch', {
containerUuid,
isClearSelection: true
})
}
} else 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
})
})
}
}
if (isReadyForQuery && !field.dependentFieldsList.length) {
dispatch('getBrowserSearch', {
containerUuid,
isClearSelection: true
})
}
} else {
showMessage({
message: language.t('notifications.mandatoryFieldMissing') + fieldsEmpty,
type: 'info'
})
}
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 {
showMessage({
message: language.t('notifications.mandatoryFieldMissing') + fieldsEmpty,
type: 'info'
})
}
}
})
@ -1066,35 +1072,28 @@ const panel = {
getFieldListEmptyMandatory: (state, getters) => ({
containerUuid,
fieldsList = [],
isEvaluateShowed = true,
row
}) => {
if (fieldsList.length <= 0) {
fieldsList = getters.getFieldsListFromPanel(containerUuid)
}
const fieldsEmpty = []
// all optionals (not mandatory) fields
fieldsList = fieldsList.filter(fieldItem => {
const isMandatory = fieldItem.isMandatory || fieldItem.isMandatoryFromLogic
if (isMandatory) {
if (isEvaluateShowed) {
return fieldIsDisplayed(fieldItem)
}
return isMandatory
}
})
fieldsList = fieldsList.filter(fieldItem => {
fieldsList.forEach(fieldItem => {
let value = fieldItem.value
// used when evaluate data in table
if (row) {
value = row[fieldItem.columnName]
}
return isEmptyValue(value)
if (isEmptyValue(value)) {
const isMandatory = fieldItem.isMandatory || fieldItem.isMandatoryFromLogic
if (fieldIsDisplayed(fieldItem) && isMandatory) {
fieldsEmpty.push(fieldItem.name)
}
}
})
return fieldsList.map(fieldItem => {
return fieldItem.name
})
return fieldsEmpty
},
/**
* Show all available fields not mandatory to show, used in components panel/filterFields.vue
@ -1264,7 +1263,7 @@ const panel = {
return {
columnName: fieldItem.columnName,
value: valueToReturn,
isSQL: isSQL
isSQL
}
})
return attributesObject

View File

@ -101,43 +101,44 @@ export function generateField({
}
// VALUE TO
if (String(parsedDefaultValueTo).includes('@') &&
String(parsedDefaultValueTo).trim() !== '-1') {
parsedDefaultValueTo = parseContext({
...moreAttributes,
columnName: `${fieldToGenerate.columnName}_To`,
value: parsedDefaultValueTo
}).value
}
if (fieldToGenerate.isRange) {
if (String(parsedDefaultValueTo).includes('@') &&
String(parsedDefaultValueTo).trim() !== '-1') {
parsedDefaultValueTo = parseContext({
...moreAttributes,
columnName: `${fieldToGenerate.columnName}_To`,
value: parsedDefaultValueTo
}).value
}
if (isEmptyValue(parsedDefaultValueTo) &&
!(fieldToGenerate.isKey || fieldToGenerate.isParent) &&
String(parsedDefaultValueTo).trim() !== '-1') {
parsedDefaultValueTo = getPreference({
parentUuid: fieldToGenerate.parentUuid,
containerUuid: fieldToGenerate.containerUuid,
columnName: `${fieldToGenerate.columnName}_To`
})
// search value preference with elementName
if (!isEmptyValue(fieldToGenerate.elementName) &&
isEmptyValue(parsedDefaultValueTo)) {
if (isEmptyValue(parsedDefaultValueTo) &&
!(fieldToGenerate.isKey || fieldToGenerate.isParent) &&
String(parsedDefaultValueTo).trim() !== '-1') {
parsedDefaultValueTo = getPreference({
parentUuid: fieldToGenerate.parentUuid,
containerUuid: fieldToGenerate.containerUuid,
columnName: `${fieldToGenerate.elementName}_To`
columnName: `${fieldToGenerate.columnName}_To`
})
// search value preference with elementName
if (!isEmptyValue(fieldToGenerate.elementName) &&
isEmptyValue(parsedDefaultValueTo)) {
parsedDefaultValueTo = getPreference({
parentUuid: fieldToGenerate.parentUuid,
containerUuid: fieldToGenerate.containerUuid,
columnName: `${fieldToGenerate.elementName}_To`
})
}
}
parsedDefaultValueTo = parsedValueComponent({
fieldType: componentReference.componentPath,
value: parsedDefaultValueTo,
displayType: fieldToGenerate.displayType,
isMandatory: fieldToGenerate.isMandatory,
isIdentifier: fieldToGenerate.columnName.includes('_ID')
})
}
parsedDefaultValueTo = parsedValueComponent({
fieldType: componentReference.componentPath,
value: parsedDefaultValueTo,
displayType: fieldToGenerate.displayType,
isMandatory: fieldToGenerate.isMandatory,
isIdentifier: fieldToGenerate.columnName.includes('_ID')
})
parentFieldsList = getParentFields(fieldToGenerate)
// evaluate logics

View File

@ -28,7 +28,7 @@ export const NUMBER = {
id: 12,
isSupported: true,
valueType: 'DECIMAL',
componentPath: 'FieldText',
componentPath: 'FieldNumber',
size: {
xs: 24,
sm: 12,
@ -104,7 +104,7 @@ export const COLOR = {
id: 27,
isSupported: false,
valueType: 'INTEGER',
componentPath: 'FieldText',
componentPath: 'FieldColor',
size: {
xs: 24,
sm: 12,

View File

@ -169,6 +169,7 @@ export function convertFieldListToShareLink(fieldList) {
return attributesListLink.slice(0, -1)
}
/**
* Find element in an array recursively
* @param {object|array} treeData
@ -256,7 +257,8 @@ export function parsedValueComponent({
isMandatory = false,
isIdentifier = false
}) {
if ((value === undefined || value === null) && !isMandatory) {
const isEmpty = isEmptyValue(value)
if (isEmpty && !isMandatory) {
if (fieldType === 'FieldYesNo') {
return Boolean(value)
}
@ -267,7 +269,7 @@ export function parsedValueComponent({
switch (fieldType) {
// data type Number
case 'FieldNumber':
if (String(value).trim() === '' || value === undefined || value === null) {
if (isEmpty) {
returnValue = undefined
if (isMandatory) {
returnValue = 0
@ -305,7 +307,7 @@ export function parsedValueComponent({
// data type Date
case 'FieldDate':
case 'FieldTime ':
if (String(value).trim() === '') {
if (isEmpty) {
value = undefined
}
if (!isNaN(value)) {
@ -321,7 +323,7 @@ export function parsedValueComponent({
break
case 'FieldSelect':
if (String(value).trim() === '') {
if (isEmpty) {
value = undefined
}
if (typeof value === 'boolean') {
@ -329,7 +331,7 @@ export function parsedValueComponent({
}
// Table (18) or Table Direct (19)
if (displayType === TABLE.id || (displayType === TABLE_DIRECT.id && isIdentifier)) {
if (value !== '' && value !== null && value !== undefined) {
if (!isEmptyValue(value)) {
value = Number(value)
}
} // Search or List
@ -342,6 +344,7 @@ export function parsedValueComponent({
}
return returnValue
}
/**
* add a tab depending on the status of the document
* @param {string} tag, document status key