-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77cfd63
commit fe49925
Showing
18 changed files
with
379 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
/** | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade Gally to newer versions in the future. | ||
* | ||
* @package Gally | ||
* @author Stephan Hochdörfer <S.Hochdoerfer@bitexpert.de>, Gally Team <elasticsuite@smile.fr> | ||
* @copyright 2022-present Smile | ||
* @license Open Software License v. 3.0 (OSL-3.0) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Gally\SyliusPlugin\Controller; | ||
|
||
use Gally\SyliusPlugin\Form\Type\Filter\GallyDynamicFilterType; | ||
use Gally\SyliusPlugin\Grid\Filter\Type\SelectFilterType; | ||
use Gally\SyliusPlugin\Search\Adapter; | ||
use Gally\SyliusPlugin\Service\FilterConverter; | ||
use Sylius\Bundle\TaxonomyBundle\Doctrine\ORM\TaxonRepository; | ||
use Sylius\Component\Channel\Context\ChannelContextInterface; | ||
use Sylius\Component\Locale\Context\LocaleContextInterface; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\Form\FormFactoryInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
final class Filter extends AbstractController | ||
{ | ||
public function __construct( | ||
private Adapter $adapter, | ||
private ChannelContextInterface $channelContext, | ||
private LocaleContextInterface $localeContext, | ||
private TaxonRepository $taxonRepository, | ||
private FormFactoryInterface $formFactory, | ||
private FilterConverter $filterConverter, | ||
) { | ||
} | ||
|
||
public function viewMore(Request $request, string $filterField): Response | ||
{ | ||
$search = $request->get('search'); | ||
$filters = $request->get('filters')['gally'] ?? []; | ||
$gallyFilters = []; | ||
foreach ($filters as $field => $value) { | ||
$gallyFilter = $this->filterConverter->convert($field, $value); | ||
if ($gallyFilter) { | ||
$gallyFilters[] = $gallyFilter; | ||
} | ||
} | ||
|
||
$choices = []; | ||
$currentTaxonId = $request->get('taxon'); | ||
$aggregationOptions = $this->adapter->viewMoreOption( | ||
$this->channelContext->getChannel(), | ||
$currentTaxonId ? $this->taxonRepository->find($currentTaxonId) : null, | ||
$this->localeContext->getLocaleCode(), | ||
$filterField, | ||
$gallyFilters, | ||
$search, | ||
); | ||
|
||
foreach ($aggregationOptions as $option) { | ||
$choices[$option['label']] = $option['value']; | ||
} | ||
|
||
$options = [ | ||
'block_prefix' => 'sylius_gally_filter_checkbox', | ||
'choices' => $choices, | ||
'expanded' => true, | ||
'multiple' => true, | ||
]; | ||
|
||
$form = $this->formFactory->createNamed('criteria')->add('gally', GallyDynamicFilterType::class); | ||
$form->get('gally')->add($filterField, SelectFilterType::class, $options); | ||
$form->get('gally')->get($filterField)->setData($filters[$filterField] ?? null); | ||
$html = $this->renderView('@GallySyliusPlugin/Grid/Filter/gally_dynamic_filter.html.twig', ['form' => $form]); | ||
|
||
return $this->json(['html' => $html]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade Gally to newer versions in the future. | ||
* | ||
* @package Gally | ||
* @author Stephan Hochdörfer <S.Hochdoerfer@bitexpert.de>, Gally Team <elasticsuite@smile.fr> | ||
* @copyright 2022-present Smile | ||
* @license Open Software License v. 3.0 (OSL-3.0) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Gally\SyliusPlugin\Grid\Filter\Type; | ||
|
||
use Sylius\Bundle\GridBundle\Form\Type\Filter\SelectFilterType as BaseSelectFilterType; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\FormInterface; | ||
use Symfony\Component\Form\FormView; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
final class SelectFilterType extends AbstractType | ||
{ | ||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$resolver->setDefined(['has_more_url']) | ||
->addAllowedTypes('has_more_url', 'string'); | ||
} | ||
|
||
public function getParent(): string | ||
{ | ||
return BaseSelectFilterType::class; | ||
} | ||
|
||
public function buildView(FormView $view, FormInterface $form, array $options): void | ||
{ | ||
$view->vars['has_more_url'] = $options['has_more_url'] ?? null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
# Define your own shop routes here | ||
#sylius_shop_partial_cart_add_item_ajax: | ||
gally_filter_view_more_ajax: | ||
path: /viewMore/{filterField} | ||
methods: [ GET ] | ||
defaults: | ||
_controller: Gally\SyliusPlugin\Controller\Filter::viewMore | ||
_format: json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#searchbar .field .view-more { | ||
color: rgba(0, 0, 0, 0.87); | ||
cursor: pointer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
$(document).ready(function() { | ||
$(document).on( | ||
'click', | ||
'#searchbarTextField .view-more', | ||
function (event) { | ||
event. preventDefault(); | ||
|
||
let linkEl = $(event.target), | ||
form = linkEl.closest('form'), | ||
choicesEl = $('#' + linkEl.data('for') + ' > .fields'); | ||
|
||
form.addClass('loading'); | ||
|
||
$.get( | ||
linkEl.data('href'), | ||
function( data ) { | ||
choicesEl.replaceWith($(data.html).find('.fields')); | ||
linkEl.hide(); | ||
} | ||
).always(function() { | ||
form.removeClass('loading'); | ||
}); | ||
} | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
{% include '@SyliusUi/_javascripts.html.twig' with {'path': 'bundles/gallysyliusplugin/nouislider.min.js'} %} | ||
{% include '@SyliusUi/_javascripts.html.twig' with {'path': 'bundles/gallysyliusplugin/range-slider.js'} %} | ||
{% include '@SyliusUi/_javascripts.html.twig' with {'path': 'bundles/gallysyliusplugin/view-more.js'} %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
{% include '@SyliusUi/_stylesheets.html.twig' with {'path': 'bundles/gallysyliusplugin/nouislider.min.css'} %} | ||
{% include '@SyliusUi/_stylesheets.html.twig' with {'path': 'bundles/gallysyliusplugin/slider.css'} %} | ||
{% include '@SyliusUi/_stylesheets.html.twig' with {'path': 'bundles/gallysyliusplugin/view-more.css'} %} |
Oops, something went wrong.