From 3a316feb6ccb306a0c861f6455fb521881888051 Mon Sep 17 00:00:00 2001 From: Kristof Jochmans Date: Mon, 29 Dec 2014 23:16:53 +0100 Subject: [PATCH 1/2] make it possible to add bulk actions on adminlists --- .../public/scss/_bootstrap-overrides.scss | 35 +++++++ .../AdminListBundle/AdminList/AdminList.php | 16 ++++ .../BulkAction/BulkActionInterface.php | 29 ++++++ .../AdminList/BulkAction/SimpleBulkAction.php | 76 +++++++++++++++ .../AbstractAdminListConfigurator.php | 45 +++++++-- .../AdminListConfiguratorInterface.php | 15 ++- .../AdminList/ListAction/SimpleListAction.php | 76 +++++++++++++++ .../AdminListTwigExtension/widget.html.twig | 93 ++++++++++++++++++- .../Resources/views/Default/list.html.twig | 57 ++++++------ 9 files changed, 402 insertions(+), 40 deletions(-) create mode 100644 src/Kunstmaan/AdminListBundle/AdminList/BulkAction/BulkActionInterface.php create mode 100644 src/Kunstmaan/AdminListBundle/AdminList/BulkAction/SimpleBulkAction.php create mode 100644 src/Kunstmaan/AdminListBundle/AdminList/ListAction/SimpleListAction.php diff --git a/src/Kunstmaan/AdminBundle/Resources/public/scss/_bootstrap-overrides.scss b/src/Kunstmaan/AdminBundle/Resources/public/scss/_bootstrap-overrides.scss index 76829a2bc9..8d4ce19225 100644 --- a/src/Kunstmaan/AdminBundle/Resources/public/scss/_bootstrap-overrides.scss +++ b/src/Kunstmaan/AdminBundle/Resources/public/scss/_bootstrap-overrides.scss @@ -214,4 +214,39 @@ textarea:focus, input[type="text"]:focus, input[type="password"]:focus, input[ty } .col-xs-1, .col-sm-1, .col-md-1, .col-lg-1 { @extend .span1; +} + + +// Custom edits for including btn-groups within btn-groups +// (useful for including dropdown buttons within a btn-group) +// https://github.com/twbs/bootstrap/issues/2140 +.btn-group > .btn-group > .btn.dropdown-toggle { + margin-left: 0; + -webkit-border-radius: 0px; + -moz-border-radius: 0px; + border-radius: 0px; +} +.btn-group > .btn-group:last-child > .btn.dropdown-toggle { + margin-left: 0; + -webkit-border-top-right-radius: 4px; + -moz-border-radius-topright: 4px; + border-top-right-radius: 4px; + -webkit-border-bottom-right-radius: 4px; + -moz-border-radius-bottomright: 4px; + border-bottom-right-radius: 4px; + border-left: 1px; +} +.btn-group > .btn-group:first-child > .btn.dropdown-toggle { + margin-right: 0; + -webkit-border-top-left-radius: 4px; + -moz-border-radius-topleft: 4px; + border-top-left-radius: 4px; + -webkit-border-bottom-left-radius: 4px; + -moz-border-radius-bottomleft: 4px; + border-bottom-left-radius: 4px; + border-right:1px; +} +// remove space between consecutive dropdown btn-groups. +.btn-group.dropdown+.btn-group.dropdown { + margin-left: 0; } \ No newline at end of file diff --git a/src/Kunstmaan/AdminListBundle/AdminList/AdminList.php b/src/Kunstmaan/AdminListBundle/AdminList/AdminList.php index 253e24cc0f..4f9ae4783b 100644 --- a/src/Kunstmaan/AdminListBundle/AdminList/AdminList.php +++ b/src/Kunstmaan/AdminListBundle/AdminList/AdminList.php @@ -267,6 +267,22 @@ public function getListActions() return $this->configurator->getListActions(); } + /** + * @return array + */ + public function getBulkActions() + { + return $this->configurator->getBulkActions(); + } + + /** + * @return bool + */ + public function hasBulkActions() + { + return $this->configurator->hasBulkActions(); + } + /** * @return Pagerfanta */ diff --git a/src/Kunstmaan/AdminListBundle/AdminList/BulkAction/BulkActionInterface.php b/src/Kunstmaan/AdminListBundle/AdminList/BulkAction/BulkActionInterface.php new file mode 100644 index 0000000000..a03739fbd3 --- /dev/null +++ b/src/Kunstmaan/AdminListBundle/AdminList/BulkAction/BulkActionInterface.php @@ -0,0 +1,29 @@ +url = $url; + $this->icon = $icon; + $this->label = $label; + $this->template = $template; + } + + /** + * @return array + */ + public function getUrl() + { + return $this->url; + } + + /** + * @return string + */ + public function getIcon() + { + return $this->icon; + } + + /** + * @return string + */ + public function getLabel() + { + return $this->label; + } + + /** + * @return string + */ + public function getTemplate() + { + return $this->template; + } +} diff --git a/src/Kunstmaan/AdminListBundle/AdminList/Configurator/AbstractAdminListConfigurator.php b/src/Kunstmaan/AdminListBundle/AdminList/Configurator/AbstractAdminListConfigurator.php index 5459c0d125..87b9dbe187 100644 --- a/src/Kunstmaan/AdminListBundle/AdminList/Configurator/AbstractAdminListConfigurator.php +++ b/src/Kunstmaan/AdminListBundle/AdminList/Configurator/AbstractAdminListConfigurator.php @@ -1,21 +1,19 @@ itemActions; } + /** + * @param ListActionInterface $listAction + * + * @return AdminListConfiguratorInterface + */ + public function addListAction(ListActionInterface $listAction) + { + $this->listActions[] = $listAction; + + return $this; + } + /** * @return bool */ @@ -419,17 +434,33 @@ public function getListActions() } /** - * @param ListActionInterface $listAction + * @param BulkActionInterface $bulkAction * * @return AdminListConfiguratorInterface */ - public function addListAction(ListActionInterface $listAction) + public function addBulkAction(BulkActionInterface $bulkAction) { - $this->listActions[] = $listAction; + $this->bulkActions[] = $bulkAction; return $this; } + /** + * @return bool + */ + public function hasBulkActions() + { + return !empty($this->bulkActions); + } + + /** + * @return BulkActionInterface[] + */ + public function getBulkActions() + { + return $this->bulkActions; + } + /** * @return string */ diff --git a/src/Kunstmaan/AdminListBundle/AdminList/Configurator/AdminListConfiguratorInterface.php b/src/Kunstmaan/AdminListBundle/AdminList/Configurator/AdminListConfiguratorInterface.php index a1177dc57c..94d1a41ef3 100644 --- a/src/Kunstmaan/AdminListBundle/AdminList/Configurator/AdminListConfiguratorInterface.php +++ b/src/Kunstmaan/AdminListBundle/AdminList/Configurator/AdminListConfiguratorInterface.php @@ -3,15 +3,13 @@ namespace Kunstmaan\AdminListBundle\AdminList\Configurator; use InvalidArgumentException; - +use Kunstmaan\AdminListBundle\AdminList\BulkAction\BulkActionInterface; use Kunstmaan\AdminListBundle\AdminList\ListAction\ListActionInterface; use Kunstmaan\AdminListBundle\AdminList\ItemAction\ItemActionInterface; use Kunstmaan\AdminListBundle\AdminList\Field; use Kunstmaan\AdminListBundle\AdminList\FilterBuilder; - use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Form\AbstractType; - use Pagerfanta\Pagerfanta; /** @@ -119,7 +117,6 @@ public function canAdd(); */ public function canExport(); - /** * @return array */ @@ -155,6 +152,16 @@ public function hasListActions(); */ public function getListActions(); + /** + * @return bool + */ + public function hasBulkActions(); + + /** + * @return BulkActionInterface[] + */ + public function getBulkActions(); + /** * @param array|object $item The item * @param string $columnName The column name diff --git a/src/Kunstmaan/AdminListBundle/AdminList/ListAction/SimpleListAction.php b/src/Kunstmaan/AdminListBundle/AdminList/ListAction/SimpleListAction.php new file mode 100644 index 0000000000..1f653da1e5 --- /dev/null +++ b/src/Kunstmaan/AdminListBundle/AdminList/ListAction/SimpleListAction.php @@ -0,0 +1,76 @@ +url = $url; + $this->icon = $icon; + $this->label = $label; + $this->template = $template; + } + + /** + * @return array + */ + public function getUrl() + { + return $this->url; + } + + /** + * @return string + */ + public function getIcon() + { + return $this->icon; + } + + /** + * @return string + */ + public function getLabel() + { + return $this->label; + } + + /** + * @return string + */ + public function getTemplate() + { + return $this->template; + } +} diff --git a/src/Kunstmaan/AdminListBundle/Resources/views/AdminListTwigExtension/widget.html.twig b/src/Kunstmaan/AdminListBundle/Resources/views/AdminListTwigExtension/widget.html.twig index 5432b27ec4..d4f353df5a 100644 --- a/src/Kunstmaan/AdminListBundle/Resources/views/AdminListTwigExtension/widget.html.twig +++ b/src/Kunstmaan/AdminListBundle/Resources/views/AdminListTwigExtension/widget.html.twig @@ -1,14 +1,23 @@ {% set extraparams = extraparams|merge(filter.currentparameters) %} {% include 'KunstmaanAdminListBundle:AdminListTwigExtension:filters.html.twig' %} + {% if adminlist.pagerfanta.haveToPaginate() %} {{ pagerfanta(adminlist.pagerfanta, 'twitter_bootstrap') }} {% endif %} +{% if adminlist.hasBulkActions %} +
+{% endif %}
+ {% if adminlist.hasBulkActions %} + + {% endif %} {% for column in adminlist.columns%} {% set columnName = column.name %} {% set columnkey = column.header %} @@ -26,12 +35,18 @@ {{ columnkey | trans }} {% endfor %} - + + {% set itemActionsPossible = false %} {% for item in adminlist.items(extraparams) %} + {% if adminlist.hasBulkActions %} + + {% endif %} {% for column in adminlist.columns%} {% set columnName = column.name %} {% set template = column.template %} @@ -43,13 +58,16 @@ {% endfor %} {% endfor %} + {% if not itemActionsPossible %} + + {% endif %}
+ + {{ 'form.actions'|trans }}{{ 'form.actions'|trans }}
+ + {% if adminlist.canEdit(item) %} + {% set itemActionsPossible = true %} Edit {% endif %} {% if adminlist.canDelete(item) %} + {% set itemActionsPossible = true %} {% include 'KunstmaanAdminListBundle:AdminListTwigExtension:sure-modal.html.twig' %} Delete {% endif %} {% if adminlist.hasItemActions() %} + {% set itemActionsPossible = true %} {% for itemAction in adminlist.getItemActions() %} {% if itemAction.template is not null %} {% include itemAction.template with {'row': item, 'item': item, 'action': itemAction} %} @@ -63,10 +81,83 @@
+{% if adminlist.hasBulkActions %} +
+ {% for action in adminlist.getBulkActions() %} + {% if action.template is not null %} + {% include action.template with {'action': action} %} + {% else %} + + {% if action.getIcon() is not null %} + {{ action.getLabel() }} + {% else %} + {{ action.getLabel() }} + {% endif %} + + {% endif %} + {% endfor %} +
+ +
+{% endif %} + {% if adminlist.pagerfanta.haveToPaginate() %} {{ pagerfanta(adminlist.pagerfanta, 'twitter_bootstrap') }} {% endif %} diff --git a/src/Kunstmaan/AdminListBundle/Resources/views/Default/list.html.twig b/src/Kunstmaan/AdminListBundle/Resources/views/Default/list.html.twig index a32dfaf2eb..aeee3b4c49 100644 --- a/src/Kunstmaan/AdminListBundle/Resources/views/Default/list.html.twig +++ b/src/Kunstmaan/AdminListBundle/Resources/views/Default/list.html.twig @@ -34,18 +34,35 @@ {% endif %} {% endif %} {% if adminlist.canExport() %} - - - Export to - - - + + {% endif %} + {% if adminlist.hasListActions %} + {% for action in adminlist.getListActions() %} + {% if action.template is not null %} + {% include action.template with {'action': action} %} + {% else %} + + {% if action.getIcon() is not null %} + {{ action.getLabel() }} + {% else %} + {{ action.getLabel() }} + {% endif %} + + {% endif %} + {% endfor %} {% endif %} @@ -58,20 +75,4 @@ {% else %} {{ adminlist_widget(adminlist, adminlist.getIndexUrl()["path"], adminlist.getIndexUrl()) }} {% endif %} - - {% if adminlist.hasListActions %} - {% for action in adminlist.getListActions() %} - {% if action.template is not null %} - {% include action.template with {'action': action} %} - {% else %} - - {% if action.getIcon() is not null %} - - {% else %} - {{ action.getLabel() }} - {% endif %} - - {% endif %} - {% endfor %} - {% endif %} {% endblock %} From 077c6d9b523c0ec60f137c7f94aedefc40804461 Mon Sep 17 00:00:00 2001 From: Kristof Jochmans Date: Mon, 29 Dec 2014 23:21:10 +0100 Subject: [PATCH 2/2] removed unused class --- .../ListAction/CsvExportListAction.php | 47 ------------------- 1 file changed, 47 deletions(-) delete mode 100644 src/Kunstmaan/AdminListBundle/AdminList/ListAction/CsvExportListAction.php diff --git a/src/Kunstmaan/AdminListBundle/AdminList/ListAction/CsvExportListAction.php b/src/Kunstmaan/AdminListBundle/AdminList/ListAction/CsvExportListAction.php deleted file mode 100644 index 8ba06ed8f0..0000000000 --- a/src/Kunstmaan/AdminListBundle/AdminList/ListAction/CsvExportListAction.php +++ /dev/null @@ -1,47 +0,0 @@ - 'KunstmaanAdminListBundle_admin_export', - 'params' => array( - '_format' => 'csv' - ) - ); - } - - /** - * @return string - */ - public function getLabel() - { - return 'Export as CSV'; - } - - /** - * @return null - */ - public function getIcon() - { - return null; - } - - /** - * @return null - */ - public function getTemplate() - { - return null; - } -}