mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 05:44:24 +00:00
address selection: use API points for Country and PostalCode + remove obsolet Address Controller
This commit is contained in:
parent
0afcf3d79e
commit
fee37b5af3
@ -1,63 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Chill\MainBundle\Controller;
|
|
||||||
|
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
|
||||||
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
|
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
|
||||||
use Chill\MainBundle\Entity\Address;
|
|
||||||
use Chill\MainBundle\Entity\AddressReference;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class AddressController
|
|
||||||
*
|
|
||||||
* @package Chill\MainBundle\Controller
|
|
||||||
*/
|
|
||||||
class AddressController extends AbstractController
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get API Data for showing endpoint
|
|
||||||
*
|
|
||||||
* @Route(
|
|
||||||
* "/{_locale}/main/api/1.0/address/{address_id}/show.{_format}",
|
|
||||||
* name="chill_main_address_api_show"
|
|
||||||
* )
|
|
||||||
* @ParamConverter("address", options={"id": "address_id"})
|
|
||||||
*/
|
|
||||||
public function showAddress(Address $address, $_format): Response
|
|
||||||
{
|
|
||||||
// TODO check ACL ?
|
|
||||||
switch ($_format) {
|
|
||||||
case 'json':
|
|
||||||
return $this->json($address);
|
|
||||||
default:
|
|
||||||
throw new BadRequestException('Unsupported format');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get API Data for showing endpoint
|
|
||||||
*
|
|
||||||
* @Route(
|
|
||||||
* "/{_locale}/main/api/1.0/address-reference/{address_reference_id}/show.{_format}",
|
|
||||||
* name="chill_main_address_reference_api_show"
|
|
||||||
* )
|
|
||||||
* @ParamConverter("addressReference", options={"id": "address_reference_id"})
|
|
||||||
*/
|
|
||||||
public function showAddressReference(AddressReference $addressReference, $_format): Response
|
|
||||||
{
|
|
||||||
// TODO check ACL ?
|
|
||||||
switch ($_format) {
|
|
||||||
case 'json':
|
|
||||||
return $this->json($addressReference);
|
|
||||||
default:
|
|
||||||
throw new BadRequestException('Unsupported format');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +1,32 @@
|
|||||||
/*
|
/*
|
||||||
* Endpoint countries GET
|
* Endpoint countries GET
|
||||||
* TODO
|
* method GET, get Country Object
|
||||||
|
* @returns {Promise} a promise containing all Country object
|
||||||
*/
|
*/
|
||||||
const fetchCountries = () => {
|
const fetchCountries = () => {
|
||||||
console.log('<<< fetching countries');
|
console.log('<<< fetching countries');
|
||||||
return [
|
|
||||||
{id: 1, name: 'France', countryCode: 'FR'},
|
const url = `/api/1.0/main/country.json`;
|
||||||
{id: 2, name: 'Belgium', countryCode: 'BE'}
|
return fetch(url)
|
||||||
];
|
.then(response => {
|
||||||
|
if (response.ok) { return response.json(); }
|
||||||
|
throw Error('Error with request resource response');
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Endpoint cities GET
|
* Endpoint cities GET
|
||||||
* TODO
|
* TODO
|
||||||
*/
|
*/
|
||||||
const fetchCities = (country) => {
|
const fetchCities = (country) => {
|
||||||
console.log('<<< fetching cities for', country);
|
console.log('<<< fetching cities for', country);
|
||||||
return [
|
//TODO use country
|
||||||
{id: 1, name: 'Bruxelles', code: '1000', country: 'BE'},
|
const url = `/api/1.0/main/postal-code.json`;
|
||||||
{id: 2, name: 'Aisne', code: '85045', country: 'FR'},
|
return fetch(url)
|
||||||
{id: 3, name: 'Saint-Gervais', code: '85230', country: 'FR'}
|
.then(response => {
|
||||||
];
|
if (response.ok) { return response.json(); }
|
||||||
|
throw Error('Error with request resource response');
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -30,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
|
||||||
|
|
||||||
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 => {
|
||||||
|
@ -13,14 +13,14 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-slot:body>
|
<template v-slot:body>
|
||||||
|
|
||||||
<h4>{{ $t('select_an_address') }}</h4>
|
<h4>{{ $t('select_an_address') }}</h4>
|
||||||
|
|
||||||
<label for="isNoAddress">
|
<label for="isNoAddress">
|
||||||
<input type="checkbox"
|
<input type="checkbox"
|
||||||
name="isNoAddress"
|
name="isNoAddress"
|
||||||
v-bind:placeholder="$t('isNoAddress')"
|
v-bind:placeholder="$t('isNoAddress')"
|
||||||
v-model="isNoAddress"
|
v-model="isNoAddress"
|
||||||
v-bind:value="value"/>
|
v-bind:value="value"/>
|
||||||
{{ $t('isNoAddress') }}
|
{{ $t('isNoAddress') }}
|
||||||
</label>
|
</label>
|
||||||
@ -29,12 +29,12 @@
|
|||||||
v-bind:address="address"
|
v-bind:address="address"
|
||||||
v-bind:getCities="getCities">
|
v-bind:getCities="getCities">
|
||||||
</country-selection>
|
</country-selection>
|
||||||
|
|
||||||
<city-selection
|
<city-selection
|
||||||
v-bind:address="address"
|
v-bind:address="address"
|
||||||
v-bind:getReferenceAddresses="getReferenceAddresses">
|
v-bind:getReferenceAddresses="getReferenceAddresses">
|
||||||
</city-selection>
|
</city-selection>
|
||||||
|
|
||||||
<address-selection
|
<address-selection
|
||||||
v-bind:address="address"
|
v-bind:address="address"
|
||||||
v-bind:updateMapCenter="updateMapCenter">
|
v-bind:updateMapCenter="updateMapCenter">
|
||||||
@ -44,12 +44,12 @@
|
|||||||
v-bind:address="address"
|
v-bind:address="address"
|
||||||
ref="addressMap">
|
ref="addressMap">
|
||||||
</address-map>
|
</address-map>
|
||||||
|
|
||||||
<address-more
|
<address-more
|
||||||
v-if="!isNoAddress"
|
v-if="!isNoAddress"
|
||||||
v-bind:address="address">
|
v-bind:address="address">
|
||||||
</address-more>
|
</address-more>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
<div class="address_form__fields__isNoAddress"></div>
|
<div class="address_form__fields__isNoAddress"></div>
|
||||||
<div class="address_form__select">
|
<div class="address_form__select">
|
||||||
@ -62,10 +62,10 @@
|
|||||||
<div class="address_form__fields__left"></div>
|
<div class="address_form__fields__left"></div>
|
||||||
<div class="address_form__fields__right"></div>
|
<div class="address_form__fields__right"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
à discuter,
|
à discuter,
|
||||||
mais je pense qu'il est préférable de profiter de l'imbriquation des classes css
|
mais je pense qu'il est préférable de profiter de l'imbriquation des classes css
|
||||||
|
|
||||||
div.address_form {
|
div.address_form {
|
||||||
div.select {
|
div.select {
|
||||||
div.header {}
|
div.header {}
|
||||||
@ -73,12 +73,12 @@
|
|||||||
div.map {}
|
div.map {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
-->
|
-->
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-slot:footer>
|
<template v-slot:footer>
|
||||||
<button class="sc-button green"
|
<button class="sc-button green"
|
||||||
@click.prevent="$emit('addNewAddress', { address, modal })">
|
@click.prevent="$emit('addNewAddress', { address, modal })">
|
||||||
<i class="fa fa-plus fa-fw"></i>{{ $t('action.add')}}
|
<i class="fa fa-plus fa-fw"></i>{{ $t('action.add')}}
|
||||||
</button>
|
</button>
|
||||||
@ -160,32 +160,30 @@ export default {
|
|||||||
this.modal.showModal = true;
|
this.modal.showModal = true;
|
||||||
this.resetAll();
|
this.resetAll();
|
||||||
this.getCountries();
|
this.getCountries();
|
||||||
|
|
||||||
//this.$nextTick(function() {
|
//this.$nextTick(function() {
|
||||||
// this.$refs.search.focus(); // positionner le curseur à l'ouverture de la modale
|
// this.$refs.search.focus(); // positionner le curseur à l'ouverture de la modale
|
||||||
//})
|
//})
|
||||||
},
|
},
|
||||||
getCountries() {
|
getCountries() {
|
||||||
console.log('getCountries');
|
console.log('getCountries');
|
||||||
this.address.loaded.countries = fetchCountries(); // à remplacer par
|
fetchCountries().then(countries => new Promise((resolve, reject) => {
|
||||||
// fetchCountries().then(countries => new Promise((resolve, reject) => {
|
this.address.loaded.countries = countries.results;
|
||||||
// this.address.loaded.countries = countries;
|
resolve()
|
||||||
// resolve()
|
}))
|
||||||
// }))
|
.catch((error) => {
|
||||||
// .catch((error) => {
|
this.errorMsg.push(error.message);
|
||||||
// this.errorMsg.push(error.message);
|
});
|
||||||
// });
|
|
||||||
},
|
},
|
||||||
getCities(country) {
|
getCities(country) {
|
||||||
console.log('getCities for', country.name);
|
console.log('getCities for', country.name);
|
||||||
this.address.loaded.cities = fetchCities(); // à remplacer par
|
fetchCities(country).then(cities => new Promise((resolve, reject) => {
|
||||||
// fetchCities(country).then(cities => new Promise((resolve, reject) => {
|
this.address.loaded.cities = cities.results;
|
||||||
// this.address.loaded.cities = cities;
|
resolve()
|
||||||
// resolve()
|
}))
|
||||||
// }))
|
.catch((error) => {
|
||||||
// .catch((error) => {
|
this.errorMsg.push(error.message);
|
||||||
// this.errorMsg.push(error.message);
|
});
|
||||||
// });
|
|
||||||
},
|
},
|
||||||
getReferenceAddresses(city) {
|
getReferenceAddresses(city) {
|
||||||
console.log('getReferenceAddresses for', city.name);
|
console.log('getReferenceAddresses for', city.name);
|
||||||
@ -195,9 +193,9 @@ export default {
|
|||||||
this.address.loaded.addresses = addresses.results;
|
this.address.loaded.addresses = addresses.results;
|
||||||
resolve();
|
resolve();
|
||||||
}))
|
}))
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.errorMsg.push(error.message);
|
this.errorMsg.push(error.message);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
updateMapCenter(point) {
|
updateMapCenter(point) {
|
||||||
console.log('point', point);
|
console.log('point', point);
|
||||||
@ -208,7 +206,7 @@ export default {
|
|||||||
resetAll() {
|
resetAll() {
|
||||||
console.log('reset all selected');
|
console.log('reset all selected');
|
||||||
this.address.loaded.addresses = [];
|
this.address.loaded.addresses = [];
|
||||||
this.address.selected.address = {};
|
this.address.selected.address = {};
|
||||||
this.address.loaded.cities = [];
|
this.address.loaded.cities = [];
|
||||||
this.address.selected.city = {};
|
this.address.selected.city = {};
|
||||||
this.address.selected.country = {};
|
this.address.selected.country = {};
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<select
|
<select
|
||||||
v-model="selected">
|
v-model="selected">
|
||||||
<option :value="{}" disabled selected>{{ $t('select_country') }}</option>
|
<option :value="{}" disabled selected>{{ $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">
|
||||||
{{ item.name }}
|
{{ item.name.fr }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@ -20,8 +20,8 @@ export default {
|
|||||||
name: 'CountrySelection',
|
name: 'CountrySelection',
|
||||||
props: ['address', 'getCities'],
|
props: ['address', 'getCities'],
|
||||||
computed: {
|
computed: {
|
||||||
countries() {
|
countries() {
|
||||||
return this.address.loaded.countries;
|
return this.address.loaded.countries; // TODO place Belgium and France first
|
||||||
},
|
},
|
||||||
selected: {
|
selected: {
|
||||||
set(value) {
|
set(value) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user