From c1b727b1c8396674a78515a3a135807d039a6ca4 Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 7 May 2021 16:02:39 +0200 Subject: [PATCH 01/13] Add API endpoints for Address and AddressReference (again) --- .../ChillMainExtension.php | 59 ++++++++++++++++++- .../Entity/AddressReference.php | 3 +- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index a40221263..eaf7711d3 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -35,6 +35,7 @@ use Chill\MainBundle\Doctrine\DQL\OverlapsI; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; use Chill\MainBundle\Doctrine\DQL\Replace; +use Symfony\Component\HttpFoundation\Request; /** * Class ChillMainExtension @@ -133,7 +134,7 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface, $loader->load('services/search.yaml'); $loader->load('services/serializer.yaml'); - $this->configureCruds($container, $config['cruds'], $config['apis'], $loader); + $this->configureCruds($container, $config['cruds'], $config['apis'], $loader); } /** @@ -212,6 +213,9 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface, $container->prependExtensionConfig('monolog', array( 'channels' => array('chill') )); + + //add crud api + $this->prependCruds($container); } /** @@ -235,4 +239,57 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface, // Note: the controller are loaded inside compiler pass } + + + /** + * @param ContainerBuilder $container + */ + protected function prependCruds(ContainerBuilder $container) + { + $container->prependExtensionConfig('chill_main', [ + 'apis' => [ + [ + 'class' => \Chill\MainBundle\Entity\Address::class, + 'name' => 'address', + 'base_path' => '/api/1.0/main/address', + 'base_role' => 'ROLE_USER', + 'actions' => [ + '_index' => [ + 'methods' => [ + Request::METHOD_GET => true, + Request::METHOD_HEAD => true + ], + ], + '_entity' => [ + 'methods' => [ + Request::METHOD_GET => true, + Request::METHOD_POST => true, + Request::METHOD_HEAD => true + ] + ], + ] + ], + [ + 'class' => \Chill\MainBundle\Entity\AddressReference::class, + 'name' => 'address_reference', + 'base_path' => '/api/1.0/main/address-reference', + 'base_role' => 'ROLE_USER', + 'actions' => [ + '_index' => [ + 'methods' => [ + Request::METHOD_GET => true, + Request::METHOD_HEAD => true + ], + ], + '_entity' => [ + 'methods' => [ + Request::METHOD_GET => true, + Request::METHOD_HEAD => true + ] + ], + ] + ] + ] + ]); + } } diff --git a/src/Bundle/ChillMainBundle/Entity/AddressReference.php b/src/Bundle/ChillMainBundle/Entity/AddressReference.php index 944cab81b..b1fca205d 100644 --- a/src/Bundle/ChillMainBundle/Entity/AddressReference.php +++ b/src/Bundle/ChillMainBundle/Entity/AddressReference.php @@ -2,12 +2,11 @@ namespace Chill\MainBundle\Entity; -use Chill\MainBundle\Entity\AddressReferenceRepository; use Doctrine\ORM\Mapping as ORM; use Chill\MainBundle\Doctrine\Model\Point; /** - * @ORM\Entity(repositoryClass=AddressReferenceRepository::class) + * @ORM\Entity() * @ORM\Table(name="chill_main_address_reference") * @ORM\HasLifecycleCallbacks() */ From b934c2eeaf4c352e9492cd969942307eb114cde4 Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 7 May 2021 17:38:15 +0200 Subject: [PATCH 02/13] add POC of a vuejs component (opens a modal) for address selection --- .../Resources/public/vuejs/Address/App.vue | 19 +++ .../Resources/public/vuejs/Address/index.js | 32 +++++ .../Resources/public/vuejs/Address/js/i18n.js | 15 +++ .../public/vuejs/Address/store/index.js | 0 .../public/vuejs/_components/AddAddress.vue | 116 ++++++++++++++++++ .../ChillMainBundle/chill.webpack.config.js | 2 + .../Resources/views/Address/new.html.twig | 12 ++ 7 files changed, 196 insertions(+) create mode 100644 src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue create mode 100644 src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/index.js create mode 100644 src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/js/i18n.js create mode 100644 src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/store/index.js create mode 100644 src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/AddAddress.vue diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue new file mode 100644 index 000000000..0b971b7d5 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue @@ -0,0 +1,19 @@ + + + diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/index.js b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/index.js new file mode 100644 index 000000000..8b31a2368 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/index.js @@ -0,0 +1,32 @@ +import { createApp } from 'vue' +import { _createI18n } from 'ChillMainAssets/vuejs/_js/i18n' +import { appMessages } from './js/i18n' +import { getDataPromise } from './store' + +import App from './App.vue'; + +// getDataPromise.then(store => { + +// console.log('store address', store.state.address); + +// const i18n = _createI18n(appMessages); +// console.log(i18n) + +// const app = createApp({ +// template: ``, +// }) +// .use(store) +// .use(i18n) +// .component('app', App) +// .mount('#address'); + +// }); + +const i18n = _createI18n(appMessages); + +const app = createApp({ + template: ``, +}) +.use(i18n) +.component('app', App) +.mount('#address'); diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/js/i18n.js b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/js/i18n.js new file mode 100644 index 000000000..0bfdfb380 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/js/i18n.js @@ -0,0 +1,15 @@ +// import { mainMessages } from 'ChillMainAssets/vuejs/_js/i18n' + +const appMessages = { + fr: { + address: { + id: "id", + }, + } +}; + +// Object.assign(appMessages.fr, mainMessages.fr); + +export { + appMessages +}; diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/store/index.js b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/store/index.js new file mode 100644 index 000000000..e69de29bb diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/AddAddress.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/AddAddress.vue new file mode 100644 index 000000000..a3ade00e0 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/AddAddress.vue @@ -0,0 +1,116 @@ + + + diff --git a/src/Bundle/ChillMainBundle/chill.webpack.config.js b/src/Bundle/ChillMainBundle/chill.webpack.config.js index 6187b31ea..78accf004 100644 --- a/src/Bundle/ChillMainBundle/chill.webpack.config.js +++ b/src/Bundle/ChillMainBundle/chill.webpack.config.js @@ -62,5 +62,7 @@ module.exports = function(encore, entries) buildCKEditor(encore); encore.addEntry('ckeditor5', __dirname + '/Resources/public/modules/ckeditor5/index.js'); + // Address + encore.addEntry('address', __dirname + '/Resources/public/vuejs/Address/index.js'); }; diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Address/new.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Address/new.html.twig index 70cc51e53..5dcc8aacd 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Address/new.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Address/new.html.twig @@ -49,4 +49,16 @@ {{ form_end(form) }} + + NEW FORM + + {% block content %} +

{{ block('title') }}

+
+ {% endblock %} + + {% block js %} + {{ encore_entry_script_tags('address') }} + {% endblock %} + {% endblock personcontent %} From efb9bc938a77b30519dc3fa53caf979015bc10af Mon Sep 17 00:00:00 2001 From: nobohan Date: Mon, 10 May 2021 12:12:04 +0200 Subject: [PATCH 03/13] Address selection: add store + addressSuggestion --- .../Resources/public/vuejs/Address/api.js | 14 +++ .../Resources/public/vuejs/Address/index.js | 34 ++---- .../Resources/public/vuejs/Address/js/i18n.js | 8 +- .../public/vuejs/Address/store/index.js | 115 ++++++++++++++++++ .../public/vuejs/_components/AddAddress.vue | 65 ++++++---- .../vuejs/_components/AddressSuggestion.vue | 50 ++++++++ 6 files changed, 234 insertions(+), 52 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/api.js create mode 100644 src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/AddressSuggestion.vue diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/api.js b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/api.js new file mode 100644 index 000000000..6ab71a429 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/api.js @@ -0,0 +1,14 @@ +/* +* Endpoint chill_main_address_reference_api_show +* method GET, get AddressReference Object +* @returns {Promise} a promise containing all AddressReference object +* +*/ +export const getReferenceAddress = () => { + const url = `/api/1.0/main/address-reference.json`; + return fetch(url) + .then(response => { + if (response.ok) { return response.json(); } + throw Error('Error with request resource response'); + }); +}; diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/index.js b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/index.js index 8b31a2368..e58cd4483 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/index.js @@ -1,32 +1,22 @@ import { createApp } from 'vue' import { _createI18n } from 'ChillMainAssets/vuejs/_js/i18n' -import { appMessages } from './js/i18n' +import { addressMessages } from './js/i18n' import { getDataPromise } from './store' import App from './App.vue'; -// getDataPromise.then(store => { +getDataPromise.then(store => { -// console.log('store address', store.state.address); + console.log('store address', store.state.referenceAddresses); -// const i18n = _createI18n(appMessages); -// console.log(i18n) + const i18n = _createI18n(addressMessages); -// const app = createApp({ -// template: ``, -// }) -// .use(store) -// .use(i18n) -// .component('app', App) -// .mount('#address'); + const app = createApp({ + template: ``, + }) + .use(store) + .use(i18n) + .component('app', App) + .mount('#address'); -// }); - -const i18n = _createI18n(appMessages); - -const app = createApp({ - template: ``, -}) -.use(i18n) -.component('app', App) -.mount('#address'); +}); diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/js/i18n.js b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/js/i18n.js index 0bfdfb380..268d6d2a0 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/js/i18n.js +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/js/i18n.js @@ -1,15 +1,13 @@ // import { mainMessages } from 'ChillMainAssets/vuejs/_js/i18n' -const appMessages = { +const addressMessages = { fr: { - address: { - id: "id", - }, + add_an_address: 'Ajouter une adresse' } }; // Object.assign(appMessages.fr, mainMessages.fr); export { - appMessages + addressMessages }; diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/store/index.js b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/store/index.js index e69de29bb..1c92719f6 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/store/index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/store/index.js @@ -0,0 +1,115 @@ +import 'es6-promise/auto'; +import { createStore } from 'vuex'; +import { getReferenceAddress } from '../api'; +//import { searchPersons } from 'ChillPersonAssets/vuejs/_api/AddPersons' + +const debug = process.env.NODE_ENV !== 'production'; + +// const id = window.accompanyingCourseId; //tmp TODO + +const getDataPromise = getReferenceAddress() + .then(referenceAddresses => new Promise((resolve, reject) => { + + const store = createStore({ + strict: debug, + state: { + referenceAddresses: referenceAddresses.results, + countries: ['france', 'belgium'] //TODO fetch countries from CHILL API + // add_persons: { + // query: "", + // suggested: [], + // selected: [] + // }, + // errorMsg: [] + }, + getters: { + getCountries: state => state.countries, + getReferenceAddresses: state => state.referenceAddresses, + // getReferenceAddressesCities: state => {}, //TODO get unique cities from addressReference + }, + mutations: { + // removeParticipation(state, item) { + // //console.log('mutation: remove item', item.id); + // state.accompanying_course.participations = state.accompanying_course.participations.filter(participation => participation !== item); + // }, + // closeParticipation(state, { participation, payload }) { + // console.log('### mutation: close item', { participation, payload }); + // // temporaire, le temps que le backend ajoute la enddate + // participation.endDate = { datetime: "2021-05-06T10:49:00+0200" }; + // // trouve dans le state le payload et le supprime du state + // state.accompanying_course.participations = state.accompanying_course.participations.filter(participation => participation !== payload); + // // pousse la participation + // state.accompanying_course.participations.push(participation); + // }, + // addParticipation(state, { participation, payload }) { + // //console.log('### mutation: add participation', participation); + // state.accompanying_course.participations.push(participation); + // //console.log('count participations from state', state.accompanying_course.participations.length); + // //console.log('avant', state.add_persons.selected); + // state.add_persons.selected = state.add_persons.selected.filter(value => value !== payload); + // //console.log('après', state.add_persons.selected); + // state.add_persons.query = ""; + // state.add_persons.suggested = []; + // }, + // setQuery(state, query) { + // //console.log('q=', query); + // state.add_persons = Object.assign({}, state.add_persons, query); + // }, + // loadSuggestions(state, suggested) { + // state.add_persons.suggested = suggested; + // }, + // updateSelected(state, value) { + // state.add_persons.selected = value; + // } + }, + actions: { + // removeParticipation({ commit }, payload) { + // commit('removeParticipation', payload); + // }, + // closeParticipation({ commit }, payload) { + // console.log('## action: fetch delete participation: payload', payload.person.id); + // postParticipation(id, payload.person.id, 'DELETE') + // .then(participation => new Promise((resolve, reject) => { + // //console.log('payload', payload); + // commit('closeParticipation', { participation, payload }); + // resolve(); + // })) + // .catch((error) => { + // console.log('error', error); + // state.errorMsg.push(error.message); + // }); + // }, + // addParticipation({ commit }, payload) { + // console.log('## action: fetch post participation: payload', payload.id); + // postParticipation(id, payload.id, 'POST') + // .then(participation => new Promise((resolve, reject) => { + // commit('addParticipation', { participation, payload }); + // resolve(); + // })) + // .catch((error) => { + // state.errorMsg.push(error.message); + // }); + // }, + // setQuery({ commit }, payload) { + // commit('setQuery', payload); + // //console.log('## action: setquery: payload', payload); + // if (payload.query.length >= 3) { + // searchPersons(payload.query) + // .then(suggested => new Promise((resolve, reject) => { + // commit('loadSuggestions', suggested.results); + // resolve(); + // })); + // } else { + // commit('loadSuggestions', []); + // } + // }, + // updateSelected({ commit }, payload) { + // //console.log('## action: update selected values: payload', payload); + // commit('updateSelected', payload); + // } + } + }); + resolve(store); + })); + +export { getDataPromise }; diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/AddAddress.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/AddAddress.vue index a3ade00e0..90f1adc9b 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/AddAddress.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/AddAddress.vue @@ -1,7 +1,6 @@