From 445e093a288f774d07834ac98d84572d9c213f56 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 2 Apr 2025 19:03:58 +0200 Subject: [PATCH] Emit duplication of document to an evaluation and add backend logic --- ...kEvaluationDocumentDuplicateController.php | 30 ++++++++++++++++++ .../components/DocumentsList.vue | 12 +++++-- .../components/FormEvaluation.vue | 17 ++++++++++ ...PeriodWorkEvaluationDocumentDuplicator.php | 14 +++++++++ .../ChillPersonBundle/chill.api.specs.yaml | 30 ++++++++++++++++++ .../translations/messages.fr.yml | 31 ++++++++++++++++++- 6 files changed, 130 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkEvaluationDocumentDuplicateController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkEvaluationDocumentDuplicateController.php index 033533b05..2420e4ecb 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkEvaluationDocumentDuplicateController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingPeriodWorkEvaluationDocumentDuplicateController.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Controller; use Chill\MainBundle\Routing\ChillUrlGeneratorInterface; +use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkVoter; use Chill\PersonBundle\Service\AccompanyingPeriodWorkEvaluationDocument\AccompanyingPeriodWorkEvaluationDocumentDuplicator; @@ -24,6 +25,7 @@ use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Security\Core\Security; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; use Symfony\Component\Serializer\SerializerInterface; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; class AccompanyingPeriodWorkEvaluationDocumentDuplicateController { @@ -56,6 +58,34 @@ class AccompanyingPeriodWorkEvaluationDocumentDuplicateController ); } + /** + * @ParamConverter("document", options={"id": "document_id"}) + * @ParamConverter("evaluation", options={"id": "evaluation_id"}) + */ + #[Route('/api/1.0/person/accompanying-course-work-evaluation-document/{document_id}/evaluation/{evaluation_id}/duplicate', methods: ['POST'])] + public function duplicateToEvaluationApi(AccompanyingPeriodWorkEvaluationDocument $document, AccompanyingPeriodWorkEvaluation $evaluation): Response + { + $work = $evaluation->getAccompanyingPeriodWork(); + + if (!$this->security->isGranted(AccompanyingPeriodWorkVoter::UPDATE, $work)) { + throw new AccessDeniedHttpException('not allowed to edit this accompanying period work'); + } + + $duplicatedDocument = $this->duplicator->duplicateToEvaluation($document, $evaluation); + + $this->entityManager->persist($duplicatedDocument); + $this->entityManager->persist($duplicatedDocument->getStoredObject()); + $this->entityManager->persist($evaluation); + $this->entityManager->flush(); + + dump($duplicatedDocument); + + return new JsonResponse( + $this->serializer->serialize($duplicatedDocument, 'json', [AbstractNormalizer::GROUPS => ['read']]), + json: true + ); + } + #[Route('/{_locale}/person/accompanying-course-work-evaluation-document/{id}/duplicate', name: 'chill_person_accompanying_period_work_evaluation_document_duplicate', methods: ['POST'])] public function duplicate(AccompanyingPeriodWorkEvaluationDocument $document): Response { diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/DocumentsList.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/DocumentsList.vue index 45ab10335..b4d5383c5 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/DocumentsList.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/DocumentsList.vue @@ -108,7 +108,7 @@ Dupliquer ici
  • - Dupliquer vers un autre actions d'accompagnement + Dupliquer vers un autre actions d'accompagnement
  • @@ -147,13 +147,19 @@ import AccompanyingPeriodWorkSelectorModal from "ChillPersonAssets/vuejs/_components/AccompanyingPeriodWorkSelector/AccompanyingPeriodWorkSelectorModal.vue"; defineProps(['documents', 'docAnchorId', 'accompanyingPeriodId']); -defineEmits(['inputDocumentTitle', 'removeDocument', 'duplicateDocument', 'statusDocumentChanged', 'goToGenerateWorkflow', 'goToGenerateNotification']); +const emit = defineEmits(['inputDocumentTitle', 'removeDocument', 'duplicateDocument', 'statusDocumentChanged', 'goToGenerateWorkflow', 'goToGenerateNotification', 'duplicateDocumentToWork']); const showAccompanyingPeriodSelector = ref(false); const selectedEvaluation = ref(null); +const selectedDocument = ref(null); + +const prepareDocumentDuplicationToWork = (d) => { + selectedDocument.value = d + showAccompanyingPeriodSelector.value = true +} watch(selectedEvaluation, (val) => { - console.log("selected evaluation changed:", val); + emit('duplicateDocumentToEvaluation', {'evaluation': val, 'document': selectedDocument.value}) }); diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/FormEvaluation.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/FormEvaluation.vue index 5184c9393..a30bcb25e 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/FormEvaluation.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/components/FormEvaluation.vue @@ -31,6 +31,7 @@ @inputDocumentTitle="onInputDocumentTitle" @removeDocument="removeDocument" @duplicateDocument="duplicateDocument" + @duplicate-document-to-evaluation="duplicateDocumentToEvaluation" @statusDocumentChanged="onStatusDocumentChanged" @goToGenerateWorkflow="goToGenerateWorkflowEvaluationDocument" @goToGenerateNotification="goToGenerateDocumentNotification" @@ -54,6 +55,7 @@ import TimeSpentInput from './TimeSpentInput.vue'; import CommentInput from './CommentInput.vue'; import DocumentsList from './DocumentsList.vue'; import DocumentActions from './DocumentActions.vue'; +import {makeFetch} from "ChillMainAssets/lib/api/apiMethods"; const props = defineProps(['evaluation', 'docAnchorId']); const store = useStore(); @@ -213,6 +215,21 @@ function duplicateDocument(document) { }); } +function duplicateDocumentToEvaluation({evaluation, document}) { + + const url = `/api/1.0/person/accompanying-course-work-evaluation-document/${document.id}/evaluation/${evaluation.id}/duplicate`; + console.log('document id', document.id, 'evaluation id', evaluation.id) + + makeFetch("POST", url) + .then((response) => { + console.log('new document', response) + this.$toast.open({ message: 'Le document a été dupliquer' }); + }) + .catch((error) => { + console.log(error); + }); +} + function onStatusDocumentChanged(newStatus) { store.commit('statusDocumentChanged', { key: props.evaluation.key, diff --git a/src/Bundle/ChillPersonBundle/Service/AccompanyingPeriodWorkEvaluationDocument/AccompanyingPeriodWorkEvaluationDocumentDuplicator.php b/src/Bundle/ChillPersonBundle/Service/AccompanyingPeriodWorkEvaluationDocument/AccompanyingPeriodWorkEvaluationDocumentDuplicator.php index 5ca37aa71..3da33cc79 100644 --- a/src/Bundle/ChillPersonBundle/Service/AccompanyingPeriodWorkEvaluationDocument/AccompanyingPeriodWorkEvaluationDocumentDuplicator.php +++ b/src/Bundle/ChillPersonBundle/Service/AccompanyingPeriodWorkEvaluationDocument/AccompanyingPeriodWorkEvaluationDocumentDuplicator.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Service\AccompanyingPeriodWorkEvaluationDocument; use Chill\DocStoreBundle\Service\StoredObjectDuplicate; +use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument; use Symfony\Component\Clock\ClockInterface; use Symfony\Contracts\Translation\TranslatorInterface; @@ -36,4 +37,17 @@ class AccompanyingPeriodWorkEvaluationDocumentDuplicator return $newDocument; } + + public function duplicateToEvaluation(AccompanyingPeriodWorkEvaluationDocument $document, AccompanyingPeriodWorkEvaluation $evaluation): AccompanyingPeriodWorkEvaluationDocument + { + $newDocument = new AccompanyingPeriodWorkEvaluationDocument(); + $newDocument + ->setTitle($document->getTitle().' ('.$this->translator->trans('accompanying_course_evaluation_document.duplicated_at', ['at' => $this->clock->now()]).')') + ->setStoredObject($this->storedObjectDuplicate->duplicate($document->getStoredObject())) + ; + + $evaluation->addDocument($newDocument); + + return $newDocument; + } } diff --git a/src/Bundle/ChillPersonBundle/chill.api.specs.yaml b/src/Bundle/ChillPersonBundle/chill.api.specs.yaml index 637ab399d..c5f244525 100644 --- a/src/Bundle/ChillPersonBundle/chill.api.specs.yaml +++ b/src/Bundle/ChillPersonBundle/chill.api.specs.yaml @@ -1993,3 +1993,33 @@ paths: application/json: schema: type: object + + /1.0/person/accompanying-course-work-evaluation-document/{document_id}/evaluation/{evaluation_id}/duplicate: + post: + tags: + - accompanying-course-work-evaluation-document + summary: Dupliate an an accompanying period work evaluation document to another evaluation + parameters: + - in: path + name: document_id + required: true + description: The document's id + schema: + type: integer + format: integer + minimum: 1 + - in: path + name: evaluation_id + required: true + description: The evaluation's id + schema: + type: integer + format: integer + minimum: 1 + responses: + 200: + description: "OK" + content: + application/json: + schema: + type: object diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 65f5e05f9..9b75b649e 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -746,6 +746,33 @@ evaluation: delay: Délai notificationDelay: Délai de notification url: Lien internet + title: Ecrire une évaluation + status: Statut + choose_a_status: Choisir un statut + startdate: Date d'ouverture + enddate: Date de fin + maxdate: Date d'échéance + warning_interval: Rappel (jours) + public_comment: Note publique + comment_placeholder: Commencez à écrire ... + generate_a_document: Générer un document + choose_a_template: Choisir un modèle + add_a_document: Ajouter un document + add: Ajouter une évaluation + time_spent: Temps de rédaction + select_time_spent: Indiquez le temps de rédaction + Documents: Documents + document_add: Générer ou téléverser un document + document_upload: Téléverser un document + document_title: Titre du document + template_title: Nom du template + browse: Ajouter un document + replace: Remplacer + download: Télécharger le fichier existant + notification_notify_referrer: Notifier le référent + notification_notify_any: Notifier d'autres utilisateurs + notification_send: Envoyer une notification + goal: desactivationDate: Date de désactivation @@ -770,7 +797,6 @@ relation: reverseTitle: Deuxième membre days: jours -months: mois years: années # specific to closing motive @@ -1505,3 +1531,6 @@ acpw_duplicate: Accompanying period work to keep: Action d'accompagnement à conserver to keep: Action d'accompagnement à conserver to delete: Action d'accompagnement à supprimer + +document_duplicate: + to_evaluation_success: "Le document a été dupliquer"