From 63e5220084da6bdac54c6dff1d3d031e1188e20d Mon Sep 17 00:00:00 2001 From: nobohan Date: Wed, 17 Nov 2021 15:21:53 +0100 Subject: [PATCH] activity: add user current location as default for a new activity --- .../vuejs/Activity/components/Location.vue | 17 +++++++++-------- .../Activity/newAccompanyingCourse.html.twig | 1 + .../Form/UserCurrentLocationType.php | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue index c8d1472bd..5fa3360b7 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue @@ -55,16 +55,17 @@ export default { } }, mounted() { - this.getLocationsList(); + getLocations().then(response => new Promise(resolve => { + console.log('getLocations', response); + this.locations = response.results; + if (window.default_location_id) { + let location = this.locations.filter(l => l.id === window.default_location_id); + this.$store.dispatch('updateLocation', location); + } + resolve(); + })) }, methods: { - getLocationsList() { - getLocations().then(response => new Promise(resolve => { - console.log('getLocations', response); - this.locations = response.results; - resolve(); - })) - }, customLabel(value) { return `${value.locationType.title.fr} ${value.name ? value.name : ''}`; } diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/newAccompanyingCourse.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/newAccompanyingCourse.html.twig index 101ad5502..d8f02a37d 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/newAccompanyingCourse.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/newAccompanyingCourse.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.default_location_id = {{ default_location_id }}; {{ encore_entry_script_tags('vue_activity') }} {% endblock %} diff --git a/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php b/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php index 607b9c31e..6d3d5f6df 100644 --- a/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php +++ b/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php @@ -29,7 +29,7 @@ class UserCurrentLocationType extends AbstractType 'class' => Location::class, 'choice_label' => function (Location $entity) { return $entity->getName() ? - $entity->getName() : + $entity->getLocationType()->getTitle()['fr'] . ' ' . $entity->getName() : //$this->translatableStringHelper->localize($entity->getLocationType()->getTitle()); //TODO does not work $entity->getLocationType()->getTitle()['fr']; },