@@ -142,6 +152,8 @@ import { mapGetters, mapState } from 'vuex';
import PickTemplate from 'ChillDocGeneratorAssets/vuejs/_components/PickTemplate.vue';
import {buildLink} from 'ChillDocGeneratorAssets/lib/document-generator';
import AddAsyncUpload from 'ChillDocStoreAssets/vuejs/_components/AddAsyncUpload.vue';
+import ListWorkflowModal from 'ChillMainAssets/vuejs/_components/EntityWorkflow/ListWorkflowModal.vue';
+import {buildLinkCreate} from 'ChillMainAssets/lib/entity-workflow/api.js';
const i18n = {
messages: {
@@ -175,7 +187,8 @@ export default {
components: {
ckeditor: CKEditor.component,
PickTemplate,
- AddAsyncUpload
+ AddAsyncUpload,
+ ListWorkflowModal,
},
i18n,
data() {
@@ -189,9 +202,6 @@ export default {
}
}
},
- mounted() {
- console.log(this.evaluation)
- },
computed: {
...mapState([
'isPosting'
@@ -279,7 +289,18 @@ export default {
if (window.confirm("Êtes-vous sûr·e de vouloir supprimer le document qui a pour titre \"" + document.title +"\" ?")) {
this.$store.commit('removeDocument', {key: this.evaluation.key, document: document});
}
- }
+ },
+ goToGenerateWorkflowEvaluationDocument({event, link, workflowName, payload}) {
+ const callback = (data) => {
+ let evaluation = data.accompanyingPeriodWorkEvaluations.find(e => e.key === this.evaluation.key);
+ let updatedDocument = evaluation.documents.find(d => d.key === payload.doc.key);
+ window.location.assign(buildLinkCreate(workflowName,
+ 'Chill\\PersonBundle\\Entity\\AccompanyingPeriod\\AccompanyingPeriodWorkEvaluationDocument', updatedDocument.id));
+ };
+
+ return this.$store.dispatch('submit', callback)
+ .catch(e => { console.log(e); throw e; });
+ },
},
}
diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js
index 89c6c8811..7f96843e5 100644
--- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js
+++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js
@@ -131,6 +131,11 @@ const store = createStore({
endDate: e.endDate !== null ? ISOToDatetime(e.endDate.datetime) : null,
maxDate: e.maxDate !== null ? ISOToDatetime(e.maxDate.datetime) : null,
warningInterval: e.warningInterval !== null ? intervalISOToDays(e.warningInterval) : null,
+ documents: e.documents.map((d, dindex) => {
+ return Object.assign(d, {
+ key: index
+ });
+ }),
});
return k;
@@ -199,16 +204,22 @@ const store = createStore({
found.results = found.results.filter(r => r.id !== result.id);
},
addDocument(state, payload) {
- state.evaluationsPicked.find(e => e.key === payload.key).documents.push(payload.document);
+ let evaluation = state.evaluationsPicked.find(e => e.key === payload.key);
+ evaluation.documents.push(Object.assign(
+ payload.document, {
+ key: evaluation.documents.length + 1,
+ workflows_availables: state.work.workflows_availables_evaluation_documents,
+ workflows: [],
+ }));
},
- removeDocument(state, payload) {
- let evaluations = state.evaluationsPicked.find(e => e.key === payload.key);
+ removeDocument(state, {key, document}) {
+ let evaluations = state.evaluationsPicked.find(e => e.key === key);
if (evaluations === undefined) {
return;
}
- evaluations.documents = evaluations.documents.filter(d => d.id !== payload.document.id);
+ evaluations.documents = evaluations.documents.filter(d => d.key !== document.key);
},
addEvaluation(state, evaluation) {
let e = {
diff --git a/src/Bundle/ChillPersonBundle/Security/Authorization/AccompanyingPeriodWorkEvaluationDocumentVoter.php b/src/Bundle/ChillPersonBundle/Security/Authorization/AccompanyingPeriodWorkEvaluationDocumentVoter.php
index b3b6dab56..7ce259714 100644
--- a/src/Bundle/ChillPersonBundle/Security/Authorization/AccompanyingPeriodWorkEvaluationDocumentVoter.php
+++ b/src/Bundle/ChillPersonBundle/Security/Authorization/AccompanyingPeriodWorkEvaluationDocumentVoter.php
@@ -1,14 +1,24 @@
accessDecisionManager->decide($token, [AccompanyingPeriodWorkEvaluationVoter::SEE],
- $subject->getAccompanyingPeriodWorkEvaluation());
+ return $this->accessDecisionManager->decide(
+ $token,
+ [AccompanyingPeriodWorkEvaluationVoter::SEE],
+ $subject->getAccompanyingPeriodWorkEvaluation()
+ );
default:
- throw new \UnexpectedValueException("The attribute $attribute is not supported");
+ throw new UnexpectedValueException("The attribute {$attribute} is not supported");
}
}
-
-
}
diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDenormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDenormalizer.php
index 12bd254c5..4680d9fa7 100644
--- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDenormalizer.php
+++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDenormalizer.php
@@ -23,7 +23,6 @@ use Symfony\Component\Serializer\Normalizer\ObjectToPopulateTrait;
use function array_key_exists;
use function array_merge;
-use function in_array;
use function is_array;
/**
@@ -33,6 +32,7 @@ use function is_array;
class AccompanyingPeriodWorkEvaluationDenormalizer implements ContextAwareDenormalizerInterface, DenormalizerAwareInterface
{
use DenormalizerAwareTrait;
+
use ObjectToPopulateTrait;
private EntityManagerInterface $em;
@@ -54,9 +54,7 @@ class AccompanyingPeriodWorkEvaluationDenormalizer implements ContextAwareDenorm
['skip' => self::class]
));
- //if (in_array('accompanying_period_work:edit', $context['groups'] ?? [], true)) {
- $this->handleEvaluationCollection($data, $evaluation, $format, $context);
- //}
+ $this->handleDocumentCollection($data, $evaluation, $format, $context);
return $evaluation;
}
@@ -70,7 +68,7 @@ class AccompanyingPeriodWorkEvaluationDenormalizer implements ContextAwareDenorm
&& 'accompanying_period_work_evaluation' === $data['type'];
}
- private function handleEvaluationCollection(array $data, AccompanyingPeriodWorkEvaluation $evaluation, string $format, array $context)
+ private function handleDocumentCollection(array $data, AccompanyingPeriodWorkEvaluation $evaluation, string $format, array $context)
{
$dataById = [];
$dataWithoutId = [];
@@ -82,29 +80,21 @@ class AccompanyingPeriodWorkEvaluationDenormalizer implements ContextAwareDenorm
$dataWithoutId[] = $e;
}
}
- dump($dataById);
- dump($dataWithoutId);
- dump($evaluation);
//partition the separate kept documents and removed one
[$kept, $removed] = $evaluation->getDocuments()
->partition(
static fn (int $key, AccompanyingPeriodWorkEvaluationDocument $a) => array_key_exists($a->getId(), $dataById)
);
- //$kept = $evaluation->getDocuments();
- dump($kept);
- dump($removed);
+
// remove the document from evaluation
foreach ($removed as $r) {
- dump($r);
$evaluation->removeDocument($r);
}
+
// handle the documents kept
foreach ($kept as $k) {
- dump($k); // Cannot iterate over $kept which is a PersistentCollection
- $evaluation->removeDocument($k);
- dump($evaluation);
- $document = $this->denormalizer->denormalize(
+ $this->denormalizer->denormalize(
$dataById[$k->getId()],
AccompanyingPeriodWorkEvaluationDocument::class,
$format,
@@ -116,12 +106,9 @@ class AccompanyingPeriodWorkEvaluationDenormalizer implements ContextAwareDenorm
]
)
);
-
- $evaluation->addDocument($document);
}
// create new document
foreach ($dataWithoutId as $newData) {
- dump($newData);
$document = $this->denormalizer->denormalize(
$newData,
AccompanyingPeriodWorkEvaluationDocument::class,
diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDocumentNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDocumentNormalizer.php
new file mode 100644
index 000000000..cf3033e65
--- /dev/null
+++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationDocumentNormalizer.php
@@ -0,0 +1,71 @@
+entityWorkflowRepository = $entityWorkflowRepository;
+ $this->metadataExtractor = $metadataExtractor;
+ $this->registry = $registry;
+ }
+
+ public function normalize($object, ?string $format = null, array $context = []): array
+ {
+ $initial = $this->normalizer->normalize($object, $format, array_merge($context, [
+ self::SKIP => spl_object_hash($object),
+ ]));
+
+ $initial['workflows_availables'] = $this->metadataExtractor->availableWorkflowFor(
+ AccompanyingPeriodWorkEvaluationDocument::class,
+ $object->getId()
+ );
+
+ $workflows = $this->entityWorkflowRepository->findBy([
+ 'relatedEntityClass' => AccompanyingPeriodWorkEvaluationDocument::class,
+ 'relatedEntityId' => $object->getId(),
+ ]);
+ $initial['workflows'] = $this->normalizer->normalize($workflows, 'json', $context);
+
+ return $initial;
+ }
+
+ public function supportsNormalization($data, ?string $format = null, array $context = [])
+ {
+ return $data instanceof AccompanyingPeriodWorkEvaluationDocument
+ && 'json' === $format
+ && (
+ !array_key_exists(self::SKIP, $context)
+ || spl_object_hash($data) !== $context[self::SKIP]
+ );
+ }
+}
diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationNormalizer.php
index 1e4649dd7..fc9b6003a 100644
--- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationNormalizer.php
+++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkEvaluationNormalizer.php
@@ -49,6 +49,15 @@ class AccompanyingPeriodWorkEvaluationNormalizer implements ContextAwareNormaliz
[self::IGNORE_EVALUATION => spl_object_hash($object)]
));
+ // due to bug: https://api-platform.com/docs/core/serialization/#collection-relation
+ // and also: https://github.com/symfony/symfony/issues/36965
+ // we have to rewrite the documents as a collection
+ $initial['documents'] = $this->normalizer->normalize(
+ $object->getDocuments()->getValues(),
+ $format,
+ $context
+ );
+
// then, we add normalization for things which are not into the entity
$initial['workflows_availables'] = $this->metadataExtractor->availableWorkflowFor(
diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkNormalizer.php
index 25f45d9df..4a110125e 100644
--- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkNormalizer.php
+++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkNormalizer.php
@@ -16,6 +16,7 @@ use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
use Chill\MainBundle\Workflow\Helper\MetadataExtractor;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
+use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument;
use Symfony\Component\Serializer\Exception\ExceptionInterface;
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
@@ -56,6 +57,15 @@ class AccompanyingPeriodWorkNormalizer implements ContextAwareNormalizerInterfac
[self::IGNORE_WORK => spl_object_hash($object)]
));
+ // due to bug: https://api-platform.com/docs/core/serialization/#collection-relation
+ // and also: https://github.com/symfony/symfony/issues/36965
+ // we have to rewrite the evaluations as a collection
+ $initial['accompanyingPeriodWorkEvaluations'] = $this->normalizer->normalize(
+ $object->getAccompanyingPeriodWorkEvaluations()->getValues(),
+ $format,
+ $context
+ );
+
// then, we add normalization for things which are not into the entity
$initial['workflows_availables'] = $this->metadataExtractor->availableWorkflowFor(
@@ -67,10 +77,15 @@ class AccompanyingPeriodWorkNormalizer implements ContextAwareNormalizerInterfac
AccompanyingPeriodWorkEvaluation::class
);
+ $initial['workflows_availables_evaluation_documents'] = $this->metadataExtractor->availableWorkflowFor(
+ AccompanyingPeriodWorkEvaluationDocument::class
+ );
+
$workflows = $this->entityWorkflowRepository->findBy([
'relatedEntityClass' => AccompanyingPeriodWork::class,
'relatedEntityId' => $object->getId(),
]);
+
$initial['workflows'] = $this->normalizer->normalize($workflows, 'json', $context);
return $initial;
diff --git a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php
index 32c71b9f0..eac460ee5 100644
--- a/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php
+++ b/src/Bundle/ChillPersonBundle/Workflow/AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler.php
@@ -17,7 +17,6 @@ use Chill\MainBundle\Workflow\EntityWorkflowHandlerInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument;
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocumentRepository;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkEvaluationDocumentVoter;
-use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkEvaluationVoter;
use Symfony\Contracts\Translation\TranslatorInterface;
class AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler implements EntityWorkflowHandlerInterface
@@ -40,10 +39,11 @@ class AccompanyingPeriodWorkEvaluationDocumentWorkflowHandler implements EntityW
public function getEntityData(EntityWorkflow $entityWorkflow, array $options = []): array
{
- $evaluation = $this->getRelatedEntity($entityWorkflow);
+ $doc = $this->getRelatedEntity($entityWorkflow);
return [
- 'persons' => $evaluation->getAccompanyingPeriodWork()->getPersons(),
+ 'persons' => $doc->getAccompanyingPeriodWorkEvaluation()
+ ->getAccompanyingPeriodWork()->getPersons(),
];
}