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);
dump($value);
if ($this->multiple) {
if (null === $denormalized) {
return [];

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
<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>
{% include "@ChillPerson/PersonResource/form.html.twig" %}
</div>

View File

@ -1,7 +1,6 @@
{{ form_start(form, {'attr' : {'id' : 'create-form'}}) }}
{{ form_errors(form) }}
{{ form_row(form.kind) }}
<div id="linked-entity">
<fieldset class="mb-3">
<div class="row">
@ -10,7 +9,7 @@
<div id="entity-selector">
<div class="form-check">
{% 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>
{% else %}
<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 class="form-check">
{% 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>
{% else %}
<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 class="form-check">
{% 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>
{% else %}
<input type="radio" id="chill_personbundle_person_resource_linkedEntity_2" name="linked-entity" class="form-check-input" value="freetext" />
@ -75,4 +74,4 @@
</ul>
{% endif %}
{{ form_end(form) }}
{{ form_end(form) }}

View File

@ -19,74 +19,66 @@
<h1>{{ 'List of resources'|trans }}</h1>
{% 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-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="denomination h3">
<span class="name">{{ resource.person }}</span>
<span class="badge rounded-pill bg-person">{{ 'person'|trans|capitalize }}</span>
</div>
</div>
{% elseif resource.thirdparty is not null %}
<div class="item-col">
<div class="denomination h3">
<span class="name">{{ resource.thirdparty }}</span>
<span class="badge rounded-pill bg-thirdparty">
{{ 'thirdparty'|trans|capitalize }}
<i class="fa fa-fw fa-user-md"></i>
</span>
</div>
</div>
{% else %}
<div class="item-col">
<div class="denomination h3">
<span>{{ resource.freetext }}</span>
</div>
</div>
{% endif %}
<div class="wh-col">
{% if resource.kind %}
<span>{{ resource.kind.title.fr|capitalize }}</span>
{% endif %}
</div>
</div>
<div class="item-col">
{% if resource.person is not null %}
<div class="denomination h3">
<span class="name">{{ resource.person }}</span>
<span class="badge rounded-pill bg-person">{{ 'person'|trans|capitalize }}</span>
</div>
{% elseif resource.thirdparty is not null %}
<div class="denomination h3">
<span class="name">{{ resource.thirdparty }}</span>
<span class="badge rounded-pill bg-thirdparty">
{{ 'thirdparty'|trans|capitalize }}
<i class="fa fa-fw fa-user-md"></i>
</span>
</div>
{% else %}
<div class="denomination h3">
<span>{{ resource.freetext }}</span>
</div>
{% endif %}
</div>
<div class="item-col">
{% if resource.kind %}
<span>{{ resource.kind.title.fr|capitalize }}</span>
{% endif %}
</div>
</div>
{% if resource.comment.comment is not null %}
{% if resource.comment.comment is not empty %}
<div class="item-row separator">
<section class="chill-entity entity-comment-embeddable">
<div>{{ resource.comment|chill_entity_render_box }}<div>
</section>
</div>
{% endif %}
<div class="item-row separator">
<div class="item-col">
<ul class="record_actions">
<li>
<a href="{{ chill_path_add_return_path('chill_person_resource_edit', {'resource_id': resource.id,
'person_id': person.id,}) }}"
class="btn btn-sm btn-edit"
title="{{ 'Edit'|trans }}"></a>
</li>
<li>
<a href="{{ chill_path_add_return_path('chill_person_resource_delete', {'person_id': person.id,
'resource_id': resource.id}) }}"
class="btn btn-sm btn-delete"
title="{{ 'Delete'|trans }}"></a>
</li>
</ul>
{% if is_granted('CHILL_PERSON_UPDATE', resource.person) %}
<div class="item-row separator">
<div class="item-col">
<ul class="record_actions">
<li>
<a href="{{ chill_path_add_return_path('chill_person_resource_edit', {'resource_id': resource.id,
'person_id': person.id,}) }}"
class="btn btn-sm btn-edit"
title="{{ 'Edit'|trans }}"></a>
</li>
<li>
<a href="{{ chill_path_add_return_path('chill_person_resource_delete', {'person_id': person.id,
'resource_id': resource.id}) }}"
class="btn btn-sm btn-delete"
title="{{ 'Delete'|trans }}"></a>
</li>
</ul>
</div>
</div>
</div>
{% endif %}
</div>
</div>
{% endfor %}
{% endfor %}
</div>
{% else %}
<p class="chill-no-data-statement">{{ 'There are no available resources'|trans }}</p>

View File

@ -76,8 +76,8 @@ class PersonDocGenNormalizer implements
'type' => 'person',
'isNull' => false,
'civility' => $this->normalizer->normalize($person->getCivility(), $format, array_merge($context, ['docgen:expects' => Civility::class])),
'firstname' => $person->getFirstName(),
'lastname' => $person->getLastName(),
'firstName' => $person->getFirstName(),
'lastName' => $person->getLastName(),
'altNames' => implode(
', ',
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 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'
# resource
You must associate at least one entity: Associez un usager, un tiers ou indiquez une description libre