mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
address: add a new address to a person
This commit is contained in:
parent
c378f59f5a
commit
7c26f0a56c
@ -1,18 +1,45 @@
|
|||||||
<template>
|
<template>
|
||||||
|
|
||||||
<div v-if="address.address">
|
<div class='person__address__create'>
|
||||||
{{ address.address.street }}, {{ address.address.streetNumber }}
|
<div>
|
||||||
|
<add-address
|
||||||
|
@addNewAddress="addNewAddress">
|
||||||
|
</add-address>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div v-if="address.text">
|
||||||
|
{{ address.text }}
|
||||||
|
</div>
|
||||||
|
<div v-if="address.postcode">
|
||||||
|
{{ address.postcode.name }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="address.city">
|
<div class='person__address__valid'>
|
||||||
{{ address.city.code }} {{ address.city.name }}
|
<h2>{{ $t('date') }}</h2>
|
||||||
</div>
|
<input
|
||||||
<div v-if="address.country">
|
type="date"
|
||||||
{{ address.country.name }}
|
name="validFrom"
|
||||||
|
:placeholder="$t('validFrom')"
|
||||||
|
v-model="validFrom"/>
|
||||||
|
<div v-if="errors.length > 0">
|
||||||
|
{{ errors }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<ul class="record_actions sticky-form-buttons">
|
||||||
|
<li class="cancel">
|
||||||
|
<a :href=backUrl class="sc-button bt-cancel">{{ $t('back_to_the_list') }}</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<button type="submit" class="sc-button bt-update centered mt-4" @click="addToPerson">
|
||||||
|
{{ $t('add_an_address_to_person') }}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<add-address
|
|
||||||
@addNewAddress="addNewAddress">
|
|
||||||
</add-address>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -23,9 +50,19 @@ export default {
|
|||||||
components: {
|
components: {
|
||||||
AddAddress
|
AddAddress
|
||||||
},
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
personId: window.personId,
|
||||||
|
backUrl: `/fr/person/${window.personId}/address/list`, //TODO better way to pass this
|
||||||
|
validFrom: new Date().toISOString().split('T')[0]
|
||||||
|
}
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
address() {
|
address() {
|
||||||
return this.$store.state.address;
|
return this.$store.state.address;
|
||||||
|
},
|
||||||
|
errors() {
|
||||||
|
return this.$store.state.errorMsg;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@ -64,6 +101,13 @@ export default {
|
|||||||
|
|
||||||
this.$store.dispatch('addAddress', newAddress);
|
this.$store.dispatch('addAddress', newAddress);
|
||||||
modal.showModal = false;
|
modal.showModal = false;
|
||||||
|
},
|
||||||
|
addToPerson() {
|
||||||
|
this.$store.dispatch('addDateToAddressAndAddressToPerson', {
|
||||||
|
personId: this.personId,
|
||||||
|
addressId: this.$store.state.address.address_id,
|
||||||
|
body: { validFrom: {datetime: `${this.validFrom}T00:00:00+0100`}}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
const addressMessages = {
|
const addressMessages = {
|
||||||
fr: {
|
fr: {
|
||||||
add_an_address_title: 'Ajouter une adresse',
|
add_an_address_title: 'Créer une adresse',
|
||||||
select_an_address_title: 'Sélectionner une adresse',
|
select_an_address_title: 'Sélectionner une adresse',
|
||||||
fill_an_address: 'Compléter l\'adresse',
|
fill_an_address: 'Compléter l\'adresse',
|
||||||
select_country: 'Choisir le pays',
|
select_country: 'Choisir le pays',
|
||||||
@ -19,7 +19,11 @@ const addressMessages = {
|
|||||||
distribution: 'Service particulier de distribution',
|
distribution: 'Service particulier de distribution',
|
||||||
create_postal_code: 'Localité inconnue. Cliquez ici pour créer une nouvelle localité',
|
create_postal_code: 'Localité inconnue. Cliquez ici pour créer une nouvelle localité',
|
||||||
postalCode_name: 'Nom de la localité',
|
postalCode_name: 'Nom de la localité',
|
||||||
postalCode_code: 'Code postal de la localité'
|
postalCode_code: 'Code postal de la localité',
|
||||||
|
date: 'Date de la nouvelle adresse',
|
||||||
|
add_an_address_to_person: 'Ajouter l\'adresse à la personne',
|
||||||
|
validFrom: 'Date de la nouvelle adresse',
|
||||||
|
back_to_the_list: 'Retour à la liste'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import 'es6-promise/auto';
|
import 'es6-promise/auto';
|
||||||
import { createStore } from 'vuex';
|
import { createStore } from 'vuex';
|
||||||
|
|
||||||
import { postAddress, postPostalCode } from '../../_api/AddAddress'
|
import { patchAddress, postAddress, postPostalCode, postAddressToPerson } from '../../_api/AddAddress'
|
||||||
|
|
||||||
const debug = process.env.NODE_ENV !== 'production';
|
const debug = process.env.NODE_ENV !== 'production';
|
||||||
|
|
||||||
@ -20,6 +20,14 @@ const store = createStore({
|
|||||||
addAddress(state, address) {
|
addAddress(state, address) {
|
||||||
console.log('@M addAddress address', address);
|
console.log('@M addAddress address', address);
|
||||||
state.address = address;
|
state.address = address;
|
||||||
|
},
|
||||||
|
addAddressToPerson(state, person) {
|
||||||
|
console.log('@M addAddressToPerson person', person);
|
||||||
|
state.person = person;
|
||||||
|
},
|
||||||
|
addDateToAddress(state, validFrom) {
|
||||||
|
console.log('@M addDateToAddress address.validFrom', validFrom);
|
||||||
|
state.validFrom = validFrom;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
@ -51,7 +59,28 @@ const store = createStore({
|
|||||||
commit('catchError', error);
|
commit('catchError', error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
addDateToAddressAndAddressToPerson({ commit }, payload) {
|
||||||
|
console.log('@A addDateToAddressAndAddressToPerson payload', payload);
|
||||||
|
|
||||||
|
patchAddress(payload.addressId, payload.body)
|
||||||
|
.then(address => new Promise((resolve, reject) => {
|
||||||
|
commit('addDateToAddress', address.validFrom);
|
||||||
|
resolve();
|
||||||
|
}).then(
|
||||||
|
postAddressToPerson(payload.personId, payload.addressId)
|
||||||
|
.then(person => new Promise((resolve, reject) => {
|
||||||
|
commit('addAddressToPerson', person);
|
||||||
|
resolve();
|
||||||
|
}))
|
||||||
|
.catch((error) => {
|
||||||
|
commit('catchError', error);
|
||||||
|
})
|
||||||
|
))
|
||||||
|
.catch((error) => {
|
||||||
|
commit('catchError', error);
|
||||||
|
});
|
||||||
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -125,6 +125,32 @@ const postPostalCode = (postalCode) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Endpoint chill_api_single_person_address
|
||||||
|
* method POST, post Person instance
|
||||||
|
*
|
||||||
|
* @id integer - id of Person
|
||||||
|
* @body Object - dictionary with changes to post
|
||||||
|
*/
|
||||||
|
const postAddressToPerson = (personId, addressId) => {
|
||||||
|
console.log(personId);
|
||||||
|
console.log(addressId);
|
||||||
|
const body = {
|
||||||
|
'id': addressId
|
||||||
|
};
|
||||||
|
const url = `/api/1.0/person/person/${personId}/address.json`
|
||||||
|
return fetch(url, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {'Content-Type': 'application/json;charset=utf-8'},
|
||||||
|
body: JSON.stringify(body)
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (response.ok) { return response.json(); }
|
||||||
|
throw Error('Error with request resource response');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
fetchCountries,
|
fetchCountries,
|
||||||
fetchCities,
|
fetchCities,
|
||||||
@ -132,5 +158,6 @@ export {
|
|||||||
fetchAddresses,
|
fetchAddresses,
|
||||||
postAddress,
|
postAddress,
|
||||||
patchAddress,
|
patchAddress,
|
||||||
postPostalCode
|
postPostalCode,
|
||||||
|
postAddressToPerson
|
||||||
};
|
};
|
||||||
|
@ -22,7 +22,8 @@ use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
|||||||
use Symfony\Component\Security\Core\Role\Role;
|
use Symfony\Component\Security\Core\Role\Role;
|
||||||
use Chill\MainBundle\CRUD\Controller\ApiController;
|
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Chill\MainBundle\Entity\Address;
|
||||||
|
|
||||||
class PersonApiController extends ApiController
|
class PersonApiController extends ApiController
|
||||||
{
|
{
|
||||||
@ -35,7 +36,7 @@ class PersonApiController extends ApiController
|
|||||||
{
|
{
|
||||||
$this->authorizationHelper = $authorizationHelper;
|
$this->authorizationHelper = $authorizationHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createEntity(string $action, Request $request): object
|
protected function createEntity(string $action, Request $request): object
|
||||||
{
|
{
|
||||||
$person = parent::createEntity($action, $request);
|
$person = parent::createEntity($action, $request);
|
||||||
@ -47,4 +48,10 @@ class PersonApiController extends ApiController
|
|||||||
|
|
||||||
return $person;
|
return $person;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function personAddressApi($id, Request $request, string $_format): Response
|
||||||
|
{
|
||||||
|
return $this->addRemoveSomething('address', $id, $request, $_format, 'address', Address::class, [ 'groups' => [ 'read' ] ]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -511,7 +511,16 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
|
|||||||
Request::METHOD_HEAD => \Chill\PersonBundle\Security\Authorization\PersonVoter::SEE,
|
Request::METHOD_HEAD => \Chill\PersonBundle\Security\Authorization\PersonVoter::SEE,
|
||||||
Request::METHOD_POST => \Chill\PersonBundle\Security\Authorization\PersonVoter::CREATE,
|
Request::METHOD_POST => \Chill\PersonBundle\Security\Authorization\PersonVoter::CREATE,
|
||||||
|
|
||||||
]
|
],
|
||||||
|
],
|
||||||
|
'address' => [
|
||||||
|
'methods' => [
|
||||||
|
Request::METHOD_POST => true,
|
||||||
|
Request::METHOD_DELETE => true,
|
||||||
|
Request::METHOD_GET => false,
|
||||||
|
Request::METHOD_HEAD => false,
|
||||||
|
],
|
||||||
|
'controller_action' => 'personAddressApi'
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
@ -6,8 +6,6 @@
|
|||||||
* @body Object - dictionary with changes to post
|
* @body Object - dictionary with changes to post
|
||||||
*/
|
*/
|
||||||
export const postAddressToHousehold = (householdId, addressId) => {
|
export const postAddressToHousehold = (householdId, addressId) => {
|
||||||
console.log(householdId);
|
|
||||||
console.log(addressId);
|
|
||||||
const body = {
|
const body = {
|
||||||
'id': addressId
|
'id': addressId
|
||||||
};
|
};
|
||||||
@ -22,3 +20,4 @@ export const postAddressToHousehold = (householdId, addressId) => {
|
|||||||
throw Error('Error with request resource response');
|
throw Error('Error with request resource response');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -22,36 +22,6 @@
|
|||||||
|
|
||||||
{% block personcontent %}
|
{% block personcontent %}
|
||||||
|
|
||||||
<h1>{{ 'New address for %name%'|trans({ '%name%': person.firstName ~ ' ' ~ person.lastName } ) }}</h1>
|
|
||||||
|
|
||||||
{{ form_start(form) }}
|
|
||||||
|
|
||||||
{{ form_row(form.isNoAddress) }}
|
|
||||||
{{ form_row(form.street) }}
|
|
||||||
{{ form_errors(form.street) }}
|
|
||||||
{{ form_row(form.streetNumber) }}
|
|
||||||
{{ form_errors(form.streetNumber) }}
|
|
||||||
{{ form_row(form.postCode) }}
|
|
||||||
{{ form_errors(form.postCode) }}
|
|
||||||
{{ form_row(form.validFrom) }}
|
|
||||||
{{ form_errors(form.validFrom) }}
|
|
||||||
|
|
||||||
<ul class="record_actions sticky-form-buttons">
|
|
||||||
<li class="cancel">
|
|
||||||
<a href="{{ path('chill_person_address_list', { 'person_id' : person.id } ) }}" class="sc-button bt-cancel">
|
|
||||||
{{ 'Back to the list'|trans }}
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
{{ form_row(form.submit, { 'attr' : { 'class': 'sc-button bt-create' }, 'label': 'Create' } ) }}
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
{{ form_end(form) }}
|
|
||||||
|
|
||||||
|
|
||||||
NEW FORM
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>{{ block('title') }}</h1>
|
<h1>{{ block('title') }}</h1>
|
||||||
<div id="address"></div>
|
<div id="address"></div>
|
||||||
@ -62,6 +32,10 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block js %}
|
{% block js %}
|
||||||
|
<script type="text/javascript">
|
||||||
|
window.personId = {{ person.id|e('js') }};
|
||||||
|
window.vueRootComponent = 'app';
|
||||||
|
</script>
|
||||||
{{ encore_entry_script_tags('address') }}
|
{{ encore_entry_script_tags('address') }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
@ -260,6 +260,44 @@ paths:
|
|||||||
422:
|
422:
|
||||||
description: "Invalid data: the data is a valid json, could be deserialized, but does not pass validation"
|
description: "Invalid data: the data is a valid json, could be deserialized, but does not pass validation"
|
||||||
|
|
||||||
|
/1.0/person/person/{id}/address.json:
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- person
|
||||||
|
summary: post an address to a person
|
||||||
|
parameters:
|
||||||
|
- name: id
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
description: The person id
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: integer
|
||||||
|
minimum: 1
|
||||||
|
requestBody:
|
||||||
|
required: true
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
description: The address id to attach to the person
|
||||||
|
responses:
|
||||||
|
401:
|
||||||
|
description: "Unauthorized"
|
||||||
|
404:
|
||||||
|
description: "Not found"
|
||||||
|
200:
|
||||||
|
description: "OK"
|
||||||
|
422:
|
||||||
|
description: "Unprocessable entity (validation errors)"
|
||||||
|
400:
|
||||||
|
description: "transition cannot be applyed"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/1.0/person/social-work/social-issue.json:
|
/1.0/person/social-work/social-issue.json:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user