-
Notifications
You must be signed in to change notification settings - Fork 0
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
2cebb34
commit 1d506ca
Showing
14 changed files
with
285 additions
and
16 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,76 @@ | ||
<?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 Gally Team <elasticsuite@smile.fr> | ||
* @copyright 2024-present Smile | ||
* @license Open Software License v. 3.0 (OSL-3.0) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Gally\OroPlugin\Controller\Frontend; | ||
|
||
use Gally\OroPlugin\Search\GallyRequestBuilder; | ||
use Gally\Sdk\GraphQl\Request as SearchRequest; | ||
use Gally\Sdk\Service\SearchManager; | ||
use Oro\Bundle\DataGridBundle\Datagrid; | ||
use Oro\Bundle\SearchBundle\Datagrid\Datasource\SearchDatasource; | ||
use Oro\Bundle\SecurityBundle\Annotation\AclAncestor; | ||
use Oro\Bundle\WebsiteSearchBundle\Event\BeforeSearchEvent; | ||
use Oro\Bundle\WebsiteSearchBundle\Resolver\QueryPlaceholderResolverInterface; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class ViewMoreController extends AbstractController | ||
{ | ||
public const PRODUCT_SEARCH_DATAGRID = 'frontend-product-search-grid'; | ||
|
||
public function __construct( | ||
private Datagrid\Manager $dataGridManager, | ||
private Datagrid\RequestParameterBagFactory $parameterBagFactory, | ||
private EventDispatcherInterface $eventDispatcher, | ||
private QueryPlaceholderResolverInterface $queryPlaceholderResolver, | ||
private GallyRequestBuilder $requestBuilder, | ||
private SearchManager $searchManager, | ||
) { | ||
} | ||
|
||
/** | ||
* @Route("/filter_view_more", name="gally_filter_view_more", methods={"GET"}) | ||
* | ||
* @AclAncestor("oro_product_frontend_view") | ||
*/ | ||
public function getDataAction(Request $request): JsonResponse | ||
{ | ||
$options = $this->searchManager->viewMoreProductFilterOption( | ||
$this->getSearchRequest(), | ||
$request->query->get('field') | ||
); | ||
|
||
return new JsonResponse($options); | ||
} | ||
|
||
private function getSearchRequest(): SearchRequest | ||
{ | ||
$dataGrid = $this->dataGridManager->getDatagrid( | ||
self::PRODUCT_SEARCH_DATAGRID, | ||
$this->parameterBagFactory->fetchParameters(self::PRODUCT_SEARCH_DATAGRID) | ||
); | ||
|
||
/** @var SearchDatasource $datasource */ | ||
$datasource = $dataGrid->acceptDatasource()->getDatasource(); | ||
$query = $datasource->getSearchQuery(); | ||
$event = new BeforeSearchEvent($query->getQuery(), []); | ||
$this->eventDispatcher->dispatch($event, BeforeSearchEvent::EVENT_NAME); | ||
$this->queryPlaceholderResolver->replace($event->getQuery()); | ||
|
||
return $this->requestBuilder->build($event->getQuery(), []); | ||
} | ||
} |
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,16 @@ | ||
services: | ||
_defaults: | ||
public: true | ||
|
||
Gally\OroPlugin\Controller\Frontend\ViewMoreController: | ||
arguments: | ||
- '@oro_datagrid.datagrid.manager' | ||
- '@oro_datagrid.datagrid.request_parameters_factory' | ||
- '@event_dispatcher' | ||
- '@Gally\OroPlugin\Resolver\QueryPlaceholderResolver' | ||
- '@Gally\OroPlugin\Search\GallyRequestBuilder' | ||
- '@Gally\Sdk\Service\SearchManager' | ||
calls: | ||
- [setContainer, ['@Psr\Container\ContainerInterface']] | ||
tags: | ||
- { name: container.service_subscriber } |
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,6 @@ | ||
gally_frontend_routes: | ||
resource: "@GallyOroBundle/Controller/Frontend" | ||
type: annotation | ||
prefix: /gally | ||
options: | ||
frontend: true |
76 changes: 76 additions & 0 deletions
76
src/Resources/public/default/templates/search-autocomplete.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<% | ||
function highlightWords(inputString, value) { | ||
if (!!inputString && _.isString(inputString)) { | ||
const highlightPattern = '<u class="search-autocomplete__highlight">$&</u>'; | ||
const inputWords = _.escape(inputString).split(' '); | ||
const reg = new RegExp(inputWords.join('|'), 'gi'); | ||
return _.escape(value).replace(reg, highlightPattern); | ||
} else { | ||
return _.escape(value); | ||
} | ||
} | ||
%> | ||
|
||
<div class="search-autocomplete"> | ||
<div class="search-autocomplete__content dropdown-menu"> | ||
<% if (total_count > 0) { %> | ||
<ul class="search-autocomplete__list" id="<%- comboboxId %>" role="listbox"> | ||
<%_.each(categories, function(category) { %> | ||
<li class="search-autocomplete__item" role="option"> | ||
<a href="<%- category.url %>" class="search-autocomplete-category" title="<%- _.__('oro.product.search.search_in_category.tooltip', { text: inputString, category: category.tree[category.tree.length - 1] }, category.count) %>"> | ||
<div class="search-autocomplete-category__image"> | ||
<span class="fa-search fa--no-offset"></span> | ||
</div> | ||
<div class="search-autocomplete-category__info"> | ||
<div class="search-autocomplete-category__head"> | ||
<%= inputString %> | ||
</div> | ||
<div class="search-autocomplete-category__body"> | ||
<% let lastCategory = category.tree.pop(); %> | ||
<%_.each(category.tree, function(categoryLeaf) { %> | ||
<span><%= categoryLeaf %> > </span> | ||
<% }) %> | ||
<span class="last-category"><%= lastCategory %></span> | ||
</div> | ||
</div> | ||
</a> | ||
</li> | ||
<% }) %> | ||
<%_.each(products, function(product) { %> | ||
<li class="search-autocomplete__item" role="option"> | ||
<a href="<%- product.url %>" class="search-autocomplete-product" title="<%- product.name %>"> | ||
<div class="search-autocomplete-product__image"> | ||
<picture> | ||
<% if (product.imageWebp && product.imageWebp !== product.image) { %> | ||
<source srcset="<%- product.imageWebp %>" type="image/webp"> | ||
<% } %> | ||
<img src="<%- product.image %>" alt="<%- product.name %>"> | ||
</picture> | ||
</div> | ||
<div class="search-autocomplete-product__info"> | ||
<div class="search-autocomplete-product__head"> | ||
<div class="search-autocomplete-product__title"><%= highlightWords(inputString, product.name) %></div> | ||
<% if (product.formatted_price) { %> | ||
<div class="search-autocomplete-product__price"><%- product.formatted_price %></div> | ||
<% } %> | ||
</div> | ||
<div class="search-autocomplete-product__body"> | ||
<div class="search-autocomplete-product__sku"><%= highlightWords(inputString, product.sku) %></div> | ||
<div class="search-autocomplete-product__status <%- product.inventory_status %>"><%- product.inventory_status_label %></div> | ||
</div> | ||
</div> | ||
</a> | ||
</li> | ||
<% }) %> | ||
<li class="search-autocomplete__item" role="option"> | ||
<button class="btn btn--link btn--no-offset search-autocomplete__submit" | ||
type="submit" | ||
><%- _.__('oro.product.autocomplete.popup.button.all.label', { productCount: total_count }, total_count) %> <span class="fa-angle-right" aria-hidden="true"></span> | ||
</button> | ||
</li> | ||
</ul> | ||
<% } else { %> | ||
<div class="search-autocomplete__no-found"><%- _.__('oro.product.autocomplete.no_found') %></div> | ||
<% } %> | ||
</div> | ||
</div> |
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,70 @@ | ||
define(function(require) { | ||
'use strict'; | ||
|
||
const $ = require('jquery'); | ||
const routing = require('routing'); | ||
const MultiSelectFilter = require('oro/filter/multiselect-filter'); | ||
const LoadingMaskView = require('oroui/js/app/views/loading-mask-view'); | ||
const __ = require('orotranslation/js/translator'); | ||
|
||
/** | ||
* Gally select filter: filter values as multiple select options and | ||
* add a view more button if all the options are not displayed | ||
* | ||
* @export oro/filter/gally-filter | ||
* @class oro.filter.GallyFilter | ||
* @extends oro.filter.MultiSelectFilter | ||
*/ | ||
const GallyFilter = MultiSelectFilter.extend({ | ||
|
||
custom_data: {}, | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
initialize: function (options) { | ||
GallyFilter.__super__.initialize.call(this, options); | ||
const viewMoreLabel = __('gally.filter.showMore.label'); | ||
this.showMoreLink = $('<a/>', {href: '#', html: viewMoreLabel, click: this.showMore.bind(this)}); | ||
}, | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
render: function() { | ||
GallyFilter.__super__.render.call(this); | ||
|
||
if (this.custom_data.hasMore) { | ||
this.selectWidget.multiselect('open'); | ||
this.selectWidget.getWidget().append(this.showMoreLink); | ||
this.selectWidget.multiselect('close'); | ||
} | ||
if (!this.subview('loading')) { | ||
this.subview('loading', new LoadingMaskView({container: this.$el})); | ||
} | ||
}, | ||
|
||
showMore: function() { | ||
this.subview('loading').show(); | ||
let urlParams = Object.fromEntries(new URLSearchParams(window.location.search)); | ||
urlParams['field'] = this.name; | ||
|
||
$.ajax({ | ||
url: routing.generate('gally_filter_view_more', urlParams), | ||
method: 'GET', | ||
success: function (response) { | ||
this.custom_data.hasMore = false; | ||
this.showMoreLink.hide(); | ||
this._setChoices(response); | ||
this.render(); | ||
this.subview('loading').hide(); | ||
}.bind(this), | ||
error: function (xhr) { | ||
this.subview('loading').hide(); | ||
}.bind(this), | ||
}); | ||
} | ||
}); | ||
|
||
return GallyFilter; | ||
}); |
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 @@ | ||
gally: | ||
filter: | ||
showMore: | ||
label: "Show more" |
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 @@ | ||
gally: | ||
filter: | ||
showMore: | ||
label: "Voir plus" |
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,6 @@ | ||
aliases: | ||
oro/filter/gally-filter$: bundles/gallyoro/js/filter/gally-filter | ||
|
||
dynamic-imports: | ||
orodatagrid: | ||
- oro/filter/gally-filter |
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