Compare commits

...

5 Commits

14 changed files with 352 additions and 357 deletions

View File

@@ -10,7 +10,7 @@
<script> <script>
import AddAddress from './components/AddAddress.vue'; import AddAddress from './components/AddAddress.vue';
import { postAddressToHousehold, postAddressToPerson } from "ChillPersonAssets/vuejs/_api/AddAddress"; import { makeFetch } from 'ChillMainAssets/lib/api/apiMethods.js';
export default { export default {
name: "App", name: "App",
@@ -31,25 +31,17 @@ export default {
: this.context.target.name + '_' + this.context.target.id ; : this.context.target.name + '_' + this.context.target.id ;
} }
}, },
mounted() {
//console.log('AddAddress: data context', this.context);
//console.log('AddAddress: data options', this.options);
},
methods: { methods: {
displayErrors() { displayErrors() {
return this.$refs.addAddress.errorMsg; return this.$refs.addAddress.errorMsg;
}, },
submitAddress(payload) { submitAddress(payload) {
console.log('@@@ click on Submit Address Button', payload);
// Existing address // Existing address
if (this.context.edit) { if (this.context.edit) {
// address is already linked, just finish ! // address is already linked, just finish !
this.$refs.addAddress.afterLastPaneAction({}); this.$refs.addAddress.afterLastPaneAction({});
this.$emit('addressEdited', payload); this.$emit('addressEdited', payload);
// New created address
// New created address
} else { } else {
this.postAddressTo(payload); this.postAddressTo(payload);
} }
@@ -60,51 +52,39 @@ export default {
*/ */
postAddressTo(payload) { postAddressTo(payload) {
this.$emit('addressCreated', payload); this.$emit('addressCreated', payload);
let url = '';
console.log('postAddress', payload.addressId, 'To', payload.target, payload.targetId);
switch (payload.target) { switch (payload.target) {
case 'household': case 'household':
postAddressToHousehold(payload.targetId, payload.addressId) url = `/api/1.0/person/household/${payload.targetId}/address.json`
.then(address => new Promise((resolve, reject) => {
console.log('..household address', address);
this.$refs.addAddress.flag.loading = false;
this.$refs.addAddress.flag.success = true;
// finish
this.$refs.addAddress.afterLastPaneAction({ addressId: address.address_id });
resolve();
}))
.catch((error) => {
this.$refs.addAddress.errorMsg.push(error);
this.$refs.addAddress.flag.loading = false;
})
;
break; break;
case 'person': case 'person':
postAddressToPerson(payload.targetId, payload.addressId) url = `/api/1.0/person/person/${payload.targetId}/address.json`
.then(address => new Promise((resolve, reject) => {
console.log('..person address', address);
this.$refs.addAddress.flag.loading = false;
this.$refs.addAddress.flag.success = true;
// finish
this.$refs.addAddress.afterLastPaneAction({ addressId: address.address_id });
resolve();
}))
.catch((error) => {
this.$refs.addAddress.errorMsg.push(error);
this.$refs.addAddress.flag.loading = false;
})
;
break; break;
case 'thirdparty': case 'thirdparty':
console.log('TODO write postAddressToThirdparty'); // TODO write postAddressToThirdparty;
break; break;
default: default:
this.$refs.addAddress.errorMsg.push('That entity is not managed by address !'); this.$refs.addAddress.errorMsg.push('This entity is not managed by address !');
} }
const body = {
'id': payload.addressId
};
makeFetch('POST', url, body)
.then((response) => {
this.$refs.addAddress.flag.loading = false;
this.$refs.addAddress.flag.success = true;
this.$refs.addAddress.afterLastPaneAction({ addressId: response.address_id });
})
.catch(({name, violations}) => {
if (name === 'ValidationException' || name === 'AccessException') {
violations.forEach((violation) => this.$toast.open({message: violation}));
} else {
this.$toast.open({message: 'An error occurred'})
}
this.$refs.addAddress.flag.loading = false;
});
} }
} }
} }

View File

@@ -36,12 +36,12 @@ const fetchCities = (country) => {
*/ */
const fetchReferenceAddresses = (postalCode) => { const fetchReferenceAddresses = (postalCode) => {
//console.log('<<< fetching references addresses for', postalCode); //console.log('<<< fetching references addresses for', postalCode);
const url = `/api/1.0/main/address-reference.json?item_per_page=1000&postal_code=${postalCode.id}`; const url = `/api/1.0/main/address-reference.json?item_per_page=1000&postal_code=${postalCode.id}`;
return fetch(url) return fetch(url)
.then(response => { .then(response => {
if (response.ok) { return response.json(); } if (response.ok) { return response.json(); }
throw Error('Error with request resource response'); throw Error('Error with request resource response');
}); });
}; };
/** /**
@@ -87,18 +87,18 @@ const postAddress = (address) => {
* @returns {Promise<Response>} * @returns {Promise<Response>}
*/ */
const duplicateAddress = (address) => { const duplicateAddress = (address) => {
const url = `/api/1.0/main/address/${address.address_id}/duplicate.json`; const url = `/api/1.0/main/address/${address.address_id}/duplicate.json`;
return fetch(url, { return fetch(url, {
'method': 'POST', 'method': 'POST',
headers: { headers: {
'Content-Type': 'application/json;charset=utf-8' 'Content-Type': 'application/json;charset=utf-8'
}, },
}).then(response => { }).then(response => {
if (response.ok) { if (response.ok) {
return response.json(); return response.json();
} }
throw Error('Error with request resource response'); throw Error('Error with request resource response');
}); });
}; };
@@ -114,7 +114,7 @@ const patchAddress = (id, body) => {
return fetch(url, { return fetch(url, {
method: 'PATCH', method: 'PATCH',
headers: { headers: {
'Content-Type': 'application/json;charset=utf-8' 'Content-Type': 'application/json;charset=utf-8'
}, },
body: JSON.stringify(body) body: JSON.stringify(body)
}) })

View File

@@ -220,16 +220,15 @@
<script> <script>
import Modal from 'ChillMainAssets/vuejs/_components/Modal'; import Modal from 'ChillMainAssets/vuejs/_components/Modal';
import { import {
duplicateAddress, duplicateAddress,
fetchCountries, fetchCountries,
fetchCities, fetchCities,
fetchReferenceAddresses, fetchReferenceAddresses,
getAddress, getAddress,
patchAddress, patchAddress,
postAddress, postAddress,
postPostalCode, postPostalCode,
} from '../api'; } from '../api';
import { postAddressToPerson, postAddressToHousehold } from "ChillPersonAssets/vuejs/_api/AddAddress.js";
import ShowPane from './ShowPane.vue'; import ShowPane from './ShowPane.vue';
import SuggestPane from './SuggestPane.vue'; import SuggestPane from './SuggestPane.vue';
import EditPane from './EditPane.vue'; import EditPane from './EditPane.vue';
@@ -246,7 +245,7 @@ export default {
DatePane DatePane
}, },
emits: { emits: {
pickAddress: null pickAddress: null
}, },
data() { data() {
return { return {
@@ -329,7 +328,7 @@ export default {
}, },
hasSuggestions() { hasSuggestions() {
if (typeof(this.context.suggestions) !== 'undefined') { if (typeof(this.context.suggestions) !== 'undefined') {
console.log('hasSuggestions', this.context.suggestions); // console.log('hasSuggestions', this.context.suggestions);
return this.context.suggestions.length > 0; return this.context.suggestions.length > 0;
} }
return false; return false;
@@ -355,14 +354,7 @@ export default {
} }
}, },
mounted() { mounted() {
//console.log('validFrom', this.validFrom);
//console.log('validTo', this.validTo);
//console.log('useDatePane', this.useDatePane);
console.log('Mounted now !');
if (this.context.edit) { if (this.context.edit) {
console.log('getInitialAddress', this.context.addressId);
this.getInitialAddress(this.context.addressId); this.getInitialAddress(this.context.addressId);
} }
this.openShowPane(); this.openShowPane();
@@ -375,32 +367,32 @@ export default {
*/ */
openShowPane() { openShowPane() {
if (this.flag.editPane === false && this.bypassFirstStep) { if (this.flag.editPane === false && this.bypassFirstStep) {
console.log('bypassFirstStep'); // console.log('bypassFirstStep');
this.closeShowPane(); this.closeShowPane();
this.openEditPane(); this.openEditPane();
} else { } else {
this.flag.showPane = true; this.flag.showPane = true;
console.log('step0: open the Show Panel'); // console.log('step0: open the Show Panel');
} }
}, },
closeShowPane() { closeShowPane() {
// Show pane can be closed only when openPanesInModal is false // Show pane can be closed only when openPanesInModal is false
if (!this.inModal) { if (!this.inModal) {
this.flag.showPane = false; this.flag.showPane = false;
console.log('step0: close the Show Panel'); // console.log('step0: close the Show Panel');
} }
}, },
openSuggestPane() { openSuggestPane() {
this.flag.suggestPane = true; this.flag.suggestPane = true;
console.log('step1: open the Suggestion Panel'); // console.log('step1: open the Suggestion Panel');
}, },
closeSuggestPane() { closeSuggestPane() {
this.flag.suggestPane = false; this.flag.suggestPane = false;
console.log('step1: close the Suggestion Panel'); // console.log('step1: close the Suggestion Panel');
}, },
openEditPane() { openEditPane() {
if (this.flag.suggestPane === false && this.displaySuggestions) { if (this.flag.suggestPane === false && this.displaySuggestions) {
console.log('displaySuggestions'); // console.log('displaySuggestions');
this.openSuggestPane(); this.openSuggestPane();
} else { } else {
if (this.flag.datePane === false) { if (this.flag.datePane === false) {
@@ -411,7 +403,7 @@ export default {
}, },
closeEditPane() { closeEditPane() {
this.flag.editPane = false; this.flag.editPane = false;
console.log('step2: close the Edit Panel'); // console.log('step2: close the Edit Panel');
if (!this.context.edit && this.useDatePane) { if (!this.context.edit && this.useDatePane) {
this.openDatePane(); this.openDatePane();
} else { } else {
@@ -423,15 +415,15 @@ export default {
}, },
openDatePane() { openDatePane() {
this.flag.datePane = true; this.flag.datePane = true;
console.log('step3: open the Date Panel'); // console.log('step3: open the Date Panel');
}, },
closeDatePane() { closeDatePane() {
this.applyChanges(); this.applyChanges();
this.flag.datePane = false; this.flag.datePane = false;
console.log('step3: close the Date Panel'); // console.log('step3: close the Date Panel');
}, },
resetPane() { resetPane() {
console.log('resetPane'); // console.log('resetPane');
this.flag.suggestPane = false; this.flag.suggestPane = false;
this.flag.editPane = false; this.flag.editPane = false;
this.flag.datePane = false; this.flag.datePane = false;
@@ -446,15 +438,15 @@ export default {
afterLastPaneAction(params) { afterLastPaneAction(params) {
this.initForm(); this.initForm();
if (this.forceRedirect) { if (this.forceRedirect) {
console.log("redirect to backUrl"); // console.log("redirect to backUrl");
window.location.assign(this.context.backUrl); window.location.assign(this.context.backUrl);
} else { } else {
console.log("don't redirect"); // console.log("don't redirect");
this.resetPane(); this.resetPane();
if (!this.context.edit) { if (!this.context.edit) {
this.context.edit = true; this.context.edit = true;
this.context.addressId = params.addressId; this.context.addressId = params.addressId;
console.log("context is now edit, with address", params.addressId); // console.log("context is now edit, with address", params.addressId);
} }
} }
}, },
@@ -490,7 +482,7 @@ export default {
if (this.flag.datePane === true) { if (this.flag.datePane === true) {
this.flag.datePane = false; this.flag.datePane = false;
} }
console.log('step2: open the Edit panel'); // console.log('step2: open the Edit panel');
this.flag.editPane = true; this.flag.editPane = true;
this.flag.loading = false; this.flag.loading = false;
resolve() resolve()
@@ -533,7 +525,7 @@ export default {
* Make form ready for new changes * Make form ready for new changes
*/ */
initForm() { initForm() {
console.log('init form'); // console.log('init form');
this.entity.loaded.addresses = []; this.entity.loaded.addresses = [];
this.entity.loaded.cities = []; this.entity.loaded.cities = [];
@@ -558,7 +550,7 @@ export default {
this.entity.selected.writeNew.address = this.context.edit; this.entity.selected.writeNew.address = this.context.edit;
this.entity.selected.writeNew.postcode = this.context.edit; this.entity.selected.writeNew.postcode = this.context.edit;
console.log('!! just set writeNew.postcode to', this.entity.selected.writeNew.postcode); // console.log('!! just set writeNew.postcode to', this.entity.selected.writeNew.postcode);
}, },
/* /*
@@ -568,7 +560,7 @@ export default {
*/ */
applyChanges() applyChanges()
{ {
console.log('apply changes'); // console.log('apply changes');
let newAddress = { let newAddress = {
'isNoAddress': this.entity.selected.isNoAddress, 'isNoAddress': this.entity.selected.isNoAddress,
@@ -598,13 +590,13 @@ export default {
// add the address reference, if any // add the address reference, if any
if (this.entity.selected.address.addressReference !== undefined) { if (this.entity.selected.address.addressReference !== undefined) {
newAddress = Object.assign(newAddress, { newAddress = Object.assign(newAddress, {
'addressReference': this.entity.selected.address.addressReference 'addressReference': this.entity.selected.address.addressReference
}); });
} }
if (this.validFrom) { if (this.validFrom) {
console.log('add validFrom in fetch body', this.entity.selected.valid.from); // console.log('add validFrom in fetch body', this.entity.selected.valid.from);
newAddress = Object.assign(newAddress, { newAddress = Object.assign(newAddress, {
'validFrom': { 'validFrom': {
datetime: `${this.entity.selected.valid.from.toISOString().split('T')[0]}T00:00:00+0100` datetime: `${this.entity.selected.valid.from.toISOString().split('T')[0]}T00:00:00+0100`
@@ -612,7 +604,7 @@ export default {
}); });
} }
if (this.validTo && null !== this.entity.selected.valid.to) { if (this.validTo && null !== this.entity.selected.valid.to) {
console.log('add validTo in fetch body', this.entity.selected.valid.to); // console.log('add validTo in fetch body', this.entity.selected.valid.to);
newAddress = Object.assign(newAddress, { newAddress = Object.assign(newAddress, {
'validTo': { 'validTo': {
datetime: `${this.entity.selected.valid.to.toISOString().split('T')[0]}T00:00:00+0100` datetime: `${this.entity.selected.valid.to.toISOString().split('T')[0]}T00:00:00+0100`
@@ -624,7 +616,7 @@ export default {
newPostcode = Object.assign(newPostcode, { newPostcode = Object.assign(newPostcode, {
'country': {'id': this.entity.selected.country.id }, 'country': {'id': this.entity.selected.country.id },
});//TODO why not assign postcodeBody here = Object.assign(postcodeBody, {'origin': 3}); ? });//TODO why not assign postcodeBody here = Object.assign(postcodeBody, {'origin': 3}); ?
console.log('writeNew postcode is true! newPostcode: ', newPostcode); // console.log('writeNew postcode is true! newPostcode: ', newPostcode);
newAddress = Object.assign(newAddress, { newAddress = Object.assign(newAddress, {
'newPostcode': newPostcode 'newPostcode': newPostcode
}); });
@@ -649,17 +641,17 @@ export default {
*/ */
addNewAddress(payload) addNewAddress(payload)
{ {
console.log('addNewAddress', payload); // console.log('addNewAddress', payload);
this.flag.loading = true; this.flag.loading = true;
if ('newPostcode' in payload) { if ('newPostcode' in payload) {
let postcodeBody = payload.newPostcode; let postcodeBody = payload.newPostcode;
postcodeBody = Object.assign(postcodeBody, {'origin': 3}); postcodeBody = Object.assign(postcodeBody, {'origin': 3});
console.log('juste before post new postcode', postcodeBody); // console.log('juste before post new postcode', postcodeBody);
return postPostalCode(postcodeBody) return postPostalCode(postcodeBody)
.then(postalCode => { .then(postalCode => {
console.log('new postcode created', postalCode.id); // console.log('new postcode created', postalCode.id);
payload.postcode = {'id': postalCode.id }; payload.postcode = {'id': postalCode.id };
return this.postNewAddress(payload); return this.postNewAddress(payload);
}); });
@@ -671,15 +663,15 @@ export default {
postNewAddress(payload) postNewAddress(payload)
{ {
console.log('postNewAddress', payload); // console.log('postNewAddress', payload);
return postAddress(payload) return postAddress(payload)
.then(address => new Promise((resolve, reject) => { .then(address => new Promise((resolve, reject) => {
this.entity.address = address; this.entity.address = address;
this.flag.loading = false; this.flag.loading = false;
this.flag.success = true; this.flag.success = true;
resolve({ resolve({
address, address,
targetOrigin: this.context.target, targetOrigin: this.context.target,
// for "legacy" use: // for "legacy" use:
target: this.context.target.name, target: this.context.target.name,
targetId: this.context.target.id, targetId: this.context.target.id,
@@ -708,10 +700,10 @@ export default {
let postcodeBody = payload.newAddress.newPostcode; let postcodeBody = payload.newAddress.newPostcode;
postcodeBody = Object.assign(postcodeBody, {'origin': 3}); postcodeBody = Object.assign(postcodeBody, {'origin': 3});
console.log('juste before post new postcode', postcodeBody); // console.log('juste before post new postcode', postcodeBody);
return postPostalCode(postcodeBody) return postPostalCode(postcodeBody)
.then(postalCode => { .then(postalCode => {
console.log('new postcode created', postalCode.id); // console.log('new postcode created', postalCode.id);
payload.newAddress.postcode = {'id': postalCode.id }; payload.newAddress.postcode = {'id': postalCode.id };
return this.patchExistingAddress(payload); return this.patchExistingAddress(payload);
}); });
@@ -722,15 +714,15 @@ export default {
}, },
patchExistingAddress(payload) { patchExistingAddress(payload) {
console.log('patchExistingAddress', payload); // console.log('patchExistingAddress', payload);
return patchAddress(payload.addressId, payload.newAddress) return patchAddress(payload.addressId, payload.newAddress)
.then(address => new Promise((resolve, reject) => { .then(address => new Promise((resolve, reject) => {
this.entity.address = address; this.entity.address = address;
this.flag.loading = false; this.flag.loading = false;
this.flag.success = true; this.flag.success = true;
return resolve({ return resolve({
address, address,
targetOrigin: this.context.target, targetOrigin: this.context.target,
// for "legacy" use: // for "legacy" use:
target: this.context.target.name, target: this.context.target.name,
targetId: this.context.target.id, targetId: this.context.target.id,
@@ -744,7 +736,7 @@ export default {
}); });
}, },
/** /**
* *
* Called when the event pick-address is emitted, which is, by the way, * Called when the event pick-address is emitted, which is, by the way,
* called when an address suggestion is picked. * called when an address suggestion is picked.
@@ -752,21 +744,21 @@ export default {
* @param address the address selected * @param address the address selected
*/ */
pickAddress(address) { pickAddress(address) {
console.log('pickAddress', address); // console.log('pickAddress', address);
duplicateAddress(address).then(newAddress => { duplicateAddress(address).then(newAddress => {
this.entity.address = newAddress; this.entity.address = newAddress;
this.flag.loading = false; this.flag.loading = false;
this.flag.success = true; this.flag.success = true;
let payload = { let payload = {
address: newAddress, address: newAddress,
targetOrigin: this.context.target, targetOrigin: this.context.target,
// for "legacy" use: // for "legacy" use:
target: this.context.target.name, target: this.context.target.name,
targetId: this.context.target.id, targetId: this.context.target.id,
addressId: this.entity.address.address_id addressId: this.entity.address.address_id
}; };
this.addressChangedCallback(payload); this.addressChangedCallback(payload);
this.closeSuggestPane(); this.closeSuggestPane();
}); });
} }
} }

View File

@@ -110,15 +110,15 @@ export default {
) )
// filter persons appearing twice in requestor and resources // filter persons appearing twice in requestor and resources
.filter( .filter(
(e, index, suggested) => { (e, index, suggested) => {
for (let i = 0; i < suggested.length; i = i+1) { for (let i = 0; i < suggested.length; i = i+1) {
if (i < index && e.id === suggested[i].id) { if (i < index && e.id === suggested[i].id) {
return false return false
}
} }
}
return true; return true;
} }
) )
}), }),
...mapGetters([ ...mapGetters([

View File

@@ -108,7 +108,7 @@ export default {
}, },
methods: { methods: {
saveFormOnTheFly(payload) { saveFormOnTheFly(payload) {
console.log('saveFormOnTheFly: type', payload.type, ', data', payload.data); // console.log('saveFormOnTheFly: type', payload.type, ', data', payload.data);
payload.target = 'participation'; payload.target = 'participation';
this.$store.dispatch('patchOnTheFly', payload) this.$store.dispatch('patchOnTheFly', payload)
.catch(({name, violations}) => { .catch(({name, violations}) => {

View File

@@ -58,7 +58,7 @@ export default {
}, },
methods: { methods: {
saveFormOnTheFly(payload) { saveFormOnTheFly(payload) {
console.log('saveFormOnTheFly: type', payload.type, ', data', payload.data); // console.log('saveFormOnTheFly: type', payload.type, ', data', payload.data);
payload.target = 'resource'; payload.target = 'resource';
this.$store.dispatch('patchOnTheFly', payload) this.$store.dispatch('patchOnTheFly', payload)
.catch(({name, violations}) => { .catch(({name, violations}) => {

View File

@@ -5,8 +5,6 @@ import { getAccompanyingCourse,
getReferrersSuggested, getReferrersSuggested,
getUsers, getUsers,
} from '../api'; } from '../api';
import { patchPerson } from "ChillPersonAssets/vuejs/_api/OnTheFly";
import { patchThirdparty } from "ChillThirdPartyAssets/vuejs/_api/OnTheFly";
import { makeFetch } from 'ChillMainAssets/lib/api/apiMethods'; import { makeFetch } from 'ChillMainAssets/lib/api/apiMethods';
@@ -17,7 +15,7 @@ let scopesPromise = fetchScopes();
let accompanyingCoursePromise = getAccompanyingCourse(id); let accompanyingCoursePromise = getAccompanyingCourse(id);
let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise]) let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
.then(([scopes, accompanyingCourse]) => new Promise((resolve, reject) => { .then(([scopes, accompanyingCourse]) => new Promise((resolve, reject) => {
const store = createStore({ const store = createStore({
strict: debug, strict: debug,
@@ -121,7 +119,7 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
state.accompanyingCourse.resources.push(resource); state.accompanyingCourse.resources.push(resource);
}, },
updatePerson(state, payload) { updatePerson(state, payload) {
console.log('### mutation: updatePerson', payload); // console.log('### mutation: updatePerson', payload);
let i = null; let i = null;
switch (payload.target) { switch (payload.target) {
case 'participation': case 'participation':
@@ -138,7 +136,7 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
} }
}, },
updateThirdparty(state, payload) { updateThirdparty(state, payload) {
console.log('### mutation: updateThirdparty', payload); // console.log('### mutation: updateThirdparty', payload);
let i = null; let i = null;
switch (payload.target) { switch (payload.target) {
case 'requestor': case 'requestor':
@@ -166,11 +164,11 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
state.accompanyingCourse.initialComment = comment; state.accompanyingCourse.initialComment = comment;
}, },
updateSocialIssues(state, value) { updateSocialIssues(state, value) {
console.log('updateSocialIssues', value); // console.log('updateSocialIssues', value);
state.accompanyingCourse.socialIssues = value; state.accompanyingCourse.socialIssues = value;
}, },
refreshSocialIssues(state, issues) { refreshSocialIssues(state, issues) {
console.log('refreshSocialIssues', issues); // console.log('refreshSocialIssues', issues);
state.accompanyingCourse.socialIssues = issues; state.accompanyingCourse.socialIssues = issues;
}, },
updateOrigin(state, value) { updateOrigin(state, value) {
@@ -355,39 +353,39 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
}, },
/** /**
* On The Fly * On The Fly
* ? should be into the dedicated component, no ? JF
* I think it's better to leave it here, because this action is dispatched in 3 different components,
* so lots of code repitition if we would put this in the components themselves.
*/ */
patchOnTheFly({ commit }, payload) { patchOnTheFly({ commit }, payload) {
// TODO should be into the dedicated component, no ? JF
console.log('## action: patch OnTheFly', payload);
let body = { type: payload.type }; let body = { type: payload.type };
const id = payload.data.id;
let url = `/api/1.0/person/person/${id}.json`;
let mutation = "updatePerson";
if (payload.type === 'person') { if (payload.type === 'person') {
body.firstName = payload.data.firstName; body.firstName = payload.data.firstName;
body.lastName = payload.data.lastName; body.lastName = payload.data.lastName;
if (payload.data.birthdate !== null) { body.birthdate = payload.data.birthdate; } if (payload.data.birthdate !== null) { body.birthdate = payload.data.birthdate; }
body.phonenumber = payload.data.phonenumber; body.phonenumber = payload.data.phonenumber;
body.mobilenumber = payload.data.mobilenumber; body.mobilenumber = payload.data.mobilenumber;
body.gender = payload.data.gender; body.gender = payload.data.gender;
console.log('id', payload.data.id, 'and body', body); } else if (payload.type === 'thirdparty') {
patchPerson(payload.data.id, body)
.then(person => new Promise((resolve, reject) => {
console.log('patch person', person);
commit('updatePerson', { target: payload.target, person: person });
resolve();
}));
}
else if (payload.type === 'thirdparty') {
body.name = payload.data.text; body.name = payload.data.text;
body.email = payload.data.email; body.email = payload.data.email;
body.telephone = payload.data.phonenumber; body.telephone = payload.data.phonenumber;
body.address = { id: payload.data.address.address_id }; body.address = { id: payload.data.address.address_id };
console.log('id', payload.data.id, 'and body', body);
patchThirdparty(payload.data.id, body) url = `/api/1.0/thirdparty/thirdparty/${id}.json`;
.then(thirdparty => new Promise((resolve, reject) => { mutation = 'updateThirdparty'
console.log('patch thirdparty', thirdparty);
commit('updateThirdparty', { target: payload.target, thirdparty: thirdparty });
resolve();
}));
} }
makeFetch('PATCH', url, body)
.then((response) => {
commit(mutation, {target: payload.target, thirdparty: response});
})
.catch((error) => {
throw error;
})
}, },
/** /**
* Update accompanying course intensity/emergency/confidentiality * Update accompanying course intensity/emergency/confidentiality
@@ -482,23 +480,22 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
let checkedScopesIds = scopes.map(scope => scope.id); let checkedScopesIds = scopes.map(scope => scope.id);
let removedScopesIds = currentServerScopesIds.filter(id => !checkedScopesIds.includes(id)); let removedScopesIds = currentServerScopesIds.filter(id => !checkedScopesIds.includes(id));
let addedScopesIds = checkedScopesIds.filter(id => !currentServerScopesIds.includes(id)); let addedScopesIds = checkedScopesIds.filter(id => !currentServerScopesIds.includes(id));
let lengthAfterOperation = currentServerScopesIds.length + addedScopesIds.length let lengthAfterOperation = currentServerScopesIds.length + addedScopesIds.length - removedScopesIds.length;
- removedScopesIds.length;
return dispatch('updateScopes', { return dispatch('updateScopes', {
addedScopesIds, removedScopesIds addedScopesIds, removedScopesIds
}) })
.catch(error => { .catch(error => {
throw error; throw error;
}) })
.then(() => { .then(() => {
// warning: when the operation of dispatch are too slow, the user may check / uncheck before // warning: when the operation of dispatch are too slow, the user may check / uncheck before
// the end of the synchronisation with the server (done by dispatch operation). Then, it leads to // the end of the synchronisation with the server (done by dispatch operation). Then, it leads to
// check/uncheck in the UI. I do not know of to avoid it. // check/uncheck in the UI. I do not know of to avoid it.
commit('setScopes', scopes); commit('setScopes', scopes);
return Promise.resolve(); return Promise.resolve();
}) })
.then(() => { .then(() => {
return dispatch('fetchReferrersSuggested'); return dispatch('fetchReferrersSuggested');
}); });
/* /*
@@ -624,10 +621,10 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
let users = await getReferrersSuggested(state.accompanyingCourse); let users = await getReferrersSuggested(state.accompanyingCourse);
commit('setReferrersSuggested', users); commit('setReferrersSuggested', users);
if ( if (
null === state.accompanyingCourse.user null === state.accompanyingCourse.user
&& !state.accompanyingCourse.confidential && !state.accompanyingCourse.confidential
&& !state.accompanyingCourse.step === 'DRAFT' && !state.accompanyingCourse.step === 'DRAFT'
&& users.length === 1 && users.length === 1
) { ) {
// set the user if unique // set the user if unique
commit('updateReferrer', users[0]); commit('updateReferrer', users[0]);
@@ -646,11 +643,11 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
"object": { "object": {
"type": "accompanying_period", "type": "accompanying_period",
"id": id "id": id
}, },
"class": "Chill\\PersonBundle\\Entity\\AccompanyingPeriod", "class": "Chill\\PersonBundle\\Entity\\AccompanyingPeriod",
"roles": [ "roles": [
"CHILL_PERSON_ACCOMPANYING_PERIOD_TOGGLE_CONFIDENTIAL" "CHILL_PERSON_ACCOMPANYING_PERIOD_TOGGLE_CONFIDENTIAL"
] ]
} }
return makeFetch('POST', url, body) return makeFetch('POST', url, body)

View File

@@ -1,51 +1,51 @@
/* // /*
* Endpoint chill_api_single_person_address // * Endpoint chill_api_single_person_address
* method POST, post Person instance // * method POST, post Person instance
* // *
* @id integer - id of Person // * @id integer - id of Person
* @body Object - dictionary with changes to post // * @body Object - dictionary with changes to post
*/ // */
const postAddressToPerson = (personId, addressId) => { // const postAddressToPerson = (personId, addressId) => {
//console.log(personId); // //console.log(personId);
//console.log(addressId); // //console.log(addressId);
const body = { // const body = {
'id': addressId // 'id': addressId
}; // };
const url = `/api/1.0/person/person/${personId}/address.json` // const url = `/api/1.0/person/person/${personId}/address.json`
return fetch(url, { // return fetch(url, {
method: 'POST', // method: 'POST',
headers: {'Content-Type': 'application/json;charset=utf-8'}, // headers: {'Content-Type': 'application/json;charset=utf-8'},
body: JSON.stringify(body) // body: JSON.stringify(body)
}) // })
.then(response => { // .then(response => {
if (response.ok) { return response.json(); } // if (response.ok) { return response.json(); }
throw Error('Error with request resource response'); // throw Error('Error with request resource response');
}); // });
}; // };
/* // /*
* Endpoint household // * Endpoint household
* method POST, post Household instance // * method POST, post Household instance
* // *
* @id integer - id of household // * @id integer - id of household
* @body Object - dictionary with changes to post // * @body Object - dictionary with changes to post
*/ // */
const postAddressToHousehold = (householdId, addressId) => { // const postAddressToHousehold = (householdId, addressId) => {
const body = { // const body = {
'id': addressId // 'id': addressId
}; // };
const url = `/api/1.0/person/household/${householdId}/address.json` // const url = `/api/1.0/person/household/${householdId}/address.json`
return fetch(url, { // return fetch(url, {
method: 'POST', // method: 'POST',
headers: {'Content-Type': 'application/json;charset=utf-8'}, // headers: {'Content-Type': 'application/json;charset=utf-8'},
body: JSON.stringify(body) // body: JSON.stringify(body)
}) // })
.then(response => { // .then(response => {
if (response.ok) { return response.json(); } // if (response.ok) { return response.json(); }
throw Error('Error with request resource response'); // throw Error('Error with request resource response');
}); // });
}; // };
export { postAddressToPerson, postAddressToHousehold }; // export { postAddressToPerson, postAddressToHousehold };

View File

@@ -3,16 +3,16 @@
*/ */
const parametersToString = ({ query, options }) => { const parametersToString = ({ query, options }) => {
let types =''; let types ='';
options.type.forEach(function(type) { options.type.forEach(function(type) {
types += '&type[]=' + type; types += '&type[]=' + type;
}); });
return 'q=' + query + types; return 'q=' + query + types;
}; };
/* /*
* Endpoint chill_person_search * Endpoint chill_person_search
* method GET, get a list of persons * method GET, get a list of persons
* *
* @query string - the query to search for * @query string - the query to search for
*/ */
const searchPersons = ({ query, options }) => { const searchPersons = ({ query, options }) => {
@@ -25,10 +25,10 @@ const searchPersons = ({ query, options }) => {
}); });
}; };
/* /*
* Endpoint v.2 chill_main_search_global * Endpoint v.2 chill_main_search_global
* method GET, get a list of persons and thirdparty * method GET, get a list of persons and thirdparty
* *
* NOTE: this is a temporary WIP endpoint, return inconsistent random results * NOTE: this is a temporary WIP endpoint, return inconsistent random results
* @query string - the query to search for * @query string - the query to search for
*/ */

View File

@@ -1,53 +1,53 @@
/* /*
* GET a person by id * GET a person by id
*/ */
const getPerson = (id) => { // const getPerson = (id) => {
const url = `/api/1.0/person/person/${id}.json`; // const url = `/api/1.0/person/person/${id}.json`;
return fetch(url) // return fetch(url)
.then(response => { // .then(response => {
if (response.ok) { return response.json(); } // if (response.ok) { return response.json(); }
throw Error('Error with request resource response'); // throw Error('Error with request resource response');
}); // });
}; // };
/* /*
* POST a new person * POST a new person
*/ */
const postPerson = (body) => { // const postPerson = (body) => {
const url = `/api/1.0/person/person.json`; // const url = `/api/1.0/person/person.json`;
return fetch(url, { // return fetch(url, {
method: 'POST', // method: 'POST',
headers: { // headers: {
'Content-Type': 'application/json;charset=utf-8' // 'Content-Type': 'application/json;charset=utf-8'
}, // },
body: JSON.stringify(body) // body: JSON.stringify(body)
}) // })
.then(response => { // .then(response => {
if (response.ok) { return response.json(); } // if (response.ok) { return response.json(); }
throw Error('Error with request resource response'); // throw Error('Error with request resource response');
}); // });
}; // };
/* /*
* PATCH an existing person * PATCH an existing person
*/ */
const patchPerson = (id, body) => { // const patchPerson = (id, body) => {
const url = `/api/1.0/person/person/${id}.json`; // const url = `/api/1.0/person/person/${id}.json`;
return fetch(url, { // return fetch(url, {
method: 'PATCH', // method: 'PATCH',
headers: { // headers: {
'Content-Type': 'application/json;charset=utf-8' // 'Content-Type': 'application/json;charset=utf-8'
}, // },
body: JSON.stringify(body) // body: JSON.stringify(body)
}) // })
.then(response => { // .then(response => {
if (response.ok) { return response.json(); } // if (response.ok) { return response.json(); }
throw Error('Error with request resource response'); // throw Error('Error with request resource response');
}); // });
}; // };
export { export {
getPerson, // getPerson,
postPerson, // postPerson,
patchPerson // patchPerson
}; };

View File

@@ -232,16 +232,16 @@ export default {
addPriorSuggestion() { addPriorSuggestion() {
//console.log('addPriorSuggestion', this.hasPriorSuggestion); //console.log('addPriorSuggestion', this.hasPriorSuggestion);
if (this.hasPriorSuggestion) { if (this.hasPriorSuggestion) {
console.log('addPriorSuggestion',); // console.log('addPriorSuggestion',);
this.suggested.unshift(this.priorSuggestion); this.suggested.unshift(this.priorSuggestion);
this.selected.unshift(this.priorSuggestion); this.selected.unshift(this.priorSuggestion);
console.log('reset priorSuggestion'); // console.log('reset priorSuggestion');
this.newPriorSuggestion(null); this.newPriorSuggestion(null);
} }
}, },
newPriorSuggestion(entity) { newPriorSuggestion(entity) {
console.log('newPriorSuggestion', entity); // console.log('newPriorSuggestion', entity);
if (entity !== null) { if (entity !== null) {
let suggestion = { let suggestion = {
key: entity.type + entity.id, key: entity.type + entity.id,
@@ -249,31 +249,30 @@ export default {
result: entity result: entity
} }
this.search.priorSuggestion = suggestion; this.search.priorSuggestion = suggestion;
console.log('search priorSuggestion', this.search.priorSuggestion); // console.log('search priorSuggestion', this.search.priorSuggestion);
} else { } else {
this.search.priorSuggestion = {}; this.search.priorSuggestion = {};
} }
}, },
saveFormOnTheFly({ type, data }) { saveFormOnTheFly({ type, data }) {
console.log('saveFormOnTheFly from addPersons, type', type, ', data', data); // console.log('saveFormOnTheFly from addPersons, type', type, ', data', data);
if (type === 'person') { if (type === 'person') {
console.log('type person with', data); const url = `/api/1.0/person/person.json`;
postPerson(data)
.then(person => new Promise((resolve, reject) => {
console.log('onthefly create: post person', person);
this.newPriorSuggestion(person);
resolve();
}));
} }
else if (type === 'thirdparty') { else if (type === 'thirdparty') {
console.log('type thirdparty with', data); const url = `/api/1.0/thirdparty/thirdparty.json`;
postThirdparty(data)
.then(thirdparty => new Promise((resolve, reject) => {
console.log('onthefly create: post thirdparty', thirdparty);
this.newPriorSuggestion(thirdparty);
resolve();
}));
} }
makeFetch('POST', url, data)
.then((response) => {
this.newPriorSuggestion(response);
})
.catch(({name, violations}) => {
if (name === 'ValidationException' || name === 'AccessException') {
violations.forEach((violation) => this.$toast.open({message: violation}));
} else {
this.$toast.open({message: 'An error occurred'})
}
});
} }
}, },
} }

View File

@@ -76,6 +76,7 @@
<script> <script>
import { getPerson } from '../../_api/OnTheFly'; import { getPerson } from '../../_api/OnTheFly';
import { makeFetch } from 'ChillMainAssets/lib/api/apiMethods';
import PersonRenderBox from '../Entity/PersonRenderBox.vue'; import PersonRenderBox from '../Entity/PersonRenderBox.vue';
export default { export default {
@@ -156,12 +157,18 @@ export default {
}, },
methods: { methods: {
loadData() { loadData() {
getPerson(this.id) const url = `/api/1.0/person/person/${this.id}.json`;
.then(person => new Promise((resolve, reject) => { makeFetch('GET', url)
this.person = person; .then((response) => {
console.log('get person', this.person); this.person = response;
resolve(); })
})); .catch(({name, violations}) => {
if (name === 'ValidationException' || name === 'AccessException') {
violations.forEach((violation) => this.$toast.open({message: violation}));
} else {
this.$toast.open({message: 'An error occurred'})
}
});
} }
} }
} }

View File

@@ -1,55 +1,55 @@
/* /*
* GET a thirdparty by id * GET a thirdparty by id
*/ */
const getThirdparty = (id) => { // const getThirdparty = (id) => {
const url = `/api/1.0/thirdparty/thirdparty/${id}.json`; // const url = `/api/1.0/thirdparty/thirdparty/${id}.json`;
return fetch(url) // return fetch(url)
.then(response => { // .then(response => {
if (response.ok) { // if (response.ok) {
return response.json(); // return response.json();
} // }
throw Error('Error with request resource response'); // throw Error('Error with request resource response');
}); // });
}; // };
/* /*
* POST a new thirdparty * POST a new thirdparty
*/ */
const postThirdparty = (body) => { // const postThirdparty = (body) => {
const url = `/api/1.0/thirdparty/thirdparty.json`; // const url = `/api/1.0/thirdparty/thirdparty.json`;
return fetch(url, { // return fetch(url, {
method: 'POST', // method: 'POST',
headers: { // headers: {
'Content-Type': 'application/json;charset=utf-8' // 'Content-Type': 'application/json;charset=utf-8'
}, // },
body: JSON.stringify(body) // body: JSON.stringify(body)
}) // })
.then(response => { // .then(response => {
if (response.ok) { return response.json(); } // if (response.ok) { return response.json(); }
throw Error('Error with request resource response'); // throw Error('Error with request resource response');
}); // });
}; // };
/* /*
* PATCH an existing thirdparty * PATCH an existing thirdparty
*/ */
const patchThirdparty = (id, body) => { // const patchThirdparty = (id, body) => {
const url = `/api/1.0/thirdparty/thirdparty/${id}.json`; // const url = `/api/1.0/thirdparty/thirdparty/${id}.json`;
return fetch(url, { // return fetch(url, {
method: 'PATCH', // method: 'PATCH',
headers: { // headers: {
'Content-Type': 'application/json;charset=utf-8' // 'Content-Type': 'application/json;charset=utf-8'
}, // },
body: JSON.stringify(body) // body: JSON.stringify(body)
}) // })
.then(response => { // .then(response => {
if (response.ok) { return response.json(); } // if (response.ok) { return response.json(); }
throw Error('Error with request resource response'); // throw Error('Error with request resource response');
}); // });
}; // };
export { export {
getThirdparty, // getThirdparty,
postThirdparty, // postThirdparty,
patchThirdparty // patchThirdparty
}; };

View File

@@ -94,7 +94,7 @@
<script> <script>
import ThirdPartyRenderBox from '../Entity/ThirdPartyRenderBox.vue'; import ThirdPartyRenderBox from '../Entity/ThirdPartyRenderBox.vue';
import AddAddress from 'ChillMainAssets/vuejs/Address/components/AddAddress'; import AddAddress from 'ChillMainAssets/vuejs/Address/components/AddAddress';
import { getThirdparty } from '../../_api/OnTheFly'; import { makeFetch } from 'ChillMainAssets/lib/api/apiMethods'
const i18n = { const i18n = {
messages: { messages: {
@@ -165,38 +165,58 @@ export default {
context.addressId = this.thirdparty.address.address_id; context.addressId = this.thirdparty.address.address_id;
context.edit = true; context.edit = true;
} }
console.log('context', context); // console.log('context', context);
//this.context = context; <-- //this.context = context; <--
return context; return context;
}, },
}, },
methods: { methods: {
loadData(){ loadData(){
getThirdparty(this.id).then(thirdparty => new Promise((resolve, reject) => { const url = `/api/1.0/thirdparty/thirdparty/${this.id}.json`;
this.thirdparty = thirdparty; makeFetch('GET', url)
this.thirdparty.kind = thirdparty.kind; .then((response) => {
console.log('get thirdparty', thirdparty); console.log(response);
if (this.action !== 'show') { this.thirdparty = response;
if (thirdparty.address !== null) { this.thirdparty.kind = response.kind
// bof! we force getInitialAddress because addressId not available when mounted if (this.action !== 'show') {
this.$refs.addAddress.getInitialAddress(thirdparty.address.address_id); if (response.address !== null) {
} // bof! we force getInitialAddress because addressId not available when mounted
} this.$refs.addAddress.getInitialAddress(response.address.address_id);
resolve(); }
})); }
})
.catch(({name, violations}) => {
if (name === 'ValidationException' || name === 'AccessException') {
violations.forEach((violation) => this.$toast.open({message: violation}));
} else {
this.$toast.open({message: 'An error occurred'})
}
});
// getThirdparty(this.id).then(thirdparty => new Promise((resolve, reject) => {
// this.thirdparty = thirdparty;
// this.thirdparty.kind = thirdparty.kind;
// console.log('get thirdparty', thirdparty);
// if (this.action !== 'show') {
// if (thirdparty.address !== null) {
// // bof! we force getInitialAddress because addressId not available when mounted
// this.$refs.addAddress.getInitialAddress(thirdparty.address.address_id);
// }
// }
// resolve();
// }));
}, },
submitAddress(payload) { submitAddress(payload) {
console.log('submitAddress', payload); // console.log('submitAddress', payload);
if (typeof payload.addressId !== 'undefined') { // <-- if (typeof payload.addressId !== 'undefined') { // <--
this.context.edit = true; this.context.edit = true;
this.context.addressId = payload.addressId; // bof! use legacy and not legacy in payload this.context.addressId = payload.addressId; // bof! use legacy and not legacy in payload
this.thirdparty.address = payload.address; // <-- this.thirdparty.address = payload.address; // <--
console.log('switch address to edit mode', this.context); // console.log('switch address to edit mode', this.context);
} }
} }
}, },
mounted() { mounted() {
console.log('mounted', this.action); // console.log('mounted', this.action);
if (this.action !== 'create') { if (this.action !== 'create') {
this.loadData(); this.loadData();
} else { } else {