fixes person resources

This commit is contained in:
Julien Fastré 2022-01-26 17:53:09 +01:00
parent 6e554e74ab
commit dc0fae7549
9 changed files with 81 additions and 89 deletions

View File

@ -45,8 +45,6 @@ class EntityToJsonTransformer implements DataTransformerInterface
{ {
$denormalized = json_decode($value, true); $denormalized = json_decode($value, true);
dump($value);
if ($this->multiple) { if ($this->multiple) {
if (null === $denormalized) { if (null === $denormalized) {
return []; return [];

View File

@ -7,7 +7,6 @@ const i18n = _createI18n(appMessages);
let appsOnPage = new Map(); let appsOnPage = new Map();
function loadDynamicPicker(element) { function loadDynamicPicker(element) {
let apps = element.querySelectorAll('[data-module="pick-dynamic"]'); let apps = element.querySelectorAll('[data-module="pick-dynamic"]');
@ -75,23 +74,23 @@ function loadDynamicPicker(element) {
} }
// document.addEventListener('show-hide-show', function(e) { document.addEventListener('show-hide-show', function(e) {
// console.log('creation event caught') console.log('creation event caught')
// loadDynamicPicker(e.detail.container) loadDynamicPicker(e.detail.container)
// }) })
// document.addEventListener('show-hide-hide', function(e) { document.addEventListener('show-hide-hide', function(e) {
// console.log('hiding event caught') console.log('hiding event caught')
// e.detail.container.querySelectorAll('[data-module="pick-dynamic"]').forEach((el) => { e.detail.container.querySelectorAll('[data-module="pick-dynamic"]').forEach((el) => {
// let uniqId = el.dataset.uniqid; let uniqId = el.dataset.uniqid;
// console.log(uniqId); console.log(uniqId);
// if (appsOnPage.has(uniqId)) { if (appsOnPage.has(uniqId)) {
// appsOnPage.get(uniqId).unmount(); appsOnPage.get(uniqId).unmount();
// console.log('App has been unmounted') console.log('App has been unmounted')
// appsOnPage.delete(uniqId); appsOnPage.delete(uniqId);
// } }
// }) })
// }) })
document.addEventListener('DOMContentLoaded', function(e) { document.addEventListener('DOMContentLoaded', function(e) {
console.log('loaded event', e) console.log('loaded event', e)

View File

@ -114,8 +114,6 @@ final class PersonResourceController extends AbstractController
]); ]);
} }
dump($resource);
return $this->render( return $this->render(
'ChillPersonBundle:PersonResource:edit.html.twig', 'ChillPersonBundle:PersonResource:edit.html.twig',
[ [
@ -139,7 +137,7 @@ final class PersonResourceController extends AbstractController
$form->handleRequest($request); $form->handleRequest($request);
if ($request->getMethod() === Request::METHOD_POST && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$this->denyAccessUnlessGranted(PersonVoter::CREATE, $personOwner); $this->denyAccessUnlessGranted(PersonVoter::CREATE, $personOwner);
$personResource = new PersonResource(); $personResource = new PersonResource();

View File

@ -55,7 +55,7 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface
* @ORM\Column(type="text", nullable=true) * @ORM\Column(type="text", nullable=true)
* @Groups({"read"}) * @Groups({"read"})
*/ */
private $freeText; private ?string $freeText = null;
/** /**
* @ORM\Id * @ORM\Id
@ -204,6 +204,10 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface
$this->setThirdParty(null); $this->setThirdParty(null);
} }
if ('' === $freeText) {
$this->freeText = null;
}
return $this; return $this;
} }
@ -266,9 +270,8 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface
*/ */
public function validate(ExecutionContextInterface $context, $payload) 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') $context->buildViolation('You must associate at least one entity')
->atPath('person')
->addViolation(); ->addViolation();
} }
} }

View File

@ -1,5 +1,5 @@
<div class="col-md col-xxl"> <div class="col-md col-xxl">
<div id="collapseForm" class="collapse"> <div id="collapseForm" class="{% if not form.vars.submitted %}collapse{% endif %}">
<h3 style="margin-bottom: 2rem;">{{ 'Add a person resource'|trans }}</h3> <h3 style="margin-bottom: 2rem;">{{ 'Add a person resource'|trans }}</h3>
{% include "@ChillPerson/PersonResource/form.html.twig" %} {% include "@ChillPerson/PersonResource/form.html.twig" %}
</div> </div>

View File

@ -1,7 +1,6 @@
{{ form_start(form, {'attr' : {'id' : 'create-form'}}) }} {{ form_start(form, {'attr' : {'id' : 'create-form'}}) }}
{{ form_errors(form) }}
{{ form_row(form.kind) }} {{ form_row(form.kind) }}
<div id="linked-entity"> <div id="linked-entity">
<fieldset class="mb-3"> <fieldset class="mb-3">
<div class="row"> <div class="row">
@ -10,7 +9,7 @@
<div id="entity-selector"> <div id="entity-selector">
<div class="form-check"> <div class="form-check">
{% if resource is defined and resource.person is not null %} {% if resource is defined and resource.person is not null %}
<input checked type="radio" id="chill_personbundle_person_resource_linkedEntity_0" name="linked-entity" class="form-check-input" value="person" /> <input checked type="radio" id="chill_personbundle_person_resource_linkedEntity_0" name="linked-entity" class="form-check-input" value="person" {% if form.vars.submitted and app.request.request.get('linked-entity', null) == 'person' %}checked{% endif %}/>
<label class="form-check-label" for="chill_personbundle_person_resource_linkedEntity_0">Usager</label> <label class="form-check-label" for="chill_personbundle_person_resource_linkedEntity_0">Usager</label>
{% else %} {% else %}
<input type="radio" id="chill_personbundle_person_resource_linkedEntity_0" name="linked-entity" class="form-check-input" value="person" /> <input type="radio" id="chill_personbundle_person_resource_linkedEntity_0" name="linked-entity" class="form-check-input" value="person" />
@ -19,7 +18,7 @@
</div> </div>
<div class="form-check"> <div class="form-check">
{% if resource is defined and resource.thirdparty is not null %} {% if resource is defined and resource.thirdparty is not null %}
<input checked type="radio" id="chill_personbundle_person_resource_linkedEntity_1" name="linked-entity" class="form-check-input" value="thirdparty" /> <input checked type="radio" id="chill_personbundle_person_resource_linkedEntity_1" name="linked-entity" class="form-check-input" value="thirdparty" {% if form.vars.submitted and app.request.request.get('linked-entity', null) == 'thirdparty' %}checked{% endif %}/>
<label class="form-check-label" for="chill_personbundle_person_resource_linkedEntity_1">Tiers</label> <label class="form-check-label" for="chill_personbundle_person_resource_linkedEntity_1">Tiers</label>
{% else %} {% else %}
<input type="radio" id="chill_personbundle_person_resource_linkedEntity_1" name="linked-entity" class="form-check-input" value="thirdparty" /> <input type="radio" id="chill_personbundle_person_resource_linkedEntity_1" name="linked-entity" class="form-check-input" value="thirdparty" />
@ -28,7 +27,7 @@
</div> </div>
<div class="form-check"> <div class="form-check">
{% if resource is defined and resource.freeText is not null %} {% if resource is defined and resource.freeText is not null %}
<input checked type="radio" id="chill_personbundle_person_resource_linkedEntity_2" name="linked-entity" class="form-check-input" value="freetext" /> <input checked type="radio" id="chill_personbundle_person_resource_linkedEntity_2" name="linked-entity" class="form-check-input" value="freetext" {% if form.vars.submitted and app.request.request.get('linked-entity', null) == 'thirdparty' %}checked{% endif %}/>
<label class="form-check-label" for="chill_personbundle_person_resource_linkedEntity_2">Description libre</label> <label class="form-check-label" for="chill_personbundle_person_resource_linkedEntity_2">Description libre</label>
{% else %} {% else %}
<input type="radio" id="chill_personbundle_person_resource_linkedEntity_2" name="linked-entity" class="form-check-input" value="freetext" /> <input type="radio" id="chill_personbundle_person_resource_linkedEntity_2" name="linked-entity" class="form-check-input" value="freetext" />

View File

@ -19,22 +19,17 @@
<h1>{{ 'List of resources'|trans }}</h1> <h1>{{ 'List of resources'|trans }}</h1>
{% if personResources|length > 0 %} {% if personResources|length > 0 %}
{% for resource in personResources %}
<div class="flex-table"> <div class="flex-table">
{% for resource in personResources %}
<div class="item-bloc"> <div class="item-bloc">
<div class="item-row"> <div class="item-row">
<div class="wrap-header">
<div class="wh-row">
<div class="wh-col">
{% if resource.person is not null %}
<div class="item-col"> <div class="item-col">
{% if resource.person is not null %}
<div class="denomination h3"> <div class="denomination h3">
<span class="name">{{ resource.person }}</span> <span class="name">{{ resource.person }}</span>
<span class="badge rounded-pill bg-person">{{ 'person'|trans|capitalize }}</span> <span class="badge rounded-pill bg-person">{{ 'person'|trans|capitalize }}</span>
</div> </div>
</div>
{% elseif resource.thirdparty is not null %} {% elseif resource.thirdparty is not null %}
<div class="item-col">
<div class="denomination h3"> <div class="denomination h3">
<span class="name">{{ resource.thirdparty }}</span> <span class="name">{{ resource.thirdparty }}</span>
<span class="badge rounded-pill bg-thirdparty"> <span class="badge rounded-pill bg-thirdparty">
@ -42,30 +37,26 @@
<i class="fa fa-fw fa-user-md"></i> <i class="fa fa-fw fa-user-md"></i>
</span> </span>
</div> </div>
</div>
{% else %} {% else %}
<div class="item-col">
<div class="denomination h3"> <div class="denomination h3">
<span>{{ resource.freetext }}</span> <span>{{ resource.freetext }}</span>
</div> </div>
</div>
{% endif %} {% endif %}
<div class="wh-col"> </div>
<div class="item-col">
{% if resource.kind %} {% if resource.kind %}
<span>{{ resource.kind.title.fr|capitalize }}</span> <span>{{ resource.kind.title.fr|capitalize }}</span>
{% endif %} {% endif %}
</div> </div>
</div> </div>
</div> {% if resource.comment.comment is not empty %}
</div>
</div>
{% if resource.comment.comment is not null %}
<div class="item-row separator"> <div class="item-row separator">
<section class="chill-entity entity-comment-embeddable"> <section class="chill-entity entity-comment-embeddable">
<div>{{ resource.comment|chill_entity_render_box }}<div> <div>{{ resource.comment|chill_entity_render_box }}<div>
</section> </section>
</div> </div>
{% endif %} {% endif %}
{% if is_granted('CHILL_PERSON_UPDATE', resource.person) %}
<div class="item-row separator"> <div class="item-row separator">
<div class="item-col"> <div class="item-col">
<ul class="record_actions"> <ul class="record_actions">
@ -84,9 +75,10 @@
</ul> </ul>
</div> </div>
</div> </div>
</div> {% endif %}
</div> </div>
{% endfor %} {% endfor %}
</div>
{% else %} {% else %}
<p class="chill-no-data-statement">{{ 'There are no available resources'|trans }}</p> <p class="chill-no-data-statement">{{ 'There are no available resources'|trans }}</p>

View File

@ -76,8 +76,8 @@ class PersonDocGenNormalizer implements
'type' => 'person', 'type' => 'person',
'isNull' => false, 'isNull' => false,
'civility' => $this->normalizer->normalize($person->getCivility(), $format, array_merge($context, ['docgen:expects' => Civility::class])), 'civility' => $this->normalizer->normalize($person->getCivility(), $format, array_merge($context, ['docgen:expects' => Civility::class])),
'firstname' => $person->getFirstName(), 'firstName' => $person->getFirstName(),
'lastname' => $person->getLastName(), 'lastName' => $person->getLastName(),
'altNames' => implode( 'altNames' => implode(
', ', ', ',
array_map( array_map(

View File

@ -50,3 +50,6 @@ household_membership:
A course must contains at least one social issue: 'Un parcours doit être associé à au moins une problématique sociale' A course must contains at least one social issue: 'Un parcours doit être associé à au moins une problématique sociale'
A course must be associated to at least one scope: 'Un parcours doit être associé à au moins un service' A course must be associated to at least one scope: 'Un parcours doit être associé à au moins un service'
The social %name% issue cannot be deleted because it is associated with an activity or an action: 'La problématique sociale "%name%" ne peut pas être supprimée car elle est associée à une activité ou une action' The social %name% issue cannot be deleted because it is associated with an activity or an action: 'La problématique sociale "%name%" ne peut pas être supprimée car elle est associée à une activité ou une action'
# resource
You must associate at least one entity: Associez un usager, un tiers ou indiquez une description libre