From 6df8e6dec85e5a7dc51d6564967f959543d923f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 6 May 2021 15:55:02 +0200 Subject: [PATCH 001/101] add person suite to phpunit --- phpunit.xml.dist | 2 -- 1 file changed, 2 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 9d74dd61a..6ce1f7b24 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -18,11 +18,9 @@ src/Bundle/ChillMainBundle/Tests/ - From c93d5ceb165565f161c03b8208301ff960c10b72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 7 May 2021 10:56:49 +0200 Subject: [PATCH 002/101] remove references to ->getContainer in favor of static:: --- .../ChillMainBundle/Test/Export/AbstractExportTest.php | 1 + .../Controller/PersonDuplicateControllerViewTest.php | 2 +- .../Tests/Export/Aggregator/AgeAggregatorTest.php | 6 ++---- .../Tests/Export/Aggregator/GenderAggregatorTest.php | 6 ++---- ...alityAggregator.php => NationalityAggregatorTest.php} | 9 +++------ .../Tests/Export/Export/CountPersonTest.php | 5 +---- .../Tests/Export/Export/ListPersonTest.php | 7 ++----- .../Tests/Export/Filter/AccompanyingPeriodFilterTest.php | 6 ++---- .../Tests/Export/Filter/BirthdayFilterTest.php | 6 ++---- .../Tests/Export/Filter/GenderFilterTest.php | 6 ++---- .../Tests/Security/Authorization/PersonVoterTest.php | 2 +- 11 files changed, 19 insertions(+), 37 deletions(-) rename src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/{NationalityAggregator.php => NationalityAggregatorTest.php} (83%) diff --git a/src/Bundle/ChillMainBundle/Test/Export/AbstractExportTest.php b/src/Bundle/ChillMainBundle/Test/Export/AbstractExportTest.php index d258c0d30..e480ab145 100644 --- a/src/Bundle/ChillMainBundle/Test/Export/AbstractExportTest.php +++ b/src/Bundle/ChillMainBundle/Test/Export/AbstractExportTest.php @@ -172,6 +172,7 @@ abstract class AbstractExportTest extends WebTestCase */ public function testInitiateQuery($modifiers, $acl, $data) { + var_dump($data); $query = $this->getExport()->initiateQuery($modifiers, $acl, $data); $this->assertTrue($query instanceof QueryBuilder || $query instanceof NativeQuery, diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/PersonDuplicateControllerViewTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/PersonDuplicateControllerViewTest.php index 1292ecbeb..e6d0c207f 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/PersonDuplicateControllerViewTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/PersonDuplicateControllerViewTest.php @@ -11,7 +11,7 @@ class PersonDuplicateControllerViewTest extends WebTestCase { static::bootKernel(); - $this->em = static::$kernel->getContainer() + $this->em = static::$container ->get('doctrine.orm.entity_manager'); $center = $this->em->getRepository('ChillMainBundle:Center') diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AgeAggregatorTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AgeAggregatorTest.php index 690f873e7..299cc62d5 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AgeAggregatorTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AgeAggregatorTest.php @@ -38,9 +38,7 @@ class AgeAggregatorTest extends AbstractAggregatorTest { static::bootKernel(); - $container = static::$kernel->getContainer(); - - $this->aggregator = $container->get('chill.person.export.aggregator_age'); + $this->aggregator = static::$container->get('chill.person.export.aggregator_age'); } public function getAggregator() @@ -63,7 +61,7 @@ class AgeAggregatorTest extends AbstractAggregatorTest static::bootKernel(); } - $em = static::$kernel->getContainer() + $em = static::$container ->get('doctrine.orm.entity_manager'); return array( diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/GenderAggregatorTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/GenderAggregatorTest.php index fd91305dd..724a793e3 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/GenderAggregatorTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/GenderAggregatorTest.php @@ -37,9 +37,7 @@ class GenderAggregatorTest extends AbstractAggregatorTest { static::bootKernel(); - $container = static::$kernel->getContainer(); - - $this->aggregator = $container->get('chill.person.export.aggregator_gender'); + $this->aggregator = static::$container->get('chill.person.export.aggregator_gender'); } public function getAggregator() @@ -60,7 +58,7 @@ class GenderAggregatorTest extends AbstractAggregatorTest static::bootKernel(); } - $em = static::$kernel->getContainer() + $em = static::$container ->get('doctrine.orm.entity_manager'); return array( diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/NationalityAggregator.php b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/NationalityAggregatorTest.php similarity index 83% rename from src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/NationalityAggregator.php rename to src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/NationalityAggregatorTest.php index 522b8edcd..1c358530c 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/NationalityAggregator.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/NationalityAggregatorTest.php @@ -17,7 +17,6 @@ */ namespace Chill\PersonBundle\Tests\Export\Aggregator; -require_once '/home/julien/dev/chill-dev/vendor/chill-project/main/Test/Export/AbstractAggregatorTest.php'; use Chill\MainBundle\Test\Export\AbstractAggregatorTest; /** @@ -25,7 +24,7 @@ use Chill\MainBundle\Test\Export\AbstractAggregatorTest; * * @author Julien Fastré */ -class NationalityAggregator extends AbstractAggregatorTest +class NationalityAggregatorTest extends AbstractAggregatorTest { /** * @@ -37,9 +36,7 @@ class NationalityAggregator extends AbstractAggregatorTest { static::bootKernel(); - $container = static::$kernel->getContainer(); - - $this->aggregator = $container->get('chill.person.export.aggregator_nationality'); + $this->aggregator = static::$container->get('chill.person.export.aggregator_nationality'); } public function getAggregator() @@ -61,7 +58,7 @@ class NationalityAggregator extends AbstractAggregatorTest static::bootKernel(); } - $em = static::$kernel->getContainer() + $em = static::$container ->get('doctrine.orm.entity_manager'); return array( diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountPersonTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountPersonTest.php index 5bb11f59a..8edc6e59d 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountPersonTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Export/CountPersonTest.php @@ -36,10 +36,7 @@ class CountPersonTest extends AbstractExportTest { static::bootKernel(); - /* @var $container \Symfony\Component\DependencyInjection\ContainerInterface */ - $container = self::$kernel->getContainer(); - - $this->export = $container->get('chill.person.export.export_count_person'); + $this->export = static::$container->get('chill.person.export.export_count_person'); } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonTest.php index 44ab79f96..2ca369a24 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Export/ListPersonTest.php @@ -40,10 +40,7 @@ class ListPersonTest extends AbstractExportTest { static::bootKernel(); - /* @var $container \Symfony\Component\DependencyInjection\ContainerInterface */ - $container = self::$kernel->getContainer(); - - $this->export = $container->get('chill.person.export.list_person'); + $this->export = static::$container->get('chill.person.export.list_person'); // add a fake request with a default locale (used in translatable string) $prophet = new \Prophecy\Prophet; @@ -51,7 +48,7 @@ class ListPersonTest extends AbstractExportTest $request->willExtend(\Symfony\Component\HttpFoundation\Request::class); $request->getLocale()->willReturn('fr'); - $container->get('request_stack') + static::$container->get('request_stack') ->push($request->reveal()); } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingPeriodFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingPeriodFilterTest.php index a0f4ed1be..bf040619c 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingPeriodFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingPeriodFilterTest.php @@ -36,10 +36,8 @@ class AccompanyingPeriodFilterTest extends AbstractFilterTest { static::bootKernel(); - $container = static::$kernel->getContainer(); - try { - $this->filter = $container->get('chill.person.export.filter_accompanying_period'); + $this->filter = static::$container->get('chill.person.export.filter_accompanying_period'); } catch (ServiceNotFoundException $e) { $this->markTestSkipped("The current configuration does not use accompanying_periods"); } @@ -67,7 +65,7 @@ class AccompanyingPeriodFilterTest extends AbstractFilterTest static::bootKernel(); } - $em = static::$kernel->getContainer() + $em = static::$container ->get('doctrine.orm.entity_manager'); return array( diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/BirthdayFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/BirthdayFilterTest.php index 1bcb040e4..e580c0f20 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/BirthdayFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/BirthdayFilterTest.php @@ -36,9 +36,7 @@ class BirthdayFilterTest extends AbstractFilterTest { static::bootKernel(); - $container = static::$kernel->getContainer(); - - $this->filter = $container->get('chill.person.export.filter_birthdate'); + $this->filter = static::$container->get('chill.person.export.filter_birthdate'); } @@ -63,7 +61,7 @@ class BirthdayFilterTest extends AbstractFilterTest static::bootKernel(); } - $em = static::$kernel->getContainer() + $em = static::$container ->get('doctrine.orm.entity_manager'); return array( diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/GenderFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/GenderFilterTest.php index dce198344..2d6d7e309 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/GenderFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/GenderFilterTest.php @@ -43,9 +43,7 @@ class GenderFilterTest extends AbstractFilterTest $request->willExtend(\Symfony\Component\HttpFoundation\Request::class); $request->getLocale()->willReturn('fr'); - $container = static::$kernel->getContainer(); - - $this->filter = $container->get('chill.person.export.filter_gender'); + $this->filter = static::$container->get('chill.person.export.filter_gender'); } @@ -75,7 +73,7 @@ class GenderFilterTest extends AbstractFilterTest static::bootKernel(); } - $em = static::$kernel->getContainer() + $em = static::$container ->get('doctrine.orm.entity_manager'); return array( diff --git a/src/Bundle/ChillPersonBundle/Tests/Security/Authorization/PersonVoterTest.php b/src/Bundle/ChillPersonBundle/Tests/Security/Authorization/PersonVoterTest.php index 474fbc103..09f6cc2ba 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Security/Authorization/PersonVoterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Security/Authorization/PersonVoterTest.php @@ -60,7 +60,7 @@ class PersonVoterTest extends KernelTestCase public function setUp() { static::bootKernel(); - $this->voter = static::$kernel->getContainer() + $this->voter = static::$container ->get('chill.person.security.authorization.person'); $this->prophet = new \Prophecy\Prophet(); } From c1b727b1c8396674a78515a3a135807d039a6ca4 Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 7 May 2021 16:02:39 +0200 Subject: [PATCH 003/101] 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 038d7ad2e1df7dacde975985f74d120fc0547ce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 7 May 2021 16:07:53 +0200 Subject: [PATCH 004/101] load third party fixtures --- composer.json | 3 +- .../DataFixtures/ORM/LoadCenters.php | 8 +- .../DataFixtures/ORM/LoadThirdParty.php | 122 ++++++++++++++++++ .../ChillThirdPartyExtension.php | 1 + .../config/services.yaml | 4 + .../config/services/fixtures.yaml | 0 6 files changed, 133 insertions(+), 5 deletions(-) create mode 100644 src/Bundle/ChillThirdPartyBundle/DataFixtures/ORM/LoadThirdParty.php create mode 100644 src/Bundle/ChillThirdPartyBundle/config/services/fixtures.yaml diff --git a/composer.json b/composer.json index 4181af68a..95074c18f 100644 --- a/composer.json +++ b/composer.json @@ -73,7 +73,8 @@ "symfony/web-profiler-bundle": "^5.0", "symfony/var-dumper": "4.*", "symfony/debug-bundle": "^5.1", - "symfony/phpunit-bridge": "^5.2" + "symfony/phpunit-bridge": "^5.2", + "nelmio/alice": "^3.8" }, "scripts": { "auto-scripts": { diff --git a/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadCenters.php b/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadCenters.php index 1da1af2f3..a3c01fdf6 100644 --- a/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadCenters.php +++ b/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadCenters.php @@ -55,11 +55,11 @@ class LoadCenters extends AbstractFixture implements OrderedFixtureInterface public function load(ObjectManager $manager) { foreach (static::$centers as $new) { - $centerA = new Center(); - $centerA->setName($new['name']); + $center = new Center(); + $center->setName($new['name']); - $manager->persist($centerA); - $this->addReference($new['ref'], $centerA); + $manager->persist($center); + $this->addReference($new['ref'], $center); static::$refs[] = $new['ref']; } diff --git a/src/Bundle/ChillThirdPartyBundle/DataFixtures/ORM/LoadThirdParty.php b/src/Bundle/ChillThirdPartyBundle/DataFixtures/ORM/LoadThirdParty.php new file mode 100644 index 000000000..63f6e9c3b --- /dev/null +++ b/src/Bundle/ChillThirdPartyBundle/DataFixtures/ORM/LoadThirdParty.php @@ -0,0 +1,122 @@ +getThirdParties()->getObjects(); + + foreach ($thirdParties as $name => $thirdParty) { + if ('a' === $name[0]) { + // this is an address + continue; + } + + foreach ($this->getCenters() as $center) { + $thirdParty->addCenter($center); + } + + $manager->persist($thirdParty); + } + + $manager->flush(); + } + + private function getCenters(): \Iterator + { + $references = \array_map(function($a) { return $a['ref']; }, + LoadCenters::$centers); + $number = random_int(1, count($references)); + + if ($number === 1) { + yield $this->getReference($references[\array_rand($references)]); + } else { + foreach (array_rand($references, $number) as $index) { + yield $this->getReference($references[$index]); + } + } + } + + public function getDependencies() + { + return [ + LoadCenters::class, + LoadPostalCodes::class + ]; + } + + private function getThirdParties(): ObjectSet + { + $loader = new NativeLoader(); + $objectSet = $loader->loadData([ + Address::class => [ + 'address{1..75}' => [ + 'street' => '', + 'streetNumber' => '', + 'validFrom' => '', + 'postCode' => $this->getPostalCode() + ], + ], + ThirdParty::class => [ + 'thirdparty{1..75}' => [ + 'name' => '', + 'telephone' => '', + 'email' => '', + 'comment' => '', + 'address' => '@address' + ] + ] + ]); + + return $objectSet; + } + + private function getPostalCode(): PostalCode + { + $ref = LoadPostalCodes::$refs[\array_rand(LoadPostalCodes::$refs)]; + return $this->getReference($ref); + if (count($this->postalCodesIds) === 0) { + // fill the postal codes + $this->em->createQuery('SELECT p.id FROM '.PostalCode::class) + ->getScalarResult(); + } + + $id = $this->postalCodesIds[\array_rand($this->postalCodesIds)]; + + return $this->em->getRepository(PostalCode::class) + ->find($id); + } + + private function createAddress(): ObjectSet + { + $loader = new NativeLoader(); + $objectSet = $loader->loadData([ + Address::class => [ + 'address1' => [ + 'name' => '', + 'telephone' => '', + 'email' => '', + 'comment' => '' + ] + ] + ]); + + return $objectSet; + + } + +} diff --git a/src/Bundle/ChillThirdPartyBundle/DependencyInjection/ChillThirdPartyExtension.php b/src/Bundle/ChillThirdPartyBundle/DependencyInjection/ChillThirdPartyExtension.php index 28e3c19df..aaf64a9e0 100644 --- a/src/Bundle/ChillThirdPartyBundle/DependencyInjection/ChillThirdPartyExtension.php +++ b/src/Bundle/ChillThirdPartyBundle/DependencyInjection/ChillThirdPartyExtension.php @@ -33,6 +33,7 @@ class ChillThirdPartyExtension extends Extension implements PrependExtensionInte $loader->load('services/search.yaml'); $loader->load('services/templating.yaml'); $loader->load('services/menu.yaml'); + $loader->load('services/fixtures.yaml'); } public function prepend(ContainerBuilder $container) diff --git a/src/Bundle/ChillThirdPartyBundle/config/services.yaml b/src/Bundle/ChillThirdPartyBundle/config/services.yaml index 0baad4766..d57dadd4a 100644 --- a/src/Bundle/ChillThirdPartyBundle/config/services.yaml +++ b/src/Bundle/ChillThirdPartyBundle/config/services.yaml @@ -1 +1,5 @@ +--- services: + Chill\ThirdPartyBundle\DataFixtures\ORM\LoadThirdParty: + tags: + - { 'name': doctrine.fixture.orm } diff --git a/src/Bundle/ChillThirdPartyBundle/config/services/fixtures.yaml b/src/Bundle/ChillThirdPartyBundle/config/services/fixtures.yaml new file mode 100644 index 000000000..e69de29bb From 44c9a65505ee1d2b9ec82c7fe113f0bb05869a49 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Fri, 7 May 2021 16:22:02 +0200 Subject: [PATCH 005/101] cleaning console log --- .../public/vuejs/AccompanyingCourse/store/index.js | 9 ++------- .../vuejs/AccompanyingCourse/store/modules/addPersons.js | 3 --- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js index 04785eca5..69ff448b3 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js @@ -23,14 +23,12 @@ let initPromise = getAccompanyingCourse(id) }, mutations: { removeParticipation(state, item) { - //console.log('mutation: remove item', item.id); + //console.log('### mutation: remove item', item.id); state.accompanyingCourse.participations = state.accompanyingCourse.participations.filter(participation => participation !== item); }, closeParticipation(state, { participation, payload }) { - console.log('### mutation: close item', { participation, payload }); - // trouve dans le state le payload et le supprime du state + //console.log('### mutation: close item', { participation, payload }); state.accompanyingCourse.participations = state.accompanyingCourse.participations.filter(participation => participation !== payload); - // pousse la participation state.accompanyingCourse.participations.push(participation); }, addParticipation(state, participation) { @@ -46,7 +44,6 @@ let initPromise = getAccompanyingCourse(id) //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(); })) @@ -58,7 +55,6 @@ let initPromise = getAccompanyingCourse(id) //console.log('## action: fetch post participation: payload', payload.id); postParticipation(id, payload.id, 'POST') .then(participation => new Promise((resolve, reject) => { - //console.log(participation, payload); addPersons.commit('addParticipation', participation); addPersons.commit('resetState', payload); resolve(); @@ -69,7 +65,6 @@ let initPromise = getAccompanyingCourse(id) }, } }); - //console.log('store object', store.state.accompanyingCourse.id); resolve(store); })); diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/modules/addPersons.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/modules/addPersons.js index e65f94fa9..800846811 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/modules/addPersons.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/modules/addPersons.js @@ -28,7 +28,6 @@ const getters = { // mutations const mutations = { setQuery(state, query) { - //console.log('q=', query); state.query = query; }, loadSuggestions(state, suggested) { @@ -38,9 +37,7 @@ const mutations = { state.selected = value; }, resetState(state, selected) { - //console.log('avant', state.selected); state.selected = state.selected.filter(value => value !== selected); - //console.log('après', state.selected); state.query = ""; state.suggested = []; } From de0e3f7dfd9779a3fb7b7884bd9b6afa0cadaa23 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Fri, 7 May 2021 16:28:33 +0200 Subject: [PATCH 006/101] move test in a test component, clean requestor component --- .../public/vuejs/AccompanyingCourse/App.vue | 5 +- .../components/Requestor.vue | 55 +------------ .../AccompanyingCourse/components/Test.vue | 81 +++++++++++++++++++ .../public/vuejs/_components/AddPersons.vue | 2 +- 4 files changed, 87 insertions(+), 56 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Test.vue diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/App.vue index 480b882dc..c1727eaf5 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/App.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/App.vue @@ -2,6 +2,7 @@ + diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue index 53600da1c..3c40f04f3 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue @@ -119,7 +119,7 @@ export default { }) }, addNewPersons() { - console.log('@@@ CLICK button addPersons') + console.log('@@@ CLICK button addNewPersons') this.selected.forEach(function(item) { //console.log('# dispatch action for each item', item); this.$store.dispatch('addParticipation', item); From b934c2eeaf4c352e9492cd969942307eb114cde4 Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 7 May 2021 17:38:15 +0200 Subject: [PATCH 007/101] 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 7a1ad24f0ef5dc38b390254756ee89709772180a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 7 May 2021 19:11:10 +0200 Subject: [PATCH 008/101] add endoint /api/1.0/search.json?q=xxx with fake data See https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/136 --- docs/source/installation/index.rst | 2 +- .../Controller/SearchController.php | 39 +++++---- .../ChillMainBundle/Search/Model/Result.php | 36 ++++++++ .../ChillMainBundle/Search/SearchApi.php | 85 +++++++++++++++++++ .../Normalizer/AddressNormalizer.php | 29 +++++++ src/Bundle/ChillMainBundle/config/routes.yaml | 7 ++ .../config/services/controller.yaml | 1 + .../config/services/search.yaml | 9 +- .../config/services/serializer.yaml | 4 + .../Normalizer/PersonNormalizer.php | 28 +++++- .../config/services/serializer.yaml | 1 + .../ChillThirdPartyExtension.php | 1 + .../Normalizer/ThirdPartyNormalizer.php | 31 +++++++ .../config/services.yaml | 3 - .../config/services/fixtures.yaml | 5 ++ .../config/services/serializer.yaml | 5 ++ 16 files changed, 261 insertions(+), 25 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Search/Model/Result.php create mode 100644 src/Bundle/ChillMainBundle/Search/SearchApi.php create mode 100644 src/Bundle/ChillMainBundle/Serializer/Normalizer/AddressNormalizer.php create mode 100644 src/Bundle/ChillThirdPartyBundle/Serializer/Normalizer/ThirdPartyNormalizer.php create mode 100644 src/Bundle/ChillThirdPartyBundle/config/services/serializer.yaml diff --git a/docs/source/installation/index.rst b/docs/source/installation/index.rst index 6aee5c526..1312480e3 100644 --- a/docs/source/installation/index.rst +++ b/docs/source/installation/index.rst @@ -82,7 +82,7 @@ Chill will be available at ``http://localhost:8001.`` Currently, there isn't any .. code-block:: bash - docker-compose exec --user $(id -u) php bin/console doctrine:fixtures:load + docker-compose exec --user $(id -u) php bin/console doctrine:fixtures:load --purge-with-truncate There are several users available: diff --git a/src/Bundle/ChillMainBundle/Controller/SearchController.php b/src/Bundle/ChillMainBundle/Controller/SearchController.php index a44af8e7b..45390ceca 100644 --- a/src/Bundle/ChillMainBundle/Controller/SearchController.php +++ b/src/Bundle/ChillMainBundle/Controller/SearchController.php @@ -22,6 +22,7 @@ namespace Chill\MainBundle\Controller; +use Chill\MainBundle\Serializer\Model\Collection; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Chill\MainBundle\Search\UnknowSearchDomainException; @@ -34,6 +35,7 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Chill\MainBundle\Search\SearchProvider; use Symfony\Contracts\Translation\TranslatorInterface; use Chill\MainBundle\Pagination\PaginatorFactory; +use Chill\MainBundle\Search\SearchApi; /** * Class SearchController @@ -42,32 +44,24 @@ use Chill\MainBundle\Pagination\PaginatorFactory; */ class SearchController extends AbstractController { - /** - * - * @var SearchProvider - */ - protected $searchProvider; + protected SearchProvider $searchProvider; - /** - * - * @var TranslatorInterface - */ - protected $translator; + protected TranslatorInterface $translator; - /** - * - * @var PaginatorFactory - */ - protected $paginatorFactory; + protected PaginatorFactory $paginatorFactory; + + protected SearchApi $searchApi; function __construct( SearchProvider $searchProvider, TranslatorInterface $translator, - PaginatorFactory $paginatorFactory + PaginatorFactory $paginatorFactory, + SearchApi $searchApi ) { $this->searchProvider = $searchProvider; $this->translator = $translator; $this->paginatorFactory = $paginatorFactory; + $this->searchApi = $searchApi; } @@ -152,6 +146,19 @@ class SearchController extends AbstractController array('results' => $results, 'pattern' => $pattern) ); } + + public function searchApi(Request $request, $_format): JsonResponse + { + //TODO this is an incomplete implementation + $query = $request->query->get('q', ''); + + $results = $this->searchApi->getResults($query, 0, 150); + $paginator = $this->paginatorFactory->create(count($results)); + + $collection = new Collection($results, $paginator); + + return $this->json($collection); + } public function advancedSearchListAction(Request $request) { diff --git a/src/Bundle/ChillMainBundle/Search/Model/Result.php b/src/Bundle/ChillMainBundle/Search/Model/Result.php new file mode 100644 index 000000000..a88c2f55f --- /dev/null +++ b/src/Bundle/ChillMainBundle/Search/Model/Result.php @@ -0,0 +1,36 @@ +relevance = $relevance; + $this->result = $result; + } + + public function getRelevance(): float + { + return $this->relevance; + } + + public function getResult() + { + return $this->result; + } + + + +} diff --git a/src/Bundle/ChillMainBundle/Search/SearchApi.php b/src/Bundle/ChillMainBundle/Search/SearchApi.php new file mode 100644 index 000000000..0c7c7b561 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Search/SearchApi.php @@ -0,0 +1,85 @@ +em = $em; + $this->search = $search; + } + + /** + * @return Model/Result[] + */ + public function getResults(string $query, int $offset, int $maxResult): array + { + // **warning again**: this is an incomplete implementation + $results = []; + + foreach ($this->getPersons($query) as $p) { + $results[] = new Model\Result((float)\rand(0, 100) / 100, $p); + } + foreach ($this->getThirdParties($query) as $t) { + $results[] = new Model\Result((float)\rand(0, 100) / 100, $t); + } + + \usort($results, function(Model\Result $a, Model\Result $b) { + return ($a->getRelevance() <=> $b->getRelevance()) * -1; + }); + + return $results; + } + + public function countResults(string $query): int + { + return 0; + } + + private function getThirdParties(string $query) + { + $thirdPartiesIds = $this->em->createQuery('SELECT t.id FROM '.ThirdParty::class.' t') + ->getScalarResult(); + + $nbResults = rand(0, 15); + if ($nbResults === 1) { + $nbResults++; + } + $ids = \array_rand($thirdPartiesIds, $nbResults); + + return $this->em->getRepository(ThirdParty::class) + ->findById($ids); + } + + private function getPersons(string $query) + { + $params = [ + SearchInterface::SEARCH_PREVIEW_OPTION => false + ]; + $search = $this->search->getResultByName($query, 'person_regular', 0, 50, $params, 'json'); + $ids = \array_map(function($r) { return $r['id']; }, $search['results']); + + + if (count($ids) === 0) { + return []; + } + + return $this->em->getRepository(Person::class) + ->findById($ids) + ; + } + +} diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/AddressNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/AddressNormalizer.php new file mode 100644 index 000000000..29d760b71 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/AddressNormalizer.php @@ -0,0 +1,29 @@ +getId(); + $data['text'] = $address->getStreet().', '.$address->getBuildingName(); + $data['postcode']['name'] = $address->getPostCode()->getName(); + + return $data; + } + + public function supportsNormalization($data, string $format = null) + { + return $data instanceof Address; + } + + +} diff --git a/src/Bundle/ChillMainBundle/config/routes.yaml b/src/Bundle/ChillMainBundle/config/routes.yaml index 3fd7eafab..bc3187add 100644 --- a/src/Bundle/ChillMainBundle/config/routes.yaml +++ b/src/Bundle/ChillMainBundle/config/routes.yaml @@ -69,6 +69,13 @@ chill_main_search: requirements: _format: html|json +chill_main_search_global: + path: '/api/1.0/search.{_format}' + controller: Chill\MainBundle\Controller\SearchController::searchApi + format: 'json' + requirements: + _format: 'json' + chill_main_advanced_search: path: /{_locale}/search/advanced/{name} controller: Chill\MainBundle\Controller\SearchController::advancedSearchAction diff --git a/src/Bundle/ChillMainBundle/config/services/controller.yaml b/src/Bundle/ChillMainBundle/config/services/controller.yaml index 5fb542786..6021e3d72 100644 --- a/src/Bundle/ChillMainBundle/config/services/controller.yaml +++ b/src/Bundle/ChillMainBundle/config/services/controller.yaml @@ -16,6 +16,7 @@ services: $searchProvider: '@chill_main.search_provider' $translator: '@Symfony\Contracts\Translation\TranslatorInterface' $paginatorFactory: '@Chill\MainBundle\Pagination\PaginatorFactory' + $searchApi: '@Chill\MainBundle\Search\SearchApi' tags: ['controller.service_arguments'] Chill\MainBundle\Controller\PermissionsGroupController: diff --git a/src/Bundle/ChillMainBundle/config/services/search.yaml b/src/Bundle/ChillMainBundle/config/services/search.yaml index e8a457415..b7a1656b3 100644 --- a/src/Bundle/ChillMainBundle/config/services/search.yaml +++ b/src/Bundle/ChillMainBundle/config/services/search.yaml @@ -1,3 +1,10 @@ services: chill_main.search_provider: - class: Chill\MainBundle\Search\SearchProvider \ No newline at end of file + class: Chill\MainBundle\Search\SearchProvider + + Chill\MainBundle\Search\SearchProvider: '@chill_main.search_provider' + + Chill\MainBundle\Search\SearchApi: + arguments: + $em: '@Doctrine\ORM\EntityManagerInterface' + $search: '@Chill\MainBundle\Search\SearchProvider' diff --git a/src/Bundle/ChillMainBundle/config/services/serializer.yaml b/src/Bundle/ChillMainBundle/config/services/serializer.yaml index fb5f57b7e..fa30b876d 100644 --- a/src/Bundle/ChillMainBundle/config/services/serializer.yaml +++ b/src/Bundle/ChillMainBundle/config/services/serializer.yaml @@ -4,6 +4,10 @@ services: tags: - { name: 'serializer.normalizer', priority: 64 } + Chill\MainBundle\Serializer\Normalizer\AddressNormalizer: + tags: + - { name: 'serializer.normalizer', priority: 64 } + Chill\MainBundle\Serializer\Normalizer\DateNormalizer: tags: - { name: 'serializer.normalizer', priority: 64 } diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonNormalizer.php index d88d27ddc..a315fb326 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonNormalizer.php @@ -25,7 +25,7 @@ use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Chill\PersonBundle\Repository\PersonRepository; use Symfony\Component\Serializer\Exception\RuntimeException; use Symfony\Component\Serializer\Exception\UnexpectedValueException; - +use Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension; /** * Serialize a Person entity @@ -41,25 +41,45 @@ class PersonNormalizer implements protected PersonRepository $repository; + private ChillEntityRenderExtension $render; + public const GET_PERSON = 'get_person'; - public function __construct(PersonRepository $repository) + public function __construct(PersonRepository $repository, ChillEntityRenderExtension $render) { $this->repository = $repository; + $this->render = $render; } public function normalize($person, string $format = null, array $context = array()) { /** @var Person $person */ return [ - 'id' => $person->getId(), + 'type' => 'person', + 'person_id' => $person->getId(), + 'text' => $this->render->renderString($person), 'firstName' => $person->getFirstName(), 'lastName' => $person->getLastName(), 'birthdate' => $this->normalizer->normalize($person->getBirthdate()), - 'center' => $this->normalizer->normalize($person->getCenter()) + 'center' => $this->normalizer->normalize($person->getCenter()), + 'phonenumber' => $person->getPhonenumber(), + 'mobilenumber' => $person->getMobilenumber(), + 'altNames' => $this->normalizeAltNames($person->getAltNames()) ]; } + protected function normalizeAltNames($altNames): array + { + $r = []; + + foreach ($altNames as $n) { + $r[] = [ 'key' => $n->getKey(), 'label' => $n->getLabel() ]; + } + + return $r; + } + + public function denormalize($data, string $type, string $format = null, array $context = []): Person { if ($context[self::GET_PERSON] ?? true) { diff --git a/src/Bundle/ChillPersonBundle/config/services/serializer.yaml b/src/Bundle/ChillPersonBundle/config/services/serializer.yaml index 092dc2320..843c984f8 100644 --- a/src/Bundle/ChillPersonBundle/config/services/serializer.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/serializer.yaml @@ -3,6 +3,7 @@ services: Chill\PersonBundle\Serializer\Normalizer\PersonNormalizer: arguments: $repository: '@Chill\PersonBundle\Repository\PersonRepository' + $render: '@Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension' tags: - { name: 'serializer.normalizer', priority: 64 } diff --git a/src/Bundle/ChillThirdPartyBundle/DependencyInjection/ChillThirdPartyExtension.php b/src/Bundle/ChillThirdPartyBundle/DependencyInjection/ChillThirdPartyExtension.php index aaf64a9e0..7ada8db8e 100644 --- a/src/Bundle/ChillThirdPartyBundle/DependencyInjection/ChillThirdPartyExtension.php +++ b/src/Bundle/ChillThirdPartyBundle/DependencyInjection/ChillThirdPartyExtension.php @@ -34,6 +34,7 @@ class ChillThirdPartyExtension extends Extension implements PrependExtensionInte $loader->load('services/templating.yaml'); $loader->load('services/menu.yaml'); $loader->load('services/fixtures.yaml'); + $loader->load('services/serializer.yaml'); } public function prepend(ContainerBuilder $container) diff --git a/src/Bundle/ChillThirdPartyBundle/Serializer/Normalizer/ThirdPartyNormalizer.php b/src/Bundle/ChillThirdPartyBundle/Serializer/Normalizer/ThirdPartyNormalizer.php new file mode 100644 index 000000000..b10ed4d7e --- /dev/null +++ b/src/Bundle/ChillThirdPartyBundle/Serializer/Normalizer/ThirdPartyNormalizer.php @@ -0,0 +1,31 @@ +getName(); + $data['thirdparty_id'] = $thirdParty->getId(); + $data['address'] = $this->normalizer->normalize($thirdParty->getAddress(), $format, + [ 'address_rendering' => 'short' ]); + + return $data; + } + + public function supportsNormalization($data, string $format = null) + { + return $data instanceof ThirdParty; + } +} diff --git a/src/Bundle/ChillThirdPartyBundle/config/services.yaml b/src/Bundle/ChillThirdPartyBundle/config/services.yaml index d57dadd4a..4f179f43e 100644 --- a/src/Bundle/ChillThirdPartyBundle/config/services.yaml +++ b/src/Bundle/ChillThirdPartyBundle/config/services.yaml @@ -1,5 +1,2 @@ --- services: - Chill\ThirdPartyBundle\DataFixtures\ORM\LoadThirdParty: - tags: - - { 'name': doctrine.fixture.orm } diff --git a/src/Bundle/ChillThirdPartyBundle/config/services/fixtures.yaml b/src/Bundle/ChillThirdPartyBundle/config/services/fixtures.yaml index e69de29bb..d57dadd4a 100644 --- a/src/Bundle/ChillThirdPartyBundle/config/services/fixtures.yaml +++ b/src/Bundle/ChillThirdPartyBundle/config/services/fixtures.yaml @@ -0,0 +1,5 @@ +--- +services: + Chill\ThirdPartyBundle\DataFixtures\ORM\LoadThirdParty: + tags: + - { 'name': doctrine.fixture.orm } diff --git a/src/Bundle/ChillThirdPartyBundle/config/services/serializer.yaml b/src/Bundle/ChillThirdPartyBundle/config/services/serializer.yaml new file mode 100644 index 000000000..286bb74ec --- /dev/null +++ b/src/Bundle/ChillThirdPartyBundle/config/services/serializer.yaml @@ -0,0 +1,5 @@ +services: + Chill\ThirdPartyBundle\Serializer\Normalizer\: + resource: '../../Serializer/Normalizer/' + tags: + - { name: 'serializer.normalizer', priority: 64 } From 8ed2e7585d4e191d8f3a2ba992b180c0540d8a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 7 May 2021 19:22:47 +0200 Subject: [PATCH 009/101] fix random thid party --- src/Bundle/ChillMainBundle/Search/SearchApi.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Search/SearchApi.php b/src/Bundle/ChillMainBundle/Search/SearchApi.php index 0c7c7b561..518edd31b 100644 --- a/src/Bundle/ChillMainBundle/Search/SearchApi.php +++ b/src/Bundle/ChillMainBundle/Search/SearchApi.php @@ -53,15 +53,19 @@ class SearchApi { $thirdPartiesIds = $this->em->createQuery('SELECT t.id FROM '.ThirdParty::class.' t') ->getScalarResult(); - $nbResults = rand(0, 15); + if ($nbResults === 1) { $nbResults++; + } elseif ($nbResults === 0) { + return []; } - $ids = \array_rand($thirdPartiesIds, $nbResults); + $ids = \array_map(function ($e) use ($thirdPartiesIds) { return $thirdPartiesIds[$e]['id'];}, + \array_rand($thirdPartiesIds, $nbResults)); - return $this->em->getRepository(ThirdParty::class) + $a = $this->em->getRepository(ThirdParty::class) ->findById($ids); + return $a; } private function getPersons(string $query) From 226f71ab2bf1a1e64064bba756a0e8a0dfb2d8f6 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Fri, 7 May 2021 19:53:08 +0200 Subject: [PATCH 010/101] requestor, just display datas --- .../AccompanyingCourseController.php | 5 ++ .../components/AccompanyingCourse.vue | 12 ++++- .../components/PersonsAssociated.vue | 30 ++++-------- .../components/Requestor.vue | 47 +++++++++++++++---- .../vuejs/AccompanyingCourse/js/i18n.js | 27 +++++++++-- .../public/vuejs/_components/AddPersons.vue | 46 +++++++++--------- .../Resources/public/vuejs/_js/i18n.js | 5 +- .../AccompanyingPeriodNormalizer.php | 2 + 8 files changed, 115 insertions(+), 59 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php index 05a1934e6..8134f6938 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php @@ -106,6 +106,11 @@ class AccompanyingCourseController extends Controller ]) ); + //$accompanyingCourse->getRequestorPerson(); + //$accompanyingCourse->getRequestorThirdParty(); + //$accompanyingCourse->isRequestorAnonymous(); + //dump($accompanyingCourse); die; + switch ($_format) { case 'json': return $this->json($accompanyingCourse); diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/AccompanyingCourse.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/AccompanyingCourse.vue index be3014ddb..3f77efadd 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/AccompanyingCourse.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/AccompanyingCourse.vue @@ -4,14 +4,22 @@
{{ $t('course.id') }}
{{ accompanyingCourse.id }}
+
{{ $t('course.step') }}
+
{{ accompanyingCourse.step }}
+
{{ $t('course.emergency') }}
+
{{ accompanyingCourse.emergency }}
+
{{ $t('course.confidential') }}
+
{{ accompanyingCourse.confidential }}
{{ $t('course.opening_date') }}
{{ $d(accompanyingCourse.openingDate.datetime, 'short') }}
{{ $t('course.closing_date') }}
-
{{ $d(accompanyingCourse.closingDate.datetime, 'short') }}
+
{{ $d(accompanyingCourse.closingDate.datetime, 'short') }}
{{ $t('course.remark') }}
{{ accompanyingCourse.remark }}
{{ $t('course.closing_motive') }}
-
{{ accompanyingCourse.closing_motive }}
+
{{ accompanyingCourse.closingMotive.name.fr }}
+
{{ $t('course.user') }}
+
{{ accompanyingCourse.user.username }}
diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonsAssociated.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonsAssociated.vue index 631534fcb..c39960620 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonsAssociated.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonsAssociated.vue @@ -2,7 +2,7 @@

{{ $t('persons_associated.title')}}

- +
@@ -12,24 +12,19 @@ - - +
{{ $t('persons_associated.firstname') }}{{ $t('action.actions') }}
- -
    - -
+ + +
@@ -40,7 +35,7 @@ import AddPersons from 'ChillPersonAssets/vuejs/_components/AddPersons.vue' export default { name: 'PersonsAssociated', - components: { + components: { PersonItem, AddPersons }, @@ -55,12 +50,7 @@ export default { closeParticipation(item) { console.log('@@ CLICK close participation: item', item); this.$store.dispatch('closeParticipation', item) - }, - /* - savePersons() { - console.log('[wip] saving persons'); } - */ } } diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Requestor.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Requestor.vue index 9931535fc..138204074 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Requestor.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Requestor.vue @@ -1,27 +1,58 @@ diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue index a4d0618aa..a800331be 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue @@ -55,7 +55,8 @@ @@ -119,16 +120,8 @@ export default { this.$nextTick(function() { this.$refs.search.focus(); }) - }, - addNewPersons() { - console.log('@@@ CLICK button addNewPersons') - this.selected.forEach(function(item) { - //console.log('# dispatch action for each item', item); - this.$store.dispatch('addParticipation', item); - }, this - ); - this.modal.showModal = false; } - } + }, + emits: ['addNewPersons'], } From ac67f56b09e2eedf6c2c94b3a26d1cdf85dfd74b Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Sat, 8 May 2021 12:57:23 +0200 Subject: [PATCH 015/101] bind options and key inside AddPersons component (wip) --- .../components/PersonsAssociated.vue | 14 ++++++++++++++ .../AccompanyingCourse/components/Requestor.vue | 10 ++++++++++ .../AccompanyingCourse/store/modules/addPersons.js | 7 +++---- .../Resources/public/vuejs/_api/AddPersons.js | 3 ++- .../public/vuejs/_components/AddPersons.vue | 11 +++++++---- 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonsAssociated.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonsAssociated.vue index e6bad4e43..05359ca78 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonsAssociated.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonsAssociated.vue @@ -25,6 +25,8 @@ @@ -42,6 +44,18 @@ export default { PersonItem, AddPersons }, + data() { + return { + addNewPersons: { + key: 'persons_associated', + options: { + type: ['person'], + priority: null, + uniq: false, + } + } + } + }, computed: mapState({ participations: state => state.accompanyingCourse.participations, counter: state => state.accompanyingCourse.participations.length diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Requestor.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Requestor.vue index f41aa65a5..33a8abd1f 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Requestor.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/Requestor.vue @@ -40,6 +40,8 @@ @@ -56,6 +58,14 @@ export default { }, data() { return { + addNewPersons: { + key: 'requestor', + options: { + type: ['person', 'thirdparty'], + priority: null, + uniq: true, + } + } } }, computed: { diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/modules/addPersons.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/modules/addPersons.js index 800846811..15cc7c5a6 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/modules/addPersons.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/modules/addPersons.js @@ -1,5 +1,4 @@ -import { searchPersons } from 'ChillPersonAssets/vuejs/_api/AddPersons' -import { postParticipation } from '../../api'; +import { searchPersons } from 'ChillPersonAssets/vuejs/_api/AddPersons'; // initial state @@ -46,10 +45,10 @@ const mutations = { // actions const actions = { setQuery({ commit }, payload) { - //console.log('## action: setquery: payload', payload); + console.log('## action: setquery: payload', payload); commit('setQuery', payload.query); if (payload.query.length >= 3) { - searchPersons(payload.query) + searchPersons(payload) .then(suggested => new Promise((resolve, reject) => { commit('loadSuggestions', suggested.results); resolve(); diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_api/AddPersons.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_api/AddPersons.js index d5ac91ac5..ccf6764bf 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_api/AddPersons.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_api/AddPersons.js @@ -8,7 +8,8 @@ const * * @query string - the query to search for */ -let searchPersons = (query) => { +let searchPersons = ({ query, options }) => { + console.log('options 2', options); let url = `/${locale}/search.${format}?name=person_regular&q=${query}`; return fetch(url) .then(response => { diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue index a800331be..e2084c711 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue @@ -72,7 +72,7 @@ import PersonSuggestion from 'ChillPersonAssets/vuejs/_components/PersonSuggesti export default { name: 'AddPersons', - props: ['buttonTitle'], + props: ['buttonTitle', 'options'], components: { Modal, PersonSuggestion, @@ -83,7 +83,6 @@ export default { showModal: false, modalDialogClass: "modal-dialog-scrollable modal-xl" }, - //button: this.buttonTitle } }, computed: { @@ -91,8 +90,8 @@ export default { addPersons: state => state.addPersons }), query: { - set(query) { - this.$store.dispatch('setQuery', { query }); + set(query, options) { + this.$store.dispatch('setQuery', { query, options }); }, get() { return this.addPersons.query; @@ -112,10 +111,14 @@ export default { }, selectedAndSuggested() { return this.$store.getters.selectedAndSuggested; + }, + options() { + return this.options; } }, methods: { openModal() { + console.log('options 1', this.options); this.modal.showModal = true; this.$nextTick(function() { this.$refs.search.focus(); From 57c420e9dda39bec522f2a433e1435b9ef36cbd6 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Sat, 8 May 2021 15:31:13 +0200 Subject: [PATCH 016/101] no store for AddPersons, move store in data component note: this allow to use same addPersons component to add participations, requestor, or interlocutors. each addPersons component has his own data() --- .../components/PersonsAssociated.vue | 12 ++-- .../vuejs/AccompanyingCourse/store/index.js | 10 +-- .../public/vuejs/_components/AddPersons.vue | 71 ++++++++++++++----- .../vuejs/_components/PersonSuggestion.vue | 18 +++-- 4 files changed, 78 insertions(+), 33 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonsAssociated.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonsAssociated.vue index 05359ca78..ee30dd34e 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonsAssociated.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonsAssociated.vue @@ -25,9 +25,10 @@ + v-bind:key="addPersons.key" + v-bind:options="addPersons.options" + @addNewPersons="addNewPersons" + ref="addPersons"> @@ -46,7 +47,7 @@ export default { }, data() { return { - addNewPersons: { + addPersons: { key: 'persons_associated', options: { type: ['person'], @@ -62,6 +63,7 @@ export default { }), methods: { removeParticipation(item) { + console.log('@@ CLICK remove participation: item', item); this.$store.dispatch('removeParticipation', item); }, closeParticipation(item) { @@ -71,10 +73,10 @@ export default { addNewPersons({ selected, modal }) { console.log('@@@ CLICK button addNewPersons', selected); selected.forEach(function(item) { - //console.log('# dispatch action for each item', item); this.$store.dispatch('addParticipation', item); }, this ); + this.$refs.addPersons.resetSearch(); // to cast child method modal.showModal = false; } } diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js index ab26379a6..b48cb43b7 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js @@ -1,6 +1,6 @@ import 'es6-promise/auto'; import { createStore } from 'vuex'; -import addPersons from './modules/addPersons' +//import addPersons from './modules/addPersons' import { getAccompanyingCourse, postParticipation } from '../api'; const debug = process.env.NODE_ENV !== 'production'; @@ -13,7 +13,7 @@ let initPromise = getAccompanyingCourse(id) const store = createStore({ strict: debug, modules: { - addPersons + //addPersons }, state: { accompanyingCourse: accompanying_course, @@ -53,12 +53,12 @@ let initPromise = getAccompanyingCourse(id) state.errorMsg.push(error.message); }); }, - addParticipation(addPersons, payload) { + addParticipation({ commit }, payload) { //console.log('## action: fetch post participation: payload', payload.id); postParticipation(id, payload.id, 'POST') .then(participation => new Promise((resolve, reject) => { - addPersons.commit('addParticipation', participation); - addPersons.commit('resetState', payload); + commit('addParticipation', participation); + //addPersons.commit('resetState', payload); resolve(); })) .catch((error) => { diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue index e2084c711..de2a1f6f3 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue @@ -44,8 +44,10 @@ + v-bind:search="search" + @updateSelected="updateSelected"> - diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/ToggleFlags.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/ToggleFlags.vue index 12c372f12..cade04dc6 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/ToggleFlags.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/ToggleFlags.vue @@ -1,5 +1,12 @@