mirror of
https://github.com/PanJiaChen/vue-element-admin.git
synced 2025-08-13 07:04:21 +08:00
* fix: #401 Display logic's showed fields. * Update evaluator.js * minor changes.
This commit is contained in:
parent
7fe04ce531
commit
20dfa472b1
@ -15,11 +15,11 @@
|
|||||||
:class="classField"
|
:class="classField"
|
||||||
>
|
>
|
||||||
<el-form-item
|
<el-form-item
|
||||||
:required="isMandatory()"
|
:required="isMandatory"
|
||||||
>
|
>
|
||||||
<template slot="label">
|
<template slot="label">
|
||||||
<operator-comparison
|
<operator-comparison
|
||||||
v-if="isAdvancedQuery && isDisplayed"
|
v-if="isAdvancedQuery"
|
||||||
key="is-field-operator-comparison"
|
key="is-field-operator-comparison"
|
||||||
:field-attributes="fieldAttributes"
|
:field-attributes="fieldAttributes"
|
||||||
:field-value="field.value"
|
:field-value="field.value"
|
||||||
@ -31,14 +31,13 @@
|
|||||||
:field-value="field.value"
|
:field-value="field.value"
|
||||||
/>
|
/>
|
||||||
<span v-else key="is-field-name">
|
<span v-else key="is-field-name">
|
||||||
{{ isFieldOnly() }}
|
{{ isFieldOnly }}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<document-status
|
<document-status
|
||||||
v-if="isDocuemntStatus"
|
v-if="isDocuemntStatus"
|
||||||
:field="fieldAttributes"
|
:field="fieldAttributes"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<translated
|
<translated
|
||||||
v-if="field.isTranslated && !isAdvancedQuery"
|
v-if="field.isTranslated && !isAdvancedQuery"
|
||||||
:field-attributes="fieldAttributes"
|
:field-attributes="fieldAttributes"
|
||||||
@ -134,8 +133,8 @@ export default {
|
|||||||
inTable: this.inTable,
|
inTable: this.inTable,
|
||||||
isAdvancedQuery: this.isAdvancedQuery,
|
isAdvancedQuery: this.isAdvancedQuery,
|
||||||
// DOM properties
|
// DOM properties
|
||||||
required: this.isMandatory(),
|
required: this.isMandatory,
|
||||||
readonly: this.isReadOnly(),
|
readonly: this.isReadOnly,
|
||||||
displayed: this.isDisplayed,
|
displayed: this.isDisplayed,
|
||||||
disabled: !this.field.isActive,
|
disabled: !this.field.isActive,
|
||||||
isSelectCreated: this.isSelectCreated
|
isSelectCreated: this.isSelectCreated
|
||||||
@ -145,7 +144,63 @@ export default {
|
|||||||
if (this.isAdvancedQuery) {
|
if (this.isAdvancedQuery) {
|
||||||
return this.field.isShowedFromUser
|
return this.field.isShowedFromUser
|
||||||
}
|
}
|
||||||
return fieldIsDisplayed(this.field) && (this.isMandatory() || this.field.isShowedFromUser || this.inTable)
|
return fieldIsDisplayed(this.field) && (this.isMandatory || this.field.isShowedFromUser || this.inTable)
|
||||||
|
},
|
||||||
|
isMandatory() {
|
||||||
|
if (this.isAdvancedQuery) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return this.field.isMandatory || this.field.isMandatoryFromLogic
|
||||||
|
},
|
||||||
|
isReadOnly() {
|
||||||
|
if (this.isAdvancedQuery) {
|
||||||
|
if (['NULL', 'NOT_NULL'].includes(this.field.operator)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.field.isActive) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
const isUpdateableAllFields = this.field.isReadOnly || this.field.isReadOnlyFromLogic
|
||||||
|
|
||||||
|
if (this.field.panelType === 'window') {
|
||||||
|
if (this.field.isAlwaysUpdateable) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (this.getterContextProcessing) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if (this.getterContextProcessed) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Evaluate record uuid without route.action
|
||||||
|
// edit mode is diferent to create new
|
||||||
|
let isWithRecord = this.field.recordUuid !== 'create-new'
|
||||||
|
if (this.inTable) {
|
||||||
|
isWithRecord = !this.isEmptyValue(this.field.recordUuid)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (!this.field.isUpdateable && isWithRecord) || (isUpdateableAllFields || this.field.isReadOnlyFromForm)
|
||||||
|
} else if (this.field.panelType === 'browser') {
|
||||||
|
if (this.inTable) {
|
||||||
|
// browser result
|
||||||
|
return this.field.isReadOnly
|
||||||
|
}
|
||||||
|
// query criteria
|
||||||
|
return this.field.isReadOnlyFromLogic
|
||||||
|
}
|
||||||
|
// other type of panels (process/report)
|
||||||
|
return isUpdateableAllFields
|
||||||
|
},
|
||||||
|
isFieldOnly() {
|
||||||
|
if (this.inTable || this.field.isFieldOnly) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
return this.field.name
|
||||||
},
|
},
|
||||||
isSelectCreated() {
|
isSelectCreated() {
|
||||||
return this.isAdvancedQuery &&
|
return this.isAdvancedQuery &&
|
||||||
@ -273,64 +328,8 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
showMessage,
|
showMessage,
|
||||||
isReadOnly() {
|
|
||||||
if (this.isAdvancedQuery) {
|
|
||||||
if (['NULL', 'NOT_NULL'].includes(this.field.operator)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.field.isActive) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
const isUpdateableAllFields = this.field.isReadOnly || this.field.isReadOnlyFromLogic
|
|
||||||
|
|
||||||
if (this.field.panelType === 'window') {
|
|
||||||
if (this.field.isAlwaysUpdateable) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if (this.getterContextProcessing) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if (this.getterContextProcessed) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Evaluate record uuid without route.action
|
|
||||||
// edit mode is diferent to create new
|
|
||||||
let isWithRecord = this.field.recordUuid !== 'create-new'
|
|
||||||
if (this.inTable) {
|
|
||||||
isWithRecord = !this.isEmptyValue(this.field.recordUuid)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (!this.field.isUpdateable && isWithRecord) || (isUpdateableAllFields || this.field.isReadOnlyFromForm)
|
|
||||||
} else if (this.field.panelType === 'browser') {
|
|
||||||
if (this.inTable) {
|
|
||||||
// browser result
|
|
||||||
return this.field.isReadOnly
|
|
||||||
}
|
|
||||||
// query criteria
|
|
||||||
return this.field.isReadOnlyFromLogic
|
|
||||||
}
|
|
||||||
// other type of panels (process/report)
|
|
||||||
return isUpdateableAllFields
|
|
||||||
},
|
|
||||||
isMandatory() {
|
|
||||||
if (this.isAdvancedQuery) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return this.field.isMandatory || this.field.isMandatoryFromLogic
|
|
||||||
},
|
|
||||||
isFieldOnly() {
|
|
||||||
if (this.inTable || this.field.isFieldOnly) {
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
return this.field.name
|
|
||||||
},
|
|
||||||
focusField() {
|
focusField() {
|
||||||
if (this.isDisplayed && this.isMandatory() && !this.isReadOnly()) {
|
if (this.isDisplayed && this.isMandatory && !this.isReadOnly) {
|
||||||
this.$refs[this.field.columnName].activeFocus()
|
this.$refs[this.field.columnName].activeFocus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
// - Process & Report: Always save a panel and parameters
|
// - Process & Report: Always save a panel and parameters
|
||||||
// - Smart Browser: Can have a search panel, table panel and process panel
|
// - Smart Browser: Can have a search panel, table panel and process panel
|
||||||
import { isEmptyValue, parsedValueComponent } from '@/utils/ADempiere/valueUtils'
|
import { isEmptyValue, parsedValueComponent } from '@/utils/ADempiere/valueUtils'
|
||||||
import evaluator, { parseContext } from '@/utils/ADempiere/contextUtils'
|
import evaluator, { getContext, parseContext } from '@/utils/ADempiere/contextUtils'
|
||||||
import { showMessage } from '@/utils/ADempiere/notification'
|
import { showMessage } from '@/utils/ADempiere/notification'
|
||||||
import { assignedGroup, fieldIsDisplayed } from '@/utils/ADempiere/dictionaryUtils'
|
import { assignedGroup, fieldIsDisplayed } from '@/utils/ADempiere/dictionaryUtils'
|
||||||
import router from '@/router'
|
import router from '@/router'
|
||||||
@ -775,28 +775,27 @@ const panel = {
|
|||||||
dependentsList.map(async fieldDependent => {
|
dependentsList.map(async fieldDependent => {
|
||||||
// isDisplayed Logic
|
// isDisplayed Logic
|
||||||
let isDisplayedFromLogic, isMandatoryFromLogic, isReadOnlyFromLogic, defaultValue
|
let isDisplayedFromLogic, isMandatoryFromLogic, isReadOnlyFromLogic, defaultValue
|
||||||
if (fieldDependent.displayLogic.trim() !== '') {
|
if (!isEmptyValue(fieldDependent.displayLogic)) {
|
||||||
isDisplayedFromLogic = evaluator.evaluateLogic({
|
isDisplayedFromLogic = evaluator.evaluateLogic({
|
||||||
context: getters,
|
context: getContext,
|
||||||
parentUuid,
|
parentUuid,
|
||||||
containerUuid,
|
containerUuid,
|
||||||
logic: fieldDependent.displayLogic,
|
logic: fieldDependent.displayLogic
|
||||||
type: 'displayed'
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// Mandatory Logic
|
// Mandatory Logic
|
||||||
if (fieldDependent.mandatoryLogic.trim() !== '') {
|
if (!isEmptyValue(fieldDependent.mandatoryLogic)) {
|
||||||
isMandatoryFromLogic = evaluator.evaluateLogic({
|
isMandatoryFromLogic = evaluator.evaluateLogic({
|
||||||
context: getters,
|
context: getContext,
|
||||||
parentUuid,
|
parentUuid,
|
||||||
containerUuid,
|
containerUuid,
|
||||||
logic: fieldDependent.mandatoryLogic
|
logic: fieldDependent.mandatoryLogic
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// Read Only Logic
|
// Read Only Logic
|
||||||
if (fieldDependent.readOnlyLogic.trim() !== '') {
|
if (!isEmptyValue(fieldDependent.readOnlyLogic)) {
|
||||||
isReadOnlyFromLogic = evaluator.evaluateLogic({
|
isReadOnlyFromLogic = evaluator.evaluateLogic({
|
||||||
context: getters,
|
context: getContext,
|
||||||
parentUuid,
|
parentUuid,
|
||||||
containerUuid,
|
containerUuid,
|
||||||
logic: fieldDependent.readOnlyLogic
|
logic: fieldDependent.readOnlyLogic
|
||||||
|
@ -129,7 +129,7 @@ export function parseContext({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (contextInfo === undefined || contextInfo.length === 0) {
|
if (contextInfo === undefined || contextInfo.length === 0) {
|
||||||
console.info(`No Context for: ${token}`)
|
// console.info(`No Context for: ${token}`)
|
||||||
isError = true
|
isError = true
|
||||||
errorsList.push(token)
|
errorsList.push(token)
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import evaluator from '@/utils/ADempiere/evaluator'
|
import evaluator from '@/utils/ADempiere/evaluator'
|
||||||
import { isEmptyValue, parsedValueComponent } from '@/utils/ADempiere/valueUtils'
|
import { isEmptyValue, parsedValueComponent } from '@/utils/ADempiere/valueUtils'
|
||||||
import { getParentFields, getPreference, parseContext } from '@/utils/ADempiere/contextUtils'
|
import { getContext, getParentFields, getPreference, parseContext } from '@/utils/ADempiere/contextUtils'
|
||||||
import REFERENCES, { FIELD_NOT_SHOWED } from '@/components/ADempiere/Field/references'
|
import REFERENCES, { FIELD_NOT_SHOWED } from '@/components/ADempiere/Field/references'
|
||||||
import { FIELD_DISPLAY_SIZES, DEFAULT_SIZE } from '@/components/ADempiere/Field/fieldSize'
|
import { FIELD_DISPLAY_SIZES, DEFAULT_SIZE } from '@/components/ADempiere/Field/fieldSize'
|
||||||
import language from '@/lang'
|
import language from '@/lang'
|
||||||
@ -26,7 +26,10 @@ export function generateField({
|
|||||||
|
|
||||||
const componentReference = evalutateTypeField(fieldToGenerate.displayType, true)
|
const componentReference = evalutateTypeField(fieldToGenerate.displayType, true)
|
||||||
const referenceType = componentReference.alias[0]
|
const referenceType = componentReference.alias[0]
|
||||||
|
let isDisplayedFromLogic = fieldToGenerate.isDisplayed
|
||||||
|
let isMandatoryFromLogic = false
|
||||||
|
let isReadOnlyFromLogic = false
|
||||||
|
let parentFieldsList = []
|
||||||
let parsedDefaultValue = fieldToGenerate.defaultValue
|
let parsedDefaultValue = fieldToGenerate.defaultValue
|
||||||
let parsedDefaultValueTo = fieldToGenerate.defaultValueTo
|
let parsedDefaultValueTo = fieldToGenerate.defaultValueTo
|
||||||
let operator = 'EQUAL'
|
let operator = 'EQUAL'
|
||||||
@ -116,6 +119,33 @@ export function generateField({
|
|||||||
referenceType,
|
referenceType,
|
||||||
isMandatory: fieldToGenerate.isMandatory
|
isMandatory: fieldToGenerate.isMandatory
|
||||||
})
|
})
|
||||||
|
|
||||||
|
parentFieldsList = getParentFields(fieldToGenerate)
|
||||||
|
|
||||||
|
// evaluate logics
|
||||||
|
const setEvaluateLogics = {
|
||||||
|
parentUuid: moreAttributes.parentUuid,
|
||||||
|
containerUuid: moreAttributes.containerUuid,
|
||||||
|
context: getContext
|
||||||
|
}
|
||||||
|
if (!isEmptyValue(fieldToGenerate.displayLogic)) {
|
||||||
|
isDisplayedFromLogic = evaluator.evaluateLogic({
|
||||||
|
...setEvaluateLogics,
|
||||||
|
logic: fieldToGenerate.displayLogic
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (!isEmptyValue(fieldToGenerate.mandatoryLogic)) {
|
||||||
|
isMandatoryFromLogic = evaluator.evaluateLogic({
|
||||||
|
...setEvaluateLogics,
|
||||||
|
logic: fieldToGenerate.mandatoryLogic
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (!isEmptyValue(fieldToGenerate.readOnlyLogic)) {
|
||||||
|
isReadOnlyFromLogic = evaluator.evaluateLogic({
|
||||||
|
...setEvaluateLogics,
|
||||||
|
logic: fieldToGenerate.readOnlyLogic
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const field = {
|
const field = {
|
||||||
@ -134,11 +164,11 @@ export function generateField({
|
|||||||
parsedDefaultValue,
|
parsedDefaultValue,
|
||||||
parsedDefaultValueTo,
|
parsedDefaultValueTo,
|
||||||
// logics to app
|
// logics to app
|
||||||
isDisplayedFromLogic: fieldToGenerate.isDisplayed,
|
isDisplayedFromLogic,
|
||||||
isReadOnlyFromLogic: false,
|
isReadOnlyFromLogic,
|
||||||
isMandatoryFromLogic: false,
|
isMandatoryFromLogic,
|
||||||
//
|
//
|
||||||
parentFieldsList: [],
|
parentFieldsList,
|
||||||
dependentFieldsList: [],
|
dependentFieldsList: [],
|
||||||
// TODO: Add support on server
|
// TODO: Add support on server
|
||||||
// app attributes
|
// app attributes
|
||||||
@ -152,31 +182,6 @@ export function generateField({
|
|||||||
defaultOperator: operator
|
defaultOperator: operator
|
||||||
}
|
}
|
||||||
|
|
||||||
// evaluate simple logics without context
|
|
||||||
if (!field.isAdvancedQuery) {
|
|
||||||
field.parentFieldsList = getParentFields(fieldToGenerate)
|
|
||||||
|
|
||||||
if (field.displayLogic.trim() !== '' && !field.displayLogic.includes('@')) {
|
|
||||||
field.isDisplayedFromLogic = evaluator.evaluateLogic({
|
|
||||||
type: 'displayed',
|
|
||||||
logic: field.displayLogic
|
|
||||||
})
|
|
||||||
field.isDisplayedFromLogic = Boolean(field.isDisplayedFromLogic)
|
|
||||||
}
|
|
||||||
if (field.mandatoryLogic.trim() !== '' && !field.mandatoryLogic.includes('@')) {
|
|
||||||
field.isMandatoryFromLogic = evaluator.evaluateLogic({
|
|
||||||
logic: field.mandatoryLogic
|
|
||||||
})
|
|
||||||
field.isMandatoryFromLogic = Boolean(field.isMandatoryFromLogic)
|
|
||||||
}
|
|
||||||
if (field.readOnlyLogic.trim() !== '' && !field.readOnlyLogic.includes('@')) {
|
|
||||||
field.isReadOnlyFromLogic = evaluator.evaluateLogic({
|
|
||||||
logic: field.readOnlyLogic
|
|
||||||
})
|
|
||||||
field.isReadOnlyFromLogic = Boolean(field.isReadOnlyFromLogic)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sizes from panel and groups
|
// Sizes from panel and groups
|
||||||
field.sizeFieldFromType = FIELD_DISPLAY_SIZES.find(item => {
|
field.sizeFieldFromType = FIELD_DISPLAY_SIZES.find(item => {
|
||||||
return item.type === field.componentPath
|
return item.type === field.componentPath
|
||||||
@ -201,9 +206,7 @@ export function generateField({
|
|||||||
|
|
||||||
// hidden field type button
|
// hidden field type button
|
||||||
const notShowedField = FIELD_NOT_SHOWED.find(itemField => {
|
const notShowedField = FIELD_NOT_SHOWED.find(itemField => {
|
||||||
if (field.displayType === itemField.id) {
|
return field.displayType === itemField.id
|
||||||
return true
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
if (notShowedField) {
|
if (notShowedField) {
|
||||||
field.isDisplayedFromLogic = false
|
field.isDisplayedFromLogic = false
|
||||||
|
@ -15,26 +15,29 @@ class evaluator {
|
|||||||
/**
|
/**
|
||||||
* Evaluate logic's
|
* Evaluate logic's
|
||||||
* @param {string} parentUuid Parent (Window / Process / Smart Browser)
|
* @param {string} parentUuid Parent (Window / Process / Smart Browser)
|
||||||
|
* @param {function} context
|
||||||
|
* @param {string} logic
|
||||||
|
* @param {boolean} defaultReturned value to return if logic or context is undefined
|
||||||
*/
|
*/
|
||||||
static evaluateLogic(objectToEvaluate) {
|
static evaluateLogic({
|
||||||
let defaultUndefined = false
|
parentUuid,
|
||||||
if (objectToEvaluate.type === 'displayed') {
|
containerUuid,
|
||||||
defaultUndefined = true
|
context,
|
||||||
}
|
logic,
|
||||||
|
defaultReturned = false
|
||||||
|
}) {
|
||||||
// empty logic
|
// empty logic
|
||||||
if (objectToEvaluate.logic === undefined ||
|
if (logic === undefined || logic === null || logic.trim() === '') {
|
||||||
objectToEvaluate.logic === null ||
|
return defaultReturned
|
||||||
objectToEvaluate.logic.trim() === '') {
|
|
||||||
return defaultUndefined
|
|
||||||
}
|
}
|
||||||
const st = objectToEvaluate.logic.trim().replace('\n', '')
|
const st = logic.trim().replace('\n', '')
|
||||||
const expr = /(\||&)/
|
const expr = /(\||&)/
|
||||||
const stList = st.split(expr)
|
const stList = st.split(expr)
|
||||||
const it = stList.length
|
const it = stList.length
|
||||||
|
|
||||||
if (((it / 2) - ((it + 1) / 2)) === 0) {
|
if (((it / 2) - ((it + 1) / 2)) === 0) {
|
||||||
console.info(`Logic does not comply with format "<expression> [<logic> <expression>]" --> ${objectToEvaluate.logic}`)
|
console.info(`Logic does not comply with format "<expression> [<logic> <expression>]" --> ${logic}`)
|
||||||
return defaultUndefined
|
return defaultReturned
|
||||||
}
|
}
|
||||||
|
|
||||||
let retValue = null
|
let retValue = null
|
||||||
@ -44,23 +47,32 @@ class evaluator {
|
|||||||
logOp = element
|
logOp = element
|
||||||
} else if (retValue === null) {
|
} else if (retValue === null) {
|
||||||
retValue = evaluator.evaluateLogicTuples({
|
retValue = evaluator.evaluateLogicTuples({
|
||||||
...objectToEvaluate,
|
parentUuid,
|
||||||
conditional: element
|
containerUuid,
|
||||||
|
context,
|
||||||
|
logic: element,
|
||||||
|
defaultReturned
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
if (logOp.trim() === '&') {
|
if (logOp.trim() === '&') {
|
||||||
retValue = retValue & evaluator.evaluateLogicTuples({
|
retValue = retValue & evaluator.evaluateLogicTuples({
|
||||||
...objectToEvaluate,
|
parentUuid,
|
||||||
conditional: element
|
containerUuid,
|
||||||
|
context,
|
||||||
|
logic: element,
|
||||||
|
defaultReturned
|
||||||
})
|
})
|
||||||
} else if (logOp.trim() === '|') {
|
} else if (logOp.trim() === '|') {
|
||||||
retValue = retValue | evaluator.evaluateLogicTuples({
|
retValue = retValue | evaluator.evaluateLogicTuples({
|
||||||
...objectToEvaluate,
|
parentUuid,
|
||||||
conditional: element
|
containerUuid,
|
||||||
|
context,
|
||||||
|
logic: element,
|
||||||
|
defaultReturned
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
console.info(`Logic operant '|' or '&' expected --> ${objectToEvaluate.logic}`)
|
console.info(`Logic operant '|' or '&' expected --> ${logic}`)
|
||||||
return defaultUndefined
|
return defaultReturned
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -69,19 +81,23 @@ class evaluator {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Evaluate Logic Tuples
|
* Evaluate Logic Tuples
|
||||||
* @param {object} objectToEvaluate Complete object
|
* @param {string} parentUuid Complete object
|
||||||
|
* @param {string} containerUuid Complete object
|
||||||
|
* @param {function} context
|
||||||
* @param {string} logic If is displayed or not (mandatory and readonly)
|
* @param {string} logic If is displayed or not (mandatory and readonly)
|
||||||
|
* @param {boolean} defaultReturned
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
static evaluateLogicTuples(objectToEvaluate) {
|
static evaluateLogicTuples({
|
||||||
let _defaultUndefined = false
|
parentUuid,
|
||||||
if (objectToEvaluate.type === 'displayed') {
|
containerUuid,
|
||||||
_defaultUndefined = true
|
context,
|
||||||
}
|
defaultReturned = false,
|
||||||
const logic = objectToEvaluate.conditional
|
logic
|
||||||
|
}) {
|
||||||
// not context info, not logic
|
// not context info, not logic
|
||||||
if (logic === undefined) {
|
if (logic === undefined || logic === null || logic.trim() === '') {
|
||||||
return _defaultUndefined
|
return defaultReturned
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,7 +113,7 @@ class evaluator {
|
|||||||
|
|
||||||
if (!st) {
|
if (!st) {
|
||||||
console.info(`.Logic tuple does not comply with format '@context@=value' where operand could be one of '=!^><' --> ${logic}`)
|
console.info(`.Logic tuple does not comply with format '@context@=value' where operand could be one of '=!^><' --> ${logic}`)
|
||||||
return _defaultUndefined
|
return defaultReturned
|
||||||
}
|
}
|
||||||
|
|
||||||
expr = /(<>|<=|==|>=|!=|<|=|>|!|\^)/gm
|
expr = /(<>|<=|==|>=|!=|<|=|>|!|\^)/gm
|
||||||
@ -113,21 +129,26 @@ class evaluator {
|
|||||||
first = first.replace(/@/g, '').trim()
|
first = first.replace(/@/g, '').trim()
|
||||||
isGlobal = first.startsWith('#')
|
isGlobal = first.startsWith('#')
|
||||||
isCountable = first.startsWith('$')
|
isCountable = first.startsWith('$')
|
||||||
const value = objectToEvaluate.context.getContext({
|
if (isGlobal || isCountable) {
|
||||||
parentUuid: (isGlobal || isCountable) ? '' : objectToEvaluate.parentUuid,
|
parentUuid = null
|
||||||
containerUuid: (isGlobal || isCountable) ? '' : objectToEvaluate.containerUuid,
|
containerUuid = null
|
||||||
|
}
|
||||||
|
|
||||||
|
const value = context({
|
||||||
|
parentUuid,
|
||||||
|
containerUuid,
|
||||||
columnName: first
|
columnName: first
|
||||||
})
|
})
|
||||||
// in context exists this column name
|
// in context exists this column name
|
||||||
if (value === null || value === undefined) {
|
if (value === null || value === undefined) {
|
||||||
// console.info(`.The column ${first} not exists in context.`)
|
// console.info(`.The column ${first} not exists in context.`)
|
||||||
return _defaultUndefined
|
return defaultReturned
|
||||||
}
|
}
|
||||||
firstEval = value // replace with it's value
|
firstEval = value // replace with it's value
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstEval === null || firstEval === undefined) {
|
if (firstEval === null || firstEval === undefined) {
|
||||||
return _defaultUndefined
|
return defaultReturned
|
||||||
}
|
}
|
||||||
if (typeof firstEval === 'string') {
|
if (typeof firstEval === 'string') {
|
||||||
firstEval = firstEval.replace(/['"]/g, '').trim() // strip ' and "
|
firstEval = firstEval.replace(/['"]/g, '').trim() // strip ' and "
|
||||||
@ -140,9 +161,9 @@ class evaluator {
|
|||||||
let secondEval = second.trim()
|
let secondEval = second.trim()
|
||||||
if (expr.test(second)) {
|
if (expr.test(second)) {
|
||||||
second = second.replace(/@/g, ' ').trim() // strip tag
|
second = second.replace(/@/g, ' ').trim() // strip tag
|
||||||
secondEval = objectToEvaluate.context.getContext({
|
secondEval = context({
|
||||||
parentUuid: (isGlobal || isCountable) ? null : objectToEvaluate.parentUuid,
|
parentUuid,
|
||||||
containerUuid: (isGlobal || isCountable) ? null : objectToEvaluate.containerUuid,
|
containerUuid,
|
||||||
columnName: first
|
columnName: first
|
||||||
}) // replace with it's value
|
}) // replace with it's value
|
||||||
}
|
}
|
||||||
@ -161,7 +182,7 @@ class evaluator {
|
|||||||
// Logical Comparison
|
// Logical Comparison
|
||||||
const result = this.evaluateLogicTuple(firstEval, operand, secondEval)
|
const result = this.evaluateLogicTuple(firstEval, operand, secondEval)
|
||||||
|
|
||||||
return result
|
return Boolean(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -172,19 +193,21 @@ class evaluator {
|
|||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
static evaluateLogicTuple(value1, operand, value2) {
|
static evaluateLogicTuple(value1, operand, value2) {
|
||||||
// Convert value 1 string value to boolean value
|
const convertStringToBoolean = (valueToParsed) => {
|
||||||
if (value1 === 'Y') {
|
const valueString = String(valueToParsed).trim()
|
||||||
value1 = true
|
if (valueString === 'Y') {
|
||||||
} else if (value1 === 'N') {
|
return true
|
||||||
value1 = false
|
} else if (valueString === 'N') {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return valueToParsed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert value 1 string value to boolean value
|
||||||
|
value1 = convertStringToBoolean(value1)
|
||||||
|
|
||||||
// Convert value 2 string value to boolean value
|
// Convert value 2 string value to boolean value
|
||||||
if (value2 === 'Y') {
|
value2 = convertStringToBoolean(value2)
|
||||||
value2 = true
|
|
||||||
} else if (value2 === 'N') {
|
|
||||||
value2 = false
|
|
||||||
}
|
|
||||||
|
|
||||||
let isValueLogic
|
let isValueLogic
|
||||||
// TODO: Add '^' operand comparison
|
// TODO: Add '^' operand comparison
|
||||||
|
Loading…
x
Reference in New Issue
Block a user