From c12f63382959dd9c05f3ca7417071abdd531f337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 28 Feb 2022 13:52:41 +0100 Subject: [PATCH] fixes --- .../ChillMainBundle/Entity/Civility.php | 1 + .../vuejs/OnTheFly/components/Create.vue | 3 -- .../vuejs/OnTheFly/components/OnTheFly.vue | 25 +++--------- .../Entity/ThirdParty.php | 4 +- .../Entity/ThirdPartyProfession.php | 2 + .../vuejs/_components/OnTheFly/ThirdParty.vue | 40 +++++++++++-------- .../Resources/public/vuejs/_js/i18n.js | 2 +- 7 files changed, 35 insertions(+), 42 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Entity/Civility.php b/src/Bundle/ChillMainBundle/Entity/Civility.php index cd4a75e5f..e5d15a751 100644 --- a/src/Bundle/ChillMainBundle/Entity/Civility.php +++ b/src/Bundle/ChillMainBundle/Entity/Civility.php @@ -17,6 +17,7 @@ use Symfony\Component\Serializer\Annotation as Serializer; /** * @ORM\Table(name="chill_main_civility") * @ORM\Entity + * @Serializer\DiscriminatorMap(typeProperty="type", mapping={"chill_main_civility": Civility::class}) */ class Civility { diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/OnTheFly/components/Create.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/OnTheFly/components/Create.vue index dcc12bc5f..22b0181e5 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/OnTheFly/components/Create.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/OnTheFly/components/Create.vue @@ -77,14 +77,11 @@ export default { return this.$refs.castPerson.$data.person; case 'thirdparty': let data = this.$refs.castThirdparty.$data.thirdparty; - data.name = data.text; - /* if (data.address !== undefined && data.address !== null) { data.address = { id: data.address.address_id } } else { data.address = null; } - */ return data; default: diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/OnTheFly/components/OnTheFly.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/OnTheFly/components/OnTheFly.vue index 061c9860b..e84496d31 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/OnTheFly/components/OnTheFly.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/OnTheFly/components/OnTheFly.vue @@ -219,31 +219,17 @@ export default { case 'thirdparty': data = this.$refs.castThirdparty.$data.thirdparty; + /* never executed ? */ break; default: if (typeof this.type === 'undefined') { // action=create or addContact + console.log('will rewrite data'); if (this.action === 'addContact') { type = 'thirdparty' data = this.$refs.castThirdparty.$data.thirdparty; - data = { - "type": "thirdparty", - "kind": "child", - "name": data.text, - "isChild": true, - "parent": {"type": "thirdparty", "id": this.parent.id}, - "comment": data.comment, - "telephone": data.phonenumber, - "email": data.email, - "address": this.parent.address - } - if ("civility" in data) { - Object.assign(data, {"civility": {"id": data.civility}} ) - } - if ("profession" in data) { - Object.assign(data, {"profession": {"id": data.profession}} ) - } - + console.log('data original', data); + data.parent = {type: "thirdparty", id: this.parent.id}; } else { type = this.$refs.castNew.radioType; data = this.$refs.castNew.castDataByType(); @@ -253,7 +239,8 @@ export default { throw 'error with object type'; } } - console.log('type', type, 'data', data) + console.log('type', type); + console.log('data', data); // pass datas to parent this.$emit('saveFormOnTheFly', { type: type, data: data }); }, diff --git a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php index 3524a659a..25ef1be65 100644 --- a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php +++ b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdParty.php @@ -707,7 +707,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface /** * @return $this */ - public function setCivility(Civility $civility): ThirdParty + public function setCivility(?Civility $civility): ThirdParty { $this->civility = $civility; @@ -812,7 +812,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface /** * @return $this */ - public function setProfession(ThirdPartyProfession $profession): ThirdParty + public function setProfession(?ThirdPartyProfession $profession): ThirdParty { $this->profession = $profession; diff --git a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdPartyProfession.php b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdPartyProfession.php index 12b0818b5..896888a73 100644 --- a/src/Bundle/ChillThirdPartyBundle/Entity/ThirdPartyProfession.php +++ b/src/Bundle/ChillThirdPartyBundle/Entity/ThirdPartyProfession.php @@ -18,6 +18,8 @@ use Symfony\Component\Serializer\Annotation as Serializer; /** * @ORM\Table(name="chill_3party.party_profession") * @ORM\Entity(repositoryClass=ThirdPartyProfessionRepository::class) + * @Serializer\DiscriminatorMap(typeProperty="type", mapping={ + * "third_party_profession": ThirdPartyProfession::class}) */ class ThirdPartyProfession { diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/OnTheFly/ThirdParty.vue b/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/OnTheFly/ThirdParty.vue index 27d02c3ec..40efa9bfb 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/OnTheFly/ThirdParty.vue +++ b/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/OnTheFly/ThirdParty.vue @@ -27,7 +27,7 @@ {{ parent.text }} -
+
-
+
- +
@@ -160,6 +160,8 @@ export default { kind: 'company', name: '', telephone: '', + civility: null, + profession: null, }, professions: [], civilities: [], @@ -214,7 +216,7 @@ export default { }, methods: { loadData(){ - getThirdparty(this.id).then(thirdparty => new Promise((resolve, reject) => { + return getThirdparty(this.id).then(thirdparty => new Promise((resolve, reject) => { this.thirdparty = thirdparty; this.thirdparty.kind = thirdparty.kind; console.log('get thirdparty', thirdparty); @@ -229,9 +231,10 @@ export default { }, loadCivilities() { const url = `/api/1.0/main/civility.json`; - makeFetch('GET', url) + return makeFetch('GET', url) .then(response => { this.$data.civilities = response.results; + return Promise.resolve(); }) .catch((error) => { console.log(error) @@ -240,9 +243,10 @@ export default { }, loadProfessions() { const url = `/api/1.0/thirdparty/professions.json`; - makeFetch('GET', url) + return makeFetch('GET', url) .then(response => { this.$data.professions = response.results; + return Promise.resolve(); }) .catch((error) => { console.log(error) @@ -259,21 +263,23 @@ export default { } }, addQuery(query) { - this.thirdparty.text = query; - } + this.thirdparty.name = query; + }, }, - mounted() { - console.log('mounted', this.action); + mounted() { + let dependencies = []; + dependencies.push(this.loadProfessions()); + dependencies.push(this.loadCivilities()); if (this.action !== 'create') { if (this.id) { - this.loadData(); + dependencies.push(this.loadData()); + // here we can do something when all promises are resolve, with + // Promise.all(dependencies).then(() => { /* do something */ }); } if (this.action === 'addContact') { this.$data.thirdparty.kind = 'child' // this.$data.thirdparty.parent = this.parent.id this.$data.thirdparty.address = null - this.loadProfessions(); - this.loadCivilities(); } } else { this.thirdparty.kind = 'company'; diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_js/i18n.js b/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_js/i18n.js index 86b39ae36..76f01e3f4 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_js/i18n.js +++ b/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_js/i18n.js @@ -4,7 +4,7 @@ const thirdpartyMessages = { name: "Dénomination", email: "Courriel", phonenumber: "Téléphone", - comment: "Comment", + comment: "Commentaire", profession: "Qualité", civility: "Civilité" },