mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
address selection: filter cities based on country
This commit is contained in:
parent
2f28cb16ef
commit
4cc308c936
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\MainBundle\Controller;
|
||||||
|
|
||||||
|
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class PostalCodeController
|
||||||
|
*
|
||||||
|
* @package Chill\MainBundle\Controller
|
||||||
|
* @author Champs Libres
|
||||||
|
*/
|
||||||
|
class PostalCodeAPIController extends ApiController
|
||||||
|
{
|
||||||
|
|
||||||
|
protected function customizeQuery(string $action, Request $request, $qb): void
|
||||||
|
{
|
||||||
|
if ($request->query->has('country')) {
|
||||||
|
|
||||||
|
$qb->where('e.country = :country')
|
||||||
|
->setParameter('country', $request->get('country'));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -290,6 +290,7 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
'controller' => \Chill\MainBundle\Controller\PostalCodeAPIController::class,
|
||||||
'class' => \Chill\MainBundle\Entity\PostalCode::class,
|
'class' => \Chill\MainBundle\Entity\PostalCode::class,
|
||||||
'name' => 'postal_code',
|
'name' => 'postal_code',
|
||||||
'base_path' => '/api/1.0/main/postal-code',
|
'base_path' => '/api/1.0/main/postal-code',
|
||||||
|
@ -16,13 +16,12 @@ const fetchCountries = () => {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Endpoint cities GET
|
* Endpoint cities GET
|
||||||
* TODO
|
* method GET, get Country Object
|
||||||
|
* @returns {Promise} a promise containing all Postal Code objects filtered with country
|
||||||
*/
|
*/
|
||||||
const fetchCities = (country) => {
|
const fetchCities = (country) => {
|
||||||
console.log('<<< fetching cities for', country);
|
console.log('<<< fetching cities for', country);
|
||||||
//TODO use country
|
const url = `/api/1.0/main/postal-code.json?item_per_page=1000&country=${country.id}`;
|
||||||
//TODO deal with huge number of postal code ... we should do suggestion...
|
|
||||||
const url = `/api/1.0/main/postal-code.json`;
|
|
||||||
return fetch(url)
|
return fetch(url)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.ok) { return response.json(); }
|
if (response.ok) { return response.json(); }
|
||||||
@ -37,7 +36,7 @@ const fetchCities = (country) => {
|
|||||||
*/
|
*/
|
||||||
const fetchReferenceAddresses = (city) => {
|
const fetchReferenceAddresses = (city) => {
|
||||||
console.log('<<< fetching references addresses for', city); // city n'est pas utilisé pour le moment
|
console.log('<<< fetching references addresses for', city); // city n'est pas utilisé pour le moment
|
||||||
|
//TODO deal with huge number of addresses... we should do suggestion...
|
||||||
const url = `/api/1.0/main/address-reference.json`;
|
const url = `/api/1.0/main/address-reference.json`;
|
||||||
return fetch(url)
|
return fetch(url)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
@ -2,12 +2,13 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<select
|
<select
|
||||||
v-model="selected">
|
v-model="selected">
|
||||||
<option :value="{}" disabled selected>{{ $t('select_country') }}</option>
|
<option :value="{}" selected disabled>{{ $t('select_country') }}</option>
|
||||||
<option
|
<option
|
||||||
v-for="item in this.countries"
|
v-for="item in this.countries"
|
||||||
v-bind:item="item"
|
v-bind:item="item"
|
||||||
v-bind:key="item.id"
|
v-bind:key="item.id"
|
||||||
v-bind:value="item">
|
v-bind:value="item"
|
||||||
|
v-bind:selected="item.countryCode === 'FR'">
|
||||||
{{ item.name.fr }}
|
{{ item.name.fr }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
@ -19,6 +20,9 @@
|
|||||||
export default {
|
export default {
|
||||||
name: 'CountrySelection',
|
name: 'CountrySelection',
|
||||||
props: ['address', 'getCities'],
|
props: ['address', 'getCities'],
|
||||||
|
// data: () => {
|
||||||
|
// selected: this.address.loaded.countries.filter(c => c.countryCode === 'FR')[0]
|
||||||
|
// },
|
||||||
computed: {
|
computed: {
|
||||||
countries() {
|
countries() {
|
||||||
const countries = this.address.loaded.countries;
|
const countries = this.address.loaded.countries;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user