From 876b51cce371b5fd329e3b0851118dbc3830b7d5 Mon Sep 17 00:00:00 2001 From: Edwin Betancourt Date: Wed, 11 Mar 2020 21:27:09 -0400 Subject: [PATCH] fix: #386 Value preference with session context. (#387) * fix: Value preference with session context. * fix set value in field isParentLink or isKey * remove unused attribute. * Add additional attributes fieldTemplate. --- src/store/modules/ADempiere/browser.js | 17 ++++--- src/store/modules/ADempiere/panel.js | 2 +- src/store/modules/ADempiere/window.js | 38 +++++++------- src/utils/ADempiere/contextUtils.js | 51 ++++++------------- src/utils/ADempiere/dictionaryUtils.js | 70 ++++++++++++-------------- 5 files changed, 78 insertions(+), 100 deletions(-) diff --git a/src/store/modules/ADempiere/browser.js b/src/store/modules/ADempiere/browser.js index a82760b4..9de18d83 100644 --- a/src/store/modules/ADempiere/browser.js +++ b/src/store/modules/ADempiere/browser.js @@ -93,16 +93,17 @@ const browser = { // Get dependent fields fieldsList - .filter(field => field.parentFieldsList && field.isActive) .forEach((field, index, list) => { - field.parentFieldsList.forEach(parentColumnName => { - const parentField = list.find(parentField => { - return parentField.columnName === parentColumnName && parentColumnName !== field.columnName + if (field.isActive && field.parentFieldsList.length) { + field.parentFieldsList.forEach(parentColumnName => { + const parentField = list.find(parentField => { + return parentField.columnName === parentColumnName && parentColumnName !== field.columnName + }) + if (parentField) { + parentField.dependentFieldsList.push(field.columnName) + } }) - if (parentField) { - parentField.dependentFieldsList.push(field.columnName) - } - }) + } }) // Convert from gRPC process list diff --git a/src/store/modules/ADempiere/panel.js b/src/store/modules/ADempiere/panel.js index cadc5398..81c17cf2 100644 --- a/src/store/modules/ADempiere/panel.js +++ b/src/store/modules/ADempiere/panel.js @@ -97,7 +97,7 @@ const panel = { }) let orderBy = 'sequence' - if ((params.panelType === 'window' && !params.isParent) || params.panelType === 'browser') { + if ((params.panelType === 'window' && !params.isParentTab) || params.panelType === 'browser') { orderBy = 'seqNoGrid' } params.fieldList = assignedGroup({ diff --git a/src/store/modules/ADempiere/window.js b/src/store/modules/ADempiere/window.js index d5e38d78..52531051 100644 --- a/src/store/modules/ADempiere/window.js +++ b/src/store/modules/ADempiere/window.js @@ -252,7 +252,7 @@ const window = { isAdvancedQuery } - let fieldUuidsequence = 0 + let isWithUuidField = false // indicates it contains the uuid field let fieldLinkColumnName // Convert from gRPC const fieldsList = tabResponse.fieldsList.map((fieldItem, index) => { @@ -263,8 +263,9 @@ const window = { fieldListIndex: index } }) - if (fieldItem.sequence > fieldUuidsequence) { - fieldUuidsequence = fieldItem.sequence + + if (!isWithUuidField && fieldItem.columnName === 'UUID') { + isWithUuidField = true } if (fieldItem.isParent) { @@ -277,30 +278,29 @@ const window = { if (!isAdvancedQuery) { // Get dependent fields fieldsList - .filter(field => field.parentFieldsList && field.isActive) .forEach((field, index, list) => { - field.parentFieldsList.forEach(parentColumnName => { - const parentField = list.find(parentField => { - return parentField.columnName === parentColumnName && parentColumnName !== field.columnName + if (field.parentFieldsList.length && field.isActive) { + field.parentFieldsList.forEach(parentColumnName => { + const parentField = list.find(parentField => { + return parentField.columnName === parentColumnName && parentColumnName !== field.columnName + }) + if (parentField) { + parentField.dependentFieldsList.push(field.columnName) + } }) - if (parentField) { - parentField.dependentFieldsList.push(field.columnName) - } - }) + } }) } - if (!fieldsList.find(field => field.columnName === 'UUID')) { - const attributesOverwrite = { - panelType: panelType, - sequence: (fieldUuidsequence + 10), + if (!isWithUuidField) { + const fieldUuid = getFieldTemplate({ + ...additionalAttributes, + isShowedFromUser: false, name: 'UUID', columnName: 'UUID', - isAdvancedQuery, componentPath: 'FieldText' - } - const field = getFieldTemplate(attributesOverwrite) - fieldsList.push(field) + }) + fieldsList.push(fieldUuid) } const window = getters.getWindow(parentUuid) diff --git a/src/utils/ADempiere/contextUtils.js b/src/utils/ADempiere/contextUtils.js index 49e90a5f..06f515d7 100644 --- a/src/utils/ADempiere/contextUtils.js +++ b/src/utils/ADempiere/contextUtils.js @@ -23,38 +23,19 @@ export const getContext = ({ * @param {string} mandatoryLogic * @param {string} readOnlyLogic * @param {string} defaultValue + * @returns {array} List column name of parent fields */ export function getParentFields({ displayLogic, mandatoryLogic, readOnlyLogic, defaultValue }) { - let parentFields = [] - // For Display logic - if (displayLogic) { - parentFields = Array.from(new Set([ - ...parentFields, - ...evaluator.parseDepends(displayLogic) - ])) - } - // For Mandatory Logic - if (mandatoryLogic) { - parentFields = Array.from(new Set([ - ...parentFields, - ...evaluator.parseDepends(mandatoryLogic) - ])) - } - // For Read Only Logic - if (readOnlyLogic) { - parentFields = Array.from(new Set([ - ...parentFields, - ...evaluator.parseDepends(readOnlyLogic) - ])) - } - // For Default Value - if (defaultValue) { - parentFields = Array.from(new Set([ - ...parentFields, - ...evaluator.parseDepends(defaultValue) - ])) - } - return parentFields + return Array.from(new Set([ + // For Display logic + ...evaluator.parseDepends(displayLogic), + // For Mandatory Logic + ...evaluator.parseDepends(mandatoryLogic), + // For Read Only Logic + ...evaluator.parseDepends(readOnlyLogic), + // For Default Value + ...evaluator.parseDepends(defaultValue) + ])) } /** @@ -88,14 +69,14 @@ export function parseContext({ if (value.includes('@SQL=')) { value = value.replace('@SQL=', '') } - // var instances = value.length - value.replace('@', '').length + // const instances = value.length - value.replace('@', '').length // if ((instances > 0) && (instances % 2) !== 0) { // could be an email address // return value // } - var token - var inString = value - var outString = '' + let token, contextInfo + let inString = value + let outString = '' let firstIndexTag = inString.indexOf('@') @@ -117,7 +98,7 @@ export function parseContext({ token = inString.substring(0, secondIndexTag) columnName = token - var contextInfo = getContext({ + contextInfo = getContext({ parentUuid, containerUuid, columnName diff --git a/src/utils/ADempiere/dictionaryUtils.js b/src/utils/ADempiere/dictionaryUtils.js index 7f676b53..2bd0f2ad 100644 --- a/src/utils/ADempiere/dictionaryUtils.js +++ b/src/utils/ADempiere/dictionaryUtils.js @@ -37,7 +37,8 @@ export function generateField({ operator = 'LIKE' } } else { - if (String(parsedDefaultValue).includes('@')) { + if (String(parsedDefaultValue).includes('@') && + String(parsedDefaultValue).trim() !== '-1') { parsedDefaultValue = parseContext({ ...moreAttributes, columnName: fieldToGenerate.columnName, @@ -46,8 +47,8 @@ export function generateField({ }).value } - if ((isEmptyValue(parsedDefaultValue) || - String(parsedDefaultValue).includes('@')) && + if (isEmptyValue(parsedDefaultValue) && + !(fieldToGenerate.isKey || fieldToGenerate.isParent) && String(parsedDefaultValue).trim() !== '-1') { parsedDefaultValue = getPreference({ parentUuid: fieldToGenerate.parentUuid, @@ -57,9 +58,7 @@ export function generateField({ // search value preference with elementName if (!isEmptyValue(fieldToGenerate.elementName) && - (isEmptyValue(parsedDefaultValue) || - String(parsedDefaultValue).includes('@')) && - String(parsedDefaultValue).trim() !== '-1') { + isEmptyValue(parsedDefaultValue)) { parsedDefaultValue = getPreference({ parentUuid: fieldToGenerate.parentUuid, containerUuid: fieldToGenerate.containerUuid, @@ -76,9 +75,8 @@ export function generateField({ }) // VALUE TO - // if (String(parsedDefaultValueTo).includes('@SQL=')) { - // parsedDefaultValueTo.replace('@SQL=', '') - if (String(parsedDefaultValueTo).includes('@')) { + if (String(parsedDefaultValueTo).includes('@') && + String(parsedDefaultValueTo).trim() !== '-1') { parsedDefaultValueTo = parseContext({ ...moreAttributes, columnName: `${fieldToGenerate.columnName}_To`, @@ -86,8 +84,8 @@ export function generateField({ }).value } - if ((isEmptyValue(parsedDefaultValueTo) || - String(parsedDefaultValueTo).includes('@')) && + if (isEmptyValue(parsedDefaultValueTo) && + !(fieldToGenerate.isKey || fieldToGenerate.isParent) && String(parsedDefaultValueTo).trim() !== '-1') { parsedDefaultValueTo = getPreference({ parentUuid: fieldToGenerate.parentUuid, @@ -97,9 +95,7 @@ export function generateField({ // search value preference with elementName if (!isEmptyValue(fieldToGenerate.elementName) && - (isEmptyValue(parsedDefaultValueTo) || - String(parsedDefaultValueTo).includes('@')) && - String(parsedDefaultValueTo).trim() !== '-1') { + isEmptyValue(parsedDefaultValueTo)) { parsedDefaultValueTo = getPreference({ parentUuid: fieldToGenerate.parentUuid, containerUuid: fieldToGenerate.containerUuid, @@ -260,16 +256,17 @@ export function generateProcess({ processToGenerate, containerUuidAssociated = u // Get dependent fields fieldDefinitionList - .filter(field => field.parentFieldsList && field.isActive) .forEach((field, index, list) => { - field.parentFieldsList.forEach(parentColumnName => { - const parentField = list.find(itemParentField => { - return itemParentField.columnName === parentColumnName && parentColumnName !== field.columnName + if (field.isActive && field.parentFieldsList.length) { + field.parentFieldsList.forEach(parentColumnName => { + const parentField = list.find(itemParentField => { + return itemParentField.columnName === parentColumnName && parentColumnName !== field.columnName + }) + if (parentField) { + parentField.dependentFieldsList.push(field.columnName) + } }) - if (parentField) { - parentField.dependentFieldsList.push(field.columnName) - } - }) + } }) } @@ -392,18 +389,7 @@ export function evalutateTypeField(displayTypeId, isAllInfo = false) { // Default template for injected fields export function getFieldTemplate(attributesOverwrite) { - const referenceValue = { - tableName: '', - keyColumnName: '', - displayColumnName: '', - query: '', - parsedQuery: '', - directQuery: '', - parsedDirectQuery: '', - validationCode: '', - windowsList: [] - } - const newField = { + return { id: 0, uuid: '', name: '', @@ -452,16 +438,26 @@ export function getFieldTemplate(attributesOverwrite) { readOnlyLogic: undefined, parentFieldsList: undefined, dependentFieldsList: [], - reference: referenceValue, + reference: { + tableName: '', + keyColumnName: '', + displayColumnName: '', + query: '', + parsedQuery: '', + directQuery: '', + parsedDirectQuery: '', + validationCode: '', + windowsList: [] + }, contextInfo: undefined, isShowedFromUser: false, isFixedTableColumn: false, sizeFieldFromType: { type: 'Button', size: DEFAULT_SIZE - } + }, + ...attributesOverwrite } - return Object.assign(newField, attributesOverwrite) } /**