From b471d0c5cf63d08ad41692582f336bf9aca32e89 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Mon, 27 Sep 2021 19:25:11 +0200 Subject: [PATCH] improved calculation fields --- .../buildComputation/parseCalculationFields.js | 12 ++++++++++-- app/imports/ui/components/global/TextField.vue | 14 +++++++++++++- .../ui/properties/forms/shared/ComputedField.vue | 12 ++++++++++-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/app/imports/api/engine/computation/buildComputation/parseCalculationFields.js b/app/imports/api/engine/computation/buildComputation/parseCalculationFields.js index 518132fc..6dbc90a4 100644 --- a/app/imports/api/engine/computation/buildComputation/parseCalculationFields.js +++ b/app/imports/api/engine/computation/buildComputation/parseCalculationFields.js @@ -2,7 +2,7 @@ import INLINE_CALCULATION_REGEX from '/imports/constants/INLINE_CALCULTION_REGEX import { prettifyParseError, parse } from '/imports/parser/parser.js'; import ErrorNode from '/imports/parser/parseTree/ErrorNode.js'; import applyFnToKey from '/imports/api/engine/computation/utility/applyFnToKey.js'; -import { get } from 'lodash'; +import { get, unset } from 'lodash'; export default function parseCalculationFields(prop, schemas){ discoverInlineCalculationFields(prop, schemas); @@ -50,6 +50,11 @@ function parseAllCalculationFields(prop, schemas){ applyFnToKey(prop, calcKey, (prop, key) => { const calcObj = get(prop, key); if (!calcObj) return; + // If the calculation isn't set, delete the whole object + if (!calcObj.calculation){ + unset(prop, key); + return; + } // Store a reference to all the calculations prop._computationDetails.calculations.push(calcObj); // Store the level to compute down to later @@ -67,7 +72,10 @@ function parseCalculation(calcObj){ try { calcObj._parsedCalculation = parse(calculation); } catch (e) { - let error = prettifyParseError(e); + let error = { + type: 'evaluation', + message: prettifyParseError(e), + }; calcObj.errors ? calcObj.errors.push(error) : calcObj.errors = [error]; diff --git a/app/imports/ui/components/global/TextField.vue b/app/imports/ui/components/global/TextField.vue index 7ff7617f..9c9f0919 100644 --- a/app/imports/ui/components/global/TextField.vue +++ b/app/imports/ui/components/global/TextField.vue @@ -2,6 +2,7 @@ + > + + + + diff --git a/app/imports/ui/properties/forms/shared/ComputedField.vue b/app/imports/ui/properties/forms/shared/ComputedField.vue index 51719474..c7d5b8a2 100644 --- a/app/imports/ui/properties/forms/shared/ComputedField.vue +++ b/app/imports/ui/properties/forms/shared/ComputedField.vue @@ -2,9 +2,17 @@
+ > + +
@@ -19,7 +27,7 @@ export default { props: { model: { type: Object, - default: () => {}, + default: () => ({}), }, }, }