mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-27 17:15:02 +00:00
wip: enable moving documents to evaluations
- Add `AccompanyingPeriodWorkEvaluationDocumentMoveController` for move functionality - Update `DocumentsList.vue` to emit move event - Adjust `FormEvaluation.vue` to handle move action
This commit is contained in:
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Controller;
|
||||||
|
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument;
|
||||||
|
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkVoter;
|
||||||
|
use Chill\PersonBundle\Service\AccompanyingPeriodWorkEvaluationDocument\AccompanyingPeriodWorkEvaluationDocumentDuplicator;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||||
|
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;
|
||||||
|
|
||||||
|
readonly class AccompanyingPeriodWorkEvaluationDocumentMoveController
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private Security $security,
|
||||||
|
private SerializerInterface $serializer,
|
||||||
|
private EntityManagerInterface $entityManager,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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}/move', methods: ['POST'])]
|
||||||
|
public function moveToEvaluationApi(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');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simply set the new evaluation - Doctrine will handle the collection updates
|
||||||
|
$document->setAccompanyingPeriodWorkEvaluation($evaluation);
|
||||||
|
|
||||||
|
$this->entityManager->persist($document);
|
||||||
|
$this->entityManager->flush();
|
||||||
|
|
||||||
|
return new JsonResponse(
|
||||||
|
$this->serializer->serialize($document, 'json', [AbstractNormalizer::GROUPS => ['read']]),
|
||||||
|
json: true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@@ -293,7 +293,10 @@ watch(selectedEvaluation, (val) => {
|
|||||||
document: selectedDocumentToDuplicate.value,
|
document: selectedDocumentToDuplicate.value,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log('this is the document to move', selectedDocumentToMove.value);
|
emit("moveDocumentToEvaluation", {
|
||||||
|
evaluation: val,
|
||||||
|
document: selectedDocumentToMove.value,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@@ -259,12 +259,12 @@ function duplicateDocumentToEvaluation({ evaluation, document }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function moveDocumentToEvaluation({ evaluation, document }) {
|
function moveDocumentToEvaluation({ evaluation, document }) {
|
||||||
const url = `/api/1.0/person/accompanying-course-work-evaluation-document/${document.id}/evaluation/${evaluation.id}/duplicate`;
|
const url = `/api/1.0/person/accompanying-course-work-evaluation-document/${document.id}/evaluation/${evaluation.id}/move`;
|
||||||
// console.log('document id', document.id, 'evaluation id', evaluation.id)
|
// console.log('document id', document.id, 'evaluation id', evaluation.id)
|
||||||
|
|
||||||
makeFetch("POST", url)
|
makeFetch("POST", url)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
console.log("new document", response);
|
console.log("document", response);
|
||||||
toast.open({ message: trans(DOCUMENT_DUPLICATE_TO_EVALUATION_SUCCESS) });
|
toast.open({ message: trans(DOCUMENT_DUPLICATE_TO_EVALUATION_SUCCESS) });
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
Reference in New Issue
Block a user