diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index 75c2aeaf6..2bb40d432 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -61,7 +61,7 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac /** * @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod") - * @Groups({"read", "docgen:read"}) + * @Groups({"read"}) */ private ?AccompanyingPeriod $accompanyingPeriod = null; @@ -75,16 +75,19 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac /** * @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityPresence") + * @Groups({"docgen:read"}) */ private ?ActivityPresence $attendee = null; /** * @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="comment_") + * @Groups({"docgen:read"}) */ private CommentEmbeddable $comment; /** * @ORM\Column(type="datetime") + * @Groups({"docgen:read"}) */ private DateTime $date; @@ -100,6 +103,7 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac /** * @ORM\Column(type="boolean", options={"default": false}) + * @Groups({"docgen:read"}) */ private bool $emergency = false; @@ -130,16 +134,19 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac /** * @ORM\ManyToMany(targetEntity="Chill\ActivityBundle\Entity\ActivityReason") + * @Groups({"docgen:read"}) */ private Collection $reasons; /** * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Scope") + * @Groups({"docgen:read"}) */ private ?Scope $scope = null; /** * @ORM\Column(type="string", options={"default": ""}) + * @Groups({"docgen:read"}) */ private string $sentReceived = ''; @@ -170,12 +177,13 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac /** * @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User") + * @Groups({"docgen:read"}) */ private User $user; /** * @ORM\ManyToMany(targetEntity="Chill\MainBundle\Entity\User") - * @Groups({"read"}) + * @Groups({"read", "docgen:read"}) */ private ?Collection $users = null; @@ -302,6 +310,18 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac return $this->documents; } + /** + * @Groups({"docgen:read"}) + */ + public function getDurationMinute(): int + { + if (null === $this->durationTime) { + return 0; + } + + return (int) round(($this->durationTime->getTimestamp() + $this->durationTime->getOffset()) / 60.0, 0); + } + public function getDurationTime(): ?DateTime { return $this->durationTime; @@ -402,6 +422,18 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac return $this->travelTime; } + /** + * @Groups({"docgen:read"}) + */ + public function getTravelTimeMinute(): int + { + if (null === $this->travelTime) { + return 0; + } + + return (int) round(($this->travelTime->getTimestamp() + $this->travelTime->getOffset()) / 60.0, 0); + } + /** * @deprecated */ diff --git a/src/Bundle/ChillActivityBundle/Entity/ActivityPresence.php b/src/Bundle/ChillActivityBundle/Entity/ActivityPresence.php index 725b1eb8e..89f616dc2 100644 --- a/src/Bundle/ChillActivityBundle/Entity/ActivityPresence.php +++ b/src/Bundle/ChillActivityBundle/Entity/ActivityPresence.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\ActivityBundle\Entity; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Serializer\Annotation as Serializer; /** * Class ActivityPresence. @@ -31,11 +32,14 @@ class ActivityPresence * @ORM\Id * @ORM\Column(name="id", type="integer") * @ORM\GeneratedValue(strategy="AUTO") + * @Serializer\Groups({"docgen:read"}) */ private ?int $id; /** * @ORM\Column(type="json") + * @Serializer\Groups({"docgen:read"}) + * @Serializer\Context({"is-translatable": true}, groups={"docgen:read"}) */ private array $name = []; diff --git a/src/Bundle/ChillActivityBundle/Entity/ActivityType.php b/src/Bundle/ChillActivityBundle/Entity/ActivityType.php index 5ad692bf4..c7448e07d 100644 --- a/src/Bundle/ChillActivityBundle/Entity/ActivityType.php +++ b/src/Bundle/ChillActivityBundle/Entity/ActivityType.php @@ -13,6 +13,7 @@ namespace Chill\ActivityBundle\Entity; use Doctrine\ORM\Mapping as ORM; use InvalidArgumentException; +use Symfony\Component\Serializer\Annotation as Serializer; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Validator\Constraints as Assert; @@ -118,6 +119,7 @@ class ActivityType * @ORM\Id * @ORM\Column(name="id", type="integer") * @ORM\GeneratedValue(strategy="AUTO") + * @Groups({"docgen:read"}) */ private ?int $id; @@ -133,7 +135,8 @@ class ActivityType /** * @ORM\Column(type="json") - * @Groups({"read"}) + * @Groups({"read", "docgen:read"}) + * @Serializer\Context({"is-translatable": true}, groups={"docgen:read"}) */ private array $name = []; diff --git a/src/Bundle/ChillDocGeneratorBundle/Resources/public/vuejs/_components/PickTemplate.vue b/src/Bundle/ChillDocGeneratorBundle/Resources/public/vuejs/_components/PickTemplate.vue index f1fb6c84b..04d563782 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Resources/public/vuejs/_components/PickTemplate.vue +++ b/src/Bundle/ChillDocGeneratorBundle/Resources/public/vuejs/_components/PickTemplate.vue @@ -17,7 +17,7 @@ @@ -48,6 +48,7 @@ export default { required: true, }, templates: { + type: Array, required: true, }, // beforeMove execute "something" before @@ -73,7 +74,11 @@ export default { return true; }, getDescription() { - return this.templates.find(t => t.id === this.template).description || ''; + let desc = this.templates.find(t => t.id === this.template); + if (null === desc) { + return ''; + } + return desc.description || ''; }, }, methods: { diff --git a/src/Bundle/ChillMainBundle/Entity/Location.php b/src/Bundle/ChillMainBundle/Entity/Location.php index 8496374d8..bff3ff37b 100644 --- a/src/Bundle/ChillMainBundle/Entity/Location.php +++ b/src/Bundle/ChillMainBundle/Entity/Location.php @@ -64,7 +64,7 @@ class Location implements TrackCreationInterface, TrackUpdateInterface /** * @ORM\Column(type="string", length=255, nullable=true) - * @Serializer\Groups({"read", "write"}) + * @Serializer\Groups({"read", "write", "docgen:read"}) */ private ?string $email = null; diff --git a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php index c6c205a47..95c447119 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php +++ b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php @@ -45,8 +45,6 @@ class EntityToJsonTransformer implements DataTransformerInterface { $denormalized = json_decode($value, true); - dump($value); - if ($this->multiple) { if (null === $denormalized) { return []; 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 c3786f137..1fd6b34f7 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js @@ -7,7 +7,6 @@ const i18n = _createI18n(appMessages); let appsOnPage = new Map(); - function loadDynamicPicker(element) { let apps = element.querySelectorAll('[data-module="pick-dynamic"]'); @@ -75,23 +74,23 @@ function loadDynamicPicker(element) { } -// document.addEventListener('show-hide-show', function(e) { -// console.log('creation event caught') -// loadDynamicPicker(e.detail.container) -// }) +document.addEventListener('show-hide-show', function(e) { + console.log('creation event caught') + loadDynamicPicker(e.detail.container) +}) -// document.addEventListener('show-hide-hide', function(e) { -// console.log('hiding event caught') -// e.detail.container.querySelectorAll('[data-module="pick-dynamic"]').forEach((el) => { -// let uniqId = el.dataset.uniqid; -// console.log(uniqId); -// if (appsOnPage.has(uniqId)) { -// appsOnPage.get(uniqId).unmount(); -// console.log('App has been unmounted') -// appsOnPage.delete(uniqId); -// } -// }) -// }) +document.addEventListener('show-hide-hide', function(e) { + console.log('hiding event caught') + e.detail.container.querySelectorAll('[data-module="pick-dynamic"]').forEach((el) => { + let uniqId = el.dataset.uniqid; + console.log(uniqId); + if (appsOnPage.has(uniqId)) { + appsOnPage.get(uniqId).unmount(); + console.log('App has been unmounted') + appsOnPage.delete(uniqId); + } + }) +}) document.addEventListener('DOMContentLoaded', function(e) { console.log('loaded event', e) diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/CommentEmbeddableDocGenNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/CommentEmbeddableDocGenNormalizer.php new file mode 100644 index 000000000..e5a37c430 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/CommentEmbeddableDocGenNormalizer.php @@ -0,0 +1,88 @@ +userRepository = $userRepository; + } + + /** + * @param CommentEmbeddable $object + * + * @throws ExceptionInterface + */ + public function normalize($object, ?string $format = null, array $context = []): array + { + if (null === $object) { + return [ + 'comment' => '', + 'isNull' => true, + 'date' => $this->normalizer->normalize(null, $format, array_merge($context, [ + 'docgen:expects' => DateTime::class, + ])), + 'user' => $this->normalizer->normalize(null, $format, array_merge($context, [ + 'docgen:expects' => User::class, + ])), + ]; + } + + $user = $this->userRepository->find($object->getUserId()); + + return [ + 'comment' => (string) $object->getComment(), + 'isNull' => false, + 'date' => $this->normalizer->normalize($object->getDate(), $format, array_merge($context, [ + 'docgen:expects' => DateTime::class, + ])), + 'user' => $this->normalizer->normalize($user, $format, array_merge($context, [ + 'docgen:expects' => User::class, + ])), + ]; + } + + public function supportsNormalization($data, ?string $format = null, array $context = []): bool + { + if ('docgen' !== $format) { + return false; + } + + if ($data instanceof CommentEmbeddable) { + return true; + } + + if ( + null === $data + && array_key_exists('docgen:expects', $context) + && CommentEmbeddable::class === $context['docgen:expects']) { + return true; + } + + return false; + } +} diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkEvaluationApiController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkEvaluationApiController.php index de9433558..cc918c1db 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkEvaluationApiController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkEvaluationApiController.php @@ -69,7 +69,7 @@ class AccompanyingPeriodWorkEvaluationApiController $paginator->setItemsPerPage(count($evaluations)); return new JsonResponse($this->serializer->serialize( - new Collection($evaluations, $paginator), + new Collection(array_values($evaluations), $paginator), 'json', [ AbstractNormalizer::GROUPS => ['read'], diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php b/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php index e35e94ac2..577a271e8 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php @@ -114,8 +114,6 @@ final class PersonResourceController extends AbstractController ]); } - dump($resource); - return $this->render( 'ChillPersonBundle:PersonResource:edit.html.twig', [ @@ -139,7 +137,7 @@ final class PersonResourceController extends AbstractController $form->handleRequest($request); - if ($request->getMethod() === Request::METHOD_POST && $form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { $this->denyAccessUnlessGranted(PersonVoter::CREATE, $personOwner); $personResource = new PersonResource(); diff --git a/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php b/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php index 4e1718a64..cdd928598 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php @@ -12,13 +12,12 @@ 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\MainBundle\Entity\User; use Chill\PersonBundle\Entity\Person; use Chill\ThirdPartyBundle\Entity\ThirdParty; -use DateTime; -use DateTimeInterface; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\DiscriminatorMap; use Symfony\Component\Serializer\Annotation\Groups; @@ -34,28 +33,20 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; */ class PersonResource implements TrackCreationInterface, TrackUpdateInterface { + use TrackCreationTrait; + use TrackUpdateTrait; + /** * @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="comment_") * @Groups({"read"}) */ private CommentEmbeddable $comment; - /** - * @ORM\Column(type="datetime") - */ - private $createdAt; - - /** - * @ORM\ManyToOne(targetEntity=User::class) - * @ORM\JoinColumn(nullable=false) - */ - private User $createdBy; - /** * @ORM\Column(type="text", nullable=true) * @Groups({"read"}) */ - private $freeText; + private ?string $freeText = null; /** * @ORM\Id @@ -92,16 +83,6 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface */ private ?ThirdParty $thirdParty = null; - /** - * @ORM\Column(type="datetime", nullable=true) - */ - private $updatedAt; - - /** - * @ORM\ManyToOne(targetEntity=User::class) - */ - private User $updatedBy; - public function __construct() { $this->comment = new CommentEmbeddable(); @@ -112,16 +93,6 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface return $this->comment; } - public function getCreatedAt(): ?DateTimeInterface - { - return $this->createdAt; - } - - public function getCreatedBy(): ?User - { - return $this->createdBy; - } - public function getFreeText(): ?string { return $this->freeText; @@ -155,16 +126,6 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface return $this->thirdParty; } - public function getUpdatedAt(): ?DateTimeInterface - { - return $this->updatedAt; - } - - public function getUpdatedBy(): ?User - { - return $this->updatedBy; - } - public function setComment(?CommentEmbeddable $comment): self { if (null === $comment) { @@ -178,23 +139,6 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface return $this; } - public function setCreatedAt(DateTimeInterface $createdAt): self - { - $this->createdAt = $createdAt; - - return $this; - } - - public function setCreatedBy(?User $createdBy): self - { - $this->createdBy = $createdBy; - - return $this; - } - - /** - * SETTERS. - */ public function setFreeText(?string $freeText): self { $this->freeText = $freeText; @@ -204,6 +148,10 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface $this->setThirdParty(null); } + if ('' === $freeText) { + $this->freeText = null; + } + return $this; } @@ -245,20 +193,6 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface return $this; } - public function setUpdatedAt(DateTimeInterface $updatedAt): self - { - $this->updatedAt = $updatedAt; - - return $this; - } - - public function setUpdatedBy(?User $updatedBy): self - { - $this->updatedBy = $updatedBy; - - return $this; - } - /** * @Assert\Callback * @@ -266,9 +200,8 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface */ public function validate(ExecutionContextInterface $context, $payload) { - if (null === $this->person && null === $this->thirdParty && null === $this->freeText) { + if (null === $this->person && null === $this->thirdParty && (null === $this->freeText || '' === $this->freeText)) { $context->buildViolation('You must associate at least one entity') - ->atPath('person') ->addViolation(); } } diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js index 21ec4b168..a46a0e221 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js @@ -58,7 +58,11 @@ const store = createStore({ return state.thirdParties.length > 0; }, getTemplatesAvailablesForEvaluation: (state) => (evaluation) => { - return state.templatesAvailablesForEvaluation.get(evaluation.id) || []; + if (state.templatesAvailablesForEvaluation.has(evaluation.id)) { + return state.templatesAvailablesForEvaluation.get(evaluation.id); + } + + return []; }, buildPayload(state) { return { @@ -171,7 +175,6 @@ const store = createStore({ }; g.id = tmpIndex() -1 state.goalsPicked.push(g); - //console.log('goals picked ids', state.goalsPicked.map(g => g.id)) }, removeGoal(state, goal) { state.goalsPicked = state.goalsPicked.filter(g => g.id !== goal.id); @@ -369,7 +372,6 @@ const store = createStore({ return makeFetch('PUT', url, payload) .then(data => { - console.log('data received', data); if (typeof(callback) !== 'undefined') { return callback(data); } else { diff --git a/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/create.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/create.html.twig index 6e05f2d6d..8fea0bd70 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/create.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/create.html.twig @@ -1,5 +1,6 @@