replace dropdown for selecting reasons and use chillEntity for reason rendering

This commit is contained in:
Julien Fastré 2020-04-21 14:41:40 +02:00
parent 544466d504
commit a9349becf7
14 changed files with 186 additions and 53 deletions

View File

@ -23,3 +23,7 @@ Version 1.5.4
- [report activity]: add aggregator for activity users
- fix bug: error when extracting activities without filter / aggregators selecting persons
Master branch
============
- [activity] replace dropdown for selecting reasons and use chillEntity for reason rendering

View File

@ -54,6 +54,8 @@ class ChillActivityExtension extends Extension implements PrependExtensionInterf
$loader->load('services/fixtures.yml');
$loader->load('services/menu.yml');
$loader->load('services/controller.yml');
$loader->load('services/form.yml');
$loader->load('services/templating.yml');
}
public function prepend(ContainerBuilder $container)

View File

@ -116,7 +116,7 @@ class ActivityType extends AbstractType
])
->add('reasons', TranslatableActivityReason::class, array(
'multiple' => true,
'required' => false
'required' => false,
))
->add('type', TranslatableActivityType::class, array(
'placeholder' => 'Choose a type',

View File

@ -3,7 +3,7 @@
/*
* Chill is a software for social workers
*
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
* Copyright (C) 2014-2020, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
@ -27,20 +27,34 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Doctrine\ORM\EntityRepository;
use Chill\ActivityBundle\Entity\ActivityReason;
use Chill\ActivityBundle\Templating\Entity\ActivityReasonRender;
/**
* Description of TranslatableActivityReason
*
* @author Champs-Libres Coop
* FormType to choose amongst activity reasons
*
*/
class TranslatableActivityReason extends AbstractType
{
private $translatableStringHelper;
/**
*
* @var TranslatableStringHelper
*/
protected $translatableStringHelper;
/**
*
* @var ActivityReasonRender
*/
protected $reasonRender;
public function __construct(TranslatableStringHelper $translatableStringHelper)
{
public function __construct(
TranslatableStringHelper $translatableStringHelper,
ActivityReasonRender $reasonRender
) {
$this->translatableStringHelper = $translatableStringHelper;
$this->reasonRender = $reasonRender;
}
public function getBlockPrefix()
@ -55,20 +69,20 @@ class TranslatableActivityReason extends AbstractType
public function configureOptions(OptionsResolver $resolver)
{
$helper = $this->translatableStringHelper;
$resolver->setDefaults(
array(
'class' => 'ChillActivityBundle:ActivityReason',
'choice_label' => function($choice, $key) use ($helper) {
return $helper->localize($choice->getName());
'choice_label' => function(ActivityReason $choice) {
return $this->reasonRender->renderString($choice, []);
},
'group_by' => function($choice, $key) use ($helper) {
return $helper->localize($choice->getCategory()->getName());
'group_by' => function(ActivityReason $choice) {
return $this->translatableStringHelper->localize($choice->getCategory()->getName());
},
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('r')
->where('r.active = true');
}
},
'attr' => [ 'class' => ' select2 ']
)
);
}

View File

@ -1,37 +1,4 @@
services:
chill.activity.form.type.translatableactivityreasoncategory:
class: Chill\ActivityBundle\Form\Type\TranslatableActivityReasonCategory
arguments:
- "@request_stack"
tags:
- { name: form.type, alias: translatable_activity_reason_category }
chill.activity.form.type.translatableactivityreason:
class: Chill\ActivityBundle\Form\Type\TranslatableActivityReason
arguments:
- "@chill.main.helper.translatable_string"
tags:
- { name: form.type, alias: translatable_activity_reason }
chill.activity.form.type.translatableactivitytype:
class: Chill\ActivityBundle\Form\Type\TranslatableActivityType
arguments:
- "@chill.main.helper.translatable_string"
- "@chill_activity.repository.activity_type"
tags:
- { name: form.type, alias: translatable_activity_type }
chill.activity.form.type.activity:
class: Chill\ActivityBundle\Form\ActivityType
arguments:
- "@security.token_storage"
- "@chill.main.security.authorization.helper"
- "@doctrine.orm.entity_manager"
- "@chill.main.helper.translatable_string"
- "%chill_activity.form.time_duration%"
tags:
- { name: form.type, alias: chill_activitybundle_activity }
services:
chill.activity.security.authorization.activity_voter:
class: Chill\ActivityBundle\Security\Authorization\ActivityVoter
arguments:

View File

@ -0,0 +1,35 @@
---
services:
chill.activity.form.type.translatableactivityreasoncategory:
class: Chill\ActivityBundle\Form\Type\TranslatableActivityReasonCategory
arguments:
- "@request_stack"
tags:
- { name: form.type, alias: translatable_activity_reason_category }
chill.activity.form.type.translatableactivityreason:
class: Chill\ActivityBundle\Form\Type\TranslatableActivityReason
arguments:
$translatableStringHelper: "@chill.main.helper.translatable_string"
$reasonRender: '@Chill\ActivityBundle\Templating\Entity\ActivityReasonRender'
tags:
- { name: form.type, alias: translatable_activity_reason }
chill.activity.form.type.translatableactivitytype:
class: Chill\ActivityBundle\Form\Type\TranslatableActivityType
arguments:
- "@chill.main.helper.translatable_string"
- "@chill_activity.repository.activity_type"
tags:
- { name: form.type, alias: translatable_activity_type }
chill.activity.form.type.activity:
class: Chill\ActivityBundle\Form\ActivityType
arguments:
- "@security.token_storage"
- "@chill.main.security.authorization.helper"
- "@doctrine.orm.entity_manager"
- "@chill.main.helper.translatable_string"
- "%chill_activity.form.time_duration%"
tags:
- { name: form.type, alias: chill_activitybundle_activity }

View File

@ -0,0 +1,7 @@
---
services:
Chill\ActivityBundle\Templating\Entity\ActivityReasonRender:
arguments:
$translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper'
tags:
- { name: 'chill.render_entity' }

View File

@ -0,0 +1,10 @@
@import '~ChillMainSass/custom/config/colors';
@import '~ChillMainSass/custom/mixins/entity';
.chill-entity.chill-entity__activity-reason {
@include entity($chill-pink, white);
}
.activity {
color: $chill-green;
}

View File

@ -0,0 +1 @@
require('./activity/activity.scss');

View File

@ -16,8 +16,6 @@
#}
{% extends "ChillPersonBundle::layout.html.twig" %}
{% import 'ChillActivityBundle:ActivityReason:macro.html.twig' as m %}
{% set activeRouteKey = 'chill_activity_activity_list' %}
{% block title %}{{ 'Activity list' |trans }}{% endblock title %}
@ -47,10 +45,15 @@
<td>{% if activity.date %}{{ activity.date|localizeddate('long', 'none') }}{% endif %}</td>
<td>{{ activity.durationTime|date('H:i') }}</td>
<td>
{% if activity.remark is not empty %}
<blockquote class="chill-user-quote">
{{ activity.remark|truncate(250, true) }}
</blockquote>
{% endif %}
{%- if activity.reasons is empty -%}
{{ 'No reason associated'|trans }}
{%- else -%}
{% for r in activity.reasons %}{{ m.reason(r) }} {% endfor %}
{% for r in activity.reasons %}{{ r|chill_entity_render_box }} {% endfor %}
{%- endif -%}
</td>
<td>{{ activity.type.name | localize_translatable_string }}</td>

View File

@ -35,7 +35,7 @@
{%- if entity.reasons is empty -%}
<dd><span class="chill-no-data-statement">{{ 'No reason associated'|trans }}</span></dd>
{%- else -%}
<dd>{% for r in entity.reasons %}{{ m.reason(r) }} {% endfor %}</dd>
<dd>{% for r in entity.reasons %}{{ r|chill_entity_render_box }} {% endfor %}</dd>
{%- endif -%}
</dl>

View File

@ -20,7 +20,7 @@
{%- if activity.reasons is empty -%}
<dd><span class="chill-no-data-statement">{{ 'No reason associated'|trans }}</span></dd>
{%- else -%}
<dd>{% for r in activity.reasons %}{{ m.reason(r) }} {% endfor %}</dd>
<dd>{% for r in activity.reasons %}{{ r|chill_entity_render_box }} {% endfor %}</dd>
{%- endif -%}
</dl>

View File

@ -0,0 +1,86 @@
<?php
/*
* Chill is a software for social workers
*
* Copyright (C) 2014-2020, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\ActivityBundle\Templating\Entity;
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
use Chill\ActivityBundle\Entity\ActivityReason;
use Chill\MainBundle\Templating\TranslatableStringHelper;
/**
* Render activity reason
*
*/
class ActivityReasonRender extends AbstractChillEntityRender
{
/**
*
* @var TranslatableStringHelper
*/
protected $translatableStringHelper;
public function __construct(TranslatableStringHelper $translatableStringHelper)
{
$this->translatableStringHelper = $translatableStringHelper;
}
public function renderBox($entity, array $options): string
{
return
$this->getDefaultOpeningBox('activity-reason').
'<i class="fa fa-question-circle"></i>&nbsp;'.
'<span class="activity-reason__category">'.
$this->translatableStringHelper->localize(
$entity->getCategory()->getName()
).
'</span>'.
'<span class="activity-reason__separator">&nbsp;>&nbsp;</span>'.
'<span class="activity-reason__reason">'.
$this->translatableStringHelper->localize(
$entity->getName()
).
'</span>'.
$this->getDefaultClosingBox()
;
}
/**
*
* @param ActivityReason $entity
* @param array $options
* @return string
*/
public function renderString($entity, array $options): string
{
return $this->translatableStringHelper->localize(
$entity->getCategory()->getName()
).
' > '.
$this->translatableStringHelper->localize(
$entity->getName()
);
}
public function supports($entity, array $options): bool
{
return $entity instanceof ActivityReason;
}
}

4
chill.webpack.config.js Normal file
View File

@ -0,0 +1,4 @@
// this file loads all assets from the Chill person bundle
module.exports = function(encore, entries) {
entries.push(__dirname + '/Resources/public/index.js');
};