mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
various improvements
This commit is contained in:
parent
6c1a946608
commit
063ceb2c53
@ -23,12 +23,12 @@ interface DocGeneratorContextWithPublicFormInterface extends DocGeneratorContext
|
||||
*/
|
||||
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void;
|
||||
|
||||
public function getFormData(DocGeneratorTemplate $template, $entity): array;
|
||||
|
||||
/**
|
||||
* has form.
|
||||
*
|
||||
* @param mixed $entity
|
||||
*/
|
||||
public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool;
|
||||
|
||||
public function getFormData(DocGeneratorTemplate $template, $entity): array;
|
||||
}
|
||||
|
@ -59,4 +59,23 @@ class AdminDocGeneratorTemplateController extends CRUDController
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
||||
function generateTemplateParameter(string $action, $entity, Request $request, array $defaultTemplateParameters = [])
|
||||
{
|
||||
switch ($action) {
|
||||
case 'new':
|
||||
$context = $this->contextManager->getContextByKey($request->get('context'));
|
||||
break;
|
||||
case 'edit':
|
||||
$context = $this->contextManager->getContextByDocGeneratorTemplate($entity);
|
||||
break;
|
||||
default:
|
||||
return parent::generateTemplateParameter($action, $entity, $request, $defaultTemplateParameters); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
return array_merge(
|
||||
$defaultTemplateParameters,
|
||||
['context' => $context]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -113,10 +113,11 @@ final class DocGeneratorTemplateController extends AbstractController
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$contextGenerationData = $form->getData();
|
||||
} elseif (!$form->isSubmitted() || ($form->isSubmitted() && !$form->isValid())) {
|
||||
$template = '@ChillDocGenerator/Generator/basic_form.html.twig';
|
||||
$templateOptions = ['entity' => $entity, 'form' => $form->createView(), 'template' => $template];
|
||||
$templatePath = '@ChillDocGenerator/Generator/basic_form.html.twig';
|
||||
$templateOptions = ['entity' => $entity, 'form' => $form->createView(),
|
||||
'template' => $template, 'context' => $context];
|
||||
|
||||
return $this->render($template, $templateOptions);
|
||||
return $this->render($templatePath, $templateOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,21 +1,39 @@
|
||||
<template>
|
||||
<div>
|
||||
<template v-if="templates.length > 0">
|
||||
<slot name="title">
|
||||
<h2>{{ $t('Generate document from template')}}</h2>
|
||||
<h2>{{ $t('generate_document')}}</h2>
|
||||
</slot>
|
||||
<select class="form-select form-select-sm" v-model="template">
|
||||
<option disabled value="">{{ $t('evaluation_choose_a_template') }}</option>
|
||||
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<slot name="label">
|
||||
<label>{{ $t('select_a_template') }}</label>
|
||||
</slot>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="input-group mb-3">
|
||||
<select class="form-select" v-model="template">
|
||||
<option disabled selected value="">{{ $t('choose_a_template') }}</option>
|
||||
<template v-for="t in templates">
|
||||
<option v-bind:value="t.id">{{ t.name.fr }}</option>
|
||||
</template>
|
||||
</select>
|
||||
<button v-if="canGenerate" class="btn btn-update btn-sm change-icon" type="button" @click="generateDocument"><i class="fa fa-fw fa-cog"></i></button>
|
||||
<button v-else class="btn btn-update btn-sm change-icon" type="button" disabled ><i class="fa fa-fw fa-cog"></i></button>
|
||||
|
||||
<div v-if="hasDescription">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" v-if="hasDescription">
|
||||
<div class="col-md-8 align-self-end">
|
||||
<p>{{ getDescription }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
</template>
|
||||
|
||||
@ -106,6 +124,15 @@ export default {
|
||||
window.location.assign(url);
|
||||
},
|
||||
},
|
||||
i18n: {
|
||||
messages: {
|
||||
fr: {
|
||||
generate_document: 'Générer un document',
|
||||
select_a_template: 'Choisir un gabarit',
|
||||
choose_a_template: 'Choisir',
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -1,11 +1,15 @@
|
||||
{% extends '@ChillDocGenerator/Admin/layout.html.twig' %}
|
||||
|
||||
{% block title %}
|
||||
{% include('@ChillMain/CRUD/_edit_title.html.twig') %}
|
||||
{% endblock %}
|
||||
{% block title 'docgen.Edit template'|trans %}
|
||||
|
||||
{% block layout_wvm_content %}
|
||||
{% embed '@ChillMain/CRUD/_edit_content.html.twig' %}
|
||||
|
||||
{% block crud_content_header %}
|
||||
<h1>{{ 'docgen.Edit template'|trans }}</h1>
|
||||
<h2>{{ 'docgen.With context %name%'|trans({'%name%': context.name|trans }) }}</h2>
|
||||
{% endblock crud_content_header %}
|
||||
|
||||
{% block content_form_actions_view %}{% endblock %}
|
||||
{% block content_form_actions_save_and_show %}{% endblock %}
|
||||
{% endembed %}
|
||||
|
@ -1,12 +1,17 @@
|
||||
{% extends '@ChillDocGenerator/Admin/layout.html.twig' %}
|
||||
|
||||
{% block title %}
|
||||
{% include('@ChillMain/CRUD/_new_title.html.twig') %}
|
||||
{% endblock %}
|
||||
{% block title 'docgen.New template'|trans %}
|
||||
|
||||
{% block layout_wvm_content %}
|
||||
{% embed '@ChillMain/CRUD/_new_content.html.twig' %}
|
||||
|
||||
{% block crud_content_header %}
|
||||
<h1>{{ 'docgen.New template'|trans }}</h1>
|
||||
<h2>{{ 'docgen.With context %name%'|trans({'%name%': context.name|trans }) }}</h2>
|
||||
{% endblock crud_content_header %}
|
||||
|
||||
{% block content_form_actions_save_and_show %}{% endblock %}
|
||||
|
||||
{% endembed %}
|
||||
{% endblock %}
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
{% extends 'ChillMainBundle::layout.html.twig' %}
|
||||
|
||||
{% block title 'Generate document'|trans %}
|
||||
{% block title 'docgen.Generate a document'|trans %}
|
||||
|
||||
{% block content %}
|
||||
<div class="col-md-10 col-xxl">
|
||||
<h1>{{ block('title') }}</h1>
|
||||
<h2>{{ template.name|localize_translatable_string }}</h2>
|
||||
|
||||
{{ form_start(form, { 'attr': { 'id': 'generate_doc_form' }}) }}
|
||||
{{ form(form) }}
|
||||
@ -12,8 +13,8 @@
|
||||
|
||||
<ul class="record_actions sticky-form-buttons">
|
||||
<li>
|
||||
<button type="submit" class="btn btn-edit" form="generate_doc_form">
|
||||
<i class="fa fa-cog"></i> {{ 'Generate'|trans }}
|
||||
<button type="submit" class="btn btn-edit change-icon" form="generate_doc_form">
|
||||
<i class="fa fa-cog"></i> {{ 'docgen.Generate'|trans }}
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
@ -168,12 +168,14 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
|
||||
switch ($type) {
|
||||
case 'array':
|
||||
return [];
|
||||
|
||||
case 'bool':
|
||||
case 'double':
|
||||
case 'float':
|
||||
case 'int':
|
||||
case 'resource':
|
||||
return null;
|
||||
|
||||
case 'string':
|
||||
return '';
|
||||
|
||||
|
@ -0,0 +1,3 @@
|
||||
docgen:
|
||||
Generate a document: Génerer un document
|
||||
Generate: Génerer
|
@ -15,7 +15,6 @@ use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Chill\MainBundle\Serializer\Normalizer\CollectionNormalizer;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
|
||||
use Chill\PersonBundle\Entity\SocialWork\Evaluation;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
@ -23,15 +22,17 @@ use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use function count;
|
||||
use function in_array;
|
||||
|
||||
class AccompanyingPeriodWorkEvaluationApiController
|
||||
{
|
||||
private DocGeneratorTemplateRepository $docGeneratorTemplateRepository;
|
||||
|
||||
private SerializerInterface $serializer;
|
||||
|
||||
private PaginatorFactory $paginatorFactory;
|
||||
|
||||
private SerializerInterface $serializer;
|
||||
|
||||
public function __construct(
|
||||
DocGeneratorTemplateRepository $docGeneratorTemplateRepository,
|
||||
SerializerInterface $serializer,
|
||||
@ -49,16 +50,17 @@ class AccompanyingPeriodWorkEvaluationApiController
|
||||
public function listTemplateByEvaluation(Evaluation $evaluation, string $_format): JsonResponse
|
||||
{
|
||||
if ('json' !== $_format) {
|
||||
throw new BadRequestHttpException("format not supported");
|
||||
throw new BadRequestHttpException('format not supported');
|
||||
}
|
||||
|
||||
$evaluations =
|
||||
array_filter(
|
||||
$this->docGeneratorTemplateRepository
|
||||
->findByEntity(AccompanyingPeriodWorkEvaluation::class),
|
||||
function (DocGeneratorTemplate $t) use ($evaluation) {
|
||||
static function (DocGeneratorTemplate $t) use ($evaluation) {
|
||||
$ids = $t->getOptions()['evaluations'] ?? [];
|
||||
return in_array($evaluation->getId(), $ids);
|
||||
|
||||
return in_array($evaluation->getId(), $ids, true);
|
||||
}
|
||||
);
|
||||
|
||||
@ -66,8 +68,10 @@ class AccompanyingPeriodWorkEvaluationApiController
|
||||
$paginator->setItemsPerPage(count($evaluations));
|
||||
|
||||
return new JsonResponse($this->serializer->serialize(
|
||||
new Collection($evaluations, $paginator), 'json', [
|
||||
AbstractNormalizer::GROUPS => ['read']
|
||||
new Collection($evaluations, $paginator),
|
||||
'json',
|
||||
[
|
||||
AbstractNormalizer::GROUPS => ['read'],
|
||||
]
|
||||
), JsonResponse::HTTP_OK, [], true);
|
||||
}
|
||||
|
@ -239,11 +239,6 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
|
||||
return $this->updatedBy;
|
||||
}
|
||||
|
||||
public function getWarningInterval(): ?DateInterval
|
||||
{
|
||||
return $this->warningInterval;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Serializer\Groups({"docgen:read"})
|
||||
*/
|
||||
@ -256,6 +251,11 @@ class AccompanyingPeriodWorkEvaluation implements TrackCreationInterface, TrackU
|
||||
return $this->getEndDate()->sub($this->getWarningInterval());
|
||||
}
|
||||
|
||||
public function getWarningInterval(): ?DateInterval
|
||||
{
|
||||
return $this->warningInterval;
|
||||
}
|
||||
|
||||
public function removeDocument(AccompanyingPeriodWorkEvaluationDocument $document): self
|
||||
{
|
||||
$this->documents->removeElement($document);
|
||||
|
@ -28,7 +28,7 @@ class Evaluation
|
||||
* @ORM\Column(type="dateinterval", nullable=true, options={"default": null})
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private ?\DateInterval $delay = null;
|
||||
private ?DateInterval $delay = null;
|
||||
|
||||
/**
|
||||
* @ORM\Id
|
||||
@ -42,7 +42,7 @@ class Evaluation
|
||||
* @ORM\Column(type="dateinterval", nullable=true, options={"default": null})
|
||||
* @Serializer\Groups({"read"})
|
||||
*/
|
||||
private ?\DateInterval $notificationDelay = null;
|
||||
private ?DateInterval $notificationDelay = null;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(
|
||||
|
@ -195,6 +195,7 @@
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<pick-template
|
||||
entityClass="Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork"
|
||||
:templates="this.templatesAvailablesForAction"
|
||||
@ -204,6 +205,7 @@
|
||||
<h3>{{ $t('Generate doc') }}</h3>
|
||||
</template>
|
||||
</pick-template>
|
||||
</div>
|
||||
|
||||
<div v-if="errors.length > 0" id="errors" class="alert alert-danger flashbag">
|
||||
<p>{{ $t('fix_these_errors') }}</p>
|
||||
|
@ -11,7 +11,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Service\DocGenerator;
|
||||
|
||||
use Chill\DocGeneratorBundle\Context\DocGeneratorContextInterface;
|
||||
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithAdminFormInterface;
|
||||
use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface;
|
||||
use Chill\DocGeneratorBundle\Context\Exception\UnexpectedTypeException;
|
||||
@ -29,8 +28,10 @@ use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use function array_key_exists;
|
||||
|
||||
class AccompanyingPeriodContext implements
|
||||
@ -47,28 +48,26 @@ class AccompanyingPeriodContext implements
|
||||
|
||||
private TranslatableStringHelperInterface $translatableStringHelper;
|
||||
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
public function __construct(
|
||||
DocumentCategoryRepository $documentCategoryRepository,
|
||||
NormalizerInterface $normalizer,
|
||||
TranslatableStringHelperInterface $translatableStringHelper,
|
||||
EntityManagerInterface $em,
|
||||
PersonRender $personRender
|
||||
PersonRender $personRender,
|
||||
TranslatorInterface $translator
|
||||
) {
|
||||
$this->documentCategoryRepository = $documentCategoryRepository;
|
||||
$this->normalizer = $normalizer;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
$this->em = $em;
|
||||
$this->personRender = $personRender;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function adminFormReverseTransform(array $data): array
|
||||
{
|
||||
$data = [
|
||||
'mainPerson' => $data['mainPerson'],
|
||||
'person1' => $data['person1'],
|
||||
'person2' => $data['person2'],
|
||||
];
|
||||
|
||||
if (array_key_exists('category', $data)) {
|
||||
$data['category'] = [
|
||||
'idInsideBundle' => $data['category']->getIdInsideBundle(),
|
||||
@ -83,8 +82,11 @@ class AccompanyingPeriodContext implements
|
||||
{
|
||||
$data = [
|
||||
'mainPerson' => $data['mainPerson'] ?? false,
|
||||
'mainPersonLabel' => $data['mainPersonLabel'] ?? $this->translator->trans('docgen.Main person'),
|
||||
'person1' => $data['person1'] ?? false,
|
||||
'person1Label' => $data['person1Label'] ?? $this->translator->trans('docgen.person 1'),
|
||||
'person2' => $data['person2'] ?? false,
|
||||
'person2Label' => $data['person2Label'] ?? $this->translator->trans('docgen.person 2'),
|
||||
];
|
||||
|
||||
if (array_key_exists('category', $data)) {
|
||||
@ -100,12 +102,27 @@ class AccompanyingPeriodContext implements
|
||||
$builder
|
||||
->add('mainPerson', CheckboxType::class, [
|
||||
'required' => false,
|
||||
'label' => 'Ask for main person',
|
||||
])
|
||||
->add('mainPersonLabel', TextType::class, [
|
||||
'label' => 'main person label',
|
||||
'required' => true,
|
||||
])
|
||||
->add('person1', CheckboxType::class, [
|
||||
'required' => false,
|
||||
'label' => 'Ask for person 1'
|
||||
])
|
||||
->add('person1Label', TextType::class, [
|
||||
'label' => 'person 1 label',
|
||||
'required' => true,
|
||||
])
|
||||
->add('person2', CheckboxType::class, [
|
||||
'required' => false,
|
||||
'label' => 'Ask for person 2'
|
||||
])
|
||||
->add('person2Label', TextType::class, [
|
||||
'label' => 'person 2 label',
|
||||
'required' => true,
|
||||
])
|
||||
->add('category', EntityType::class, [
|
||||
'placeholder' => 'Choose a document category',
|
||||
@ -138,6 +155,7 @@ class AccompanyingPeriodContext implements
|
||||
'choice_label' => function (Person $p) { return $this->personRender->renderString($p, []); },
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'label' => $options[$key.'Label'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@ -175,7 +193,7 @@ class AccompanyingPeriodContext implements
|
||||
public function getFormData(DocGeneratorTemplate $template, $entity): array
|
||||
{
|
||||
return [
|
||||
'course' => $entity
|
||||
'course' => $entity,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,8 @@ class AccompanyingPeriodWorkContext implements
|
||||
public function buildAdminForm(FormBuilderInterface $builder): void
|
||||
{
|
||||
$this->periodContext->buildAdminForm($builder);
|
||||
|
||||
$builder->remove('category');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,7 +100,6 @@ class AccompanyingPeriodWorkEvaluationContext implements
|
||||
|
||||
/**
|
||||
* @param AccompanyingPeriodWorkEvaluation $entity
|
||||
* @return void
|
||||
*/
|
||||
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void
|
||||
{
|
||||
@ -141,8 +140,10 @@ class AccompanyingPeriodWorkEvaluationContext implements
|
||||
*/
|
||||
public function getFormData(DocGeneratorTemplate $template, $entity): array
|
||||
{
|
||||
return $this->accompanyingPeriodWorkContext->getFormData($template,
|
||||
$entity->getAccompanyingPeriodWork());
|
||||
return $this->accompanyingPeriodWorkContext->getFormData(
|
||||
$template,
|
||||
$entity->getAccompanyingPeriodWork()
|
||||
);
|
||||
}
|
||||
|
||||
public static function getKey(): string
|
||||
|
@ -448,3 +448,8 @@ Household addresses: Adresses de domicile
|
||||
Insert an address: Insérer une adresse
|
||||
see social issues: Voir les problématiques sociales
|
||||
see persons associated: Voir les usagers concernés
|
||||
|
||||
docgen:
|
||||
Main person: Personne principale
|
||||
person 1: Première personne
|
||||
person 2: Deuxième personne
|
||||
|
Loading…
x
Reference in New Issue
Block a user