From ee45ff61a6f6497fb8f50be02b7245603d1ef1fb Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 31 Jul 2024 14:55:35 +0200 Subject: [PATCH 1/8] Reorganize person resource code to create an abstract class --- .../Entity/Person/AbstractPersonResource.php | 190 ++++++++++++++++++ .../Entity/Person/PersonResource.php | 177 +--------------- 2 files changed, 191 insertions(+), 176 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Entity/Person/AbstractPersonResource.php diff --git a/src/Bundle/ChillPersonBundle/Entity/Person/AbstractPersonResource.php b/src/Bundle/ChillPersonBundle/Entity/Person/AbstractPersonResource.php new file mode 100644 index 000000000..a13670b97 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Entity/Person/AbstractPersonResource.php @@ -0,0 +1,190 @@ +comment = new CommentEmbeddable(); + } + + public function getComment(): CommentEmbeddable + { + return $this->comment; + } + + public function getFreeText(): ?string + { + return $this->freeText; + } + + public function getKind(): ?PersonResourceKind + { + return $this->kind; + } + + public function getPerson(): ?Person + { + return $this->person; + } + + public function getPersonOwner(): ?Person + { + return $this->personOwner; + } + + /** + * @Groups({"read", "docgen:read"}) + */ + public function getResourceKind(): string + { + if ($this->getPerson() instanceof Person) { + return 'person'; + } + + if ($this->getThirdParty() instanceof ThirdParty) { + return 'thirdparty'; + } + + if (null !== $this->getFreeText()) { + return 'freetext'; + } + + return 'none'; + } + + public function getThirdParty(): ?ThirdParty + { + return $this->thirdParty; + } + + public function setComment(?CommentEmbeddable $comment): self + { + if (null === $comment) { + $this->comment->setComment(''); + + return $this; + } + + $this->comment = $comment; + + return $this; + } + + public function setFreeText(?string $freeText): self + { + $this->freeText = $freeText; + + if ('' !== $freeText && null !== $freeText) { + $this->setPerson(null); + $this->setThirdParty(null); + } + + if ('' === $freeText) { + $this->freeText = null; + } + + return $this; + } + + public function setKind(?PersonResourceKind $kind): self + { + $this->kind = $kind; + + return $this; + } + + public function setPerson(?Person $person): self + { + $this->person = $person; + + if (null !== $person) { + $this->setFreeText(''); + $this->setThirdParty(null); + } + + return $this; + } + + public function setPersonOwner(?Person $personOwner): self + { + $this->personOwner = $personOwner; + + return $this; + } + + public function setThirdParty(?ThirdParty $thirdParty): self + { + $this->thirdParty = $thirdParty; + + if (null !== $thirdParty) { + $this->setFreeText(''); + $this->setPerson(null); + } + + return $this; + } + + /** + * @Assert\Callback + */ + public function validate(ExecutionContextInterface $context, mixed $payload): void + { + if (null === $this->person && null === $this->thirdParty && (null === $this->freeText || '' === $this->freeText)) { + $context->buildViolation('You must associate at least one entity') + ->addViolation(); + } + + if (null !== $this->person && $this->person === $this->personOwner) { + $context->buildViolation('You cannot associate a resource with the same person') + ->addViolation(); + } + } + +} diff --git a/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php b/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php index dec0ea87a..0fac5689d 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php @@ -27,191 +27,16 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; #[Serializer\DiscriminatorMap(typeProperty: 'type', mapping: ['personResource' => PersonResource::class])] #[ORM\Entity] #[ORM\Table(name: 'chill_person_resource')] -class PersonResource implements TrackCreationInterface, TrackUpdateInterface +class PersonResource extends AbstractPersonResource implements TrackCreationInterface, TrackUpdateInterface { - use TrackCreationTrait; - - use TrackUpdateTrait; - - #[Groups(['read', 'docgen:read'])] - #[ORM\Embedded(class: CommentEmbeddable::class, columnPrefix: 'comment_')] - private CommentEmbeddable $comment; - - #[Groups(['read', 'docgen:read'])] - #[ORM\Column(type: \Doctrine\DBAL\Types\Types::TEXT, nullable: true)] - private ?string $freeText = null; - #[Groups(['read', 'docgen:read'])] #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: \Doctrine\DBAL\Types\Types::INTEGER)] private ?int $id = null; - #[Groups(['read', 'docgen:read'])] - #[ORM\ManyToOne(targetEntity: PersonResourceKind::class, inversedBy: 'personResources')] - #[ORM\JoinColumn(nullable: true)] - private ?PersonResourceKind $kind = null; - - /** - * The person which host the owner of this resource. - */ - #[Groups(['read', 'docgen:read'])] - #[ORM\ManyToOne(targetEntity: Person::class)] - #[ORM\JoinColumn(nullable: true)] - private ?Person $person = null; - - /** - * The person linked with this resource. - */ - #[Groups(['read'])] - #[ORM\ManyToOne(targetEntity: Person::class, inversedBy: 'resources')] - #[ORM\JoinColumn(nullable: false)] - private ?Person $personOwner = null; - - #[Groups(['read', 'docgen:read'])] - #[ORM\ManyToOne(targetEntity: ThirdParty::class, inversedBy: 'personResources')] - #[ORM\JoinColumn(nullable: true)] - private ?ThirdParty $thirdParty = null; - - public function __construct() - { - $this->comment = new CommentEmbeddable(); - } - - public function getComment(): CommentEmbeddable - { - return $this->comment; - } - - public function getFreeText(): ?string - { - return $this->freeText; - } - - /** - * GETTERS. - */ public function getId(): ?int { return $this->id; } - - public function getKind(): ?PersonResourceKind - { - return $this->kind; - } - - public function getPerson(): ?Person - { - return $this->person; - } - - public function getPersonOwner(): ?Person - { - return $this->personOwner; - } - - #[Groups(['read', 'docgen:read'])] - public function getResourceKind(): string - { - if ($this->getPerson() instanceof Person) { - return 'person'; - } - - if ($this->getThirdParty() instanceof ThirdParty) { - return 'thirdparty'; - } - - if (null !== $this->getFreeText()) { - return 'freetext'; - } - - return 'none'; - } - - public function getThirdParty(): ?ThirdParty - { - return $this->thirdParty; - } - - public function setComment(?CommentEmbeddable $comment): self - { - if (null === $comment) { - $this->comment->setComment(''); - - return $this; - } - - $this->comment = $comment; - - return $this; - } - - public function setFreeText(?string $freeText): self - { - $this->freeText = $freeText; - - if ('' !== $freeText && null !== $freeText) { - $this->setPerson(null); - $this->setThirdParty(null); - } - - if ('' === $freeText) { - $this->freeText = null; - } - - return $this; - } - - public function setKind(?PersonResourceKind $kind): self - { - $this->kind = $kind; - - return $this; - } - - public function setPerson(?Person $person): self - { - $this->person = $person; - - if (null !== $person) { - $this->setFreeText(''); - $this->setThirdParty(null); - } - - return $this; - } - - public function setPersonOwner(?Person $personOwner): self - { - $this->personOwner = $personOwner; - - return $this; - } - - public function setThirdParty(?ThirdParty $thirdParty): self - { - $this->thirdParty = $thirdParty; - - if (null !== $thirdParty) { - $this->setFreeText(''); - $this->setPerson(null); - } - - return $this; - } - - #[Assert\Callback] - public function validate(ExecutionContextInterface $context, mixed $payload) - { - if (null === $this->person && null === $this->thirdParty && (null === $this->freeText || '' === $this->freeText)) { - $context->buildViolation('You must associate at least one entity') - ->addViolation(); - } - - if (null !== $this->person && $this->person === $this->personOwner) { - $context->buildViolation('You cannot associate a resource with the same person') - ->addViolation(); - } - } } From 2f9884072cc41cb868c8d33d92c37f3017a056b5 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 31 Jul 2024 15:12:36 +0200 Subject: [PATCH 2/8] Add missing use statement for Groups annotation --- .../ChillPersonBundle/Entity/Person/AbstractPersonResource.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Bundle/ChillPersonBundle/Entity/Person/AbstractPersonResource.php b/src/Bundle/ChillPersonBundle/Entity/Person/AbstractPersonResource.php index a13670b97..c3c87dc97 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person/AbstractPersonResource.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person/AbstractPersonResource.php @@ -12,6 +12,7 @@ use Chill\ThirdPartyBundle\Entity\ThirdParty; use Symfony\Component\Validator\Context\ExecutionContextInterface; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation as Serializer; +use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; #[ORM\MappedSuperclass] From d52e54fd2af8c8b5859665480f29febe9e758f52 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 14 Aug 2024 13:38:58 +0200 Subject: [PATCH 3/8] Make loadDynamicPicker available within windows where dynamicPicker tags are added --- .../Resources/public/module/pick-entity/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js b/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js index 6b33c0f52..03220630f 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js @@ -159,3 +159,5 @@ document.addEventListener('DOMContentLoaded', function(e) { loadDynamicPicker(document) }) +window.loadDynamicPicker = loadDynamicPicker; + From 6445342136f3a0cfaf43ce14c6895572da7f4ed0 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 14 Aug 2024 14:23:03 +0200 Subject: [PATCH 4/8] Fix remove button not showing in CollectionType forms with allow_delete option --- .../ChillMainBundle/Resources/public/module/collection/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/Resources/public/module/collection/index.ts b/src/Bundle/ChillMainBundle/Resources/public/module/collection/index.ts index de428335d..b48324786 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/module/collection/index.ts +++ b/src/Bundle/ChillMainBundle/Resources/public/module/collection/index.ts @@ -60,7 +60,7 @@ export const handleAdd = (button: any): void => { entry.innerHTML = content; entry.classList.add('entry'); - if ("dataCollectionRegular" in collection.dataset) { + if ("collectionRegular" in collection.dataset) { initializeRemove(collection, entry); if (empty_explain !== null) { empty_explain.remove(); From c0c448fb390c665937f41342c56841cc74f544fb Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 14 Aug 2024 14:26:04 +0200 Subject: [PATCH 5/8] Remove dump from code --- .../ACPFilters/PeriodHavingActivityBetweenDatesFilter.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/PeriodHavingActivityBetweenDatesFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/PeriodHavingActivityBetweenDatesFilter.php index 2b30a075c..03cb00be1 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/PeriodHavingActivityBetweenDatesFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ACPFilters/PeriodHavingActivityBetweenDatesFilter.php @@ -80,8 +80,6 @@ final readonly class PeriodHavingActivityBetweenDatesFilter implements FilterInt $qb ->setParameter($from, $this->rollingDateConverter->convert($data['start_date'])) ->setParameter($to, $this->rollingDateConverter->convert($data['end_date'])); - - dump($qb->getQuery()->getResult()); } public function applyOn() From 85811cc6ae693264aa3095f0e971fa274aae0505 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 14 Aug 2024 14:45:59 +0200 Subject: [PATCH 6/8] Run php-cs-fixer and rector --- .../Entity/Person/AbstractPersonResource.php | 25 ++++++++++++------- .../Entity/Person/PersonResource.php | 7 ------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Entity/Person/AbstractPersonResource.php b/src/Bundle/ChillPersonBundle/Entity/Person/AbstractPersonResource.php index c3c87dc97..cfdf88555 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person/AbstractPersonResource.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person/AbstractPersonResource.php @@ -1,5 +1,14 @@ addViolation(); } } - } diff --git a/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php b/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php index 0fac5689d..4c86f8c4c 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php @@ -12,17 +12,10 @@ declare(strict_types=1); namespace Chill\PersonBundle\Entity\Person; use Chill\MainBundle\Doctrine\Model\TrackCreationInterface; -use Chill\MainBundle\Doctrine\Model\TrackCreationTrait; use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface; -use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait; -use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; -use Chill\PersonBundle\Entity\Person; -use Chill\ThirdPartyBundle\Entity\ThirdParty; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation as Serializer; use Symfony\Component\Serializer\Annotation\Groups; -use Symfony\Component\Validator\Constraints as Assert; -use Symfony\Component\Validator\Context\ExecutionContextInterface; #[Serializer\DiscriminatorMap(typeProperty: 'type', mapping: ['personResource' => PersonResource::class])] #[ORM\Entity] From 305105faae70361ad31aee25118579d8a526dfe0 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 14 Aug 2024 15:27:00 +0200 Subject: [PATCH 7/8] Fix CalendarContextTest after faulty php cs fix --- .../Tests/Service/DocGenerator/CalendarContextTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Tests/Service/DocGenerator/CalendarContextTest.php b/src/Bundle/ChillCalendarBundle/Tests/Service/DocGenerator/CalendarContextTest.php index 4a4b4f7d4..c06872a66 100644 --- a/src/Bundle/ChillCalendarBundle/Tests/Service/DocGenerator/CalendarContextTest.php +++ b/src/Bundle/ChillCalendarBundle/Tests/Service/DocGenerator/CalendarContextTest.php @@ -47,7 +47,7 @@ final class CalendarContextTest extends TestCase { $expected = [ - 'track_datetime' => true, + 'trackDatetime' => true, 'askMainPerson' => true, 'mainPersonLabel' => 'docgen.calendar.Destinee', 'askThirdParty' => false, @@ -61,7 +61,7 @@ final class CalendarContextTest extends TestCase { $expected = [ - 'track_datetime' => true, + 'trackDatetime' => true, 'askMainPerson' => true, 'mainPersonLabel' => 'docgen.calendar.Destinee', 'askThirdParty' => false, From 6e2a08cae8943e959194bb059b49cb797df04cef Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 21 Aug 2024 10:22:13 +0200 Subject: [PATCH 8/8] Resolve multiple entries not being saved in collectiontype --- .../Resources/public/module/collection/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/public/module/collection/index.ts b/src/Bundle/ChillMainBundle/Resources/public/module/collection/index.ts index b48324786..875e99fad 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/module/collection/index.ts +++ b/src/Bundle/ChillMainBundle/Resources/public/module/collection/index.ts @@ -53,10 +53,13 @@ export const handleAdd = (button: any): void => { let empty_explain: HTMLLIElement | null = collection.querySelector('li[data-collection-empty-explain]'), entry = document.createElement('li'), - counter = collection.childNodes.length + 1, - content = prototype.replace(new RegExp('__name__', 'g'), counter.toString()), + counter = collection.querySelectorAll('li.entry').length, // Updated counter logic + content = prototype.replace(/__name__/g, counter.toString()), event = new CustomEvent('collection-add-entry', {detail: new CollectionEventPayload(collection, entry)}); + console.log(counter) + console.log(content) + entry.innerHTML = content; entry.classList.add('entry');