From d4fc52d493ac0712cb62877c1504988ae1e046f2 Mon Sep 17 00:00:00 2001 From: Luca Fumagalli <59696408+lucfumagalli@users.noreply.github.com> Date: Fri, 22 Mar 2024 09:59:02 +0100 Subject: [PATCH] [DataObject] Add objects or variant filtering dropdown in grid tab (#465) * 464 fix filtering objects and added to toolbar a select option * added translations for select in grid view * Update src/Helper/GridHelperService.php Co-authored-by: JiaJia Ji * Update translations/admin.en.yaml Co-authored-by: JiaJia Ji * hidden visibility if class does not "allow inheritance" * fixed filtered list based on what type of objects you want show * Update public/js/pimcore/object/helpers/gridTabAbstract.js Co-authored-by: Sebastian Blank * Update label of select Co-authored-by: JiaJia Ji * removing old code Co-authored-by: JiaJia Ji * refactoring set objects --------- Co-authored-by: JiaJia Ji Co-authored-by: Sebastian Blank --- .../pimcore/object/helpers/gridTabAbstract.js | 40 +++++++++++++++++++ src/Helper/GridHelperService.php | 15 +++++-- translations/admin.en.yaml | 3 ++ 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/public/js/pimcore/object/helpers/gridTabAbstract.js b/public/js/pimcore/object/helpers/gridTabAbstract.js index b30e99ea8d..f06b65493a 100644 --- a/public/js/pimcore/object/helpers/gridTabAbstract.js +++ b/public/js/pimcore/object/helpers/gridTabAbstract.js @@ -231,6 +231,45 @@ pimcore.object.helpers.gridTabAbstract = Class.create({ this.store.getProxy().setExtraParam("query", this.searchFilter); + var selectObjectOptions = Ext.create('Ext.data.Store', { + fields: ['name', 'value'], + data: [ + [t("all_types"), "all_objects"], + [t("only_object"), "only_objects"], + [t("only_variant"), "only_variant_objects"], + ] + }); + + this.selectObjectType = new Ext.form.ComboBox({ + fieldLabel: t('select_objects_type'), + name: 'objects_type', + labelWidth: 120, + xtype: "combo", + displayField:'name', + valueField: "value", + hidden: !this.element.data.general.allowInheritance, + store: selectObjectOptions, + editable: false, + width : 300, + triggerAction: 'all', + value: 'all_objects', + listeners: { + change: function(comboBox,selected){ + this.grid.getStore().setRemoteFilter(false); + this.grid.filters.clearFilters(); + this.grid.getStore().clearFilter(); + + this.store.getProxy().setExtraParam("filter_by_object_type", selected); + + this.pagingtoolbar.moveFirst(); + + this.grid.getStore().setRemoteFilter(true); + + this.saveColumnConfigButton.show(); + }.bind(this) + } + }); + this.checkboxOnlyDirectChildren = new Ext.form.Checkbox({ name: "onlyDirectChildren", style: "margin-bottom: 5px; margin-left: 5px", @@ -296,6 +335,7 @@ pimcore.object.helpers.gridTabAbstract = Class.create({ this.languageInfo, "-", this.toolbarFilterInfo, this.clearFilterButton, "->", + this.selectObjectType, "-", this.checkboxOnlyDirectChildren, "-", this.exportButton, "-", this.columnConfigButton, diff --git a/src/Helper/GridHelperService.php b/src/Helper/GridHelperService.php index 7311da8d55..28103086f9 100644 --- a/src/Helper/GridHelperService.php +++ b/src/Helper/GridHelperService.php @@ -670,10 +670,19 @@ public function prepareListingForGrid(array $requestParams, string $requestedLan } } - if ($class->getShowVariants()) { - $list->setObjectTypes([DataObject::OBJECT_TYPE_OBJECT, DataObject::OBJECT_TYPE_VARIANT]); + if ($class->getAllowVariants()) { + if ($class->getShowVariants()) { + $list->setObjectTypes([DataObject::OBJECT_TYPE_OBJECT, DataObject::OBJECT_TYPE_VARIANT]); + } + if (isset($requestParams['filter_by_object_type'])){ + if ($requestParams['filter_by_object_type'] === "only_objects") { + $list->setObjectTypes([DataObject::OBJECT_TYPE_OBJECT]); + } elseif($requestParams['filter_by_object_type'] === "only_variant_objects") { + $list->setObjectTypes([DataObject::OBJECT_TYPE_VARIANT]); + } + } } - + $this->addGridFeatureJoins($list, $featureJoins, $class, $featureAndSlugFilters); $this->addSlugJoins($list, $slugJoins, $featureAndSlugFilters); diff --git a/translations/admin.en.yaml b/translations/admin.en.yaml index f52f4b4981..f65f0be866 100644 --- a/translations/admin.en.yaml +++ b/translations/admin.en.yaml @@ -432,6 +432,9 @@ system_columns: 'System columns' columns: Columns children_grid: 'Children Grid' only_children: 'just direct children' +only_object: 'just objects' +only_variant: 'just variants object' +select_objects_type: "Type to show" cut: Cut paste_cut_element: 'Paste cut-out element' memorize_tabs: 'Memorize open tabs'