From 087f567af25705dc6c56fb8bcb7760aa56bcf389 Mon Sep 17 00:00:00 2001 From: Alexandre Castelain Date: Tue, 14 May 2024 14:33:46 +0200 Subject: [PATCH 01/15] Changed the renamed attribute --- docs/src/reference/types/action/form.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/reference/types/action/form.md b/docs/src/reference/types/action/form.md index 6409d693..09b69e87 100644 --- a/docs/src/reference/types/action/form.md +++ b/docs/src/reference/types/action/form.md @@ -44,7 +44,7 @@ $builder ### `button_attr` -- **type**: `array` +- **type**: `array` or `callable` - **default**: `[]` An array of attributes used to render the form submit button. @@ -54,7 +54,7 @@ use Kreyu\Bundle\DataTableBundle\Action\Type\ButtonActionType; $builder ->addAction('remove', ButtonActionType::class, [ - 'attr' => [ + 'button_attr' => [ 'class' => 'btn btn-danger', ], ]) From 080bf6cdcfe426bc9286579951121e85106d15ac Mon Sep 17 00:00:00 2001 From: Alexandre Castelain Date: Thu, 11 Jul 2024 14:38:15 +0200 Subject: [PATCH 02/15] #88 Create the DropdownActionType --- assets/controllers/dropdown.js | 15 ++++++++++++++ assets/package.json | 5 +++++ src/Action/Type/DropdownActionType.php | 24 +++++++++++++++++++++++ src/Resources/config/actions.php | 6 ++++++ src/Resources/views/themes/base.html.twig | 20 +++++++++++++++++++ 5 files changed, 70 insertions(+) create mode 100644 assets/controllers/dropdown.js create mode 100644 src/Action/Type/DropdownActionType.php diff --git a/assets/controllers/dropdown.js b/assets/controllers/dropdown.js new file mode 100644 index 00000000..abbefd06 --- /dev/null +++ b/assets/controllers/dropdown.js @@ -0,0 +1,15 @@ +import {Controller} from '@hotwired/stimulus' + +export default class extends Controller { + static values = { + toggledClass: { type: String, default: 'show' }, + } + + static targets = [ + 'content', + ]; + + toggle() { + this.contentTarget.classList.toggle(this.toggledClassValue) + } +} diff --git a/assets/package.json b/assets/package.json index f638d601..d5880b68 100755 --- a/assets/package.json +++ b/assets/package.json @@ -14,6 +14,11 @@ "main": "controllers/batch.js", "fetch": "eager", "enabled": true + }, + "dropdown": { + "main": "controllers/dropdown.js", + "fetch": "eager", + "enabled": true } }, "importmap": { diff --git a/src/Action/Type/DropdownActionType.php b/src/Action/Type/DropdownActionType.php new file mode 100644 index 00000000..2d0d73d9 --- /dev/null +++ b/src/Action/Type/DropdownActionType.php @@ -0,0 +1,24 @@ +vars['actions'] = $options['actions']; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->define('actions') + ->allowedTypes('array') + ->required() + ; + } +} diff --git a/src/Resources/config/actions.php b/src/Resources/config/actions.php index 5f76912b..bc7bbd2e 100755 --- a/src/Resources/config/actions.php +++ b/src/Resources/config/actions.php @@ -8,6 +8,7 @@ use Kreyu\Bundle\DataTableBundle\Action\ActionRegistryInterface; use Kreyu\Bundle\DataTableBundle\Action\Type\ActionType; use Kreyu\Bundle\DataTableBundle\Action\Type\ButtonActionType; +use Kreyu\Bundle\DataTableBundle\Action\Type\DropdownActionType; use Kreyu\Bundle\DataTableBundle\Action\Type\FormActionType; use Kreyu\Bundle\DataTableBundle\Action\Type\LinkActionType; use Kreyu\Bundle\DataTableBundle\Action\Type\ResolvedActionTypeFactory; @@ -60,4 +61,9 @@ ->set('kreyu_data_table.action.type.form', FormActionType::class) ->tag('kreyu_data_table.action.type') ; + + $services + ->set('kreyu_data_table.action.type.dropdown', DropdownActionType::class) + ->tag('kreyu_data_table.action.type') + ; }; diff --git a/src/Resources/views/themes/base.html.twig b/src/Resources/views/themes/base.html.twig index efe06bf8..28b99439 100755 --- a/src/Resources/views/themes/base.html.twig +++ b/src/Resources/views/themes/base.html.twig @@ -539,6 +539,26 @@ {% endblock %} +{% block action_dropdown_value %} + + + +{% endblock %} + {% block sort_arrow_none %}{% endblock %} {% block sort_arrow_asc %}↑{% endblock %} From 6a6f4fed09a1d3bef9930821ba6b42d464f4aec8 Mon Sep 17 00:00:00 2001 From: Alexandre Castelain Date: Thu, 11 Jul 2024 14:51:52 +0200 Subject: [PATCH 03/15] #88 Add the bootstrap 5 theme --- src/Resources/views/themes/bootstrap_5.html.twig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Resources/views/themes/bootstrap_5.html.twig b/src/Resources/views/themes/bootstrap_5.html.twig index 9c385d7d..5cc83497 100755 --- a/src/Resources/views/themes/bootstrap_5.html.twig +++ b/src/Resources/views/themes/bootstrap_5.html.twig @@ -708,6 +708,22 @@ {% endif %} {% endblock %} +{% block action_dropdown_value %} + +{% endblock %} + {% block sort_arrow_none %} From 10913c8abec553f7d8fac76f8c65a8e6d2f360fc Mon Sep 17 00:00:00 2001 From: Alexandre Castelain Date: Thu, 11 Jul 2024 15:30:36 +0200 Subject: [PATCH 04/15] #88 Extract the RowActionBuilder methods in another interface. --- src/Action/Type/DropdownActionType.php | 2 +- src/Builder/RowActionBuilderInterface.php | 30 +++++++++++++++++++ src/DataTableBuilderInterface.php | 22 ++------------ .../views/themes/bootstrap_5.html.twig | 6 ++-- 4 files changed, 36 insertions(+), 24 deletions(-) create mode 100644 src/Builder/RowActionBuilderInterface.php diff --git a/src/Action/Type/DropdownActionType.php b/src/Action/Type/DropdownActionType.php index 2d0d73d9..31f8a7c7 100644 --- a/src/Action/Type/DropdownActionType.php +++ b/src/Action/Type/DropdownActionType.php @@ -11,7 +11,7 @@ class DropdownActionType extends AbstractActionType { public function buildView(ActionView $view, ActionInterface $action, array $options): void { - $view->vars['actions'] = $options['actions']; + $view->vars['actions'] = []; } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Builder/RowActionBuilderInterface.php b/src/Builder/RowActionBuilderInterface.php new file mode 100644 index 00000000..33dbfd0f --- /dev/null +++ b/src/Builder/RowActionBuilderInterface.php @@ -0,0 +1,30 @@ +|null $type + */ + public function createRowAction(string $name, ?string $type = null, array $options = []): ActionBuilderInterface; + + /** + * @param class-string|null $type + */ + public function addRowAction(ActionBuilderInterface|string $action, ?string $type = null, array $options = []): static; + + public function removeRowAction(string $name): static; +} diff --git a/src/DataTableBuilderInterface.php b/src/DataTableBuilderInterface.php index 65769139..af1bb2b4 100755 --- a/src/DataTableBuilderInterface.php +++ b/src/DataTableBuilderInterface.php @@ -6,6 +6,7 @@ use Kreyu\Bundle\DataTableBundle\Action\ActionBuilderInterface; use Kreyu\Bundle\DataTableBundle\Action\Type\ActionTypeInterface; +use Kreyu\Bundle\DataTableBundle\Builder\RowActionBuilderInterface; use Kreyu\Bundle\DataTableBundle\Column\ColumnBuilderInterface; use Kreyu\Bundle\DataTableBundle\Column\Type\ColumnTypeInterface; use Kreyu\Bundle\DataTableBundle\Exception\InvalidArgumentException; @@ -15,7 +16,7 @@ use Kreyu\Bundle\DataTableBundle\Filter\Type\FilterTypeInterface; use Kreyu\Bundle\DataTableBundle\Query\ProxyQueryInterface; -interface DataTableBuilderInterface extends DataTableConfigBuilderInterface +interface DataTableBuilderInterface extends DataTableConfigBuilderInterface, RowActionBuilderInterface { public const BATCH_CHECKBOX_COLUMN_NAME = '__batch'; @@ -140,25 +141,6 @@ public function setAutoAddingBatchCheckboxColumn(bool $autoAddingBatchCheckboxCo */ public function getRowActions(): array; - /** - * @throws InvalidArgumentException if row action of given name does not exist - */ - public function getRowAction(string $name): ActionBuilderInterface; - - public function hasRowAction(string $name): bool; - - /** - * @param class-string|null $type - */ - public function createRowAction(string $name, ?string $type = null, array $options = []): ActionBuilderInterface; - - /** - * @param class-string|null $type - */ - public function addRowAction(ActionBuilderInterface|string $action, ?string $type = null, array $options = []): static; - - public function removeRowAction(string $name): static; - public function isAutoAddingActionsColumn(): bool; public function setAutoAddingActionsColumn(bool $autoAddingActionsColumn): static; diff --git a/src/Resources/views/themes/bootstrap_5.html.twig b/src/Resources/views/themes/bootstrap_5.html.twig index 5cc83497..bf22d7e4 100755 --- a/src/Resources/views/themes/bootstrap_5.html.twig +++ b/src/Resources/views/themes/bootstrap_5.html.twig @@ -717,9 +717,9 @@ {% endblock %} From 3c90c86297a73090758b9830bfbd85d025cd7823 Mon Sep 17 00:00:00 2001 From: Alexandre Castelain Date: Thu, 11 Jul 2024 16:02:15 +0200 Subject: [PATCH 05/15] #88 Run php-cs-fixer --- src/Action/Type/DropdownActionType.php | 1 + src/Builder/RowActionBuilderInterface.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Action/Type/DropdownActionType.php b/src/Action/Type/DropdownActionType.php index 31f8a7c7..7797436d 100644 --- a/src/Action/Type/DropdownActionType.php +++ b/src/Action/Type/DropdownActionType.php @@ -1,4 +1,5 @@ Date: Wed, 8 Jan 2025 10:54:34 +0100 Subject: [PATCH 06/15] Add the LinkDropdownItemActionType and handle it in the views --- src/Action/Type/DropdownActionType.php | 13 ++++++++++- .../LinkDropdownItemActionType.php | 15 +++++++++++++ src/Resources/config/actions.php | 6 +++++ src/Resources/views/themes/base.html.twig | 22 +++++++++++++------ .../views/themes/bootstrap_5.html.twig | 14 ++++++++---- 5 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 src/Action/Type/DropdownItemActionType/LinkDropdownItemActionType.php diff --git a/src/Action/Type/DropdownActionType.php b/src/Action/Type/DropdownActionType.php index 7797436d..ffb1849b 100644 --- a/src/Action/Type/DropdownActionType.php +++ b/src/Action/Type/DropdownActionType.php @@ -4,15 +4,26 @@ namespace Kreyu\Bundle\DataTableBundle\Action\Type; +use Kreyu\Bundle\DataTableBundle\Action\ActionBuilderInterface; use Kreyu\Bundle\DataTableBundle\Action\ActionInterface; use Kreyu\Bundle\DataTableBundle\Action\ActionView; use Symfony\Component\OptionsResolver\OptionsResolver; class DropdownActionType extends AbstractActionType { + public function buildView(ActionView $view, ActionInterface $action, array $options): void { - $view->vars['actions'] = []; + $itemActions = []; + /** @var ActionBuilderInterface $itemActionBuilder */ + foreach ($options['actions'] as $itemActionBuilder) { + $itemAction = $itemActionBuilder->getAction(); + $itemAction->setDataTable($action->getDataTable()); + + $itemActions[] = $itemAction->createView($view->parent); + } + + $view->vars['actions'] = $itemActions; } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Action/Type/DropdownItemActionType/LinkDropdownItemActionType.php b/src/Action/Type/DropdownItemActionType/LinkDropdownItemActionType.php new file mode 100644 index 00000000..1b388228 --- /dev/null +++ b/src/Action/Type/DropdownItemActionType/LinkDropdownItemActionType.php @@ -0,0 +1,15 @@ +set('kreyu_data_table.action.type.dropdown', DropdownActionType::class) ->tag('kreyu_data_table.action.type') ; + + $services + ->set('kreyu_data_table.action.type.link_dropdown_item', LinkDropdownItemActionType::class) + ->tag('kreyu_data_table.action.type') + ; }; diff --git a/src/Resources/views/themes/base.html.twig b/src/Resources/views/themes/base.html.twig index c9f460cc..bb29956f 100755 --- a/src/Resources/views/themes/base.html.twig +++ b/src/Resources/views/themes/base.html.twig @@ -632,7 +632,7 @@ {% endblock %} -{% block action_dropdown_value %} +{% block action_dropdown_control %} -