mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
[Taxon] Make taxon sortable
This commit is contained in:
parent
8e4e690335
commit
9c1052d4bc
12 changed files with 108 additions and 28 deletions
|
|
@ -9,10 +9,10 @@ Feature: Reordering taxons
|
|||
And the store classifies its products as "Belts" and "Wallets"
|
||||
And I am logged in as an administrator
|
||||
|
||||
@todo
|
||||
@ui @javascript
|
||||
Scenario: Changing order of the taxon
|
||||
Given I want to see all taxons in store
|
||||
When I want to move up "Watches" taxon
|
||||
Then I should see 2 taxons on the list
|
||||
Then I should see 4 taxons on the list
|
||||
And I should see the taxon named "T-Shirts" in the list
|
||||
But the first taxon on the list should be "Watches"
|
||||
|
|
|
|||
|
|
@ -141,6 +141,10 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
|
|||
*/
|
||||
public function getFirstLeafName(TaxonInterface $parentTaxon = null)
|
||||
{
|
||||
$this->getDocument()->waitFor(5, function () {
|
||||
return;
|
||||
});
|
||||
|
||||
return $this->getLeafs($parentTaxon)[0]->getText();
|
||||
}
|
||||
|
||||
|
|
@ -175,6 +179,9 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
|
|||
if ($leaf->getText() === $taxon->getName()) {
|
||||
$moveButton = $leaf->getParent()->find('css', sprintf('.%s', $direction));
|
||||
$moveButton->click();
|
||||
$moveButton->waitFor(5, function () use ($moveButton) {
|
||||
return !$moveButton->hasClass('loading');
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,3 @@
|
|||
sylius_admin_api_taxon:
|
||||
resource: "@SyliusAdminBundle/Resources/config/routing/api/taxon.yml"
|
||||
prefix: /taxons
|
||||
|
||||
sylius_admin_api_product:
|
||||
resource: "@SyliusAdminBundle/Resources/config/routing/api/product.yml"
|
||||
prefix: /products
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
sylius_admin_api_taxon_index:
|
||||
path: /
|
||||
methods: [GET]
|
||||
defaults:
|
||||
_controller: sylius.controller.taxon:indexAction
|
||||
_format: json
|
||||
_sylius:
|
||||
grid: sylius_admin_taxon
|
||||
|
|
@ -20,6 +20,14 @@ sylius_admin_taxon_index:
|
|||
route: sylius_admin_taxon_create
|
||||
permanent: true
|
||||
|
||||
sylius_admin_taxon_move:
|
||||
path: /taxons/{id}/move
|
||||
methods: [PUT]
|
||||
defaults:
|
||||
_controller: sylius.controller.taxon:updateAction
|
||||
_sylius:
|
||||
form: sylius_taxon_position
|
||||
|
||||
sylius_admin_taxon_create_for_parent:
|
||||
path: /taxons/new/{id}
|
||||
defaults:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
(function ($) {
|
||||
'use strict';
|
||||
|
||||
$(document).ready(function() {
|
||||
$('.sylius-taxon-move-up').api({
|
||||
method: 'PUT',
|
||||
beforeSend: function (settings) {
|
||||
settings.data = {
|
||||
position: $(this).data('position') - 1
|
||||
};
|
||||
|
||||
return settings;
|
||||
},
|
||||
onSuccess: function (response) {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
|
||||
$('.sylius-taxon-move-down').api({
|
||||
method: 'PUT',
|
||||
beforeSend: function (settings) {
|
||||
settings.data = {
|
||||
position: $(this).data('position') + 1
|
||||
};
|
||||
|
||||
return settings;
|
||||
},
|
||||
onSuccess: function (response) {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
});
|
||||
})( jQuery );
|
||||
|
|
@ -11,6 +11,7 @@
|
|||
'use strict';
|
||||
|
||||
$.fn.api.settings.api = {
|
||||
'get taxons' : '/admin/api/taxons'
|
||||
'get taxons': '/admin/taxons?_format=json',
|
||||
'move taxon': '/admin/taxons/{id}/move?_format=json'
|
||||
};
|
||||
})(jQuery);
|
||||
|
|
|
|||
|
|
@ -18,12 +18,12 @@
|
|||
{{ buttons.create(path('sylius_admin_taxon_create_for_parent', { 'id': taxon.id }), 'sylius.ui.add'|trans) }}
|
||||
{{ buttons.edit(path('sylius_admin_taxon_update', { 'id': taxon.id })) }}
|
||||
{{ buttons.delete(path('sylius_admin_taxon_delete', { 'id': taxon.id }), 'sylius.ui.delete'|trans) }}
|
||||
<a class="ui icon button yellow" href="#">
|
||||
<div class="ui icon button yellow sylius-taxon-move-up" data-action="move taxon" data-id="{{ taxon.id }}" data-position="{{ taxon.position }}">
|
||||
<i class="icon arrow up"></i>
|
||||
</a>
|
||||
<a class="ui icon button yellow" href="#">
|
||||
</div>
|
||||
<div class="ui icon button yellow sylius-taxon-move-down" data-action="move taxon" data-id="{{ taxon.id }}" data-position="{{ taxon.position }}">
|
||||
<i class="icon arrow down"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="list">
|
||||
{{ tree.render(taxon.children) }}
|
||||
|
|
@ -33,7 +33,6 @@
|
|||
{% endfor %}
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
{{ buttons.create(path('sylius_admin_taxon_create')) }}
|
||||
<div class="ui segment">
|
||||
<div id="taxons-list" class="ui list">
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ class TaxonRepository extends EntityRepository implements TaxonRepositoryInterfa
|
|||
->leftJoin('o.children', 'children')
|
||||
->andWhere('o.parent = :parent')
|
||||
->addOrderBy('o.root')
|
||||
->addOrderBy('o.left')
|
||||
->addOrderBy('o.position')
|
||||
->setParameter('parent', $taxon)
|
||||
;
|
||||
|
||||
|
|
@ -100,7 +100,7 @@ class TaxonRepository extends EntityRepository implements TaxonRepositoryInterfa
|
|||
->leftJoin('o.translations', 'translation')
|
||||
->where('translation.permalink = :permalink')
|
||||
->setParameter('permalink', $permalink)
|
||||
->orderBy('o.left')
|
||||
->orderBy('o.position')
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
|
|
@ -131,6 +131,7 @@ class TaxonRepository extends EntityRepository implements TaxonRepositoryInterfa
|
|||
$queryBuilder = $this->createQueryBuilder('o');
|
||||
$queryBuilder
|
||||
->andWhere($queryBuilder->expr()->isNull($this->getPropertyName('parent')))
|
||||
->orderBy('o.position')
|
||||
;
|
||||
|
||||
return $queryBuilder->getQuery()->getResult();
|
||||
|
|
@ -144,7 +145,7 @@ class TaxonRepository extends EntityRepository implements TaxonRepositoryInterfa
|
|||
$queryBuilder = $this->createQueryBuilder('o');
|
||||
$queryBuilder
|
||||
->orderBy('o.root')
|
||||
->addOrderBy('o.left')
|
||||
->addOrderBy('o.position')
|
||||
;
|
||||
|
||||
return $queryBuilder->getQuery()->getResult();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\TaxonomyBundle\Form\Type;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
/**
|
||||
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
|
||||
*/
|
||||
final class TaxonPositionType extends AbstractResourceType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('position', IntegerType::class, [
|
||||
'label' => 'sylius.form.taxon.position',
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'sylius_taxon_position';
|
||||
}
|
||||
}
|
||||
|
|
@ -37,14 +37,10 @@
|
|||
<cascade-all />
|
||||
</cascade>
|
||||
<order-by>
|
||||
<order-by-field name="left" direction="ASC" />
|
||||
<order-by-field name="position" direction="ASC" />
|
||||
</order-by>
|
||||
</one-to-many>
|
||||
|
||||
<order-by>
|
||||
<order-by-field name="position" direction="ASC" />
|
||||
</order-by>
|
||||
|
||||
<field name="code" column="code" type="string" unique="true" />
|
||||
<field name="left" column="tree_left" type="integer">
|
||||
<gedmo:tree-left />
|
||||
|
|
|
|||
|
|
@ -17,6 +17,11 @@
|
|||
<argument type="service" id="sylius.repository.taxon" />
|
||||
<tag name="form.type" alias="sylius_taxon_choice" />
|
||||
</service>
|
||||
<service id="sylius.form.type.taxon_position" class="Sylius\Bundle\TaxonomyBundle\Form\Type\TaxonPositionType">
|
||||
<argument>%sylius.model.taxon.class%</argument>
|
||||
<argument>%sylius.validation_groups.taxon%</argument>
|
||||
<tag name="form.type" alias="sylius_taxon_position" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.factory.taxon.decorated" class="Sylius\Component\Taxonomy\Factory\TaxonFactory"
|
||||
decorates="sylius.factory.taxon" public="false">
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue