diff --git a/CHANGELOG.md b/CHANGELOG.md index c2b13f38d..37519663c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/DependencyInjection/ChillActivityExtension.php b/DependencyInjection/ChillActivityExtension.php index 0a5144a17..1bc1c4bb9 100644 --- a/DependencyInjection/ChillActivityExtension.php +++ b/DependencyInjection/ChillActivityExtension.php @@ -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) diff --git a/Form/ActivityType.php b/Form/ActivityType.php index fd4514b56..407ceaa70 100644 --- a/Form/ActivityType.php +++ b/Form/ActivityType.php @@ -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', diff --git a/Form/Type/TranslatableActivityReason.php b/Form/Type/TranslatableActivityReason.php index af8a7dcd1..8043f95ba 100644 --- a/Form/Type/TranslatableActivityReason.php +++ b/Form/Type/TranslatableActivityReason.php @@ -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, * , * * 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 '] ) ); } diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 3df2ececf..fc3b65faf 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -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: diff --git a/Resources/config/services/form.yml b/Resources/config/services/form.yml new file mode 100644 index 000000000..e9f81c14e --- /dev/null +++ b/Resources/config/services/form.yml @@ -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 } diff --git a/Resources/config/services/templating.yml b/Resources/config/services/templating.yml new file mode 100644 index 000000000..e96f72211 --- /dev/null +++ b/Resources/config/services/templating.yml @@ -0,0 +1,7 @@ +--- +services: + Chill\ActivityBundle\Templating\Entity\ActivityReasonRender: + arguments: + $translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper' + tags: + - { name: 'chill.render_entity' } diff --git a/Resources/public/activity/activity.scss b/Resources/public/activity/activity.scss new file mode 100644 index 000000000..bef8788f8 --- /dev/null +++ b/Resources/public/activity/activity.scss @@ -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; +} diff --git a/Resources/public/index.js b/Resources/public/index.js new file mode 100644 index 000000000..74b2a8646 --- /dev/null +++ b/Resources/public/index.js @@ -0,0 +1 @@ +require('./activity/activity.scss'); diff --git a/Resources/views/Activity/list.html.twig b/Resources/views/Activity/list.html.twig index 4061d6469..061990614 100644 --- a/Resources/views/Activity/list.html.twig +++ b/Resources/views/Activity/list.html.twig @@ -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 @@ {% if activity.date %}{{ activity.date|localizeddate('long', 'none') }}{% endif %} {{ activity.durationTime|date('H:i') }} + {% if activity.remark is not empty %} +
+ {{ activity.remark|truncate(250, true) }} +
+ {% 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 -%} {{ activity.type.name | localize_translatable_string }} diff --git a/Resources/views/Activity/show.html.twig b/Resources/views/Activity/show.html.twig index 8a9bb3afc..e5bf0da51 100644 --- a/Resources/views/Activity/show.html.twig +++ b/Resources/views/Activity/show.html.twig @@ -35,7 +35,7 @@ {%- if entity.reasons is empty -%}
{{ 'No reason associated'|trans }}
{%- else -%} -
{% for r in entity.reasons %}{{ m.reason(r) }} {% endfor %}
+
{% for r in entity.reasons %}{{ r|chill_entity_render_box }} {% endfor %}
{%- endif -%} diff --git a/Resources/views/Timeline/activity_person_context.html.twig b/Resources/views/Timeline/activity_person_context.html.twig index 6d08d5b14..0af6d456c 100644 --- a/Resources/views/Timeline/activity_person_context.html.twig +++ b/Resources/views/Timeline/activity_person_context.html.twig @@ -20,7 +20,7 @@ {%- 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 -%} diff --git a/Templating/Entity/ActivityReasonRender.php b/Templating/Entity/ActivityReasonRender.php new file mode 100644 index 000000000..f405621c5 --- /dev/null +++ b/Templating/Entity/ActivityReasonRender.php @@ -0,0 +1,86 @@ +, + * + * 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 . + */ +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'). + ' '. + ''. + $this->translatableStringHelper->localize( + $entity->getCategory()->getName() + ). + ''. + ' > '. + ''. + $this->translatableStringHelper->localize( + $entity->getName() + ). + ''. + $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; + } +} diff --git a/chill.webpack.config.js b/chill.webpack.config.js new file mode 100644 index 000000000..724184f63 --- /dev/null +++ b/chill.webpack.config.js @@ -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'); +};