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>
|
||||
|
||||
<div v-if="address.address">
|
||||
{{ address.address.street }}, {{ address.address.streetNumber }}
|
||||
<div class='person__address__create'>
|
||||
<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 v-if="address.city">
|
||||
{{ address.city.code }} {{ address.city.name }}
|
||||
</div>
|
||||
<div v-if="address.country">
|
||||
{{ address.country.name }}
|
||||
<div class='person__address__valid'>
|
||||
<h2>{{ $t('date') }}</h2>
|
||||
<input
|
||||
type="date"
|
||||
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>
|
||||
|
||||
<add-address
|
||||
@addNewAddress="addNewAddress">
|
||||
</add-address>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
@ -23,9 +50,19 @@ export default {
|
||||
components: {
|
||||
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: {
|
||||
address() {
|
||||
return this.$store.state.address;
|
||||
},
|
||||
errors() {
|
||||
return this.$store.state.errorMsg;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@ -64,6 +101,13 @@ export default {
|
||||
|
||||
this.$store.dispatch('addAddress', newAddress);
|
||||
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 = {
|
||||
fr: {
|
||||
add_an_address_title: 'Ajouter une adresse',
|
||||
add_an_address_title: 'Créer une adresse',
|
||||
select_an_address_title: 'Sélectionner une adresse',
|
||||
fill_an_address: 'Compléter l\'adresse',
|
||||
select_country: 'Choisir le pays',
|
||||
@ -19,7 +19,11 @@ const addressMessages = {
|
||||
distribution: 'Service particulier de distribution',
|
||||
create_postal_code: 'Localité inconnue. Cliquez ici pour créer une nouvelle 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 { createStore } from 'vuex';
|
||||
|
||||
import { postAddress, postPostalCode } from '../../_api/AddAddress'
|
||||
import { patchAddress, postAddress, postPostalCode, postAddressToPerson } from '../../_api/AddAddress'
|
||||
|
||||
const debug = process.env.NODE_ENV !== 'production';
|
||||
|
||||
@ -20,6 +20,14 @@ const store = createStore({
|
||||
addAddress(state, address) {
|
||||
console.log('@M addAddress 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: {
|
||||
@ -51,7 +59,28 @@ const store = createStore({
|
||||
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 {
|
||||
fetchCountries,
|
||||
fetchCities,
|
||||
@ -132,5 +158,6 @@ export {
|
||||
fetchAddresses,
|
||||
postAddress,
|
||||
patchAddress,
|
||||
postPostalCode
|
||||
postPostalCode,
|
||||
postAddressToPerson
|
||||
};
|
||||
|
@ -22,7 +22,8 @@ use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Chill\MainBundle\CRUD\Controller\ApiController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
|
||||
class PersonApiController extends ApiController
|
||||
{
|
||||
@ -35,7 +36,7 @@ class PersonApiController extends ApiController
|
||||
{
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
}
|
||||
|
||||
|
||||
protected function createEntity(string $action, Request $request): object
|
||||
{
|
||||
$person = parent::createEntity($action, $request);
|
||||
@ -47,4 +48,10 @@ class PersonApiController extends ApiController
|
||||
|
||||
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_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
|
||||
*/
|
||||
export const postAddressToHousehold = (householdId, addressId) => {
|
||||
console.log(householdId);
|
||||
console.log(addressId);
|
||||
const body = {
|
||||
'id': addressId
|
||||
};
|
||||
@ -22,3 +20,4 @@ export const postAddressToHousehold = (householdId, addressId) => {
|
||||
throw Error('Error with request resource response');
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -22,36 +22,6 @@
|
||||
|
||||
{% 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 %}
|
||||
<h1>{{ block('title') }}</h1>
|
||||
<div id="address"></div>
|
||||
@ -62,6 +32,10 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
<script type="text/javascript">
|
||||
window.personId = {{ person.id|e('js') }};
|
||||
window.vueRootComponent = 'app';
|
||||
</script>
|
||||
{{ encore_entry_script_tags('address') }}
|
||||
{% endblock %}
|
||||
|
||||
|
@ -260,6 +260,44 @@ paths:
|
||||
422:
|
||||
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:
|
||||
get:
|
||||
tags:
|
||||
|
Loading…
x
Reference in New Issue
Block a user