From 01cc2301367f0d835445b5dad5223d0d2b378d85 Mon Sep 17 00:00:00 2001
From: Mathieu Jaumotte
Date: Thu, 5 Aug 2021 22:04:41 +0200
Subject: [PATCH 1/8] Submitting address, and validFrom field
---
.../Resources/public/vuejs/Address/App.vue | 29 +++---
.../vuejs/Address/components/AddAddress.vue | 75 +++++++++++----
.../vuejs/Address/components/ShowAddress.vue | 95 ++++++++++++-------
3 files changed, 134 insertions(+), 65 deletions(-)
diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue
index a820c253d..efe444075 100644
--- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue
+++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue
@@ -1,10 +1,19 @@
+
+ {{ error }}
+
+
+
+ {{ addAddress.result.address_id }}
+
+
@@ -24,10 +33,8 @@ export default {
personId: window.personId,
addressId: window.addressId,
backUrl: `/fr/person/${window.personId}/address/list`, //TODO better way to pass this
- validFrom: new Date().toISOString().split('T')[0]
},
addAddress: {
- key: 'person',
options: {
/// Options override default
@@ -39,19 +46,15 @@ export default {
/// Display each step in page or Modal
//bindModal: { step1: false, step2: false } //TODO true-false must not be possible
- }
+ },
+ type: 'person',
+ result: null // <== returned from addAddress component
}
}
},
methods: {
- submitAddress({ submited, flag }) {
- console.log('@@@ CLICK button submitAddress');
-
- console.log('address to post:', submited);
- console.log('datas by refs: ', this.$refs.addAddress.entity.address.text);
-
- this.$refs.addAddress.initForm(); // to cast child method
- flag.showPane = false;
+ displayErrors() {
+ return this.$refs.addAddress.errorMsg;
}
}
}
diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue
index fc38f630b..0199dff4d 100644
--- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue
+++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue
@@ -26,7 +26,8 @@
v-bind:options="this.options"
v-bind:default="this.default"
v-bind:entity="this.entity"
- v-bind:flag="this.flag">
+ v-bind:flag="this.flag"
+ ref="showAddress">
@@ -36,7 +37,7 @@
{{ $t('action.edit')}}
@@ -51,8 +52,9 @@
v-bind:default="this.default"
v-bind:entity="this.entity"
v-bind:flag="this.flag"
+ ref="showAddress"
v-bind:insideModal="false" @openEditPane="openEditPane"
- @submitAddress="$emit('submitAddress', { getSubmited , flag })">
+ @submitAddress="submitAddress">
@@ -122,8 +124,7 @@ import {
export default {
name: "AddAddress",
- props: ['context', 'options'],
- emits: ['submitAddress'],
+ props: ['context', 'options', 'result'],
components: {
Modal,
ShowAddress,
@@ -173,6 +174,10 @@ export default {
zoom: 12
},
},
+ valid: {
+ from: null,
+ to: null
+ },
errorMsg: []
}
},
@@ -197,11 +202,8 @@ export default {
return (this.context.edit) ? this.options.title.edit : this.options.title.create;
}
return (this.context.edit) ? this.default.title.edit : this.default.title.create;
- },
-
- getSubmited() {
- return this.entity.address;
}
+
},
mounted() {
if (!this.step1WithModal) {
@@ -221,11 +223,13 @@ export default {
}
this.flag.showPane = true;
},
+
openEditPane() {
console.log('open the Edit panel');
this.initForm();
this.getCountries();
},
+
closeEditPane() {
console.log('close the Edit Panel (with validation)');
this.applyChanges();
@@ -373,7 +377,6 @@ export default {
* then update existing address with backend datas when promise is resolved
*/
updateAddress(payload) {
- console.log('updateAddress payload', payload);
// TODO change the condition because it writes new postal code in edit mode now: !writeNewPostalCode
this.flag.loading = true;
@@ -387,7 +390,6 @@ export default {
body.postcode = {'id': postalCode.id },
patchAddress(payload.addressId, body)
.then(address => new Promise((resolve, reject) => {
- console.log('update address');
this.entity.address = address;
this.flag.loading = false;
resolve();
@@ -401,7 +403,6 @@ export default {
} else {
patchAddress(payload.addressId, payload.newAddress)
.then(address => new Promise((resolve, reject) => {
- console.log('update address');
this.entity.address = address;
this.flag.loading = false;
resolve();
@@ -418,7 +419,6 @@ export default {
* creating new address, and receive backend datas when promise is resolved
*/
addAddress(payload) {
- console.log('addAddress payload', payload);
this.flag.loading = true;
if('newPostcode' in payload){
@@ -431,7 +431,6 @@ export default {
body.postcode = {'id': postalCode.id},
postAddress(body)
.then(address => new Promise((resolve, reject) => {
- console.log('add address');
this.entity.address = address;
resolve();
this.flag.loading = false;
@@ -445,7 +444,6 @@ export default {
} else {
postAddress(payload)
.then(address => new Promise((resolve, reject) => {
- console.log('add address');
this.entity.address = address;
resolve();
this.flag.loading = false;
@@ -455,9 +453,52 @@ export default {
this.flag.loading = false;
});
}
+ },
+
+ /*
+ * When submited
+ */
+ submitAddress() {
+ console.log('@@@ CLICK button submitAddress');
+ this.addDateToAddressAndAddressToPerson({
+ personId: this.context.personId,
+ addressId: this.entity.address.address_id,
+ body: { validFrom: { datetime: `${this.$refs.showAddress.validFrom}T00:00:00+0100`}},
+ backUrl: this.context.backUrl
+ });
+ this.initForm();
+ this.flag.showPane = false;
+ },
+
+ addDateToAddressAndAddressToPerson(payload) {
+ console.log('addDateToAddressAndAddressToPerson payload', payload);
+ this.flag.loading = true;
+ patchAddress(payload.addressId, payload.body)
+ .then(address => new Promise((resolve, reject) => {
+ this.valid.from = address.validFrom;
+ resolve();
+ }).then(
+ postAddressToPerson(payload.personId, payload.addressId)
+ .then(person => new Promise((resolve, reject) => {
+
+ console.log('commit addAddressToPerson !!!', person);
+ this.result = person;
+
+ this.flag.loading = false;
+ this.flag.success = true;
+ window.location.assign(payload.backUrl);
+ resolve();
+ }))
+ .catch((error) => {
+ this.errorMsg.push(error);
+ this.flag.loading = false;
+ })
+ ))
+ .catch((error) => {
+ this.errorMsg.push(error);
+ this.flag.loading = false;
+ });
}
-
-
}
}
diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowAddress.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowAddress.vue
index c59104aca..e19c4f333 100644
--- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowAddress.vue
+++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowAddress.vue
@@ -20,41 +20,63 @@
{{ address.country.name.fr }}
+
+
+
+ {{ $t('floor') }}: {{ address.floor }}
+
+
+
+
+ {{ $t('corridor') }}: {{ address.corridor }}
+
+
+
+
+ {{ $t('steps') }}: {{ address.steps }}
+
+
+
+
+ {{ $t('flat') }}: {{ address.flat }}
+
+
+
+
+ {{ $t('buildingName') }}: {{ address.buildingName }}
+
+
+
+
+
+
+
+ {{ $t('distribution') }}: {{ address.distribution }}
+
+
+
-
-
- {{ $t('floor') }}: {{ address.floor }}
-
-
-
-
- {{ $t('corridor') }}: {{ address.corridor }}
-
-
-
-
- {{ $t('steps') }}: {{ address.steps }}
-
-
-
-
- {{ $t('flat') }}: {{ address.flat }}
-
-
-
-
- {{ $t('buildingName') }}: {{ address.buildingName }}
-
-
-
-
-
-
-
- {{ $t('distribution') }}: {{ address.distribution }}
-
+
+
{{ $t('date') }}
+
+
+
+
+
+
+ {{ $t('loading') }}
+
+
+ {{ $t('person_address_creation_success') }}
+
@@ -93,7 +115,7 @@ export default {
'errorMsg',
'insideModal'
],
- emits: ['openEditPane', 'submitAddress'],
+ emits: ['openEditPane', 'submitAddress', 'validFrom'],
computed: {
address() {
return this.entity.address;
@@ -109,6 +131,9 @@ export default {
},
getSubmited() {
return this.entity.address;
+ },
+ validFrom() {
+ return new Date().toISOString().split('T')[0];
}
}
};
From 9f3ceb94f08851470a29bb21c5437a7d69eb982a Mon Sep 17 00:00:00 2001
From: Mathieu Jaumotte
Date: Fri, 6 Aug 2021 15:53:50 +0200
Subject: [PATCH 2/8] adding options to custom button, and improve
stepWithModal options
---
.../Resources/public/vuejs/Address/App.vue | 17 ++++---
.../vuejs/Address/components/AddAddress.vue | 49 +++++++++++++------
.../translations/messages.fr.yml | 1 +
3 files changed, 46 insertions(+), 21 deletions(-)
diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue
index efe444075..a2eec127d 100644
--- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue
+++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue
@@ -4,11 +4,6 @@
class="alert alert-danger my-2">
{{ error }}
-
-
- {{ addAddress.result.address_id }}
-
-
- {{ $t(getTextButton) }}
+ class="btn mt-4" :class="getClassButton"
+ type="button" name="button" :title="$t(getTextButton)">
+ {{ $t(getTextButton) }}
+
+
Date: Fri, 6 Aug 2021 16:25:04 +0200
Subject: [PATCH 3/8] when creating new address, start first with edit panel
---
.../public/vuejs/Address/components/AddAddress.vue | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue
index b4fc037a1..f543bccc1 100644
--- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue
+++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue
@@ -203,7 +203,6 @@ export default {
}
return step2;
},
-
getTextTitle() {
if (this.options.title) {
return (this.context.edit) ? this.options.title.edit : this.options.title.create;
@@ -242,7 +241,16 @@ export default {
if (this.context.addressId) {
this.getInitialAddress(this.context.addressId);
}
- this.flag.showPane = true;
+ // when create new address, start first with editPane
+ if ( this.context.edit === false
+ && this.flag.editPane === false
+ ) {
+ this.openEditPane();
+ this.flag.editPane = true;
+
+ } else {
+ this.flag.showPane = true;
+ }
},
openEditPane() {
From b62597426c3a2e0146cd1e58976d829f1e41b22d Mon Sep 17 00:00:00 2001
From: Mathieu Jaumotte
Date: Fri, 6 Aug 2021 16:30:48 +0200
Subject: [PATCH 4/8] classes for address-valid
---
.../Resources/public/chill/scss/render_box.scss | 4 ++--
.../Resources/public/vuejs/Address/components/ShowAddress.vue | 4 ++--
.../ChillMainBundle/Resources/views/Entity/address.html.twig | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss b/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss
index 68bbe2afc..cd57ba3cd 100644
--- a/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss
+++ b/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss
@@ -94,8 +94,8 @@ section.chill-entity {
}
span.address-valid {
- &.address-since {}
- &.address-until {}
+ &.date-since {}
+ &.date-until {}
}
}
diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowAddress.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowAddress.vue
index e19c4f333..07e4617d3 100644
--- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowAddress.vue
+++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowAddress.vue
@@ -58,8 +58,8 @@
-
-
{{ $t('date') }}
+
+
{{ $t('date') }}
{% endblock %}
-{% block css %}
- {{ encore_entry_link_tags('vue_address') }}
-{% endblock %}
-
-{% block js %}
-
- {{ encore_entry_script_tags('vue_address') }}
-{% endblock %}
From 47d704b52149afe34e07c446da244eca02ef07f7 Mon Sep 17 00:00:00 2001
From: Mathieu Jaumotte
Date: Fri, 6 Aug 2021 21:46:10 +0200
Subject: [PATCH 8/8] passing option backUrl from include template twig
---
.../views/Address/_insert_vue_address.html.twig | 11 ++++++++---
.../Resources/views/Person/view.html.twig | 1 +
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Address/_insert_vue_address.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Address/_insert_vue_address.html.twig
index bb70a976a..17c111e06 100644
--- a/src/Bundle/ChillPersonBundle/Resources/views/Address/_insert_vue_address.html.twig
+++ b/src/Bundle/ChillPersonBundle/Resources/views/Address/_insert_vue_address.html.twig
@@ -5,7 +5,12 @@
window.mode = '{{ mode|e('js') }}';
window.personId = {{ person.id|e('js') }};
window.addressId = {{ address_id|e('js') }};
- window.backUrl = '{{ path('chill_person_view', { 'person_id': person.id })|e('js') }}';
+{% if backUrl is defined %}
+ window.backUrl = '{{ backUrl|e('js') }}';
+{% else %}
+ window.backUrl = '{{ path('chill_person_address_list', { 'person_id': person.id })|e('js') }}';
+{% endif %}
+
{% if modalTitle is defined %}
window.modalTitle = '{{ modalTitle|trans|e('js') }}';
{% endif %}
@@ -23,10 +28,10 @@
window.button.display = false;
{% endif %}
{% if binModalStep1 is defined and binModalStep1 == false %}
- window.binModalStep1 = false
+ window.binModalStep1 = false;
{% endif %}
{% if binModalStep2 is defined and binModalStep2 == false %}
- window.binModalStep2 = false
+ window.binModalStep2 = false;
{% endif %}
diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig
index 5e5169575..53166ab9e 100644
--- a/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig
+++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig
@@ -203,6 +203,7 @@ This view should receive those arguments:
{# include vue_address component #}
{% include '@ChillPerson/Address/_insert_vue_address.html.twig' with {
address_id: person.lastAddress.id,
+ backUrl: path('chill_person_view', { 'person_id': person.id }),
mode: 'edit',
modalTitle: 'Edit address',
buttonText: 'Edit address',