From 9623a35e6fa98b233a876409709ac4e15c0a4785 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 16 Nov 2022 10:57:06 +0100 Subject: [PATCH 001/415] #16 EventBundle participation (fix errors and improve ux) --- .../Form/Type/PickEventType.php | 2 +- .../views/Event/listByPerson.html.twig | 21 ++----------------- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/src/Bundle/ChillEventBundle/Form/Type/PickEventType.php b/src/Bundle/ChillEventBundle/Form/Type/PickEventType.php index 782bd7628..4e8179f10 100644 --- a/src/Bundle/ChillEventBundle/Form/Type/PickEventType.php +++ b/src/Bundle/ChillEventBundle/Form/Type/PickEventType.php @@ -151,7 +151,7 @@ class PickEventType extends AbstractType } else { $centers = $this->authorizationHelper->getReachableCenters( $this->user, - (string) $options['role'] + (string) $options['role']->getRole() ); } diff --git a/src/Bundle/ChillEventBundle/Resources/views/Event/listByPerson.html.twig b/src/Bundle/ChillEventBundle/Resources/views/Event/listByPerson.html.twig index 53e97c3c4..9ffd5093c 100644 --- a/src/Bundle/ChillEventBundle/Resources/views/Event/listByPerson.html.twig +++ b/src/Bundle/ChillEventBundle/Resources/views/Event/listByPerson.html.twig @@ -108,31 +108,14 @@ {{ chill_pagination(paginator) }} {% endif %} -
+
{{ form_start(form_add_event_participation_by_person) }} - {# - - #} {{ form_widget(form_add_event_participation_by_person.event_id, { 'attr' : { 'class' : 'form-control' } } ) }}
- {# - - #} - {{ form_widget(form_add_event_participation_by_person.submit, { 'attr' : { 'class' : 'btn btn-success' } } ) }} + {{ form_widget(form_add_event_participation_by_person.submit, { 'attr' : { 'class' : 'btn btn-sm btn-success' } } ) }}
{{ form_rest(form_add_event_participation_by_person) }} {{ form_end(form_add_event_participation_by_person) }}
-{# -{{ form(form_add_event_participation_by_person) }} -#} - -
- -
- -
-
- {% endblock %} From 928869666c42db48e8b4a7f747228c877e18b24c Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 16 Nov 2022 13:03:25 +0100 Subject: [PATCH 002/415] #16 fix errors and some design regressions in eventBundle --- .../views/Event/confirm_delete.html.twig | 3 +- .../Resources/views/Event/edit.html.twig | 5 +- .../Resources/views/Event/list.html.twig | 73 ++++++++++--------- .../views/Event/listByPerson.html.twig | 63 ++++++++-------- .../Resources/views/Event/new.html.twig | 2 + .../views/Event/newPickCenter.html.twig | 3 +- .../Resources/views/Event/show.html.twig | 9 ++- .../Participation/confirm_delete.html.twig | 4 +- .../Participation/edit-multiple.html.twig | 8 +- .../views/Participation/edit.html.twig | 2 + .../Participation/new-multiple.html.twig | 4 +- .../views/Participation/new.html.twig | 3 +- .../Resources/views/layout.html.twig | 4 +- .../Form/Type/PickPersonType.php | 2 +- 14 files changed, 101 insertions(+), 84 deletions(-) diff --git a/src/Bundle/ChillEventBundle/Resources/views/Event/confirm_delete.html.twig b/src/Bundle/ChillEventBundle/Resources/views/Event/confirm_delete.html.twig index 86b7c6fd2..c3a13b55a 100644 --- a/src/Bundle/ChillEventBundle/Resources/views/Event/confirm_delete.html.twig +++ b/src/Bundle/ChillEventBundle/Resources/views/Event/confirm_delete.html.twig @@ -5,6 +5,7 @@ {% block title 'Delete event'|trans %} {% block event_content %} +
{{ include('@ChillMain/Util/confirmation_template.html.twig', { @@ -15,6 +16,6 @@ 'form' : delete_form } ) }} - +
{% endblock %} diff --git a/src/Bundle/ChillEventBundle/Resources/views/Event/edit.html.twig b/src/Bundle/ChillEventBundle/Resources/views/Event/edit.html.twig index 288c81edd..a528f1f5c 100644 --- a/src/Bundle/ChillEventBundle/Resources/views/Event/edit.html.twig +++ b/src/Bundle/ChillEventBundle/Resources/views/Event/edit.html.twig @@ -3,6 +3,7 @@ {% block title 'Event edit'|trans %} {% block event_content -%} +

{{ 'Event edit'|trans }}

{{ form_start(edit_form) }} @@ -28,6 +29,8 @@ {{ form_widget(edit_form.submit, { 'attr' : { 'class' : 'btn btn-update' } }) }} - + {{ form_end(edit_form) }} + +
{% endblock %} diff --git a/src/Bundle/ChillEventBundle/Resources/views/Event/list.html.twig b/src/Bundle/ChillEventBundle/Resources/views/Event/list.html.twig index 6e77b6df8..8d5f49da8 100644 --- a/src/Bundle/ChillEventBundle/Resources/views/Event/list.html.twig +++ b/src/Bundle/ChillEventBundle/Resources/views/Event/list.html.twig @@ -6,42 +6,42 @@

{{ 'Results %start%-%end% of %total%'|trans({ '%start%' : start, '%end%': start + events|length, '%total%' : total } ) }}

- +
- - - - - - + + + + + + - {% for event in events %} - - - - - + + + + - - {% endfor %} + {% endif %} + + + + + {% endfor %}
{{ 'Name'|trans }}{{ 'Date'|trans }}{{ 'Event type'|trans }} 
{{ 'Name'|trans }}{{ 'Date'|trans }}{{ 'Event type'|trans }} 
{{ event.name }}{{ event.date|format_date('long') }}{{ event.type.name|localize_translatable_string }} -
    -
  • - {# {% if is_granted('CHILL_EVENT_SEE_DETAILS', event) %} #} - - {{ 'See'|trans }} - - {# {% endif %} #} - {% if is_granted('CHILL_EVENT_UPDATE', event) %} + {% for event in events %} +
{{ event.name }}{{ event.date|format_date('long') }}{{ event.type.name|localize_translatable_string }} + -
- + {% endif %} {% if preview == false %} -{{ chill_pagination(paginator) }} + {{ chill_pagination(paginator) }} {% endif %} + diff --git a/src/Bundle/ChillEventBundle/Resources/views/Event/listByPerson.html.twig b/src/Bundle/ChillEventBundle/Resources/views/Event/listByPerson.html.twig index 9ffd5093c..ef2dae85c 100644 --- a/src/Bundle/ChillEventBundle/Resources/views/Event/listByPerson.html.twig +++ b/src/Bundle/ChillEventBundle/Resources/views/Event/listByPerson.html.twig @@ -44,59 +44,59 @@ {{ participation.role.name|localize_translatable_string }} {{ participation.status.name|localize_translatable_string }} -
    +
    {% set currentPath = path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')) %} {% set returnLabel = 'Back to %person% events'|trans({ '%person%' : currentPerson } ) %} {% if is_granted('CHILL_EVENT_SEE_DETAILS', participation.event) %} -
  • -
  • + class="btn btn-primary btn-sm" title="{{ 'See details of the event'|trans }}"> + + {% endif %} {% if is_granted('CHILL_EVENT_UPDATE', participation.event) and is_granted('CHILL_EVENT_PARTICIPATION_UPDATE', participation) %} -
  • -
  • + +
+
{% else %} -
  • {% if is_granted('CHILL_EVENT_UPDATE', participation.event) %} - - {{ 'Edit the event'|trans }} - + + {{ 'Edit the event'|trans }} + {% endif %} {% if is_granted('CHILL_EVENT_PARTICIPATION_UPDATE', participation) %} - - {{ 'Edit the participation'|trans }} - + + {{ 'Edit the participation'|trans }} + {% endif %} -
  • {% endif %} - + {% endfor %} @@ -108,11 +108,14 @@ {{ chill_pagination(paginator) }} {% endif %} -
    +
    {{ form_start(form_add_event_participation_by_person) }} - {{ form_widget(form_add_event_participation_by_person.event_id, { 'attr' : { 'class' : 'form-control' } } ) }} -
    - {{ form_widget(form_add_event_participation_by_person.submit, { 'attr' : { 'class' : 'btn btn-sm btn-success' } } ) }} + {{ form_widget(form_add_event_participation_by_person.event_id, { 'attr' : { + 'class' : 'custom-select', + 'style': 'min-width: 15em; max-width: 18em; display: inline-block;' + }}) }} +
    + {{ form_widget(form_add_event_participation_by_person.submit, { 'attr' : { 'class' : 'btn btn-sm btn-save' } } ) }}
    {{ form_rest(form_add_event_participation_by_person) }} {{ form_end(form_add_event_participation_by_person) }} diff --git a/src/Bundle/ChillEventBundle/Resources/views/Event/new.html.twig b/src/Bundle/ChillEventBundle/Resources/views/Event/new.html.twig index 44d24040b..f0d1b0ea2 100644 --- a/src/Bundle/ChillEventBundle/Resources/views/Event/new.html.twig +++ b/src/Bundle/ChillEventBundle/Resources/views/Event/new.html.twig @@ -3,6 +3,7 @@ {% block title 'Event creation'|trans %} {% block event_content -%} +

    {{ 'Event creation'|trans }}

    {{ form_start(form) }} @@ -26,4 +27,5 @@ {{ form_end(form) }} +
    {% endblock %} diff --git a/src/Bundle/ChillEventBundle/Resources/views/Event/newPickCenter.html.twig b/src/Bundle/ChillEventBundle/Resources/views/Event/newPickCenter.html.twig index c4fb4aacd..a10d754e6 100644 --- a/src/Bundle/ChillEventBundle/Resources/views/Event/newPickCenter.html.twig +++ b/src/Bundle/ChillEventBundle/Resources/views/Event/newPickCenter.html.twig @@ -3,6 +3,7 @@ {% block title 'Event creation'|trans %} {% block event_content -%} +

    {{ 'Event creation'|trans }}

    {{ form_start(form) }} @@ -22,5 +23,5 @@ {{ form_end(form) }} - +
    {% endblock %} diff --git a/src/Bundle/ChillEventBundle/Resources/views/Event/show.html.twig b/src/Bundle/ChillEventBundle/Resources/views/Event/show.html.twig index 6af5dd80a..4ce92a200 100644 --- a/src/Bundle/ChillEventBundle/Resources/views/Event/show.html.twig +++ b/src/Bundle/ChillEventBundle/Resources/views/Event/show.html.twig @@ -5,9 +5,10 @@ {% import 'ChillPersonBundle:Person:macro.html.twig' as person_macro %} {% block event_content -%} +

    {{ 'Details of an event'|trans }}

    - +
    @@ -69,7 +70,7 @@

    {% transchoice count %}%count% participations to this event{% endtranschoice %}

    {% if count > 0 %} -
    {{ 'Name'|trans }}
    +
    @@ -117,7 +118,7 @@ {% endif %} -
    +
    {{ form_start(form_add_participation_by_person) }}
    @@ -150,5 +151,5 @@
    {{ chill_delegated_block('block_footer_show', { 'event': event }) }}
    - +
    {% endblock %} diff --git a/src/Bundle/ChillEventBundle/Resources/views/Participation/confirm_delete.html.twig b/src/Bundle/ChillEventBundle/Resources/views/Participation/confirm_delete.html.twig index 9b023a915..0d993b075 100644 --- a/src/Bundle/ChillEventBundle/Resources/views/Participation/confirm_delete.html.twig +++ b/src/Bundle/ChillEventBundle/Resources/views/Participation/confirm_delete.html.twig @@ -5,7 +5,7 @@ {% block title 'Remove participation'|trans %} {% block event_content %} - +
    {{ include('@ChillMain/Util/confirmation_template.html.twig', { 'title' : 'Remove participation'|trans, @@ -15,6 +15,6 @@ 'form' : delete_form } ) }} - +
    {% endblock %} diff --git a/src/Bundle/ChillEventBundle/Resources/views/Participation/edit-multiple.html.twig b/src/Bundle/ChillEventBundle/Resources/views/Participation/edit-multiple.html.twig index a50615414..f0f522a3d 100644 --- a/src/Bundle/ChillEventBundle/Resources/views/Participation/edit-multiple.html.twig +++ b/src/Bundle/ChillEventBundle/Resources/views/Participation/edit-multiple.html.twig @@ -3,9 +3,10 @@ {% import 'ChillPersonBundle:Person:macro.html.twig' as person_macro %} {% block event_content -%} +

    {{ 'Participation Edit'|trans }}

    -
    {{ 'Person'|trans }}
    +
    @@ -18,11 +19,11 @@
    {{ 'Associated event'|trans }}
    -

    {{ 'Participations'|trans }}

    +

    {{ 'Participations'|trans }}

    {{ form_start(form) }} - +
    @@ -59,4 +60,5 @@ {{ form_end(form) }} + {% endblock %} diff --git a/src/Bundle/ChillEventBundle/Resources/views/Participation/edit.html.twig b/src/Bundle/ChillEventBundle/Resources/views/Participation/edit.html.twig index 19592526e..db716b3dc 100644 --- a/src/Bundle/ChillEventBundle/Resources/views/Participation/edit.html.twig +++ b/src/Bundle/ChillEventBundle/Resources/views/Participation/edit.html.twig @@ -3,6 +3,7 @@ {% import 'ChillPersonBundle:Person:macro.html.twig' as person_macro %} {% block event_content -%} +

    {{ 'Participation Edit'|trans }}

    {{ 'Person'|trans }}
    @@ -42,4 +43,5 @@ {{ form_end(form) }} + {% endblock %} diff --git a/src/Bundle/ChillEventBundle/Resources/views/Participation/new-multiple.html.twig b/src/Bundle/ChillEventBundle/Resources/views/Participation/new-multiple.html.twig index a0551ff1a..224b7265f 100644 --- a/src/Bundle/ChillEventBundle/Resources/views/Participation/new-multiple.html.twig +++ b/src/Bundle/ChillEventBundle/Resources/views/Participation/new-multiple.html.twig @@ -18,7 +18,7 @@ {% block event_content -%}

    {{ 'Participation creation'|trans }}

    -
    +
    @@ -30,7 +30,7 @@ {% include 'ChillEventBundle:Participation:_ignored_participations.html.twig' with ignored_participations %} {{ form_start(form) }} -
    {{ 'Associated event'|trans }}
    +
    diff --git a/src/Bundle/ChillEventBundle/Resources/views/Participation/new.html.twig b/src/Bundle/ChillEventBundle/Resources/views/Participation/new.html.twig index 33f7bc213..3fbea8b68 100644 --- a/src/Bundle/ChillEventBundle/Resources/views/Participation/new.html.twig +++ b/src/Bundle/ChillEventBundle/Resources/views/Participation/new.html.twig @@ -5,6 +5,7 @@ {% block title 'Participation creation'|trans %} {% block event_content -%} +

    {{ 'Participation creation'|trans }}

    {{ 'Person'|trans }}
    @@ -43,5 +44,5 @@ {{ form_end(form) }} - + {% endblock %} diff --git a/src/Bundle/ChillEventBundle/Resources/views/layout.html.twig b/src/Bundle/ChillEventBundle/Resources/views/layout.html.twig index 45eb6e481..e34a10e18 100644 --- a/src/Bundle/ChillEventBundle/Resources/views/layout.html.twig +++ b/src/Bundle/ChillEventBundle/Resources/views/layout.html.twig @@ -16,9 +16,9 @@ * along with this program. If not, see . #} -{% extends "@ChillMain/layoutWithVerticalMenu.html.twig" %} +{% extends "@ChillMain/layout.html.twig" %} -{% block layout_wvm_content %} +{% block content %} {% block event_content %}

    {{ 'Event' |trans }}

    {% endblock %} diff --git a/src/Bundle/ChillPersonBundle/Form/Type/PickPersonType.php b/src/Bundle/ChillPersonBundle/Form/Type/PickPersonType.php index 9e7938675..501af5b9d 100644 --- a/src/Bundle/ChillPersonBundle/Form/Type/PickPersonType.php +++ b/src/Bundle/ChillPersonBundle/Form/Type/PickPersonType.php @@ -144,7 +144,7 @@ class PickPersonType extends AbstractType }, $this->user->getGroupCenters()->toArray()); } else { $centers = $this->authorizationHelper - ->getReachableCenters($this->user, $options['role']); + ->getReachableCenters($this->user, $options['role']->getRole()); } if (null === $options['centers']) { From 56a7833858245059a615960c4d995e861c4b107d Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 16 Nov 2022 17:44:48 +0100 Subject: [PATCH 003/415] #16 Fix html5 widget for ChillDateTimeType --- src/Bundle/ChillMainBundle/Form/Type/ChillDateTimeType.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/Form/Type/ChillDateTimeType.php b/src/Bundle/ChillMainBundle/Form/Type/ChillDateTimeType.php index 639848d9a..0063ee7d9 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/ChillDateTimeType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/ChillDateTimeType.php @@ -27,7 +27,6 @@ class ChillDateTimeType extends AbstractType { $resolver ->setDefault('date_widget', 'single_text') - ->setDefault('date_format', 'dd-MM-yyyy') ->setDefault('time_widget', 'choice') ->setDefault('minutes', range(0, 59, 5)) ->setDefault('hours', range(8, 22)) From 53980dd75720ffc52fa3e199dedd2f67defd6d0f Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 16 Nov 2022 22:30:05 +0100 Subject: [PATCH 004/415] #16 replace hardcoded country and map_center in vue add-address by symfony config yaml variables --- .../DependencyInjection/ChillMainExtension.php | 8 +++++++- .../DependencyInjection/Configuration.php | 13 ++++++++++++- .../public/vuejs/Address/components/AddAddress.vue | 7 +++++-- .../Address/components/AddAddress/AddressMap.vue | 2 +- .../components/AddAddress/CountrySelection.vue | 2 +- .../public/vuejs/Address/components/ShowPane.vue | 2 +- .../Resources/public/vuejs/Address/index.js | 3 ++- .../views/Address/_insert_vue_address.html.twig | 2 ++ 8 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index 627841364..48a4a164c 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -142,7 +142,12 @@ class ChillMainExtension extends Extension implements 'chill_main.access_permissions_group_list', $config['access_permissions_group_list'] ); - + + $container->setParameter( + 'chill_main.add_address', + $config['add_address'] + ); + $container->setParameter( 'chill_main.routing.resources', $config['routing']['resources'] @@ -215,6 +220,7 @@ class ChillMainExtension extends Extension implements 'installation' => [ 'name' => $config['installation_name'], ], 'available_languages' => $config['available_languages'], + 'add_address' => $config['add_address'] ], 'form_themes' => ['@ChillMain/Form/fields.html.twig'], ]; diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php index d3e4da1a6..2c957296e 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php @@ -266,7 +266,18 @@ class Configuration implements ConfigurationInterface ->end() ->end() // end of root/children ->end() // end of root -; + ; + + $rootNode->children() + ->arrayNode('add_address')->children() + ->scalarNode('default_country')->cannotBeEmpty()->end() + ->arrayNode('map_center')->children() + ->scalarNode('x')->cannotBeEmpty()->end() + ->scalarNode('y')->cannotBeEmpty()->end() + ->scalarNode('z')->cannotBeEmpty()->end() + ->end() + ->end() + ; return $treeBuilder; } diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue index fcd64ed70..b47ae520d 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue @@ -309,8 +309,11 @@ export default { addressMap: { // Note: LeafletJs demands [lat, lon] // cfr https://macwright.com/lonlat/ - center : [48.8589, 2.3469], - zoom: 12 + center : [ + this.context.defaults.map_center.x, + this.context.defaults.map_center.y + ], + zoom: this.context.defaults.map_center.z }, }, errorMsg: [] diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/AddressMap.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/AddressMap.vue index 80d2ca01a..2422dfdce 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/AddressMap.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/AddressMap.vue @@ -44,7 +44,7 @@ export default { //console.log('update map with : ', this.entity.addressMap.center) if (this.marker && this.entity.addressMap.center) { this.marker.setLatLng(this.entity.addressMap.center); - this.map.setView(this.entity.addressMap.center, 15); + this.map.setView(this.entity.addressMap.center, this.entity.addressMap.zoom); } } }, diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/CountrySelection.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/CountrySelection.vue index 6e64b2985..e82599c77 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/CountrySelection.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress/CountrySelection.vue @@ -30,7 +30,7 @@ export default { data() { return { value: this.selectCountryByCode( - this.context.edit ? this.entity.selected.country.code : 'FR' + this.context.edit ? this.entity.selected.country.code : this.context.defaults.default_country ) } }, diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowPane.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowPane.vue index 7f7b1b529..bc246d542 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowPane.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowPane.vue @@ -102,7 +102,7 @@ export default { ], emits: ['openEditPane'], mounted() { - console.log('context', this.context) + //console.log('context', this.context) }, computed: { address() { diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/index.js b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/index.js index 9241aa29d..ab0fb0bd4 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/index.js @@ -20,7 +20,8 @@ containers.forEach((container) => { }, edit: container.dataset.mode === 'edit', //boolean addressId: parseInt(container.dataset.addressId) || null, - backUrl: container.dataset.backUrl || null + backUrl: container.dataset.backUrl || null, + defaults: JSON.parse(container.dataset.addressDefaults) }, options: { /// Options override default. diff --git a/src/Bundle/ChillMainBundle/Resources/views/Address/_insert_vue_address.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Address/_insert_vue_address.html.twig index 571f4257f..70780eb90 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Address/_insert_vue_address.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Address/_insert_vue_address.html.twig @@ -72,6 +72,8 @@ {% if onlyButton is defined and onlyButton == 1 %} data-hide-address="true" {% endif %} + + data-address-defaults="{{ add_address|json_encode|e('html') }}" > {{ encore_entry_script_tags('vue_address') }} From e90782500b58748950693f3d19b1851a07d73d2f Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 16 Nov 2022 23:10:11 +0100 Subject: [PATCH 005/415] #16 add default value for config variables --- .../ChillMainBundle/DependencyInjection/Configuration.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php index 2c957296e..07eb53d63 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php @@ -270,11 +270,11 @@ class Configuration implements ConfigurationInterface $rootNode->children() ->arrayNode('add_address')->children() - ->scalarNode('default_country')->cannotBeEmpty()->end() + ->scalarNode('default_country')->cannotBeEmpty()->defaultValue('BE')->end() ->arrayNode('map_center')->children() - ->scalarNode('x')->cannotBeEmpty()->end() - ->scalarNode('y')->cannotBeEmpty()->end() - ->scalarNode('z')->cannotBeEmpty()->end() + ->scalarNode('x')->cannotBeEmpty()->defaultValue(50.8443)->end() + ->scalarNode('y')->cannotBeEmpty()->defaultValue(4.3523)->end() + ->scalarNode('z')->cannotBeEmpty()->defaultValue(15)->end() ->end() ->end() ; From 3ca46efd2c92d9a8ae8be508fcde1862d6a1578b Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 17 Nov 2022 16:12:30 +0100 Subject: [PATCH 006/415] #16 pass default variables to add-address component when it is called from another vue component --- .../public/vuejs/Activity/components/Location/NewLocation.vue | 3 ++- .../Resources/views/Activity/editAccompanyingCourse.html.twig | 1 + .../Resources/views/Activity/editPerson.html.twig | 1 + .../Resources/views/Activity/newAccompanyingCourse.html.twig | 1 + .../Resources/views/Activity/newPerson.html.twig | 1 + src/Bundle/ChillMainBundle/Resources/views/layout.html.twig | 1 + .../vuejs/AccompanyingCourse/components/CourseLocation.vue | 3 ++- .../public/vuejs/HouseholdMembersEditor/store/index.js | 3 +++ .../Resources/public/vuejs/_components/OnTheFly/Person.vue | 3 ++- .../Resources/views/AccompanyingCourse/edit.html.twig | 1 + .../Resources/views/Household/members_editor.html.twig | 1 + .../Resources/public/vuejs/_components/OnTheFly/ThirdParty.vue | 3 ++- 12 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location/NewLocation.vue b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location/NewLocation.vue index 6a6289875..568c8747a 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location/NewLocation.vue +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location/NewLocation.vue @@ -117,7 +117,8 @@ export default { target: { //name, id }, edit: false, - addressId: null + addressId: null, + defaults: window.addaddress } } } diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/editAccompanyingCourse.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/editAccompanyingCourse.html.twig index d0359e223..a07fde4aa 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/editAccompanyingCourse.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/editAccompanyingCourse.html.twig @@ -22,6 +22,7 @@ '{{ "You are going to leave a page with unsubmitted data. Are you sure you want to leave ?"|trans }}'); }); window.activity = {{ activity_json|json_encode|raw }}; + window.addaddress = {{ add_address|json_encode|raw }}; {{ encore_entry_script_tags('vue_activity') }} {% endblock %} diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/editPerson.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/editPerson.html.twig index 91b3867c1..efb511bab 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/editPerson.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/editPerson.html.twig @@ -37,6 +37,7 @@ '{{ "You are going to leave a page with unsubmitted data. Are you sure you want to leave ?"|trans }}'); }); window.activity = {{ activity_json|json_encode|raw }}; + window.addaddress = {{ add_address|json_encode|raw }}; {{ encore_entry_script_tags('vue_activity') }} {% endblock %} diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/newAccompanyingCourse.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/newAccompanyingCourse.html.twig index 47a61bd86..05a92fb5a 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/newAccompanyingCourse.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/newAccompanyingCourse.html.twig @@ -18,6 +18,7 @@ {{ encore_entry_script_tags('mod_async_upload') }} {{ encore_entry_script_tags('vue_activity') }} diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/newPerson.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/newPerson.html.twig index d57fc3412..f1a13b61f 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/newPerson.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/newPerson.html.twig @@ -21,6 +21,7 @@ '{{ "You are going to leave a page with unsubmitted data. Are you sure you want to leave ?"|trans }}'); }); window.activity = {{ activity_json|json_encode|raw }}; + window.addaddress = {{ add_address|json_encode|raw }}; {{ encore_entry_script_tags('vue_activity') }} {% endblock %} diff --git a/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig b/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig index 5543809fc..cafe8dd0d 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig @@ -109,6 +109,7 @@ }); chill.categoryLinkParentChildSelect(); }); + window.addaddress = {{ add_address|json_encode|raw }}; {% block js %}{% endblock %} diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/CourseLocation.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/CourseLocation.vue index 42f974dd1..99e3519f4 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/CourseLocation.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/CourseLocation.vue @@ -164,7 +164,8 @@ export default { id: this.accompanyingCourse.id }, edit: false, - addressId: null + addressId: null, + defaults: window.addaddress } if (this.accompanyingCourse.location) { context['edit'] = true; diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/store/index.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/store/index.js index f3801576d..bbdde0dfa 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/store/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdMembersEditor/store/index.js @@ -5,6 +5,7 @@ import { fetchHouseholdByAddressReference } from 'ChillPersonAssets/lib/househol import { datetimeToISO, dateToISO, ISOToDate } from 'ChillMainAssets/chill/js/date.js'; const debug = process.env.NODE_ENV !== 'production'; +//console.log('AJAJAJA', window.addaddress); const concerned = window.household_members_editor_data.persons.map(p => { return { @@ -115,6 +116,7 @@ const store = createStore({ name: state.household.type, id: state.household.id }, + defaults: window.addaddress, suggestions: state.addressesSuggestion }; } else { @@ -125,6 +127,7 @@ const store = createStore({ name: state.household.type, id: state.household.id }, + defaults: window.addaddress, }; } }, diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/OnTheFly/Person.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/OnTheFly/Person.vue index 4f8909233..646d92b35 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/OnTheFly/Person.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/OnTheFly/Person.vue @@ -201,7 +201,8 @@ export default { context: { target: {}, // boilerplate for getting the address id edit: false, - addressId: null + addressId: null, + defaults: window.addaddress } }, errors: [] diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/edit.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/edit.html.twig index b3520349b..4197f6418 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/edit.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/edit.html.twig @@ -10,6 +10,7 @@ {{ encore_entry_script_tags('vue_accourse') }} {% endblock %} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Household/members_editor.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Household/members_editor.html.twig index 8b0134f6b..12d1ddf57 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Household/members_editor.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Household/members_editor.html.twig @@ -19,6 +19,7 @@ {{ encore_entry_script_tags('vue_household_members_editor') }} {% endblock %} diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/OnTheFly/ThirdParty.vue b/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/OnTheFly/ThirdParty.vue index 0ea011dc4..765d67fe8 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/OnTheFly/ThirdParty.vue +++ b/src/Bundle/ChillThirdPartyBundle/Resources/public/vuejs/_components/OnTheFly/ThirdParty.vue @@ -232,7 +232,8 @@ export default { id: this.id }, edit: false, - addressId: null + addressId: null, + defaults: window.addaddress }; if ( !(this.thirdparty.address === undefined || this.thirdparty.address === null) && this.thirdparty.address.address_id !== null From 8894491dac7162f2341fd1764f53df1218e931f8 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 17 Nov 2022 21:43:03 +0100 Subject: [PATCH 007/415] #16 fix error with vue_activity component in person context (when accompanyingPeriod is null) --- .../Resources/public/vuejs/Activity/store.js | 2 +- .../Resources/public/vuejs/Activity/store.locations.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.js b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.js index ca56a5dae..9f710abeb 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.js +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.js @@ -30,7 +30,7 @@ const store = createStore({ }, getters: { suggestedEntities(state) { - if (typeof state.activity.accompanyingPeriod === "undefined") { + if (typeof state.activity.accompanyingPeriod === "undefined" || state.activity.accompanyingPeriod === null) { return []; } const allEntities = [ diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.locations.js b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.locations.js index 6125140a5..051f0b4f6 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.locations.js +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/store.locations.js @@ -39,6 +39,9 @@ const makeConcernedThirdPartiesLocation = (locationType, store) => { return locations; }; const makeAccompanyingPeriodLocation = (locationType, store) => { + if (store.state.activity.accompanyingPeriod === null) { + return {}; + } const accPeriodLocation = store.state.activity.accompanyingPeriod.location; return { type: 'location', From 448d93cd029c1a72d541786323b7e8e34597339b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 18 Nov 2022 16:11:03 +0100 Subject: [PATCH 008/415] Fixed: [address] Add missing window.addaddress in person create page, and third party create and update page --- .../Resources/public/vuejs/Address/mod_input_address_index.js | 2 +- .../ChillPersonBundle/Resources/views/Person/create.html.twig | 3 +++ .../Resources/views/ThirdParty/new.html.twig | 3 +++ .../Resources/views/ThirdParty/update.html.twig | 3 +++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/mod_input_address_index.js b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/mod_input_address_index.js index cb7da6e07..6e9fd917c 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/mod_input_address_index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/mod_input_address_index.js @@ -19,7 +19,6 @@ const addAddressInput = (inputs) => { if (container === null) { throw Error("no container"); } - console.log('useValidFrom', el.dataset.useValidFrom === '1'); const app = createApp({ template: ``, @@ -34,6 +33,7 @@ const addAddressInput = (inputs) => { }, edit: isEdit, addressId: addressIdInt, + defaults: window.addaddress, }, options: { /// Options override default. diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/create.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/create.html.twig index 03bece4d5..a731016b9 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/create.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/create.html.twig @@ -143,6 +143,9 @@ {{ encore_entry_script_tags('page_suggest_names') }} {{ encore_entry_script_tags('page_create_person') }} {{ encore_entry_script_tags('mod_input_address') }} + {% endblock js %} {% block css %} diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/new.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/new.html.twig index 09a38c14f..dea9def7d 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/new.html.twig +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/new.html.twig @@ -22,6 +22,9 @@ {% block js %} {{ encore_entry_script_tags('mod_input_address') }} + {% endblock %} {% block css %} diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/update.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/update.html.twig index 2d9c39002..84de129bb 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/update.html.twig +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/update.html.twig @@ -38,6 +38,9 @@ {% block js %} {{ encore_entry_script_tags('mod_input_address') }} + {% endblock %} {% block css %} From cd54fdd13f620e5d43a410ba1d88ac54a716e0d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 18 Nov 2022 16:12:49 +0100 Subject: [PATCH 009/415] Feature: [activity] automatically add a person to an activity, if created in the person context See https://gitlab.com/Chill-Projet/chill-bundles/-/issues/28 --- src/Bundle/ChillActivityBundle/Controller/ActivityController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php index c7908fcaf..d76bffe80 100644 --- a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php +++ b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php @@ -359,6 +359,7 @@ final class ActivityController extends AbstractController if ($person instanceof Person) { $entity->setPerson($person); + $entity->getPersons()->add($person); } if ($accompanyingPeriod instanceof AccompanyingPeriod) { From d35dacf5627ce58aaccbdbec18293c2059870088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sun, 20 Nov 2022 21:27:19 +0100 Subject: [PATCH 010/415] Fixed: [budget] Fix voter on household's budget --- .../ChillBudgetBundle/Entity/Charge.php | 18 +++++++------ .../ChillBudgetBundle/Entity/Resource.php | 18 +++++++------ .../Authorization/BudgetElementVoter.php | 25 ++++++++++++++++--- 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/Bundle/ChillBudgetBundle/Entity/Charge.php b/src/Bundle/ChillBudgetBundle/Entity/Charge.php index dc03eef80..eab153b2e 100644 --- a/src/Bundle/ChillBudgetBundle/Entity/Charge.php +++ b/src/Bundle/ChillBudgetBundle/Entity/Charge.php @@ -11,8 +11,8 @@ declare(strict_types=1); namespace Chill\BudgetBundle\Entity; -use Chill\MainBundle\Entity\Center; -use Chill\MainBundle\Entity\HasCenterInterface; +use Chill\MainBundle\Entity\HasCentersInterface; +use Chill\PersonBundle\Entity\Person; use DateTimeImmutable; use Doctrine\ORM\Mapping as ORM; @@ -22,7 +22,7 @@ use Doctrine\ORM\Mapping as ORM; * @ORM\Table(name="chill_budget.charge") * @ORM\Entity(repositoryClass="Chill\BudgetBundle\Repository\ChargeRepository") */ -class Charge extends AbstractElement implements HasCenterInterface +class Charge extends AbstractElement implements HasCentersInterface { public const HELP_ASKED = 'running'; @@ -46,22 +46,24 @@ class Charge extends AbstractElement implements HasCenterInterface private $help = self::HELP_NOT_RELEVANT; /** - * @var int - * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ - private $id; + private ?int $id = null; public function __construct() { $this->setStartDate(new DateTimeImmutable('today')); } - public function getCenter(): ?Center + public function getCenters(): array { - return $this->getPerson()->getCenter(); + if (null !== $this->getPerson()) { + return [$this->getPerson()->getCenter()]; + } + + return $this->getHousehold()->getCurrentPersons()->map(static fn (Person $p) => $p->getCenter())->toArray(); } public function getHelp() diff --git a/src/Bundle/ChillBudgetBundle/Entity/Resource.php b/src/Bundle/ChillBudgetBundle/Entity/Resource.php index 949872d6c..bed9f23c3 100644 --- a/src/Bundle/ChillBudgetBundle/Entity/Resource.php +++ b/src/Bundle/ChillBudgetBundle/Entity/Resource.php @@ -11,8 +11,8 @@ declare(strict_types=1); namespace Chill\BudgetBundle\Entity; -use Chill\MainBundle\Entity\Center; -use Chill\MainBundle\Entity\HasCenterInterface; +use Chill\MainBundle\Entity\HasCentersInterface; +use Chill\PersonBundle\Entity\Person; use DateTimeImmutable; use Doctrine\ORM\Mapping as ORM; @@ -22,25 +22,27 @@ use Doctrine\ORM\Mapping as ORM; * @ORM\Table(name="chill_budget.resource") * @ORM\Entity(repositoryClass="Chill\BudgetBundle\Repository\ResourceRepository") */ -class Resource extends AbstractElement implements HasCenterInterface +class Resource extends AbstractElement implements HasCentersInterface { /** - * @var int - * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ - private $id; + private ?int $id = null; public function __construct() { $this->setStartDate(new DateTimeImmutable('today')); } - public function getCenter(): ?Center + public function getCenters(): array { - return $this->getPerson()->getCenter(); + if (null !== $this->getPerson()) { + return [$this->getPerson()->getCenter()]; + } + + return $this->getHousehold()->getCurrentPersons()->map(static fn (Person $p) => $p->getCenter())->toArray(); } /** diff --git a/src/Bundle/ChillBudgetBundle/Security/Authorization/BudgetElementVoter.php b/src/Bundle/ChillBudgetBundle/Security/Authorization/BudgetElementVoter.php index 0a428d324..5203f9092 100644 --- a/src/Bundle/ChillBudgetBundle/Security/Authorization/BudgetElementVoter.php +++ b/src/Bundle/ChillBudgetBundle/Security/Authorization/BudgetElementVoter.php @@ -20,7 +20,7 @@ use Chill\PersonBundle\Entity\Household\Household; use Chill\PersonBundle\Entity\Person; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; -use function in_array; +use UnexpectedValueException; class BudgetElementVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterface { @@ -68,12 +68,29 @@ class BudgetElementVoter extends AbstractChillVoter implements ProvideRoleHierar protected function supports($attribute, $subject) { - return (in_array($attribute, self::ROLES, true) && $subject instanceof AbstractElement) - || (($subject instanceof Person || $subject instanceof Household) && in_array($attribute, [self::SEE, self::CREATE], true)); + return $this->voter->supports($attribute, $subject); } protected function voteOnAttribute($attribute, $subject, TokenInterface $token) { - return $this->voter->voteOnAttribute($attribute, $subject, $token); + if ( + $subject instanceof Person + || ($subject instanceof AbstractElement && null !== $person = $subject->getPerson())) { + return $this->voter->voteOnAttribute($attribute, $person ?? $subject, $token); + } + + if ( + $subject instanceof Household + || ($subject instanceof AbstractElement && null !== $household = $subject->getHousehold())) { + foreach (($household ?? $subject)->getCurrentPersons() as $person) { + if ($this->voter->voteOnAttribute($attribute, $person, $token)) { + return true; + } + } + + return false; + } + + throw new UnexpectedValueException('This subject is not supported, or is an element not associated with person or household'); } } From d3e784de152a5fb9cb2c71f819962b57b19835a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sun, 20 Nov 2022 21:28:07 +0100 Subject: [PATCH 011/415] DX: fix cs --- .../DependencyInjection/ChillMainExtension.php | 6 +++--- .../DependencyInjection/Configuration.php | 17 ++++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php index 48a4a164c..7b2ed1861 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/ChillMainExtension.php @@ -142,12 +142,12 @@ class ChillMainExtension extends Extension implements 'chill_main.access_permissions_group_list', $config['access_permissions_group_list'] ); - + $container->setParameter( 'chill_main.add_address', $config['add_address'] ); - + $container->setParameter( 'chill_main.routing.resources', $config['routing']['resources'] @@ -220,7 +220,7 @@ class ChillMainExtension extends Extension implements 'installation' => [ 'name' => $config['installation_name'], ], 'available_languages' => $config['available_languages'], - 'add_address' => $config['add_address'] + 'add_address' => $config['add_address'], ], 'form_themes' => ['@ChillMain/Form/fields.html.twig'], ]; diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php index 07eb53d63..595321bed 100644 --- a/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php +++ b/src/Bundle/ChillMainBundle/DependencyInjection/Configuration.php @@ -266,18 +266,17 @@ class Configuration implements ConfigurationInterface ->end() ->end() // end of root/children ->end() // end of root - ; - +; + $rootNode->children() ->arrayNode('add_address')->children() - ->scalarNode('default_country')->cannotBeEmpty()->defaultValue('BE')->end() - ->arrayNode('map_center')->children() - ->scalarNode('x')->cannotBeEmpty()->defaultValue(50.8443)->end() - ->scalarNode('y')->cannotBeEmpty()->defaultValue(4.3523)->end() - ->scalarNode('z')->cannotBeEmpty()->defaultValue(15)->end() - ->end() + ->scalarNode('default_country')->cannotBeEmpty()->defaultValue('BE')->end() + ->arrayNode('map_center')->children() + ->scalarNode('x')->cannotBeEmpty()->defaultValue(50.8443)->end() + ->scalarNode('y')->cannotBeEmpty()->defaultValue(4.3523)->end() + ->scalarNode('z')->cannotBeEmpty()->defaultValue(15)->end() ->end() - ; + ->end(); return $treeBuilder; } From 368846e09bf586c77fb2dbe2049b0ec0d26f87bd Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 8 Dec 2022 10:39:58 +0100 Subject: [PATCH 012/415] FIXED: [api] sort users list by label https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/681 --- .../ChillMainBundle/Controller/UserApiController.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Bundle/ChillMainBundle/Controller/UserApiController.php b/src/Bundle/ChillMainBundle/Controller/UserApiController.php index b29fe7c8e..1e103a934 100644 --- a/src/Bundle/ChillMainBundle/Controller/UserApiController.php +++ b/src/Bundle/ChillMainBundle/Controller/UserApiController.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\MainBundle\Controller; use Chill\MainBundle\CRUD\Controller\ApiController; +use Chill\MainBundle\Pagination\PaginatorInterface; use Doctrine\ORM\QueryBuilder; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; @@ -70,4 +71,14 @@ class UserApiController extends ApiController $query->andWhere($query->expr()->eq('e.enabled', "'TRUE'")); } } + + /** + * @param mixed $query + * @param mixed $_format + */ + protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator, $_format) + { + return $query->orderBy('e.label', 'ASC'); + } + } From 8e65b3851adc011af0848794a6349c4777f3a4e8 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 8 Dec 2022 14:03:04 +0100 Subject: [PATCH 013/415] FIXED: [api] sort socialactions by ordering https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/677 --- .../Controller/SocialWorkSocialActionApiController.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/SocialWorkSocialActionApiController.php b/src/Bundle/ChillPersonBundle/Controller/SocialWorkSocialActionApiController.php index a0d15b6db..4d6cfd82d 100644 --- a/src/Bundle/ChillPersonBundle/Controller/SocialWorkSocialActionApiController.php +++ b/src/Bundle/ChillPersonBundle/Controller/SocialWorkSocialActionApiController.php @@ -13,7 +13,9 @@ namespace Chill\PersonBundle\Controller; use Chill\MainBundle\CRUD\Controller\ApiController; use Chill\MainBundle\Pagination\PaginatorFactory; +use Chill\MainBundle\Pagination\PaginatorInterface; use Chill\MainBundle\Serializer\Model\Collection; +use Chill\PersonBundle\Entity\SocialWork\SocialAction; use Chill\PersonBundle\Repository\SocialWork\SocialIssueRepository; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; @@ -41,7 +43,12 @@ class SocialWorkSocialActionApiController extends ApiController throw $this->createNotFoundException('socialIssue not found'); } - $socialActions = $socialIssue->getRecursiveSocialActions(); + $socialActions = $socialIssue->getRecursiveSocialActions()->toArray(); + + usort($socialActions, function (SocialAction $sa, SocialAction $sb) { + return $sa->getOrdering() <=> $sb->getOrdering(); + }); + $pagination = $this->paginator->create(count($socialActions)); // max one page $pagination->setItemsPerPage(count($socialActions)); From 7e6ef3dafe62d2451cff507bd5e93ffff1ad2779 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 8 Dec 2022 14:22:06 +0100 Subject: [PATCH 014/415] fix some errors in twig templates --- .../src/Resources/views/asideActivity/index.html.twig | 2 +- .../src/Resources/views/asideActivity/new.html.twig | 4 ++-- .../Resources/views/SingleTask/List/index_my_tasks.html.twig | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillAsideActivityBundle/src/Resources/views/asideActivity/index.html.twig b/src/Bundle/ChillAsideActivityBundle/src/Resources/views/asideActivity/index.html.twig index 4dd12e042..5ffc73684 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Resources/views/asideActivity/index.html.twig +++ b/src/Bundle/ChillAsideActivityBundle/src/Resources/views/asideActivity/index.html.twig @@ -87,5 +87,5 @@ {% endif %} - + {% endblock %} diff --git a/src/Bundle/ChillAsideActivityBundle/src/Resources/views/asideActivity/new.html.twig b/src/Bundle/ChillAsideActivityBundle/src/Resources/views/asideActivity/new.html.twig index 09acf9859..99ff217b1 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Resources/views/asideActivity/new.html.twig +++ b/src/Bundle/ChillAsideActivityBundle/src/Resources/views/asideActivity/new.html.twig @@ -1,4 +1,4 @@ -{% extends '@ChillMain/Admin/layout.html.twig' %} +{% extends '@ChillMain/layout.html.twig' %} {% block js %} {{ parent() }} @@ -14,7 +14,7 @@ {% include('@ChillMain/CRUD/_new_title.html.twig') %} {% endblock %} -{% block admin_content %} +{% block content %} {% embed '@ChillMain/CRUD/_new_content.html.twig' %} {% block content_form_actions_save_and_show %}{% endblock %} {% endembed %} diff --git a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/List/index_my_tasks.html.twig b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/List/index_my_tasks.html.twig index 5d7e88542..359d02ef0 100644 --- a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/List/index_my_tasks.html.twig +++ b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/List/index_my_tasks.html.twig @@ -1,4 +1,4 @@ -{% extends 'ChillMainBundle::layout.html.twig' %} +{% extends '@ChillMain/layout.html.twig' %} {% block title 'My tasks'|trans %} From a32d20e320b7f85576018e2def4c7c8b61981e76 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 8 Dec 2022 15:00:45 +0100 Subject: [PATCH 015/415] Fixed: [form] improve Aside Activity category form selector --- .../src/Form/AsideActivityFormType.php | 34 +---------- .../Type/PickAsideActivityCategoryType.php | 59 +++++++++++++++++++ 2 files changed, 62 insertions(+), 31 deletions(-) create mode 100644 src/Bundle/ChillAsideActivityBundle/src/Form/Type/PickAsideActivityCategoryType.php diff --git a/src/Bundle/ChillAsideActivityBundle/src/Form/AsideActivityFormType.php b/src/Bundle/ChillAsideActivityBundle/src/Form/AsideActivityFormType.php index 5c438bd0a..6fbef0fd7 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Form/AsideActivityFormType.php +++ b/src/Bundle/ChillAsideActivityBundle/src/Form/AsideActivityFormType.php @@ -12,8 +12,7 @@ declare(strict_types=1); namespace Chill\AsideActivityBundle\Form; use Chill\AsideActivityBundle\Entity\AsideActivity; -use Chill\AsideActivityBundle\Entity\AsideActivityCategory; -use Chill\AsideActivityBundle\Templating\Entity\CategoryRender; +use Chill\AsideActivityBundle\Form\Type\PickAsideActivityCategoryType; use Chill\MainBundle\Form\Type\ChillDateType; use Chill\MainBundle\Form\Type\ChillTextareaType; use Chill\MainBundle\Form\Type\PickUserDynamicType; @@ -21,8 +20,6 @@ use DateInterval; use DateTime; use DateTimeImmutable; use DateTimeZone; -use Doctrine\ORM\EntityRepository; -use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToTimestampTransformer; @@ -37,20 +34,16 @@ use function in_array; final class AsideActivityFormType extends AbstractType { - private CategoryRender $categoryRender; - private TokenStorageInterface $storage; private array $timeChoices; public function __construct( ParameterBagInterface $parameterBag, - TokenStorageInterface $storage, - CategoryRender $categoryRender + TokenStorageInterface $storage ) { $this->timeChoices = $parameterBag->get('chill_aside_activity.form.time_duration'); $this->storage = $storage; - $this->categoryRender = $categoryRender; } public function buildForm(FormBuilderInterface $builder, array $options) @@ -81,28 +74,7 @@ final class AsideActivityFormType extends AbstractType 'required' => true, ] ) - ->add( - 'type', - EntityType::class, - [ - 'label' => 'Type', - 'required' => true, - 'class' => AsideActivityCategory::class, - 'placeholder' => 'Choose the activity category', - 'query_builder' => static function (EntityRepository $er) { - $qb = $er->createQueryBuilder('ac'); - $qb->where($qb->expr()->eq('ac.isActive', 'TRUE')) - ->addOrderBy('ac.ordering', 'ASC'); - - return $qb; - }, - 'choice_label' => function (AsideActivityCategory $asideActivityCategory) { - $options = []; - - return $this->categoryRender->renderString($asideActivityCategory, $options); - }, - ] - ) + ->add('type', PickAsideActivityCategoryType::class) ->add('duration', ChoiceType::class, $durationTimeOptions) ->add('note', ChillTextareaType::class, [ 'label' => 'Note', diff --git a/src/Bundle/ChillAsideActivityBundle/src/Form/Type/PickAsideActivityCategoryType.php b/src/Bundle/ChillAsideActivityBundle/src/Form/Type/PickAsideActivityCategoryType.php new file mode 100644 index 000000000..ddf8246f9 --- /dev/null +++ b/src/Bundle/ChillAsideActivityBundle/src/Form/Type/PickAsideActivityCategoryType.php @@ -0,0 +1,59 @@ +categoryRender = $categoryRender; + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver + ->setDefaults([ + 'label' => 'Type', + 'required' => true, + 'class' => AsideActivityCategory::class, + 'placeholder' => 'Choose the activity category', + 'query_builder' => static function (EntityRepository $er) { + $qb = $er->createQueryBuilder('ac'); + $qb->where($qb->expr()->eq('ac.isActive', 'TRUE')) + ->addOrderBy('ac.ordering', 'ASC'); + + return $qb; + }, + 'choice_label' => function (AsideActivityCategory $asideActivityCategory) { + $options = []; + return $this->categoryRender->renderString($asideActivityCategory, $options); + }, + 'attr' => ['class' => 'select2'], + ]); + } + + public function getParent(): string + { + return EntityType::class; + } +} + From 34602d0a561c3adaf944cafb930df644f49b84fd Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 8 Dec 2022 16:24:33 +0100 Subject: [PATCH 016/415] Fixed: markdown resolution for private comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit note: j'ai une branche locale wip ou j'essaie d'implémenter un renderbox pour les private comments --- .../ChillActivityBundle/Resources/views/Activity/show.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/show.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/show.html.twig index 49e71bfad..a3203d806 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/show.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/show.html.twig @@ -156,7 +156,7 @@
    - {{ entity.privateComment.comments[userId] }} + {{ entity.privateComment.comments[userId]|chill_markdown_to_html }}
    From ff7f5a5dd36d6de54f2e5b03bb1d0cb50544987f Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Fri, 9 Dec 2022 12:39:29 +0100 Subject: [PATCH 017/415] Fixed: [vue][accompanyingCourse] typeError in toaster when removing referrer https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/667 --- .../Resources/public/vuejs/AccompanyingCourse/store/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js index 8324a3d82..c2ded503b 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js @@ -785,7 +785,7 @@ let initPromise = (root) => Promise.all([getScopesPromise(root), accompanyingCou return makeFetch('PATCH', url, body) .then((response) => { commit('updateReferrer', response.user); - if (null !== payload.user_job && payload.user_job !== state.accompanyingCourse.job) { + if (null !== payload && null !== payload.user_job && payload.user_job !== state.accompanyingCourse.job) { this.dispatch('updateJob', payload.user_job); } // commit('setFilteredReferrersSuggested'); // this mutation doesn't exist? From 4fcfe3f5d25296a94159370f5969f622b9f77143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sun, 11 Dec 2022 01:22:39 +0100 Subject: [PATCH 018/415] Feature: [cron] Create a cron manager --- .../ChillMainBundle/Cron/CronJobInterface.php | 23 ++ .../ChillMainBundle/Cron/CronManager.php | 159 ++++++++++++++ .../Entity/CronJobExecution.php | 92 ++++++++ .../Repository/CronJobExecutionRepository.php | 57 +++++ .../CronJobExecutionRepositoryInterface.php | 34 +++ .../Tests/Cron/CronManagerTest.php | 201 ++++++++++++++++++ 6 files changed, 566 insertions(+) create mode 100644 src/Bundle/ChillMainBundle/Cron/CronJobInterface.php create mode 100644 src/Bundle/ChillMainBundle/Cron/CronManager.php create mode 100644 src/Bundle/ChillMainBundle/Entity/CronJobExecution.php create mode 100644 src/Bundle/ChillMainBundle/Repository/CronJobExecutionRepository.php create mode 100644 src/Bundle/ChillMainBundle/Repository/CronJobExecutionRepositoryInterface.php create mode 100644 src/Bundle/ChillMainBundle/Tests/Cron/CronManagerTest.php diff --git a/src/Bundle/ChillMainBundle/Cron/CronJobInterface.php b/src/Bundle/ChillMainBundle/Cron/CronJobInterface.php new file mode 100644 index 000000000..4e1ca9ff6 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Cron/CronJobInterface.php @@ -0,0 +1,23 @@ + + */ + private iterable $jobs; + + private LoggerInterface $logger; + + /** + * @param CronJobInterface[] $jobs + */ + public function __construct( + CronJobExecutionRepositoryInterface $cronJobExecutionRepository, + EntityManagerInterface $entityManager, + iterable $jobs, + LoggerInterface $logger + ) { + $this->cronJobExecutionRepository = $cronJobExecutionRepository; + $this->entityManager = $entityManager; + $this->jobs = $jobs; + $this->logger = $logger; + } + + public function run(?string $forceJob = null): void + { + if (null !== $forceJob) { + $this->runForce($forceJob); + + return; + } + + [$orderedJobs, $lasts] = $this->getOrderedJobs(); + + foreach ($orderedJobs as $job) { + if ($job->canRun($lasts[$job->getKey()] ?? null)) { + if (array_key_exists($job->getKey(), $lasts)) { + $this->entityManager + ->createQuery(self::UPDATE_BEFORE_EXEC) + ->setParameters([ + 'now' => new DateTimeImmutable('now'), + 'key' => $job->getKey(), + ]); + } else { + $execution = new CronJobExecution($job->getKey()); + $this->entityManager->persist($execution); + $this->entityManager->flush(); + } + $this->entityManager->clear(); + + try { + $this->logger->info(sprintf('%sWill run job', self::LOG_PREFIX), ['job' => $job->getKey()]); + $job->run(); + + $this->entityManager + ->createQuery(self::UPDATE_AFTER_EXEC) + ->setParameters([ + 'now' => new DateTimeImmutable('now'), + 'status' => CronJobExecution::SUCCESS, + 'key' => $job->getKey(), + ]) + ->execute(); + + $this->logger->info(sprintf('%sSuccessfully run job', self::LOG_PREFIX), ['job' => $job->getKey()]); + + return; + } catch (Exception $e) { + $this->logger->error(sprintf('%sRunning job failed', self::LOG_PREFIX), ['job' => $job->getKey()]); + $this->entityManager + ->createQuery(self::UPDATE_AFTER_EXEC) + ->setParameters([ + 'now' => new DateTimeImmutable('now'), + 'status' => CronJobExecution::FAILURE, + 'key' => $job->getKey(), + ]) + ->execute(); + + return; + } + } + } + } + + /** + * @return array<0: CronJobInterface[], 1: array> + */ + private function getOrderedJobs(): array + { + /** @var array $lasts */ + $lasts = []; + + foreach ($this->cronJobExecutionRepository->findAll() as $execution) { + $lasts[$execution->getKey()] = $execution; + } + + // order by last, NULL first + $orderedJobs = iterator_to_array($this->jobs); + usort( + $orderedJobs, + static function (CronJobInterface $a, CronJobInterface $b) use ($lasts): int { + if ( + (!array_key_exists($a->getKey(), $lasts) && !array_key_exists($b->getKey(), $lasts)) + ) { + return 0; + } + + if (!array_key_exists($a->getKey(), $lasts) && array_key_exists($b->getKey(), $lasts)) { + return -1; + } + + if (!array_key_exists($b->getKey(), $lasts) && array_key_exists($a->getKey(), $lasts)) { + return 1; + } + + return $lasts[$a->getKey()]->getLastStart() <=> $lasts[$b->getKey()]->getLastStart(); + } + ); + + return [$orderedJobs, $lasts]; + } + + private function runForce(string $forceJob): void + { + foreach ($this->jobs as $job) { + $job->run(); + } + } +} diff --git a/src/Bundle/ChillMainBundle/Entity/CronJobExecution.php b/src/Bundle/ChillMainBundle/Entity/CronJobExecution.php new file mode 100644 index 000000000..e0899e21f --- /dev/null +++ b/src/Bundle/ChillMainBundle/Entity/CronJobExecution.php @@ -0,0 +1,92 @@ +key = $key; + $this->lastStart = new DateTimeImmutable('now'); + } + + public function getKey(): string + { + return $this->key; + } + + public function getLastEnd(): DateTimeImmutable + { + return $this->lastEnd; + } + + public function getLastStart(): DateTimeImmutable + { + return $this->lastStart; + } + + public function getLastStatus(): ?int + { + return $this->lastStatus; + } + + public function setLastEnd(?DateTimeImmutable $lastEnd): CronJobExecution + { + $this->lastEnd = $lastEnd; + + return $this; + } + + public function setLastStart(DateTimeImmutable $lastStart): CronJobExecution + { + $this->lastStart = $lastStart; + + return $this; + } + + public function setLastStatus(?int $lastStatus): CronJobExecution + { + $this->lastStatus = $lastStatus; + + return $this; + } +} diff --git a/src/Bundle/ChillMainBundle/Repository/CronJobExecutionRepository.php b/src/Bundle/ChillMainBundle/Repository/CronJobExecutionRepository.php new file mode 100644 index 000000000..eb0b63724 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Repository/CronJobExecutionRepository.php @@ -0,0 +1,57 @@ +repository = $entityManager->getRepository($this->getClassName()); + } + + public function find($id): ?CronJobExecution + { + return $this->repository->find($id); + } + + /** + * @return array|CronJobExecution[] + */ + public function findAll(): array + { + return $this->repository->findAll(); + } + + /** + * @return array|CronJobExecution[] + */ + public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array + { + return $this->repository->findBy($criteria, $orderBy, $limit, $offset); + } + + public function findOneBy(array $criteria): ?CronJobExecution + { + return $this->repository->findOneBy($criteria); + } + + public function getClassName(): string + { + return CronJobExecutionRepository::class; + } +} diff --git a/src/Bundle/ChillMainBundle/Repository/CronJobExecutionRepositoryInterface.php b/src/Bundle/ChillMainBundle/Repository/CronJobExecutionRepositoryInterface.php new file mode 100644 index 000000000..df894bbfb --- /dev/null +++ b/src/Bundle/ChillMainBundle/Repository/CronJobExecutionRepositoryInterface.php @@ -0,0 +1,34 @@ +prophesize(CronJobInterface::class); + $jobToExecute->getKey()->willReturn('to-exec'); + $jobToExecute->canRun(Argument::type(CronJobExecution::class))->willReturn(true); + $jobToExecute->run()->shouldBeCalled(); + + $executions = [ + ['key' => $jobOld1->getKey(), 'lastStart' => new DateTimeImmutable('yesterday'), 'lastEnd' => new DateTimeImmutable('1 hours ago'), 'lastStatus' => CronJobExecution::SUCCESS], + ['key' => $jobOld2->getKey(), 'lastStart' => new DateTimeImmutable('3 days ago'), 'lastEnd' => new DateTimeImmutable('36 hours ago'), 'lastStatus' => CronJobExecution::SUCCESS], + // this is the oldest one + ['key' => 'to-exec', 'lastStart' => new DateTimeImmutable('1 month ago'), 'lastEnd' => new DateTimeImmutable('10 days ago'), 'lastStatus' => CronJobExecution::SUCCESS], + ]; + + $cronManager = new CronManager( + $this->buildCronJobExecutionRepository($executions), + $this->buildEntityManager([]), + new ArrayObject([$jobOld1, $jobToExecute->reveal(), $jobOld2]), + new NullLogger() + ); + + $cronManager->run(); + } + + public function testSelectNewJobFirstAndNewJobIsFirstInList(): void + { + $jobAlreadyExecuted = new JobCanRun('k'); + $jobNeverExecuted = $this->prophesize(CronJobInterface::class); + $jobNeverExecuted->getKey()->willReturn('never-executed'); + $jobNeverExecuted->run()->shouldBeCalled(); + $jobNeverExecuted->canRun(null)->willReturn(true); + + $executions = [ + ['key' => $jobAlreadyExecuted->getKey(), 'lastStart' => new DateTimeImmutable('yesterday'), 'lastEnd' => new DateTimeImmutable('1 hours ago'), 'lastStatus' => CronJobExecution::SUCCESS], + ]; + + $cronManager = new CronManager( + $this->buildCronJobExecutionRepository($executions), + $this->buildEntityManager([Argument::type(CronJobExecution::class)]), + new ArrayObject([$jobNeverExecuted->reveal(), $jobAlreadyExecuted]), + new NullLogger() + ); + + $cronManager->run(); + } + + public function testSelectNewJobFirstAndNewJobIsLastInList(): void + { + $jobAlreadyExecuted = new JobCanRun('k'); + $jobNeverExecuted = $this->prophesize(CronJobInterface::class); + $jobNeverExecuted->getKey()->willReturn('never-executed'); + $jobNeverExecuted->run()->shouldBeCalled(); + $jobNeverExecuted->canRun(null)->willReturn(true); + + $executions = [ + ['key' => $jobAlreadyExecuted->getKey(), 'lastStart' => new DateTimeImmutable('yesterday'), 'lastEnd' => new DateTimeImmutable('1 hours ago'), 'lastStatus' => CronJobExecution::SUCCESS], + ]; + + $cronManager = new CronManager( + $this->buildCronJobExecutionRepository($executions), + $this->buildEntityManager([Argument::type(CronJobExecution::class)]), + new ArrayObject([$jobAlreadyExecuted, $jobNeverExecuted->reveal()]), + new NullLogger() + ); + + $cronManager->run(); + } + + /** + * @param array $executions + */ + private function buildCronJobExecutionRepository(array $executions): CronJobExecutionRepositoryInterface + { + $repository = $this->prophesize(CronJobExecutionRepositoryInterface::class); + + $repository->findAll()->willReturn( + array_map( + static function (array $exec): CronJobExecution { + $e = new CronJobExecution($exec['key']); + $e->setLastStart($exec['lastStart']); + + if (array_key_exists('lastEnd', $exec)) { + $e->setLastEnd($exec['lastEnd']); + } + + if (array_key_exists('lastStatus', $exec)) { + $e->setLastStatus($exec['lastStatus']); + } + + return $e; + }, + $executions + ) + ); + + return $repository->reveal(); + } + + private function buildEntityManager(array $persistArgsShouldBeCalled = []): EntityManagerInterface + { + $em = $this->prophesize(EntityManagerInterface::class); + + if ([] === $persistArgsShouldBeCalled) { + $em->persist(Argument::any())->shouldNotBeCalled(); + } else { + foreach ($persistArgsShouldBeCalled as $arg) { + $em->persist($arg)->shouldBeCalled(); + } + $em->flush()->shouldBeCalled(); + } + + // other methods + $em->clear()->shouldBeCalled(); + + $query = $this->prophesize(AbstractQuery::class); + $query->setParameters(Argument::type('array'))->willReturn($query->reveal()); + $query->execute()->shouldBeCalled(); + + $em->createQuery(Argument::type('string'))->willReturn($query->reveal()); + + return $em->reveal(); + } +} + +class JobCanRun implements CronJobInterface +{ + private string $key; + + public function __construct(string $key) + { + $this->key = $key; + } + + public function canRun(?CronJobExecution $cronJobExecution): bool + { + return true; + } + + public function getKey(): string + { + return $this->key; + } + + public function run(): void + { + } +} + +class JobCannotRun implements CronJobInterface +{ + public function canRun(?CronJobExecution $cronJobExecution): bool + { + return false; + } + + public function getKey(): string + { + return 'job-b'; + } + + public function run(): void + { + } +} From e0c9e12008754f7349a3a2f6935418d51259453c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 12 Dec 2022 14:35:18 +0100 Subject: [PATCH 019/415] Feature: [cron] Create a cron job to refresh materialized view address - geographical unit association --- ...eographicalUnitMaterializedViewCronJob.php | 60 +++++++++++++++++++ ...aphicalUnitMaterializedViewCronJobTest.php | 46 ++++++++++++++ .../ChillMainBundle/config/services.yaml | 9 +-- 3 files changed, 108 insertions(+), 7 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Service/AddressGeographicalUnit/RefreshAddressToGeographicalUnitMaterializedViewCronJob.php create mode 100644 src/Bundle/ChillMainBundle/Tests/Services/AddressGeographicalUnit/RefreshAddressToGeographicalUnitMaterializedViewCronJobTest.php diff --git a/src/Bundle/ChillMainBundle/Service/AddressGeographicalUnit/RefreshAddressToGeographicalUnitMaterializedViewCronJob.php b/src/Bundle/ChillMainBundle/Service/AddressGeographicalUnit/RefreshAddressToGeographicalUnitMaterializedViewCronJob.php new file mode 100644 index 000000000..a141f5100 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Service/AddressGeographicalUnit/RefreshAddressToGeographicalUnitMaterializedViewCronJob.php @@ -0,0 +1,60 @@ +connection = $connection; + } + + public function canRun(?CronJobExecution $cronJobExecution): bool + { + if ($cronJobExecution->getKey() !== $this->getKey()) { + throw new UnexpectedValueException(); + } + + if (null === $cronJobExecution) { + return true; + } + + $now = new DateTimeImmutable('now'); + + return $cronJobExecution->getLastStart() < $now->sub(new DateInterval('P1D')) + && in_array($now->format('H'), self::ACCEPTED_HOURS, true) + // introduce a random component to ensure a roll when multiple instances are hosted on same machines + && mt_rand(0, 5) === 0; + } + + public function getKey(): string + { + return 'refresh-materialized-view-address-to-geog-units'; + } + + public function run(): void + { + $this->connection->executeQuery('REFRESH MATERIALIZED VIEW view_chill_main_address_geographical_unit'); + } +} diff --git a/src/Bundle/ChillMainBundle/Tests/Services/AddressGeographicalUnit/RefreshAddressToGeographicalUnitMaterializedViewCronJobTest.php b/src/Bundle/ChillMainBundle/Tests/Services/AddressGeographicalUnit/RefreshAddressToGeographicalUnitMaterializedViewCronJobTest.php new file mode 100644 index 000000000..f4e4a586e --- /dev/null +++ b/src/Bundle/ChillMainBundle/Tests/Services/AddressGeographicalUnit/RefreshAddressToGeographicalUnitMaterializedViewCronJobTest.php @@ -0,0 +1,46 @@ +connection = self::$container->get(Connection::class); + } + + public function testFullRun(): void + { + $job = new \Chill\MainBundle\Service\AddressGeographicalUnit\RefreshAddressToGeographicalUnitMaterializedViewCronJob( + $this->connection + ); + + $lastExecution = new CronJobExecution($job->getKey()); + $lastExecution->setLastStart(new DateTimeImmutable('2 days ago')); + + $this->assertIsBool($job->canRun($lastExecution)); + + $job->run(); + } +} diff --git a/src/Bundle/ChillMainBundle/config/services.yaml b/src/Bundle/ChillMainBundle/config/services.yaml index f99c80d2c..7bd1b1038 100644 --- a/src/Bundle/ChillMainBundle/config/services.yaml +++ b/src/Bundle/ChillMainBundle/config/services.yaml @@ -102,12 +102,7 @@ services: Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface: '@Chill\MainBundle\Security\Resolver\CenterResolverDispatcher' - Chill\MainBundle\Service\Import\: - resource: '../Service/Import/' - autowire: true - autoconfigure: true - - Chill\MainBundle\Service\RollingDate\: - resource: '../Service/RollingDate/' + Chill\MainBundle\Service\: + resource: '../Service/' autowire: true autoconfigure: true From 49380f5f616e5bddbb36874f3f1da178a602d814 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 12 Dec 2022 14:51:43 +0100 Subject: [PATCH 020/415] fix template regressions with add_address component Component works in modal or in main frame. CSS Flex position parent-children directives were broken. Hope that fix don't introduce others display bug in any cases ! --- .../vuejs/Address/components/AddAddress.vue | 178 +++++++++--------- .../vuejs/Address/components/EditPane.vue | 1 + .../vuejs/Address/components/ShowPane.vue | 19 +- .../views/Household/address_edit.html.twig | 22 +-- .../views/Household/address_move.html.twig | 22 +-- 5 files changed, 117 insertions(+), 125 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue index fcd64ed70..8cb871de6 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue @@ -48,33 +48,35 @@ -
    - - - - - - -
    + @@ -118,40 +120,42 @@ -
    - - - - - - -
    + @@ -192,32 +196,34 @@ -
    - - - - diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/EditPane.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/EditPane.vue index 9636a173f..9ae464e3e 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/EditPane.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/EditPane.vue @@ -187,6 +187,7 @@ div.address-form { div#address_map { height: 400px; width: 100%; + z-index: 1; } } diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowPane.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowPane.vue index 7f7b1b529..f910e6422 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowPane.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowPane.vue @@ -1,6 +1,6 @@