#16 replace hardcoded country and map_center in vue add-address by symfony config yaml variables

This commit is contained in:
Mathieu Jaumotte 2022-11-16 22:30:05 +01:00
parent 56a7833858
commit 53980dd757
8 changed files with 31 additions and 8 deletions

View File

@ -142,7 +142,12 @@ class ChillMainExtension extends Extension implements
'chill_main.access_permissions_group_list', 'chill_main.access_permissions_group_list',
$config['access_permissions_group_list'] $config['access_permissions_group_list']
); );
$container->setParameter(
'chill_main.add_address',
$config['add_address']
);
$container->setParameter( $container->setParameter(
'chill_main.routing.resources', 'chill_main.routing.resources',
$config['routing']['resources'] $config['routing']['resources']
@ -215,6 +220,7 @@ class ChillMainExtension extends Extension implements
'installation' => [ 'installation' => [
'name' => $config['installation_name'], ], 'name' => $config['installation_name'], ],
'available_languages' => $config['available_languages'], 'available_languages' => $config['available_languages'],
'add_address' => $config['add_address']
], ],
'form_themes' => ['@ChillMain/Form/fields.html.twig'], 'form_themes' => ['@ChillMain/Form/fields.html.twig'],
]; ];

View File

@ -266,7 +266,18 @@ class Configuration implements ConfigurationInterface
->end() ->end()
->end() // end of root/children ->end() // end of root/children
->end() // end of root ->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; return $treeBuilder;
} }

View File

@ -309,8 +309,11 @@ export default {
addressMap: { addressMap: {
// Note: LeafletJs demands [lat, lon] // Note: LeafletJs demands [lat, lon]
// cfr https://macwright.com/lonlat/ // cfr https://macwright.com/lonlat/
center : [48.8589, 2.3469], center : [
zoom: 12 this.context.defaults.map_center.x,
this.context.defaults.map_center.y
],
zoom: this.context.defaults.map_center.z
}, },
}, },
errorMsg: [] errorMsg: []

View File

@ -44,7 +44,7 @@ export default {
//console.log('update map with : ', this.entity.addressMap.center) //console.log('update map with : ', this.entity.addressMap.center)
if (this.marker && this.entity.addressMap.center) { if (this.marker && this.entity.addressMap.center) {
this.marker.setLatLng(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);
} }
} }
}, },

View File

@ -30,7 +30,7 @@ export default {
data() { data() {
return { return {
value: this.selectCountryByCode( 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
) )
} }
}, },

View File

@ -102,7 +102,7 @@ export default {
], ],
emits: ['openEditPane'], emits: ['openEditPane'],
mounted() { mounted() {
console.log('context', this.context) //console.log('context', this.context)
}, },
computed: { computed: {
address() { address() {

View File

@ -20,7 +20,8 @@ containers.forEach((container) => {
}, },
edit: container.dataset.mode === 'edit', //boolean edit: container.dataset.mode === 'edit', //boolean
addressId: parseInt(container.dataset.addressId) || null, addressId: parseInt(container.dataset.addressId) || null,
backUrl: container.dataset.backUrl || null backUrl: container.dataset.backUrl || null,
defaults: JSON.parse(container.dataset.addressDefaults)
}, },
options: { options: {
/// Options override default. /// Options override default.

View File

@ -72,6 +72,8 @@
{% if onlyButton is defined and onlyButton == 1 %} {% if onlyButton is defined and onlyButton == 1 %}
data-hide-address="true" data-hide-address="true"
{% endif %} {% endif %}
data-address-defaults="{{ add_address|json_encode|e('html') }}"
></div> ></div>
{{ encore_entry_script_tags('vue_address') }} {{ encore_entry_script_tags('vue_address') }}