From 9d58e789fe995be886ad300142db8499e66a8702 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Mon, 4 Feb 2019 11:44:19 +0100 Subject: [PATCH 1/2] [Index] introduce iterator interpreter --- .../Interpreter/IteratorInterpreterType.php | 28 ++++ .../Resources/config/pimcore/admin.yml | 3 +- .../IndexBundle/Resources/config/services.yml | 9 +- .../pimcore/js/index/interpreters/iterator.js | 130 ++++++++++++++++++ .../pimcore/js/index/interpreters/nested.js | 18 ++- .../js/index/interpreters/nestedcontainer.js | 12 +- .../js/index/interpreters/nestedlocalized.js | 12 +- .../js/index/interpreters/nestedrelational.js | 13 +- .../Index/Interpreter/IteratorInterpreter.php | 51 +++++++ 9 files changed, 248 insertions(+), 28 deletions(-) create mode 100644 src/CoreShop/Bundle/IndexBundle/Form/Type/Interpreter/IteratorInterpreterType.php create mode 100644 src/CoreShop/Bundle/IndexBundle/Resources/public/pimcore/js/index/interpreters/iterator.js create mode 100644 src/CoreShop/Component/Index/Interpreter/IteratorInterpreter.php diff --git a/src/CoreShop/Bundle/IndexBundle/Form/Type/Interpreter/IteratorInterpreterType.php b/src/CoreShop/Bundle/IndexBundle/Form/Type/Interpreter/IteratorInterpreterType.php new file mode 100644 index 0000000000..14ad5a157b --- /dev/null +++ b/src/CoreShop/Bundle/IndexBundle/Form/Type/Interpreter/IteratorInterpreterType.php @@ -0,0 +1,28 @@ +add('interpreter', InterpreterType::class); + } +} diff --git a/src/CoreShop/Bundle/IndexBundle/Resources/config/pimcore/admin.yml b/src/CoreShop/Bundle/IndexBundle/Resources/config/pimcore/admin.yml index 621c4666c2..9ecec8de6c 100644 --- a/src/CoreShop/Bundle/IndexBundle/Resources/config/pimcore/admin.yml +++ b/src/CoreShop/Bundle/IndexBundle/Resources/config/pimcore/admin.yml @@ -17,6 +17,7 @@ core_shop_index: index_interpreter_nested_relational: '/bundles/coreshopindex/pimcore/js/index/interpreters/nestedrelational.js' index_interpreter_objectproperty: '/bundles/coreshopindex/pimcore/js/index/interpreters/objectproperty.js' index_interpreter_expression: '/bundles/coreshopindex/pimcore/js/index/interpreters/expression.js' + index_interpreter_iterator: '/bundles/coreshopindex/pimcore/js/index/interpreters/iterator.js' index_interpreter_objecttype: '/bundles/coreshopindex/pimcore/js/index/objecttype/abstract.js' index_worker_abstract: '/bundles/coreshopindex/pimcore/js/index/worker/abstract.js' index_worker_mysql: '/bundles/coreshopindex/pimcore/js/index/worker/mysql.js' @@ -41,4 +42,4 @@ core_shop_index: index: '/bundles/coreshopindex/pimcore/css/index.css' editmode_js: core_extension_document_tag_filter: '/bundles/coreshopindex/pimcore/js/coreExtension/document/coreShopFilter.js' - core_extension_document_tag_index: '/bundles/coreshopindex/pimcore/js/coreExtension/document/coreShopIndex.js' \ No newline at end of file + core_extension_document_tag_index: '/bundles/coreshopindex/pimcore/js/coreExtension/document/coreShopIndex.js' diff --git a/src/CoreShop/Bundle/IndexBundle/Resources/config/services.yml b/src/CoreShop/Bundle/IndexBundle/Resources/config/services.yml index 99d7660bf5..9e19b4979e 100755 --- a/src/CoreShop/Bundle/IndexBundle/Resources/config/services.yml +++ b/src/CoreShop/Bundle/IndexBundle/Resources/config/services.yml @@ -197,6 +197,13 @@ services: tags: - { name: coreshop.index.interpreter, type: nestedRelational, form-type: CoreShop\Bundle\IndexBundle\Form\Type\Interpreter\NestedInterpreterType} + coreshop.index.interpreter.iterator: + class: CoreShop\Component\Index\Interpreter\IteratorInterpreter + arguments: + - '@coreshop.registry.index.interpreter' + tags: + - { name: coreshop.index.interpreter, type: iterator, form-type: CoreShop\Bundle\IndexBundle\Form\Type\Interpreter\IteratorInterpreterType} + # Index Column Types coreshop.index.column_type.classification_store: class: CoreShop\Bundle\IndexBundle\Form\Type\Column\IndexColumnTypeClassificationStoreType @@ -277,4 +284,4 @@ services: class: CoreShop\Component\Index\Service\IndexUpdaterService arguments: - '@coreshop.repository.index' - - '@coreshop.registry.index.worker' \ No newline at end of file + - '@coreshop.registry.index.worker' diff --git a/src/CoreShop/Bundle/IndexBundle/Resources/public/pimcore/js/index/interpreters/iterator.js b/src/CoreShop/Bundle/IndexBundle/Resources/public/pimcore/js/index/interpreters/iterator.js new file mode 100644 index 0000000000..5b025bee03 --- /dev/null +++ b/src/CoreShop/Bundle/IndexBundle/Resources/public/pimcore/js/index/interpreters/iterator.js @@ -0,0 +1,130 @@ +/** + * Import Definitions. + * + * LICENSE + * + * This source file is subject to the GNU General Public License version 3 (GPLv3) + * For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt + * files that are distributed with this source code. + * + * @copyright Copyright (c) 2016-2018 w-vision AG (https://www.w-vision.ch) + * @license https://github.com/w-vision/ImportDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) + */ + +pimcore.registerNS('coreshop.index.interpreters.iterator'); + +coreshop.index.interpreters.iterator = Class.create(coreshop.index.interpreters.abstract, { + getStore: function() { + return pimcore.globalmanager.get('coreshop_index_interpreters'); + }, + + getClassItem: function() { + return coreshop.index.interpreters; + }, + + getForm: function (record, config) { + this.interpreterPanel = new Ext.form.FormPanel({ + defaults: { anchor: '90%' }, + layout: 'form', + title: t('coreshop_index_interpreter_settings'), + border: true, + hidden: true + }); + + this.getStore().clearFilter(); + + this.interpreterTypeCombo = new Ext.form.ComboBox({ + fieldLabel : t('coreshop_index_field_interpreter'), + name : 'interpreter', + length : 255, + value : config && config.interpreter ? config.interpreter.type : null, + store : this.getStore(), + valueField : 'name', + displayField : 'name', + queryMode : 'local', + listeners : { + change : function (combo, newValue) { + this.interpreterPanel.removeAll(); + + this.getInterpreterPanelLayout(newValue, record, config, {}); + }.bind(this) + } + }); + + this.interpreterContainer = new Ext.Panel({ + autoScroll: true, + forceLayout: true, + items: [ + this.interpreterTypeCombo, + this.interpreterPanel + ], + border: false + }); + + if (config && config.interpreter && config.interpreter.type) { + this.getInterpreterPanelLayout(config.interpreter.type, record, config, config.interpreter.interpreterConfig); + } + + return this.interpreterContainer; + }, + + destroy: function () { + if (this.interpreterContainer) { + this.interpreterContainer.destroy(); + } + }, + + getInterpreterPanelLayout : function (type, record, parentConfig, config) { + if (type) { + type = type.toLowerCase(); + var classItem = this.getClassItem(); + + if (classItem[type]) { + this.interpreter = new classItem[type]; + + this.interpreterPanel.add(this.interpreter.getForm(record, Ext.isObject(config) ? config : {}, parentConfig)); + this.interpreterPanel.show(); + } else { + this.interpreterPanel.hide(); + + this.interpreter = null; + } + } else { + this.interpreterPanel.hide(); + } + }, + + isValid: function() { + if (!this.interpreter) { + return false; + } + + return this.interpreter.isValid(); + }, + + getInterpreterData: function () { + // get defined conditions + if (this.interpreter) { + var interpreterConfig = {}; + var interpreterForm = this.interpreterPanel.getForm(); + + if (Ext.isFunction(this.interpreter.getInterpreterData)) { + interpreterConfig = this.interpreter.getInterpreterData(); + } + else { + Ext.Object.each(interpreterForm.getFieldValues(), function (key, value) { + interpreterConfig[key] = value; + }.bind(this)); + } + + return { + interpreter: { + interpreterConfig: interpreterConfig, + type: this.interpreterTypeCombo.getValue() + } + }; + } + + return {}; + } +}); diff --git a/src/CoreShop/Bundle/IndexBundle/Resources/public/pimcore/js/index/interpreters/nested.js b/src/CoreShop/Bundle/IndexBundle/Resources/public/pimcore/js/index/interpreters/nested.js index 0114e5e0df..74c1d824a0 100644 --- a/src/CoreShop/Bundle/IndexBundle/Resources/public/pimcore/js/index/interpreters/nested.js +++ b/src/CoreShop/Bundle/IndexBundle/Resources/public/pimcore/js/index/interpreters/nested.js @@ -1,16 +1,16 @@ -/** - * Import Definitions. - * - * LICENSE +/* + * CoreShop. * * This source file is subject to the GNU General Public License version 3 (GPLv3) * For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt * files that are distributed with this source code. * - * @copyright Copyright (c) 2016-2018 w-vision AG (https://www.w-vision.ch) - * @license https://github.com/w-vision/ImportDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) + * @copyright Copyright (c) 2015-2019 Dominik Pfaffenbauer (https://www.pfaffenbauer.at) + * @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3) + * */ + pimcore.registerNS('coreshop.index.interpreters.nested'); coreshop.index.interpreters.nested = Class.create(coreshop.index.interpreters.abstract, { @@ -18,7 +18,11 @@ coreshop.index.interpreters.nested = Class.create(coreshop.index.interpreters.ab // init var _this = this; var addMenu = []; - var records = pimcore.globalmanager.get('coreshop_index_interpreters').getRange().map(function(interpreter) {return interpreter.get('type')}); + var store = pimcore.globalmanager.get('coreshop_index_interpreters').getRange(); + + store.clearFilter(); + + var records = store.map(function(interpreter) {return interpreter.get('type')}); Ext.each(records, function (interpreter) { if (interpreter === 'abstract') diff --git a/src/CoreShop/Bundle/IndexBundle/Resources/public/pimcore/js/index/interpreters/nestedcontainer.js b/src/CoreShop/Bundle/IndexBundle/Resources/public/pimcore/js/index/interpreters/nestedcontainer.js index 4a0bdf766b..03facd16eb 100644 --- a/src/CoreShop/Bundle/IndexBundle/Resources/public/pimcore/js/index/interpreters/nestedcontainer.js +++ b/src/CoreShop/Bundle/IndexBundle/Resources/public/pimcore/js/index/interpreters/nestedcontainer.js @@ -1,16 +1,16 @@ -/** - * Import Definitions. - * - * LICENSE +/* + * CoreShop. * * This source file is subject to the GNU General Public License version 3 (GPLv3) * For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt * files that are distributed with this source code. * - * @copyright Copyright (c) 2016-2018 w-vision AG (https://www.w-vision.ch) - * @license https://github.com/w-vision/ImportDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) + * @copyright Copyright (c) 2015-2019 Dominik Pfaffenbauer (https://www.pfaffenbauer.at) + * @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3) + * */ + pimcore.registerNS('coreshop.index.interpreters.nestedcontainer'); coreshop.index.interpreters.nestedcontainer = Class.create({ diff --git a/src/CoreShop/Bundle/IndexBundle/Resources/public/pimcore/js/index/interpreters/nestedlocalized.js b/src/CoreShop/Bundle/IndexBundle/Resources/public/pimcore/js/index/interpreters/nestedlocalized.js index f2932991c8..474d65ac2d 100644 --- a/src/CoreShop/Bundle/IndexBundle/Resources/public/pimcore/js/index/interpreters/nestedlocalized.js +++ b/src/CoreShop/Bundle/IndexBundle/Resources/public/pimcore/js/index/interpreters/nestedlocalized.js @@ -1,16 +1,16 @@ -/** - * Import Definitions. - * - * LICENSE +/* + * CoreShop. * * This source file is subject to the GNU General Public License version 3 (GPLv3) * For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt * files that are distributed with this source code. * - * @copyright Copyright (c) 2016-2018 w-vision AG (https://www.w-vision.ch) - * @license https://github.com/w-vision/ImportDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) + * @copyright Copyright (c) 2015-2019 Dominik Pfaffenbauer (https://www.pfaffenbauer.at) + * @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3) + * */ + pimcore.registerNS('coreshop.index.interpreters.nestedlocalized'); coreshop.index.interpreters.nestedlocalized = Class.create(coreshop.index.interpreters.nested, { diff --git a/src/CoreShop/Bundle/IndexBundle/Resources/public/pimcore/js/index/interpreters/nestedrelational.js b/src/CoreShop/Bundle/IndexBundle/Resources/public/pimcore/js/index/interpreters/nestedrelational.js index c821520925..17cda923e7 100644 --- a/src/CoreShop/Bundle/IndexBundle/Resources/public/pimcore/js/index/interpreters/nestedrelational.js +++ b/src/CoreShop/Bundle/IndexBundle/Resources/public/pimcore/js/index/interpreters/nestedrelational.js @@ -1,18 +1,17 @@ -/** - * Import Definitions. - * - * LICENSE +/* + * CoreShop. * * This source file is subject to the GNU General Public License version 3 (GPLv3) * For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt * files that are distributed with this source code. * - * @copyright Copyright (c) 2016-2018 w-vision AG (https://www.w-vision.ch) - * @license https://github.com/w-vision/ImportDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3) + * @copyright Copyright (c) 2015-2019 Dominik Pfaffenbauer (https://www.pfaffenbauer.at) + * @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3) + * */ pimcore.registerNS('coreshop.index.interpreters.nestedrelational'); coreshop.index.interpreters.nestedrelational = Class.create(coreshop.index.interpreters.nested, { - + }); diff --git a/src/CoreShop/Component/Index/Interpreter/IteratorInterpreter.php b/src/CoreShop/Component/Index/Interpreter/IteratorInterpreter.php new file mode 100644 index 0000000000..b632dfff63 --- /dev/null +++ b/src/CoreShop/Component/Index/Interpreter/IteratorInterpreter.php @@ -0,0 +1,51 @@ +interpreterRegistry = $interpreterRegistry; + } + + /** + * {@inheritdoc} + */ + public function interpret($value, IndexableInterface $indexable, IndexColumnInterface $config, $interpreterConfig = []) + { + Assert::isArray($value, 'IteratorInterpreter can only be used with array values'); + + $interpreter = $interpreterConfig['interpreter']; + $interpreterObject = $this->interpreterRegistry->get($interpreter['type']); + + foreach ($value as &$val) { + $val = $interpreterObject->interpret($val, $indexable, $config, $interpreter['interpreterConfig']); + } + + return $value; + } +} From cae7d598891a21be8c2e9b63b8bc0a9dd3535e19 Mon Sep 17 00:00:00 2001 From: Dominik Pfaffenbauer Date: Mon, 4 Feb 2019 13:33:21 +0100 Subject: [PATCH 2/2] [Index] introduce iterator interpreter - stan --- .../Component/Index/Interpreter/IteratorInterpreter.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/CoreShop/Component/Index/Interpreter/IteratorInterpreter.php b/src/CoreShop/Component/Index/Interpreter/IteratorInterpreter.php index b632dfff63..0bdcae472c 100644 --- a/src/CoreShop/Component/Index/Interpreter/IteratorInterpreter.php +++ b/src/CoreShop/Component/Index/Interpreter/IteratorInterpreter.php @@ -40,6 +40,9 @@ public function interpret($value, IndexableInterface $indexable, IndexColumnInte Assert::isArray($value, 'IteratorInterpreter can only be used with array values'); $interpreter = $interpreterConfig['interpreter']; + /** + * @var InterpreterInterface $interpreterObject + */ $interpreterObject = $this->interpreterRegistry->get($interpreter['type']); foreach ($value as &$val) {