From ac4b0df91ce53709c9030a3be8bfde325c71b700 Mon Sep 17 00:00:00 2001 From: Edwin Betancourt Date: Tue, 11 Feb 2020 15:54:10 -0400 Subject: [PATCH] fix: #316 Add Smart Browser validation to research with mandatory parameters. (#317) * fix: Add Smart Browser validation to research with mandatory parameters. * Delete duplicated code. --- .../ADempiere/ContextMenu/contextMenuMixin.js | 46 +++++++------------ src/store/modules/ADempiere/browser.js | 20 ++++---- src/store/modules/ADempiere/panel.js | 3 +- src/utils/ADempiere/dictionaryUtils.js | 42 +++++++++-------- src/utils/ADempiere/valueUtils.js | 2 +- 5 files changed, 54 insertions(+), 59 deletions(-) diff --git a/src/components/ADempiere/ContextMenu/contextMenuMixin.js b/src/components/ADempiere/ContextMenu/contextMenuMixin.js index 81c59c5c..447c5691 100644 --- a/src/components/ADempiere/ContextMenu/contextMenuMixin.js +++ b/src/components/ADempiere/ContextMenu/contextMenuMixin.js @@ -1,4 +1,4 @@ -import { showNotification } from '@/utils/ADempiere/notification' +import { showNotification, showMessage } from '@/utils/ADempiere/notification' import Item from './items' import { convertFieldListToShareLink, recursiveTreeSearch } from '@/utils/ADempiere/valueUtils' import { supportedTypes, exportFileFromJson } from '@/utils/ADempiere/exportUtil' @@ -195,6 +195,7 @@ export const contextMixin = { this.getReferences() }, methods: { + showMessage, showNotification, actionContextMenu(event) { switch (event.srcKey) { @@ -217,35 +218,9 @@ export const contextMixin = { }) break case 'f5': - if (this.panelType === 'window') { - this.$store.dispatch('getDataListTab', { - parentUuid: this.parentUuid, - containerUuid: this.containerUuid, - isRefreshPanel: true, - recordUuid: this.recordUuid - }) - } else if (this.panelType === 'browser') { - this.$store.dispatch('getBrowserSearch', { - containerUuid: this.containerUuid, - isClearSelection: true - }) - } + this.refreshData() break } - // this.$store.dispatch('resetPanelToNew', { - // parentUuid: this.parentUuid, - // containerUuid: this.containerUuid, - // recordUuid: this.recordUuid, - // panelType: 'window', - // isNewRecord: true - // }) - // this.$store.dispatch('deleteEntity', { - // parentUuid: this.parentUuid, - // containerUuid: this.containerUuid, - // recordUuid: this.recordUuid, - // panelType: 'window', - // isNewRecord: false - // }) }, refreshData() { if (this.panelType === 'window') { @@ -256,10 +231,21 @@ export const contextMixin = { recordUuid: this.recordUuid }) } else if (this.panelType === 'browser') { - this.$store.dispatch('getBrowserSearch', { + const fieldsEmpty = this.$store.getters.getFieldListEmptyMandatory({ containerUuid: this.containerUuid, - isClearSelection: true + fieldsList: this.getterFieldList }) + if (fieldsEmpty.length) { + this.showMessage({ + message: this.$t('notifications.mandatoryFieldMissing') + fieldsEmpty, + type: 'info' + }) + } else { + this.$store.dispatch('getBrowserSearch', { + containerUuid: this.containerUuid, + isClearSelection: true + }) + } } }, getReferences() { diff --git a/src/store/modules/ADempiere/browser.js b/src/store/modules/ADempiere/browser.js index 1a3b9149..b3da8d9e 100644 --- a/src/store/modules/ADempiere/browser.js +++ b/src/store/modules/ADempiere/browser.js @@ -67,13 +67,18 @@ const browser = { field.isShowedFromUser = true } - // Only isQueryCriteria fields, displayed in main panel - if (field.isQueryCriteria && !isEmptyValue(field.value) && String(field.value) !== '-1') { - field.isShowedFromUser = true + // Only isQueryCriteria fields with values, displayed in main panel + if (field.isQueryCriteria) { + if (isEmptyValue(field.value)) { + // isMandatory params to showed search criteria + if (field.isMandatory || field.isMandatoryFromLogic) { + isMandatoryParams = true + } + } else { + field.isShowedFromUser = true + } } - // TODO: Evaluate if not change when iterate - isMandatoryParams = field.isMandatory return field }) fieldsList = fieldsList.concat(fieldsRangeList) @@ -83,7 +88,7 @@ const browser = { .filter(field => field.parentFieldsList && field.isActive) .forEach((field, index, list) => { field.parentFieldsList.forEach(parentColumnName => { - var parentField = list.find(parentField => { + const parentField = list.find(parentField => { return parentField.columnName === parentColumnName && parentColumnName !== field.columnName }) if (parentField) { @@ -124,11 +129,10 @@ const browser = { // Panel for save on store const newBrowser = { ...browserResponse, - containerUuid: browserResponse.uuid, + containerUuid, fieldList: fieldsList, panelType, // app attributes - isMandatoryParams, isShowedCriteria: Boolean(fieldsList.length && isMandatoryParams), isShowedTotals: true } diff --git a/src/store/modules/ADempiere/panel.js b/src/store/modules/ADempiere/panel.js index 757f5369..55b89b2b 100644 --- a/src/store/modules/ADempiere/panel.js +++ b/src/store/modules/ADempiere/panel.js @@ -731,7 +731,8 @@ const panel = { } // Default Value if (fieldDependent.defaultValue.trim() !== '' && - fieldDependent.defaultValue.includes('@')) { + fieldDependent.defaultValue.includes('@') && + String(fieldDependent.defaultValue).trim() !== '-1') { defaultValue = parseContext({ parentUuid, containerUuid, diff --git a/src/utils/ADempiere/dictionaryUtils.js b/src/utils/ADempiere/dictionaryUtils.js index 4f9b44fd..0f26cbd0 100644 --- a/src/utils/ADempiere/dictionaryUtils.js +++ b/src/utils/ADempiere/dictionaryUtils.js @@ -30,19 +30,21 @@ export function generateField(fieldToGenerate, moreAttributes, typeRange = false value: parsedDefaultValue }).value } - if (isEmptyValue(parsedDefaultValue)) { + if (isEmptyValue(parsedDefaultValue) && String(parsedDefaultValue).trim() !== '-1') { parsedDefaultValue = getPreference({ parentUuid: fieldToGenerate.parentUuid, containerUuid: fieldToGenerate.containerUuid, columnName: fieldToGenerate.columnName }) - } - if (isEmptyValue(parsedDefaultValue) && !isEmptyValue(fieldToGenerate.elementName)) { - parsedDefaultValue = getPreference({ - parentUuid: fieldToGenerate.parentUuid, - containerUuid: fieldToGenerate.containerUuid, - columnName: fieldToGenerate.elementName - }) + + // search value preference with elementName + if (isEmptyValue(parsedDefaultValue) && !isEmptyValue(fieldToGenerate.elementName)) { + parsedDefaultValue = getPreference({ + parentUuid: fieldToGenerate.parentUuid, + containerUuid: fieldToGenerate.containerUuid, + columnName: fieldToGenerate.elementName + }) + } } } parsedDefaultValue = parsedValueComponent({ @@ -63,19 +65,21 @@ export function generateField(fieldToGenerate, moreAttributes, typeRange = false value: parsedDefaultValueTo }).value } - if (isEmptyValue(parsedDefaultValueTo)) { + if (isEmptyValue(parsedDefaultValueTo) && String(parsedDefaultValueTo).trim() !== '-1') { parsedDefaultValueTo = getPreference({ parentUuid: fieldToGenerate.parentUuid, containerUuid: fieldToGenerate.containerUuid, columnName: `${fieldToGenerate.columnName}_To` }) - } - if (isEmptyValue(parsedDefaultValueTo) && !isEmptyValue(fieldToGenerate.elementName)) { - parsedDefaultValueTo = getPreference({ - parentUuid: fieldToGenerate.parentUuid, - containerUuid: fieldToGenerate.containerUuid, - columnName: `${fieldToGenerate.elementName}_To` - }) + + // search value preference with elementName + if (isEmptyValue(parsedDefaultValueTo) && !isEmptyValue(fieldToGenerate.elementName)) { + parsedDefaultValueTo = getPreference({ + parentUuid: fieldToGenerate.parentUuid, + containerUuid: fieldToGenerate.containerUuid, + columnName: `${fieldToGenerate.elementName}_To` + }) + } } } parsedDefaultValueTo = parsedValueComponent({ @@ -101,9 +105,9 @@ export function generateField(fieldToGenerate, moreAttributes, typeRange = false parsedDefaultValue, parsedDefaultValueTo, // logics to app - isDisplayedFromLogic: Boolean(fieldToGenerate.isDisplayed), - isReadOnlyFromLogic: Boolean(fieldToGenerate.isReadOnly), - isMandatoryFromLogic: Boolean(fieldToGenerate.isMandatory), + isDisplayedFromLogic: fieldToGenerate.isDisplayed, + isReadOnlyFromLogic: false, + isMandatoryFromLogic: false, // parentFieldsList: [], dependentFieldsList: [], diff --git a/src/utils/ADempiere/valueUtils.js b/src/utils/ADempiere/valueUtils.js index 7e2fed55..b9275151 100644 --- a/src/utils/ADempiere/valueUtils.js +++ b/src/utils/ADempiere/valueUtils.js @@ -10,7 +10,7 @@ import { convertValueFromGRPC } from '@/api/ADempiere/data' export function isEmptyValue(value) { if (value === undefined || value == null) { return true - } else if (value === -1 || value === '-1') { + } else if (value === -1 || String(value).trim() === '-1') { return true } else if (typeof value === 'string') { return Boolean(!value.trim().length)