mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
replace dropdown for selecting reasons and use chillEntity for reason rendering
This commit is contained in:
parent
544466d504
commit
a9349becf7
@ -23,3 +23,7 @@ Version 1.5.4
|
|||||||
- [report activity]: add aggregator for activity users
|
- [report activity]: add aggregator for activity users
|
||||||
- fix bug: error when extracting activities without filter / aggregators selecting persons
|
- 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
|
||||||
|
@ -54,6 +54,8 @@ class ChillActivityExtension extends Extension implements PrependExtensionInterf
|
|||||||
$loader->load('services/fixtures.yml');
|
$loader->load('services/fixtures.yml');
|
||||||
$loader->load('services/menu.yml');
|
$loader->load('services/menu.yml');
|
||||||
$loader->load('services/controller.yml');
|
$loader->load('services/controller.yml');
|
||||||
|
$loader->load('services/form.yml');
|
||||||
|
$loader->load('services/templating.yml');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function prepend(ContainerBuilder $container)
|
public function prepend(ContainerBuilder $container)
|
||||||
|
@ -116,7 +116,7 @@ class ActivityType extends AbstractType
|
|||||||
])
|
])
|
||||||
->add('reasons', TranslatableActivityReason::class, array(
|
->add('reasons', TranslatableActivityReason::class, array(
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'required' => false
|
'required' => false,
|
||||||
))
|
))
|
||||||
->add('type', TranslatableActivityType::class, array(
|
->add('type', TranslatableActivityType::class, array(
|
||||||
'placeholder' => 'Choose a type',
|
'placeholder' => 'Choose a type',
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* Chill is a software for social workers
|
* 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>
|
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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 Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
|
use Chill\ActivityBundle\Entity\ActivityReason;
|
||||||
|
use Chill\ActivityBundle\Templating\Entity\ActivityReasonRender;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description of TranslatableActivityReason
|
* FormType to choose amongst activity reasons
|
||||||
*
|
*
|
||||||
* @author Champs-Libres Coop
|
|
||||||
*/
|
*/
|
||||||
class TranslatableActivityReason extends AbstractType
|
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->translatableStringHelper = $translatableStringHelper;
|
||||||
|
$this->reasonRender = $reasonRender;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBlockPrefix()
|
public function getBlockPrefix()
|
||||||
@ -55,20 +69,20 @@ class TranslatableActivityReason extends AbstractType
|
|||||||
|
|
||||||
public function configureOptions(OptionsResolver $resolver)
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
{
|
{
|
||||||
$helper = $this->translatableStringHelper;
|
|
||||||
$resolver->setDefaults(
|
$resolver->setDefaults(
|
||||||
array(
|
array(
|
||||||
'class' => 'ChillActivityBundle:ActivityReason',
|
'class' => 'ChillActivityBundle:ActivityReason',
|
||||||
'choice_label' => function($choice, $key) use ($helper) {
|
'choice_label' => function(ActivityReason $choice) {
|
||||||
return $helper->localize($choice->getName());
|
return $this->reasonRender->renderString($choice, []);
|
||||||
},
|
},
|
||||||
'group_by' => function($choice, $key) use ($helper) {
|
'group_by' => function(ActivityReason $choice) {
|
||||||
return $helper->localize($choice->getCategory()->getName());
|
return $this->translatableStringHelper->localize($choice->getCategory()->getName());
|
||||||
},
|
},
|
||||||
'query_builder' => function (EntityRepository $er) {
|
'query_builder' => function (EntityRepository $er) {
|
||||||
return $er->createQueryBuilder('r')
|
return $er->createQueryBuilder('r')
|
||||||
->where('r.active = true');
|
->where('r.active = true');
|
||||||
}
|
},
|
||||||
|
'attr' => [ 'class' => ' select2 ']
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,37 +1,4 @@
|
|||||||
services:
|
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 }
|
|
||||||
|
|
||||||
chill.activity.security.authorization.activity_voter:
|
chill.activity.security.authorization.activity_voter:
|
||||||
class: Chill\ActivityBundle\Security\Authorization\ActivityVoter
|
class: Chill\ActivityBundle\Security\Authorization\ActivityVoter
|
||||||
arguments:
|
arguments:
|
||||||
|
35
Resources/config/services/form.yml
Normal file
35
Resources/config/services/form.yml
Normal 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 }
|
7
Resources/config/services/templating.yml
Normal file
7
Resources/config/services/templating.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
services:
|
||||||
|
Chill\ActivityBundle\Templating\Entity\ActivityReasonRender:
|
||||||
|
arguments:
|
||||||
|
$translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper'
|
||||||
|
tags:
|
||||||
|
- { name: 'chill.render_entity' }
|
10
Resources/public/activity/activity.scss
Normal file
10
Resources/public/activity/activity.scss
Normal 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;
|
||||||
|
}
|
1
Resources/public/index.js
Normal file
1
Resources/public/index.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
require('./activity/activity.scss');
|
@ -16,8 +16,6 @@
|
|||||||
#}
|
#}
|
||||||
{% extends "ChillPersonBundle::layout.html.twig" %}
|
{% extends "ChillPersonBundle::layout.html.twig" %}
|
||||||
|
|
||||||
{% import 'ChillActivityBundle:ActivityReason:macro.html.twig' as m %}
|
|
||||||
|
|
||||||
{% set activeRouteKey = 'chill_activity_activity_list' %}
|
{% set activeRouteKey = 'chill_activity_activity_list' %}
|
||||||
|
|
||||||
{% block title %}{{ 'Activity list' |trans }}{% endblock title %}
|
{% block title %}{{ 'Activity list' |trans }}{% endblock title %}
|
||||||
@ -47,10 +45,15 @@
|
|||||||
<td>{% if activity.date %}{{ activity.date|localizeddate('long', 'none') }}{% endif %}</td>
|
<td>{% if activity.date %}{{ activity.date|localizeddate('long', 'none') }}{% endif %}</td>
|
||||||
<td>{{ activity.durationTime|date('H:i') }}</td>
|
<td>{{ activity.durationTime|date('H:i') }}</td>
|
||||||
<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 -%}
|
{%- if activity.reasons is empty -%}
|
||||||
{{ 'No reason associated'|trans }}
|
{{ 'No reason associated'|trans }}
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
{% for r in activity.reasons %}{{ m.reason(r) }} {% endfor %}
|
{% for r in activity.reasons %}{{ r|chill_entity_render_box }} {% endfor %}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
</td>
|
</td>
|
||||||
<td>{{ activity.type.name | localize_translatable_string }}</td>
|
<td>{{ activity.type.name | localize_translatable_string }}</td>
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
{%- if entity.reasons is empty -%}
|
{%- if entity.reasons is empty -%}
|
||||||
<dd><span class="chill-no-data-statement">{{ 'No reason associated'|trans }}</span></dd>
|
<dd><span class="chill-no-data-statement">{{ 'No reason associated'|trans }}</span></dd>
|
||||||
{%- else -%}
|
{%- 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 -%}
|
{%- endif -%}
|
||||||
|
|
||||||
</dl>
|
</dl>
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
{%- if activity.reasons is empty -%}
|
{%- if activity.reasons is empty -%}
|
||||||
<dd><span class="chill-no-data-statement">{{ 'No reason associated'|trans }}</span></dd>
|
<dd><span class="chill-no-data-statement">{{ 'No reason associated'|trans }}</span></dd>
|
||||||
{%- else -%}
|
{%- 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 -%}
|
{%- endif -%}
|
||||||
|
|
||||||
</dl>
|
</dl>
|
||||||
|
86
Templating/Entity/ActivityReasonRender.php
Normal file
86
Templating/Entity/ActivityReasonRender.php
Normal 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> '.
|
||||||
|
'<span class="activity-reason__category">'.
|
||||||
|
$this->translatableStringHelper->localize(
|
||||||
|
$entity->getCategory()->getName()
|
||||||
|
).
|
||||||
|
'</span>'.
|
||||||
|
'<span class="activity-reason__separator"> > </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
4
chill.webpack.config.js
Normal 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');
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user