2020-10-25 00:31:38 +02:00
|
|
|
<template lang="pug">
|
2022-11-11 06:01:50 +01:00
|
|
|
v-row.mb-4
|
2022-04-27 12:34:58 +02:00
|
|
|
v-col(cols=12 md=6)
|
|
|
|
v-combobox(ref='place'
|
|
|
|
:rules="[$validators.required('common.where')]"
|
|
|
|
:label="$t('common.where')"
|
|
|
|
:hint="$t('event.where_description')"
|
|
|
|
:prepend-icon='mdiMapMarker'
|
|
|
|
no-filter
|
2022-06-01 14:07:55 +02:00
|
|
|
hide-no-data
|
|
|
|
@input.native='search'
|
|
|
|
persistent-hint
|
2022-11-15 17:37:13 +01:00
|
|
|
:value='value.name'
|
2022-11-19 13:20:37 +01:00
|
|
|
item-text='name'
|
2022-06-01 14:07:55 +02:00
|
|
|
:items="places"
|
2022-04-27 12:34:58 +02:00
|
|
|
@change='selectPlace')
|
|
|
|
template(v-slot:item="{ item, attrs, on }")
|
|
|
|
v-list-item(v-bind='attrs' v-on='on')
|
2022-06-22 14:07:28 +02:00
|
|
|
v-list-item-content(two-line v-if='item.create')
|
|
|
|
v-list-item-title <v-icon color='primary' v-text='mdiPlus' :aria-label='$t("common.add")'></v-icon> {{$t('common.add')}} <strong>{{item.name}}</strong>
|
2022-04-27 12:34:58 +02:00
|
|
|
v-list-item-content(two-line v-else)
|
|
|
|
v-list-item-title(v-text='item.name')
|
|
|
|
v-list-item-subtitle(v-text='item.address')
|
2020-10-25 00:31:38 +02:00
|
|
|
|
2022-12-10 19:33:32 +01:00
|
|
|
|
2022-04-27 12:34:58 +02:00
|
|
|
v-col(cols=12 md=6)
|
2023-02-17 00:23:35 +01:00
|
|
|
v-row.mx-0.my-0.align-center.justify-center
|
|
|
|
v-combobox.mr-4(v-model="virtualLocations" v-if="settings.allow_event_only_online && value.name === 'online'"
|
|
|
|
:prepend-icon='mdiLink'
|
2023-02-19 17:59:28 +01:00
|
|
|
:hint="$t('event.online_locations_help')"
|
2023-02-17 00:23:35 +01:00
|
|
|
:label="$t('event.online_event_urls')"
|
|
|
|
clearable chips small-chips multiple deletable-chips hide-no-data hide-selected persistent-hint
|
|
|
|
:delimiters="[',', ';', '; ']"
|
|
|
|
:items="virtualLocations"
|
|
|
|
@change='selectLocations')
|
|
|
|
template(v-slot:selection="{ item, on, attrs, selected, parent }")
|
|
|
|
v-chip(v-bind="attrs" close :close-icon='mdiCloseCircle' @click:close='parent.selectItem(item)'
|
|
|
|
:input-value="selected" label small) {{ item }}
|
|
|
|
template(v-slot:append)
|
|
|
|
v-icon(v-text='mdiCog' :disabled='!value.name' @click="whereInputAdvancedDialog = true")
|
|
|
|
|
|
|
|
v-text-field.mr-4(v-if="!settings.allow_geolocation && value.name !== 'online'"
|
2022-12-11 01:14:04 +01:00
|
|
|
ref='address'
|
|
|
|
:prepend-icon='mdiMap'
|
|
|
|
:disabled='disableAddress'
|
|
|
|
:rules="[ v => disableAddress ? true : $validators.required('common.address')(v)]"
|
|
|
|
:label="$t('common.address')"
|
|
|
|
:hint="$t('event.address_description')"
|
|
|
|
persistent-hint
|
|
|
|
@change="changeAddress"
|
|
|
|
:value="value.address")
|
2023-02-17 00:23:35 +01:00
|
|
|
template(v-slot:append v-if="settings.allow_event_also_online && place.name !== 'online'")
|
|
|
|
v-icon(v-text='mdiCog' :disabled='!value.name' @click="whereInputAdvancedDialog = true")
|
|
|
|
|
|
|
|
v-combobox(ref='address' v-if="settings.allow_geolocation && value.name !== 'online' || (!settings.allow_event_only_online && value.name === 'online')"
|
|
|
|
:prepend-icon='mdiMapSearch'
|
|
|
|
:disabled='disableAddress'
|
|
|
|
@input.native='searchAddress'
|
|
|
|
:label="$t('common.address')"
|
|
|
|
:rules="[ v => disableAddress ? true : $validators.required('common.address')(v)]"
|
|
|
|
:value='value.address'
|
|
|
|
item-text='address'
|
|
|
|
persistent-hint hide-no-data clearable no-filter
|
|
|
|
:loading='loading'
|
|
|
|
@change='selectAddress'
|
|
|
|
@focus='searchAddress'
|
|
|
|
:items="addressList"
|
|
|
|
:hint="$t('event.address_description_osm')")
|
|
|
|
template(v-slot:message="{message, key}")
|
|
|
|
span(v-html='message' :key="key")
|
|
|
|
template(v-slot:item="{ item, attrs, on }")
|
|
|
|
v-list-item(v-bind='attrs' v-on='on')
|
|
|
|
v-icon.pr-4(v-text='loadCoordinatesResultIcon(item)')
|
|
|
|
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}`')
|
|
|
|
template(v-slot:append v-if="settings.allow_event_also_online || settings.allow_geolocation")
|
|
|
|
v-icon(v-text='mdiCog' :disabled='!value.name || (!value.isNew && !settings.allow_event_also_online) ' @click="whereInputAdvancedDialog = true")
|
|
|
|
|
|
|
|
v-dialog(v-model='whereInputAdvancedDialog' :key="whereAdvancedId" destroy-on-close max-width='700px' :fullscreen='$vuetify.breakpoint.xsOnly' dense)
|
|
|
|
WhereInputAdvanced(ref='whereAdvanced' :place.sync='value' :event='event' @close='whereInputAdvancedDialog = false && this.$refs.address.blur()'
|
|
|
|
:virtualLocations.sync="virtualLocations"
|
|
|
|
:online_event_only_value.sync='online_event_only'
|
|
|
|
@update:onlineEvent="changeOnlineEvent"
|
|
|
|
@update:virtualLocations="selectLocations"
|
|
|
|
)
|
2020-10-25 00:31:38 +02:00
|
|
|
|
2023-02-17 00:23:35 +01:00
|
|
|
|
2020-10-25 00:31:38 +02:00
|
|
|
</template>
|
|
|
|
<script>
|
2023-02-17 00:23:35 +01:00
|
|
|
import { mdiMap, mdiMapMarker, mdiPlus, mdiMapSearch, mdiRoadVariant, mdiHome, mdiCityVariant, mdiCog, mdiLink, mdiCloseCircle } from '@mdi/js'
|
2022-09-02 08:32:13 +02:00
|
|
|
import { mapState } from 'vuex'
|
2022-11-18 14:13:59 +01:00
|
|
|
import debounce from 'lodash/debounce'
|
2022-11-15 17:37:13 +01:00
|
|
|
import get from 'lodash/get'
|
2023-02-17 00:23:35 +01:00
|
|
|
import WhereInputAdvanced from './WhereInputAdvanced.vue'
|
|
|
|
import nominatim from '../server/services/geocoding/nominatim'
|
|
|
|
import photon from '../server/services/geocoding/photon'
|
2020-10-25 00:31:38 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'WhereInput',
|
2020-10-27 11:56:47 +01:00
|
|
|
props: {
|
2023-02-17 00:23:35 +01:00
|
|
|
value: { type: Object, default: () => ({}) },
|
|
|
|
event: { type: Object, default: () => null },
|
2020-10-27 11:56:47 +01:00
|
|
|
},
|
2023-02-17 00:23:35 +01:00
|
|
|
components: { WhereInputAdvanced },
|
2022-12-06 00:03:53 +01:00
|
|
|
data ( {$store} ) {
|
2020-10-25 00:31:38 +02:00
|
|
|
return {
|
2023-02-17 00:23:35 +01:00
|
|
|
mdiMap, mdiMapMarker, mdiPlus, mdiMapSearch, mdiRoadVariant, mdiHome, mdiCityVariant, mdiCog, mdiLink, mdiCloseCircle,
|
|
|
|
places: [],
|
2021-01-21 01:11:08 +01:00
|
|
|
place: { },
|
|
|
|
placeName: '',
|
2022-09-02 08:32:13 +02:00
|
|
|
disableAddress: true,
|
2022-11-18 14:13:59 +01:00
|
|
|
addressList: [],
|
2022-11-18 14:33:38 +01:00
|
|
|
loading: false,
|
|
|
|
nominatim_osm_type: {
|
|
|
|
way: mdiRoadVariant,
|
|
|
|
house: mdiHome,
|
|
|
|
node: mdiMapMarker,
|
|
|
|
relation: mdiCityVariant,
|
|
|
|
},
|
2022-12-06 00:03:53 +01:00
|
|
|
nominatim_class: ['amenity', 'shop', 'tourism', 'leisure', 'building'],
|
|
|
|
photon_osm_key: ['amenity', 'shop', 'tourism', 'leisure', 'building'],
|
|
|
|
photon_osm_type: {
|
|
|
|
'W': mdiRoadVariant,
|
|
|
|
'N': mdiMapMarker,
|
|
|
|
'R': mdiCityVariant,
|
|
|
|
},
|
2023-02-17 00:23:35 +01:00
|
|
|
geocoding_provider_type: $store.state.settings.geocoding_provider_type || 'Nominatim',
|
|
|
|
nominatimProvider: nominatim,
|
|
|
|
photonProvider: photon,
|
|
|
|
whereInputAdvancedDialog: false,
|
|
|
|
virtualLocations: this.event.locations || [],
|
|
|
|
online_event_only: (this.value.name === 'online') ? true : false,
|
|
|
|
whereAdvancedId: 1
|
2020-10-25 00:31:38 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2022-09-02 08:32:13 +02:00
|
|
|
...mapState(['settings']),
|
2021-01-21 01:11:08 +01:00
|
|
|
filteredPlaces () {
|
|
|
|
if (!this.placeName) { return this.places }
|
2022-05-03 18:33:20 +02:00
|
|
|
const placeName = this.placeName.trim().toLowerCase()
|
2021-01-21 01:11:08 +01:00
|
|
|
let nameMatch = false
|
|
|
|
const matches = this.places.filter(p => {
|
|
|
|
const tmpName = p.name.toLowerCase()
|
|
|
|
const tmpAddress = p.address.toLowerCase()
|
|
|
|
if (tmpName.includes(placeName)) {
|
|
|
|
if (tmpName === placeName) { nameMatch = true }
|
|
|
|
return true
|
|
|
|
}
|
2022-04-27 12:34:58 +02:00
|
|
|
return tmpAddress.includes(placeName)
|
2021-01-21 01:11:08 +01:00
|
|
|
})
|
|
|
|
if (!nameMatch) {
|
|
|
|
matches.unshift({ create: true, name: this.placeName })
|
|
|
|
}
|
|
|
|
return matches
|
|
|
|
}
|
2020-10-25 00:31:38 +02:00
|
|
|
},
|
2023-01-09 17:02:15 +01:00
|
|
|
mounted () {
|
|
|
|
this.$nextTick( () => {
|
|
|
|
this.search()
|
|
|
|
})
|
|
|
|
},
|
2020-10-25 00:31:38 +02:00
|
|
|
methods: {
|
2022-06-01 14:07:55 +02:00
|
|
|
search: debounce(async function(ev) {
|
2023-01-09 17:02:15 +01:00
|
|
|
const search = ev ? ev.target.value.trim().toLowerCase() : ''
|
2022-06-01 14:07:55 +02:00
|
|
|
this.places = await this.$axios.$get(`place?search=${search}`)
|
2023-02-17 00:23:35 +01:00
|
|
|
|
|
|
|
// Filter out the place with name 'online' if not allowed
|
|
|
|
if (this.places.length && !this.settings.allow_event_only_online) {
|
|
|
|
this.places = this.places.filter(p => p.name !== 'online')
|
|
|
|
}
|
|
|
|
if (!search && this.places.length) {
|
|
|
|
return this.places
|
|
|
|
}
|
|
|
|
const matches = this.places.filter(p => p.name !== 'online').find(p => search === p.name.toLocaleLowerCase())
|
2022-06-22 14:07:28 +02:00
|
|
|
if (!matches && search) {
|
2022-06-01 14:07:55 +02:00
|
|
|
this.places.unshift({ create: true, name: ev.target.value.trim() })
|
|
|
|
}
|
2023-01-26 23:30:18 +01:00
|
|
|
}, 200),
|
2022-11-18 14:33:38 +01:00
|
|
|
loadCoordinatesResultIcon(item) {
|
2022-12-06 00:03:53 +01:00
|
|
|
if (this.geocoding_provider_type == "Nominatim") {
|
|
|
|
if ( this.nominatim_class.includes(item.class)) {
|
|
|
|
return this.mdiHome
|
|
|
|
}
|
|
|
|
return this.nominatim_osm_type[item.type]
|
|
|
|
} else if (this.geocoding_provider_type == "Photon") {
|
|
|
|
if ( this.photon_osm_key.includes(item.class)) {
|
|
|
|
return this.mdiHome
|
|
|
|
}
|
|
|
|
return this.photon_osm_type[item.type]
|
2022-11-18 14:33:38 +01:00
|
|
|
}
|
|
|
|
},
|
2020-10-25 00:31:38 +02:00
|
|
|
selectPlace (p) {
|
2023-02-17 00:23:35 +01:00
|
|
|
// force online events under place: online address: online
|
|
|
|
this.online_event_only = false
|
|
|
|
this.place.isNew = false
|
|
|
|
this.whereAdvancedId++
|
|
|
|
|
2021-01-21 01:11:08 +01:00
|
|
|
if (!p) { return }
|
|
|
|
if (typeof p === 'object' && !p.create) {
|
2022-11-19 13:20:37 +01:00
|
|
|
if (p.id === this.value.id) return
|
2022-10-27 15:09:11 +02:00
|
|
|
this.place.name = p.name
|
2020-11-04 10:55:30 +01:00
|
|
|
this.place.address = p.address
|
2022-09-08 20:37:20 +02:00
|
|
|
if (this.settings.allow_geolocation) {
|
2022-09-19 05:13:57 +02:00
|
|
|
this.place.latitude = p.latitude
|
|
|
|
this.place.longitude = p.longitude
|
2022-09-02 08:32:13 +02:00
|
|
|
}
|
2022-05-06 23:02:43 +02:00
|
|
|
this.place.id = p.id
|
2023-02-17 00:23:35 +01:00
|
|
|
if (this.settings.allow_event_only_online && this.place.name === 'online') {
|
|
|
|
this.online_event_only = true
|
|
|
|
}
|
2020-10-25 00:31:38 +02:00
|
|
|
this.disableAddress = true
|
2020-11-04 10:55:30 +01:00
|
|
|
} else { // this is a new place
|
2023-02-17 00:23:35 +01:00
|
|
|
this.place.isNew = true
|
|
|
|
this.whereAdvancedId++
|
|
|
|
|
2022-10-27 15:09:11 +02:00
|
|
|
this.place.name = (p.name || p).trim()
|
|
|
|
const tmpPlace = this.place.name.toLocaleLowerCase()
|
2021-06-07 00:00:31 +02:00
|
|
|
// search for a place with the same name
|
2022-06-01 14:07:55 +02:00
|
|
|
const place = this.places.find(p => !p.create && p.name.trim().toLocaleLowerCase() === tmpPlace)
|
2021-06-07 00:00:31 +02:00
|
|
|
if (place) {
|
2022-05-03 18:33:20 +02:00
|
|
|
this.place.name = place.name
|
2022-05-06 23:02:43 +02:00
|
|
|
this.place.id = place.id
|
2021-06-07 00:00:31 +02:00
|
|
|
this.place.address = place.address
|
|
|
|
this.disableAddress = true
|
|
|
|
} else {
|
2022-05-06 23:02:43 +02:00
|
|
|
delete this.place.id
|
2021-06-07 00:00:31 +02:00
|
|
|
this.place.address = ''
|
2022-09-08 20:37:20 +02:00
|
|
|
if (this.settings.allow_geolocation) {
|
2022-09-02 08:32:13 +02:00
|
|
|
this.place.details = p.details
|
2022-09-19 05:13:57 +02:00
|
|
|
this.place.latitude = p.latitude
|
|
|
|
this.place.longitude = p.longitude
|
2022-09-02 08:32:13 +02:00
|
|
|
}
|
2023-02-17 00:23:35 +01:00
|
|
|
// Prevent to provide link for 'event only online' if not allowed: reset locations
|
|
|
|
if (!this.settings.allow_event_only_online && this.place.name === 'online') {
|
|
|
|
this.event.locations = []
|
|
|
|
}
|
2021-06-07 00:00:31 +02:00
|
|
|
this.disableAddress = false
|
|
|
|
this.$refs.place.blur()
|
|
|
|
this.$refs.address.focus()
|
|
|
|
}
|
2020-10-25 00:31:38 +02:00
|
|
|
}
|
2020-11-04 10:55:30 +01:00
|
|
|
this.$emit('input', { ...this.place })
|
2020-10-25 00:31:38 +02:00
|
|
|
},
|
2022-12-10 19:33:32 +01:00
|
|
|
changeAddress (v) {
|
|
|
|
this.place.address = v
|
|
|
|
this.$emit('input', { ...this.place })
|
|
|
|
this.disableDetails = false
|
|
|
|
},
|
2022-11-18 14:13:59 +01:00
|
|
|
selectAddress (v) {
|
2022-09-02 08:32:13 +02:00
|
|
|
if (!v) { return }
|
|
|
|
if (typeof v === 'object') {
|
2022-09-19 05:13:57 +02:00
|
|
|
this.place.latitude = v.lat
|
|
|
|
this.place.longitude = v.lon
|
2022-11-15 17:37:13 +01:00
|
|
|
this.place.address = v.address
|
|
|
|
// }
|
|
|
|
} else {
|
|
|
|
this.place.address = v
|
|
|
|
this.place.latitude = this.place.longitude = null
|
2022-09-02 08:32:13 +02:00
|
|
|
}
|
|
|
|
this.$emit('input', { ...this.place })
|
|
|
|
},
|
2022-11-18 14:13:59 +01:00
|
|
|
searchAddress: debounce(async function(ev) {
|
2022-09-08 20:37:20 +02:00
|
|
|
const pre_searchCoordinates = ev.target.value.trim().toLowerCase()
|
|
|
|
const searchCoordinates = pre_searchCoordinates.replace('/', ',')
|
|
|
|
if (searchCoordinates.length) {
|
2022-10-28 08:27:47 +02:00
|
|
|
this.loading = true
|
2022-12-06 00:03:53 +01:00
|
|
|
const ret = await this.$axios.$get(`placeOSM/${this.geocoding_provider_type}/${searchCoordinates}`)
|
|
|
|
|
2023-02-17 00:23:35 +01:00
|
|
|
// this.geocoding_provider.mapQueryResults(ret)
|
2022-12-06 00:03:53 +01:00
|
|
|
|
2023-02-17 00:23:35 +01:00
|
|
|
if (this.geocoding_provider_type == "Nominatim") {
|
|
|
|
this.addressList = nominatim.mapQueryResults(ret)
|
|
|
|
} else if (this.geocoding_provider_type == "Photon") {
|
|
|
|
this.addressList = photon.mapQueryResults(ret)
|
2022-11-15 17:37:13 +01:00
|
|
|
}
|
2022-10-28 08:27:47 +02:00
|
|
|
this.loading = false
|
2022-09-02 08:32:13 +02:00
|
|
|
}
|
2023-02-17 00:23:35 +01:00
|
|
|
}, 1000),
|
|
|
|
selectLocations () {
|
|
|
|
this.event.locations = []
|
|
|
|
this.virtualLocations && this.virtualLocations.forEach((item, i) => {
|
|
|
|
if (!item.startsWith('http')) {
|
|
|
|
this.virtualLocations[i] = `https://${item}`
|
|
|
|
}
|
|
|
|
this.event.locations[i] = {'type': 'virtualLocation', 'url': this.virtualLocations[i] }
|
|
|
|
})
|
|
|
|
},
|
|
|
|
changeOnlineEvent(v) {
|
|
|
|
this.online_event_only = v
|
|
|
|
// console.log(this.online_event_only)
|
|
|
|
if (this.online_event_only) { this.place.name = this.place.address = 'online' }
|
|
|
|
if (!this.online_event_only) { this.place.name = this.place.address = '' }
|
|
|
|
this.place.latitude = null
|
|
|
|
this.place.longitude = null
|
|
|
|
|
|
|
|
// update virtualLocations
|
|
|
|
this.event.locations && this.selectLocations()
|
|
|
|
this.$emit('input', { ...this.place })
|
|
|
|
},
|
2020-10-25 00:31:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|