aliocza/sortable-ui-bundle

提供了一种排序管理列表的方法

安装次数: 5,120

依赖者: 0

建议者: 0

安全性: 0

星级: 2

关注者: 1

分支: 2

开放问题: 0

类型:symfony-bundle

dev-master / 0.1.x-dev 2016-08-12 10:10 UTC

This package is not auto-updated.

Last update: 2024-09-15 01:46:39 UTC


README

这是为了更好的GUI而全面重写的。

原始的 'bundle' 由 https://github.com/pix-digital/pixSortableBehaviorBundle 提供

原始的 'cookbook' 由 https://github.com/sonata-project/SonataAdminBundle/blob/master/Resources/doc/cookbook/recipe_sortable_listing.rst 提供

未来的功能

  • 多级拖放

  • 改进性能代码

  • 注释代码

配置

# app/config/config.yml
aliocza_sortable_ui:
    db_driver: orm # default value : orm (orm is only supported)
    position_field:
        default: sort #default value : position
        entities:
            AppBundle/Entity/Foobar: order
            AppBundle/Entity/Baz: rang

Sonata Admin 的 cookbooks

先决条件

  • 您已经安装并运行了 SonataAdmin 和 DoctrineORM

  • 您已经有一个实体类,您想为其实现排序功能。为了示例,我们将称之为 Client

  • 您已经设置了一个管理员,在这个例子中,我们将称之为 ClientAdmin

捆绑

食谱

首先,我们将在我们的 Client 实体中添加一个位置字段。

    use Gedmo\Mapping\Annotation as Gedmo;
    // ...
    /**
     * @Gedmo\SortablePosition
     * @ORM\Column(name="position", type="integer")
     */
    private $position;

然后我们需要注入 Sortable 监听器。如果您只启用了 Gedmo 捆绑包,您只需将监听器添加到您的 config.yml 中并跳过此步骤。

services:
    gedmo.listener.sortable:
        class: Gedmo\Sortable\SortableListener
        tags:
            - { name: doctrine.event_subscriber, connection: default }
        calls:
            - [ setAnnotationReader, [ "@annotation_reader" ] ]

在我们的 ClientAdmin 中,我们将在 configureListFields 方法中添加一个自定义操作,并使用 alioczaSortableUiBundle 中提供的默认 twig 模板。

	$listMapper
	    ->add('_action', 'actions', array(
            'actions' => array(
                'drag' => array(
                            'template' => 'AlioczaSortableUiBundle:Default:drag.html.twig'
                ),
            )
        )
    );

为了为这些操作添加新的路由,我们还添加了以下方法,并覆盖了添加按钮的模板

    <?php
    // src/AppBundle/Admin/ClientAdmin.php

    namespace AppBundle/Admin;

    use Sonata\AdminBundle\Route\RouteCollection;
    // ...
    private $positionService;
    
    protected $datagridValues = array(
        '_sort_order' => 'ASC',
        '_sort_by' => 'position',
        );
    
    protected function configureRoutes(RouteCollection $collection) {
    // ...
        $collection->add('drag', 'drag');
    }
    
    public function configure() {
        $this->setTemplate('list', 'AlioczaSortableUiBundle:CRUD:base_list.html.twig');
    }

    public function setPositionService(\Aliocza\SortableUiBundle\Services\PositionHandler $positionHandler) {
        $this->positionService = $positionHandler;
    }
    

现在,您可以将您的 services.yml 更新为使用 alioczaSortableUiBundle 的处理器提供程序

	services:
	    app.admin.client:
	        class: AppBundle\Admin\ClientAdmin
	        tags:
	            - { name: sonata.admin, manager_type: orm, label: "Clients" }
	        arguments:
	            - ~
	            - AppBundle\Entity\Client
	            - 'AlioczaSortableUiBundle:SortableUiAdmin' # define the new controller via the third argument
	        calls:
	            - [ setTranslationDomain, [AppBundle]]
	            - [ setPositionService, ['@aliocza_sortable_ui.position']]