From 741f7f65c2dfcec5e9305133121f4b462a791c31 Mon Sep 17 00:00:00 2001 From: yuri Date: Wed, 1 Feb 2017 12:11:49 +0200 Subject: [PATCH 1/3] formula fix --- client/res/templates/fields/formula/detail.tpl | 7 +++++++ client/src/views/fields/formula.js | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 client/res/templates/fields/formula/detail.tpl diff --git a/client/res/templates/fields/formula/detail.tpl b/client/res/templates/fields/formula/detail.tpl new file mode 100644 index 0000000000..0d793ef94d --- /dev/null +++ b/client/res/templates/fields/formula/detail.tpl @@ -0,0 +1,7 @@ + + +
+
+
{{{value}}}
+
+
\ No newline at end of file diff --git a/client/src/views/fields/formula.js b/client/src/views/fields/formula.js index b3079a4ecf..c4d12476a5 100644 --- a/client/src/views/fields/formula.js +++ b/client/src/views/fields/formula.js @@ -30,7 +30,7 @@ Espo.define('views/fields/formula', 'views/fields/text', function (Dep) { return Dep.extend({ - detailTemplate: 'fields/formula/edit', + detailTemplate: 'fields/formula/detail', editTemplate: 'fields/formula/edit', From a26436d3dea85290579c36caf009f90eb2254d7c Mon Sep 17 00:00:00 2001 From: yuri Date: Wed, 1 Feb 2017 15:55:15 +0200 Subject: [PATCH 2/3] fix formula field --- client/src/views/fields/formula.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/views/fields/formula.js b/client/src/views/fields/formula.js index c4d12476a5..5fd59eecaa 100644 --- a/client/src/views/fields/formula.js +++ b/client/src/views/fields/formula.js @@ -88,7 +88,7 @@ Espo.define('views/fields/formula', 'views/fields/text', function (Dep) { this.$editor = this.$el.find('#' + this.containerId); - if (this.mode === 'edit' || this.mode == 'detail') { + if (this.$editor.size() && this.mode === 'edit' || this.mode == 'detail') { this.$editor .css('height', this.height + 'px') .css('fontSize', '14px'); From 6d4b3f24cb42b9756046c13da2ad835a3d81d7f0 Mon Sep 17 00:00:00 2001 From: yuri Date: Thu, 2 Feb 2017 11:18:25 +0200 Subject: [PATCH 3/3] fix formula --- .../Core/Formula/Functions/AttributeType.php | 2 +- .../EntityGroup/AttributeFetchedType.php | 4 +- .../Functions/EntityGroup/AttributeType.php | 20 ++++++- .../EntityGroup/IsAttributeChangedType.php | 33 +++++------- .../EntityGroup/IsAttributeNotChangedType.php | 6 +-- application/Espo/Core/Formula/Parser.php | 2 +- tests/unit/Espo/Core/Formula/FormulaTest.php | 52 +++++++++++++++---- 7 files changed, 80 insertions(+), 39 deletions(-) diff --git a/application/Espo/Core/Formula/Functions/AttributeType.php b/application/Espo/Core/Formula/Functions/AttributeType.php index 355a083dc4..6d7df402dc 100644 --- a/application/Espo/Core/Formula/Functions/AttributeType.php +++ b/application/Espo/Core/Formula/Functions/AttributeType.php @@ -1,4 +1,4 @@ -value)) { + throw new Error(); + } + + if (count($item->value) < 1) { + throw new Error(); + } + + $attribute = $this->evaluate($item->value[0]); + + return $this->getAttributeValue($attribute); + } } \ No newline at end of file diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeChangedType.php b/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeChangedType.php index 5ebbdb3c8e..aa55f2f37d 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeChangedType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeChangedType.php @@ -1,4 +1,4 @@ -value)) { - $attributeList = $attribute; - foreach ($item->value as $value) { - $attribute = $this->evaluate($item->value); - $attributeList[] = $attribute; - } - } else { - $attribute = $this->evaluate($item->value); - $attributeList[] = $attribute; + if (!is_array($item->value)) { + throw new Error(); } - return $this->check($attributeList); + if (count($item->value) < 1) { + throw new Error(); + } + + $attribute = $this->evaluate($item->value[0]); + + return $this->check($attribute); } - protected function check(array $attributeList) + protected function check($attribute) { - $result = true; - foreach ($attributeList as $i => $attribute) { - if (!$this->getEntity()->isAttributeChanged($attribute)) { - $result = false; - break; - } - } - return $result; + return $this->getEntity()->isAttributeChanged($attribute); } } \ No newline at end of file diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeNotChangedType.php b/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeNotChangedType.php index ac7e7718c3..8251e99e79 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeNotChangedType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeNotChangedType.php @@ -1,4 +1,4 @@ -assertEquals('Test', $result); } - function testAttributeFetched() + function testEntityAttribute() + { + $item = json_decode(' + { + "type": "entity\\\\attribute", + "value": [ + { + "type": "value", + "value": "name" + } + ] + } + '); + + $this->setEntityAttributes($this->entity, array( + 'name' => 'Test' + )); + + $result = $this->formula->process($item, $this->entity); + + $this->assertEquals('Test', $result); + } + + function testEntityAttributeFetched() { $item = json_decode(' { "type": "entity\\\\attributeFetched", - "value": "name" + "value": [ + { + "type": "value", + "value": "name" + } + ] } '); @@ -162,10 +190,12 @@ class FormulaTest extends \PHPUnit_Framework_TestCase $item = json_decode(' { "type": "entity\\\\isAttributeChanged", - "value": { - "type": "value", - "value": "name" - } + "value": [ + { + "type": "value", + "value": "name" + } + ] } '); @@ -188,10 +218,12 @@ class FormulaTest extends \PHPUnit_Framework_TestCase $item = json_decode(' { "type": "entity\\\\isAttributeNotChanged", - "value": { - "type": "value", - "value": "name" - } + "value": [ + { + "type": "value", + "value": "name" + } + ] } ');