From 5b6faf2341b8a964a5ff97d0a272322f8e7fbb06 Mon Sep 17 00:00:00 2001 From: Pascal Dunaj Date: Thu, 12 Nov 2020 10:25:25 +0100 Subject: [PATCH 1/3] Calculated fields and fixes --- .../Operators/MultiRelatedOperatorsTrait.php | 1 + .../fieldConditionPanel/numeric.js | 20 +--------- .../js/pimcore/searchConfig/resultPanel.js | 9 +---- .../Service/FilterService.php | 39 ++++++++++++++++++- 4 files changed, 41 insertions(+), 28 deletions(-) diff --git a/src/AdvancedSearchBundle/Filter/FieldDefinitionAdapter/Operators/MultiRelatedOperatorsTrait.php b/src/AdvancedSearchBundle/Filter/FieldDefinitionAdapter/Operators/MultiRelatedOperatorsTrait.php index e851e76..c174ec0 100644 --- a/src/AdvancedSearchBundle/Filter/FieldDefinitionAdapter/Operators/MultiRelatedOperatorsTrait.php +++ b/src/AdvancedSearchBundle/Filter/FieldDefinitionAdapter/Operators/MultiRelatedOperatorsTrait.php @@ -12,6 +12,7 @@ protected function getFieldOperators(): array { return [ ['fieldName' => 'contains_related', 'fieldLabel' => 'bundle_advancedSearch_character_operator_contain'], + ['fieldName' => 'not_contain_related', 'fieldLabel' => 'bundle_advancedSearch_character_operator_not_contain'], ]; } } diff --git a/src/AdvancedSearchBundle/Resources/public/js/pimcore/searchConfig/fieldConditionPanel/numeric.js b/src/AdvancedSearchBundle/Resources/public/js/pimcore/searchConfig/fieldConditionPanel/numeric.js index 6b1ba28..f14328d 100644 --- a/src/AdvancedSearchBundle/Resources/public/js/pimcore/searchConfig/fieldConditionPanel/numeric.js +++ b/src/AdvancedSearchBundle/Resources/public/js/pimcore/searchConfig/fieldConditionPanel/numeric.js @@ -61,28 +61,12 @@ pimcore.bundle.advancedSearch.searchConfig.fieldConditionPanel.numeric = Class.c }, getFilterValues: function() { - - var filterEntryData = {}, - operator = "must", - operatorFieldValue = this.operatorField.getValue(); - - if(operatorFieldValue == "eq") { - filterEntryData = this.termField.getValue() - } else { - filterEntryData[operatorFieldValue] = this.termField.getValue(); - } - - if(operatorFieldValue == "exists" || operatorFieldValue == "not_exists") { - operator = operatorFieldValue; - } - return { fieldname: this.fieldSelectionInformation.fieldName, - filterEntryData: filterEntryData, - operator: operator, + filterEntryData: this.termField.getValue(), + operator: this.operatorField.getValue(), ignoreInheritance: this.inheritanceField.getValue() }; - } }); diff --git a/src/AdvancedSearchBundle/Resources/public/js/pimcore/searchConfig/resultPanel.js b/src/AdvancedSearchBundle/Resources/public/js/pimcore/searchConfig/resultPanel.js index 3c8c40c..ee663f2 100644 --- a/src/AdvancedSearchBundle/Resources/public/js/pimcore/searchConfig/resultPanel.js +++ b/src/AdvancedSearchBundle/Resources/public/js/pimcore/searchConfig/resultPanel.js @@ -207,14 +207,7 @@ pimcore.bundle.advancedSearch.searchConfig.resultPanel = Class.create(pimcore.ob ] }); - - this.pagingtoolbar = Ext.create("Ext.PagingToolbar", { - pageSize: itemsPerPage, - store: this.store, - displayInfo: true, - displayMsg: '{0} - {1} / {2}', - emptyMsg: t("no_objects_found") - }); + this.pagingtoolbar = pimcore.helpers.grid.buildDefaultPagingToolbar(this.store, {pageSize: itemsPerPage}); this.languageInfo = new Ext.Toolbar.TextItem({ text: t("grid_current_language") + ": " + pimcore.available_languages[this.gridLanguage] diff --git a/src/AdvancedSearchBundle/Service/FilterService.php b/src/AdvancedSearchBundle/Service/FilterService.php index 1568444..d9d148d 100644 --- a/src/AdvancedSearchBundle/Service/FilterService.php +++ b/src/AdvancedSearchBundle/Service/FilterService.php @@ -81,6 +81,10 @@ class FilterService 'expression' => '%s LIKE ?', 'data' => '%,_data_,%', ], + 'not_contain_related' => [ + 'expression' => 'NOT (%s LIKE ?) OR %s IS NULL', + 'data' => '%,_data_,%', + ], ]; /** @@ -126,9 +130,14 @@ public function __construct( public function getFieldDefinitionAdapter(ClassDefinition\Data $fieldDefinition, bool $considerInheritance) { $adapter = null; + $fieldType = $fieldDefinition->fieldtype; + + if ($fieldDefinition instanceof ClassDefinition\Data\CalculatedValue) { + $fieldType = $this->getCalculatedValueFieldType($fieldDefinition); + } - if ($this->filterLocator->has($fieldDefinition->fieldtype)) { - $adapter = $this->filterLocator->get($fieldDefinition->fieldtype); + if ($this->filterLocator->has($fieldType)) { + $adapter = $this->filterLocator->get($fieldType); $adapter->setConsiderInheritance($considerInheritance); $adapter->setFieldDefinition($fieldDefinition); } @@ -136,6 +145,32 @@ public function getFieldDefinitionAdapter(ClassDefinition\Data $fieldDefinition, return $adapter; } + private function getCalculatedValueFieldType(ClassDefinition\Data\CalculatedValue $fieldDefinition): ?string + { + $calculatorClass = $fieldDefinition->getCalculatorClass(); + if (!$calculatorClass) { + return null; + } + + $reflection = new \ReflectionClass($calculatorClass); + if (!$reflection->hasMethod('compute')) { + return null; + } + + $method = $reflection->getMethod('compute'); + if (!$method->hasReturnType()) { + return 'input'; + } + + $map = [ + 'bool' => 'checkbox', + 'int' => 'numeric', + 'float' => 'numeric', + 'string' => 'input', + ]; + return $map[strtolower($method->getReturnType())] ?? 'input'; + } + /** * returns selectable fields with their type information for search frontend * From 5f9b547101aa07a2f0620ddf278b43d799027e19 Mon Sep 17 00:00:00 2001 From: Pascal Dunaj Date: Thu, 12 Nov 2020 11:27:46 +0100 Subject: [PATCH 2/3] Permissions fix --- src/AdvancedSearchBundle/Resources/public/js/pimcore/startup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AdvancedSearchBundle/Resources/public/js/pimcore/startup.js b/src/AdvancedSearchBundle/Resources/public/js/pimcore/startup.js index 31b4392..04503c3 100644 --- a/src/AdvancedSearchBundle/Resources/public/js/pimcore/startup.js +++ b/src/AdvancedSearchBundle/Resources/public/js/pimcore/startup.js @@ -13,7 +13,7 @@ pimcore.bundle.advancedSearch = Class.create(pimcore.plugin.admin, { var perspectiveCfg = pimcore.globalmanager.get("perspective"); var user = pimcore.globalmanager.get("user"); - if (user.roles.length === 0 || user.roles.includes("3")) { + if (user.roles.length === 0) { var searchMenu = pimcore.globalmanager.get("layout_toolbar").searchMenu; if (searchMenu && perspectiveCfg.inToolbar("search.advancedSearch")) { Ext.get('pimcore_menu_search').insertSibling('', 'after'); From 51c3f847297aa808bdc8e577979f17687ab13a01 Mon Sep 17 00:00:00 2001 From: Pascal Dunaj Date: Thu, 12 Nov 2020 11:29:14 +0100 Subject: [PATCH 3/3] Permissions fix --- .../Resources/public/js/pimcore/startup.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/AdvancedSearchBundle/Resources/public/js/pimcore/startup.js b/src/AdvancedSearchBundle/Resources/public/js/pimcore/startup.js index 04503c3..a12ffa4 100644 --- a/src/AdvancedSearchBundle/Resources/public/js/pimcore/startup.js +++ b/src/AdvancedSearchBundle/Resources/public/js/pimcore/startup.js @@ -12,13 +12,10 @@ pimcore.bundle.advancedSearch = Class.create(pimcore.plugin.admin, { pimcoreReady: function (params, broker) { var perspectiveCfg = pimcore.globalmanager.get("perspective"); var user = pimcore.globalmanager.get("user"); - - if (user.roles.length === 0) { - var searchMenu = pimcore.globalmanager.get("layout_toolbar").searchMenu; - if (searchMenu && perspectiveCfg.inToolbar("search.advancedSearch")) { - Ext.get('pimcore_menu_search').insertSibling('', 'after'); - pimcore.bundle.advancedSearch.helper.rebuildAdvancedSearchMenu(); - } + var searchMenu = pimcore.globalmanager.get("layout_toolbar").searchMenu; + if (searchMenu && perspectiveCfg.inToolbar("search.advancedSearch")) { + Ext.get('pimcore_menu_search').insertSibling('', 'after'); + pimcore.bundle.advancedSearch.helper.rebuildAdvancedSearchMenu(); } } });