-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajoute une recherche de lieu à la carte
- Loading branch information
1 parent
f3b46ca
commit e82d659
Showing
8 changed files
with
122 additions
and
0 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
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
45 changes: 45 additions & 0 deletions
45
src/Infrastructure/Controller/Map/Fragments/MapSearchController.php
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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Infrastructure\Controller\Map\Fragments; | ||
|
||
use App\Application\RoadGeocoderInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
final class MapSearchController | ||
{ | ||
public function __construct( | ||
private \Twig\Environment $twig, | ||
private RoadGeocoderInterface $roadGeocoder, | ||
) { | ||
} | ||
|
||
#[Route( | ||
'/carte/search', | ||
name: 'fragment_carto_search', | ||
methods: ['GET'], | ||
)] | ||
public function __invoke(Request $request): Response | ||
{ | ||
$search = $request->query->get('search'); | ||
|
||
if (!$search) { | ||
throw new BadRequestHttpException(); | ||
} | ||
|
||
$results = $this->roadGeocoder->findPlacesForMap($search); | ||
|
||
return new Response( | ||
$this->twig->render( | ||
name: 'map/fragments/search_results.html.twig', | ||
context: [ | ||
'results' => $results, | ||
], | ||
), | ||
); | ||
} | ||
} |
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 @@ | ||
<div | ||
class="fr-x-autocomplete-wrapper" | ||
data-controller="autocomplete" | ||
data-autocomplete-url-value="{{ path('fragment_carto_search') }}" | ||
data-autocomplete-query-param-value="search" | ||
data-autocomplete-min-length-value="3" | ||
data-autocomplete-delay-value="500" | ||
data-autocomplete-loading-status-value="{{ 'common.autocomplete.status.loading'|trans }}" | ||
data-autocomplete-empty-status-value="{{ 'common.autocomplete.status.min_chars'|trans({ '%minChars%': 3 }) }}" | ||
data-action="autocomplete.change->reset#reset" | ||
> | ||
<div class="fr-search-bar"> | ||
<label for="map_search" class="app-sr-only"> | ||
{{ 'map.search_form.search'|trans }} | ||
</label> | ||
|
||
<input | ||
id="map_search" | ||
name="map_search" | ||
type="text" | ||
class="fr-input" | ||
spellcheck="false" | ||
autocomplete="false" | ||
data-autocomplete-target="input" | ||
placeholder="{{ 'map.search_form.search.placeholder'|trans }}" | ||
> | ||
|
||
<button class="fr-btn" aria-label="{{ 'common.form.search'|trans }}">{{ 'common.form.search'|trans }}</button> | ||
</div> | ||
|
||
<ul | ||
id="map_search-results" | ||
role="listbox" | ||
aria-label="{{ 'map.search_form.results_label'|trans }}" | ||
class="fr-x-autocomplete" | ||
data-autocomplete-target="results" | ||
> | ||
<li role="status" data-autocomplete-target="status"></li> | ||
</ul> | ||
</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,7 @@ | ||
{% for result in results %} | ||
<li role="option" data-autocomplete-value="{{ result.coordinates }}">{{ result.label }}</li> | ||
{% endfor %} | ||
|
||
<template id="status"> | ||
{{ 'common.autocomplete.results_count'|trans({ '%count%': results|length }) }} | ||
</template> |
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