2019-07-27 22:07:08 +02:00
|
|
|
<template lang='pug'>
|
2022-06-11 12:00:29 +02:00
|
|
|
v-container
|
2022-09-07 11:48:19 +02:00
|
|
|
v-card-title {{ $t('common.places') }}
|
2022-06-11 12:00:29 +02:00
|
|
|
v-spacer
|
|
|
|
v-text-field(v-model='search'
|
|
|
|
:append-icon='mdiMagnify' outlined rounded
|
2022-11-29 14:40:19 +01:00
|
|
|
:label="$t('common.search')"
|
2022-06-11 12:00:29 +02:00
|
|
|
single-line hide-details)
|
|
|
|
v-card-subtitle(v-html="$t('admin.place_description')")
|
2019-09-13 10:15:23 +02:00
|
|
|
|
2022-06-11 12:00:29 +02:00
|
|
|
v-dialog(v-model='dialog' width='600' :fullscreen='$vuetify.breakpoint.xsOnly')
|
2022-09-07 11:48:19 +02:00
|
|
|
v-card
|
|
|
|
v-card-title {{ $t('admin.edit_place') }}
|
2023-02-17 00:23:35 +01:00
|
|
|
v-card-text.mb-4
|
2022-06-11 12:00:29 +02:00
|
|
|
v-form(v-model='valid' ref='form' lazy-validation)
|
|
|
|
v-text-field(
|
|
|
|
:rules="[$validators.required('common.name')]"
|
|
|
|
:label="$t('common.name')"
|
|
|
|
v-model='place.name'
|
|
|
|
:placeholder='$t("common.name")')
|
2023-02-17 00:23:35 +01:00
|
|
|
|
|
|
|
v-text-field(
|
|
|
|
:rules="[ v => $validators.required('common.address')(v)]"
|
|
|
|
:label="$t('common.address')"
|
|
|
|
v-model='place.address'
|
|
|
|
persistent-hint)
|
|
|
|
|
|
|
|
v-combobox.mt-0.mb-4(ref='geocodedAddress'
|
|
|
|
v-if="(settings.allow_geolocation && place.name !== 'online')"
|
|
|
|
:disabled="!(settings.allow_geolocation && place.name !== 'online')"
|
2022-11-18 14:14:15 +01:00
|
|
|
:prepend-icon='mdiMapSearch'
|
|
|
|
@input.native='searchAddress'
|
2023-02-17 00:23:35 +01:00
|
|
|
:label="$t('admin.search_address')"
|
|
|
|
:value='place.latitude && place.longitude && place.geocodedAddress'
|
2022-11-18 14:14:15 +01:00
|
|
|
persistent-hint hide-no-data clearable no-filter
|
|
|
|
:loading='loading'
|
|
|
|
@change='selectAddress'
|
|
|
|
@focus='searchAddress'
|
|
|
|
:items="addressList"
|
2023-02-17 00:23:35 +01:00
|
|
|
:hint="$t('event.address_description_osm')")
|
|
|
|
template(v-slot:message="{message, key}")
|
|
|
|
span(v-html='message' :key="key")
|
2022-11-18 14:14:15 +01:00
|
|
|
template(v-slot:item="{ item, attrs, on }")
|
|
|
|
v-list-item(v-bind='attrs' v-on='on')
|
|
|
|
v-list-item-content(two-line v-if='item')
|
|
|
|
v-list-item-title(v-text='item.name')
|
|
|
|
v-list-item-subtitle(v-text='`${item.address}`')
|
2022-09-19 05:13:57 +02:00
|
|
|
|
2023-02-17 00:23:35 +01:00
|
|
|
v-row.mt-4(v-if="(settings.allow_geolocation && place.name !== 'online')")
|
|
|
|
v-col.py-0(cols=12 md=6)
|
|
|
|
v-text-field(v-model="place.latitude"
|
|
|
|
:value="place.latitude"
|
|
|
|
:prepend-icon='mdiLatitude'
|
|
|
|
:disabled="(!settings.allow_geolocation || place.name === 'online')"
|
|
|
|
:label="$t('common.latitude')"
|
|
|
|
:rules="$validators.latitude")
|
|
|
|
v-col.py-0(cols=12 md=6)
|
|
|
|
v-text-field(v-model="place.longitude"
|
|
|
|
:prepend-icon='mdiLongitude'
|
|
|
|
:disabled="!settings.allow_geolocation || place.name === 'online'"
|
|
|
|
:label="$t('common.longitude')"
|
|
|
|
:rules="$validators.longitude")
|
|
|
|
|
|
|
|
MapEdit.mt-4(:place='place' :key="mapEdit" v-if="settings.allow_geolocation && place.name !== 'online' && place.latitude && place.longitude")
|
2022-09-02 08:32:13 +02:00
|
|
|
|
2022-06-11 12:00:29 +02:00
|
|
|
v-card-actions
|
2022-09-07 11:48:19 +02:00
|
|
|
v-spacer
|
|
|
|
v-btn(@click='dialog = false' outlined color='warning') {{ $t('common.cancel') }}
|
|
|
|
v-btn(@click='savePlace' color='primary' outlined :loading='loading'
|
|
|
|
:disable='!valid || loading') {{ $t('common.save') }}
|
2020-07-25 21:41:22 +02:00
|
|
|
|
2022-06-11 12:00:29 +02:00
|
|
|
v-card-text
|
|
|
|
v-data-table(
|
|
|
|
:headers='headers'
|
|
|
|
:items='places'
|
2022-09-07 11:48:19 +02:00
|
|
|
:hide-default-footer='places.length < 5'
|
2022-11-29 14:40:19 +01:00
|
|
|
:header-props='{ sortIcon: mdiChevronDown }'
|
2022-06-11 12:00:29 +02:00
|
|
|
:footer-props='{ prevIcon: mdiChevronLeft, nextIcon: mdiChevronRight }'
|
|
|
|
:search='search')
|
2022-11-18 14:14:15 +01:00
|
|
|
template(v-slot:item.map='{ item }')
|
|
|
|
span {{item.latitude && item.longitude && 'YEP' }}
|
2022-09-07 11:48:19 +02:00
|
|
|
template(v-slot:item.actions='{ item }')
|
2022-06-11 12:00:29 +02:00
|
|
|
v-btn(@click='editPlace(item)' color='primary' icon)
|
|
|
|
v-icon(v-text='mdiPencil')
|
2022-06-18 01:09:25 +02:00
|
|
|
nuxt-link(:to='`/place/${item.name}`')
|
2022-06-11 12:00:29 +02:00
|
|
|
v-icon(v-text='mdiEye')
|
2022-06-01 14:08:13 +02:00
|
|
|
|
2019-07-27 22:07:08 +02:00
|
|
|
</template>
|
|
|
|
<script>
|
2023-02-17 00:23:35 +01:00
|
|
|
import { mdiPencil, mdiChevronLeft, mdiChevronRight, mdiMagnify, mdiEye, mdiMapSearch, mdiChevronDown,
|
|
|
|
mdiLatitude, mdiLongitude } from '@mdi/js'
|
2022-09-02 08:32:13 +02:00
|
|
|
import { mapState } from 'vuex'
|
2022-11-18 14:14:15 +01:00
|
|
|
import debounce from 'lodash/debounce'
|
2023-02-17 00:23:35 +01:00
|
|
|
import nominatim from '../../server/services/geocoding/nominatim'
|
|
|
|
import photon from '../../server/services/geocoding/photon'
|
|
|
|
// import geolocation from '../../server/helpers/geolocation/index'
|
2022-02-08 14:45:19 +01:00
|
|
|
|
2019-07-27 22:07:08 +02:00
|
|
|
export default {
|
2023-02-17 00:23:35 +01:00
|
|
|
components: {
|
|
|
|
[process.client && 'MapEdit']: () => import('@/components/MapEdit.vue')
|
|
|
|
},
|
2022-12-06 01:28:42 +01:00
|
|
|
data( {$store} ) {
|
2019-09-11 19:12:24 +02:00
|
|
|
return {
|
2022-11-29 14:40:19 +01:00
|
|
|
mdiPencil, mdiChevronRight, mdiChevronLeft, mdiMagnify, mdiEye, mdiMapSearch, mdiChevronDown,
|
2023-02-17 00:23:35 +01:00
|
|
|
mdiLatitude, mdiLongitude,
|
2020-10-07 11:29:40 +02:00
|
|
|
loading: false,
|
2020-10-07 10:06:49 +02:00
|
|
|
dialog: false,
|
2020-10-09 00:42:03 +02:00
|
|
|
valid: false,
|
2022-06-01 14:08:13 +02:00
|
|
|
places: [],
|
2022-11-18 14:14:15 +01:00
|
|
|
addressList: [],
|
|
|
|
address: '',
|
2022-03-07 16:39:02 +01:00
|
|
|
search: '',
|
2020-07-28 12:24:39 +02:00
|
|
|
place: { name: '', address: '', id: null },
|
|
|
|
headers: [
|
2022-11-29 14:40:19 +01:00
|
|
|
{ value: 'name', text: this.$t('common.name') },
|
|
|
|
{ value: 'address', text: this.$t('common.address') },
|
2022-11-18 14:14:15 +01:00
|
|
|
{ value: 'map', text: 'Map' },
|
2022-11-29 14:40:19 +01:00
|
|
|
{ value: 'actions', text: this.$t('common.actions'), align: 'right' }
|
2022-12-06 00:03:53 +01:00
|
|
|
],
|
2023-02-17 00:23:35 +01:00
|
|
|
geocoding_provider_type: $store.state.settings.geocoding_provider_type || 'Nominatim',
|
|
|
|
nominatimProvider: nominatim,
|
|
|
|
photonProvider: photon
|
2019-07-27 22:07:08 +02:00
|
|
|
}
|
|
|
|
},
|
2022-09-07 11:48:19 +02:00
|
|
|
async fetch() {
|
2022-12-13 15:41:39 +01:00
|
|
|
this.places = await this.$axios.$get('/places')
|
2022-06-01 14:08:13 +02:00
|
|
|
},
|
2023-02-17 00:23:35 +01:00
|
|
|
mounted() {
|
|
|
|
// this.currentGeocodingProvider = geolocation.getGeocodingProvider(this.settings.geocoding_provider_type)
|
|
|
|
},
|
2022-09-02 08:32:13 +02:00
|
|
|
computed: {
|
|
|
|
...mapState(['settings']),
|
|
|
|
},
|
2019-07-27 22:07:08 +02:00
|
|
|
methods: {
|
2022-09-07 11:48:19 +02:00
|
|
|
editPlace(item) {
|
2019-09-11 19:12:24 +02:00
|
|
|
this.place.name = item.name
|
|
|
|
this.place.address = item.address
|
2022-09-08 20:37:20 +02:00
|
|
|
if (this.settings.allow_geolocation) {
|
2023-02-17 00:23:35 +01:00
|
|
|
this.place.geocodedAddress = ''
|
|
|
|
this.mapEdit++
|
2022-09-19 05:13:57 +02:00
|
|
|
this.place.latitude = item.latitude
|
|
|
|
this.place.longitude = item.longitude
|
2022-09-02 08:32:13 +02:00
|
|
|
}
|
2019-09-11 19:12:24 +02:00
|
|
|
this.place.id = item.id
|
2020-10-07 10:06:49 +02:00
|
|
|
this.dialog = true
|
2019-09-11 19:12:24 +02:00
|
|
|
},
|
2022-09-07 11:48:19 +02:00
|
|
|
async savePlace() {
|
2020-10-09 00:42:03 +02:00
|
|
|
if (!this.$refs.form.validate()) return
|
2020-10-07 11:29:40 +02:00
|
|
|
this.loading = true
|
2020-07-25 21:41:22 +02:00
|
|
|
await this.$axios.$put('/place', this.place)
|
2022-06-07 21:10:17 +02:00
|
|
|
await this.$fetch()
|
2020-10-07 11:29:40 +02:00
|
|
|
this.loading = false
|
2020-10-07 10:06:49 +02:00
|
|
|
this.dialog = false
|
2022-11-18 14:14:15 +01:00
|
|
|
},
|
|
|
|
selectAddress (v) {
|
|
|
|
if (!v) { return }
|
|
|
|
if (typeof v === 'object') {
|
2023-02-17 00:23:35 +01:00
|
|
|
this.place.latitude = v.lat
|
|
|
|
this.place.longitude = v.lon
|
|
|
|
this.place.address = v.address
|
|
|
|
if (this.settings.allow_geolocation) {
|
|
|
|
this.place.geocodedAddress = v.address
|
|
|
|
}
|
2022-11-18 14:14:15 +01:00
|
|
|
} else {
|
|
|
|
this.place.address = v
|
|
|
|
this.place.latitude = this.place.longitude = null
|
|
|
|
}
|
|
|
|
this.$emit('input', { ...this.place })
|
2022-12-06 00:03:53 +01:00
|
|
|
},
|
2022-11-18 14:14:15 +01:00
|
|
|
searchAddress: debounce(async function(ev) {
|
|
|
|
const pre_searchCoordinates = ev.target.value.trim().toLowerCase()
|
|
|
|
const searchCoordinates = pre_searchCoordinates.replace('/', ',')
|
|
|
|
|
|
|
|
if (searchCoordinates.length) {
|
|
|
|
this.loading = true
|
2022-12-06 00:03:53 +01:00
|
|
|
const ret = await this.$axios.$get(`placeOSM/${this.geocoding_provider_type}/${searchCoordinates}`)
|
2022-12-06 01:28:42 +01:00
|
|
|
if (this.geocoding_provider_type == "Nominatim") {
|
2023-02-17 00:23:35 +01:00
|
|
|
this.addressList = nominatim.mapQueryResults(ret)
|
2022-12-06 01:28:42 +01:00
|
|
|
} else if (this.geocoding_provider_type == "Photon") {
|
2023-02-17 00:23:35 +01:00
|
|
|
this.addressList = photon.mapQueryResults(ret)
|
2022-11-18 14:14:15 +01:00
|
|
|
}
|
|
|
|
this.loading = false
|
|
|
|
}
|
2023-02-17 00:23:35 +01:00
|
|
|
}, 1000)
|
2019-07-27 22:07:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|