From 8c8103a5ee1be52f389315b02fa069f10e25b7a8 Mon Sep 17 00:00:00 2001 From: lesion Date: Wed, 5 Apr 2023 16:14:55 +0200 Subject: [PATCH] refactoring online events --- components/WhereInput.vue | 137 ++++++++++++++------------ components/WhereInputAdvanced.vue | 68 +++++-------- components/admin/Settings.vue | 26 ++--- locales/en.json | 15 ++- pages/add/_edit.vue | 3 +- pages/event/_slug.vue | 34 +++---- pages/place/_place.vue | 4 +- server/api/controller/event.js | 4 +- server/api/controller/settings.js | 3 +- server/helpers.js | 3 +- store/index.js | 5 +- webcomponents/src/GancioEvents.svelte | 2 +- 12 files changed, 139 insertions(+), 165 deletions(-) diff --git a/components/WhereInput.vue b/components/WhereInput.vue index 78cc2ae7..554de17e 100644 --- a/components/WhereInput.vue +++ b/components/WhereInput.vue @@ -1,6 +1,7 @@ diff --git a/components/WhereInputAdvanced.vue b/components/WhereInputAdvanced.vue index 527117e4..9b2e9241 100644 --- a/components/WhereInputAdvanced.vue +++ b/components/WhereInputAdvanced.vue @@ -3,30 +3,8 @@ v-card v-card-title {{ $t('event.where_advanced_options') }} v-card-subtitle {{ $t('event.where_advanced_options_description') }} - v-card-text(v-if='settings.allow_event_also_online') - v-switch.mt-0.mb-0(v-model='event_only_online_update' - v-if='settings.allow_event_only_online' - persistent-hint - :label="$t('event.event_only_online_label')") - - v-combobox.mt-0.mb-0.mr-4.my-5(v-model="onlineLocations_update" - v-if="place.name !== 'online' && settings.allow_event_also_online" - :prepend-icon='mdiLink' - :hint="$t('event.online_locations_help')" - :label="$t('event.online_locations')" - clearable chips small-chips multiple deletable-chips hide-no-data hide-selected persistent-hint - :delimiters="[',', ';', '; ']" - :items="onlineLocations_update") - template(v-slot:selection="{ item, index, on, attrs, selected, parent }") - v-chip(v-bind="attrs" :outlined='index !== 0' - close :close-icon='mdiCloseCircle' @click:close='parent.selectItem(item)' - :input-value="selected" label small) {{ item }} - - v-divider(v-if='showGeocoded && showOnline') - - v-card-text.mt-5(v-if='showGeocoded') - v-combobox(ref='geocodedAddress' v-if="settings.allow_geolocation && place.name !== 'online' || (!settings.allow_event_only_online && place.name === 'online')" - v-focus + v-card-text(v-if='showGeocoded') + v-combobox(ref='geocodedAddress' :prepend-icon='mdiMapSearch' @input.native='searchAddress' :label="$t('common.search_coordinates')" @@ -63,7 +41,23 @@ v-card :rules="$validators.longitude") p.mt-4(v-if='place.isNew' v-html="$t('event.address_geocoded_disclaimer')") - MapEdit.mt-4(:place='place' :key='mapEdit' v-if="(settings.allow_geolocation && place.name !== 'online' && place.latitude && place.longitude)" ) + MapEdit.mt-4(:place='place' v-if="(settings.allow_geolocation && place.name !== 'online' && place.latitude && place.longitude)" ) + + v-divider(v-if='settings.allow_online_event && showGeocoded') + + v-card-text.mt-6(v-if='settings.allow_online_event') + v-combobox(v-model="onlineLocations_update" + :prepend-icon='mdiLink' + :hint="$t('event.online_locations_help')" + :label="$t('event.online_locations')" + clearable chips small-chips multiple deletable-chips hide-no-data hide-selected persistent-hint + :delimiters="[',', ';']" + :items="onlineLocations_update") + template(v-slot:selection="{ item, index, on, attrs, selected, parent }") + v-chip(v-bind="attrs" :outlined='index !== 0' + close :close-icon='mdiCloseCircle' @click:close='parent.selectItem(item)' + :input-value="selected" label small) {{ item }} + v-card-actions v-spacer @@ -75,7 +69,6 @@ import { mdiMap, mdiLatitude, mdiLongitude, mdiCog, mdiLink, mdiCloseCircle, mdi mdiMapSearch, mdiRoadVariant, mdiHome, mdiCityVariant } from '@mdi/js' import { mapState } from 'vuex' import debounce from 'lodash/debounce' -import get from 'lodash/get' import geolocation from '../server/helpers/geolocation/index' export default { @@ -83,7 +76,6 @@ export default { props: { place: { type: Object, default: () => ({}) }, event: { type: Object, default: () => null }, - event_only_online_value: { type: Boolean, default: false }, onlineLocations: { type: Array, default: [] } }, components: { @@ -93,18 +85,13 @@ export default { return { mdiMap, mdiLatitude, mdiLongitude, mdiCog, mdiLink, mdiCloseCircle, mdiMapMarker, mdiMapSearch, mdiRoadVariant, mdiHome, mdiCityVariant, - showOnline: $store.state.settings.allow_event_also_online, - showGeocoded: $store.state.settings.allow_geolocation && this.place.name !== 'online', - disableGeocoded: this.place.name === 'online' || !this.place.isNew, - event_only_online: this.place.name === 'online', - mapEdit: 1, addressList: [], loading: false, iconsMapper: { - 'mdiHome': mdiHome, - 'mdiRoadVariant': mdiRoadVariant, - 'mdiMapMarker': mdiMapMarker, - 'mdiCityVariant': mdiCityVariant + mdiHome, + mdiRoadVariant, + mdiMapMarker, + mdiCityVariant }, currentGeocodingProvider: geolocation.getGeocodingProvider($store.state.settings.geocoding_provider_type), prevAddress: '' @@ -112,12 +99,8 @@ export default { }, computed: { ...mapState(['settings']), - event_only_online_update: { - get () { return this.event_only_online_value }, - set (value) { - this.$emit('update:onlineEvent', value) - this.close() - } + showGeocoded () { + return this.settings.allow_geolocation && this.place.name !== 'online' && this.place.isNew }, onlineLocations_update: { get () { return this.onlineLocations }, @@ -155,7 +138,6 @@ export default { } else { this.place.latitude = this.place.longitude = null } - this.mapEdit++ this.prevAddress = v.address }, } diff --git a/components/admin/Settings.vue b/components/admin/Settings.vue index 6f6cd632..d5cc2c2b 100644 --- a/components/admin/Settings.vue +++ b/components/admin/Settings.vue @@ -52,18 +52,14 @@ v-container inset :label="$t('admin.recurrent_event_visible')") + v-switch.mt-1(v-model='allow_online_event' + inset + :label="$t('admin.allow_online_event')") + v-switch.mt-1(v-model='allow_geolocation' inset :label="$t('admin.allow_geolocation')") - v-switch.mt-1(v-model='allow_event_only_online' - inset - :label="$t('admin.allow_event_only_online')") - - v-switch.mt-1(v-model='allow_event_also_online' - inset - :label="$t('admin.allow_event_also_online')") - v-dialog(v-model='showSMTP' destroy-on-close max-width='700px' :fullscreen='$vuetify.breakpoint.xsOnly') SMTP(@close='showSMTP = false') @@ -134,17 +130,9 @@ export default { get () { return this.settings.allow_geolocation }, set (value) { this.setSetting({ key: 'allow_geolocation', value }) } }, - allow_event_only_online: { - get () { return this.settings.allow_event_only_online }, - set (value) { this.setSetting({ key: 'allow_event_only_online', value }) - if (value == true) { this.allow_event_also_online = value } - } - }, - allow_event_also_online: { - get () { return this.settings.allow_event_also_online }, - set (value) { this.setSetting({ key: 'allow_event_also_online', value }) - if (value == false) { this.setSetting({ key: 'allow_event_only_online', value }) } - } + allow_online_event: { + get () { return this.settings.allow_online_event }, + set (value) { this.setSetting({ key: 'allow_online_event', value }) } }, filteredTimezones () { const current_timezone = DateTime.local().zoneName diff --git a/locales/en.json b/locales/en.json index f14c78f7..d1d0a0e5 100644 --- a/locales/en.json +++ b/locales/en.json @@ -101,7 +101,8 @@ "recurring_event_actions": "Recurring event actions", "latitude": "Latitude", "longitude": "Longitude", - "search_coordinates": "Search coordinates" + "search_coordinates": "Search coordinates", + "online": "On-line" }, "login": { "description": "By logging in you can publish new events.", @@ -143,7 +144,7 @@ "updated": "Event updated", "where_description": "Where's the event? If not present you can create it.", "address_description": "What is the address?", - "address_description_osm": "Search tiping the address. (OpenStreetMap contributors)", + "address_description_osm": "Search coordinates by typing the address. (OpenStreetMap contributors)", "confirmed": "Event confirmed", "not_found": "Could not find event", "remove_confirmation": "Are you sure you want to remove this event?", @@ -184,12 +185,8 @@ "download_flyer": "Download flyer", "where_advanced_options": "Place - Advanced options", "where_advanced_options_description": "Define here additional place properties", - "event_only_online": "Online event", - "event_only_online_label": "The event is only online", - "event_also_online": "Partecipate remotely", "online_locations": "Online locations", - "online_locations_help": "For instance a url to a videconference room, and a fallback url (max. 3)", - "online_locations_url": "Online locations", + "online_locations_help": "For instance an url to a videconference room and a fallback url (max. 3)", "online_locations_fallback_urls": "Fallback links", "address_geocoded_disclaimer": "If you cannot find the street address or the housenumber you are looking for in the geocoding results, you can manually insert them in the 'Address' field without loose the coordinates. Consider also that the OpenStreetMap project is open to contributions. If you have Android, we recommend StreetComplete " }, @@ -209,6 +206,8 @@ "allow_anon_event": "Allow anonymous events (has to be confirmed)?", "allow_multidate_event": "Allow multi-day events", "allow_recurrent_event": "Allow recurring events", + "allow_online_event": "Allow online events", + "allow_online_event_hint": "Ask for urls ", "allow_geolocation": "Allow events geolocation", "recurrent_event_visible": "Show recurring events by default", "federation": "Federation / ActivityPub", @@ -308,8 +307,6 @@ "tilelayer_test_success": "The tilelayer service at {service_name} is working", "tilelayer_test_error": "The tilelayer service is not reachable at {service_name}", "geolocation": "Geolocation", - "allow_event_only_online": "Allow event only online", - "allow_event_also_online": "Allow event also online", "colors": "Colors" }, "auth": { diff --git a/pages/add/_edit.vue b/pages/add/_edit.vue index e482a03f..338087d7 100644 --- a/pages/add/_edit.vue +++ b/pages/add/_edit.vue @@ -141,6 +141,7 @@ export default { data.event.media = event.media || [] data.event.parentId = event.parentId data.event.recurrent = event.recurrent + data.event.online_locations = event.online_locations return data } return {} @@ -233,7 +234,7 @@ export default { formData.append('place_id', this.event.place.id) } formData.append('place_name', this.event.place.name.trim()) - formData.append('place_address', this.event.place.address) + formData.append('place_address', this.event.place.address || null) if (this.settings.allow_geolocation) { formData.append('place_latitude', this.event.place.latitude || '') diff --git a/pages/event/_slug.vue b/pages/event/_slug.vue index f6dd3f07..b719419b 100644 --- a/pages/event/_slug.vue +++ b/pages/event/_slug.vue @@ -17,17 +17,17 @@ v-container#event.pa-2.pa-sm-2(itemscope itemtype="https://schema.org/Event" v-t strong.p-name.text--primary(itemprop="name") {{event.title}} v-divider v-container.eventDetails - time.dt-start(:datetime='$time.unixFormat(event.start_datetime, "yyyy-MM-dd HH:mm")' itemprop="startDate" :content="$time.unixFormat(event.start_datetime, \"yyyy-MM-dd'T'HH:mm\")") + time.dt-start(:datetime='$time.unixFormat(event.start_datetime, "yyyy-MM-dd HH:mm")' itemprop="startDate" :content='$time.unixFormat(event.start_datetime, "yyyy-MM-dd\'T\'HH:mm")') v-icon(v-text='mdiCalendar' small) strong.ml-2.text-uppercase {{$time.when(event)}} - .d-none.dt-end(v-if='event.end_datetime' itemprop="endDate" :content="$time.unixFormat(event.end_datetime,\"yyyy-MM-dd'T'HH:mm\")") {{$time.unixFormat(event.end_datetime,"yyyy-MM-dd'T'HH:mm")}} + .d-none.dt-end(v-if='event.end_datetime' itemprop="endDate" :content='$time.unixFormat(event.end_datetime,"yyyy-MM-dd\'T\'HH:mm")') {{$time.unixFormat(event.end_datetime,"yyyy-MM-dd'T'HH:mm")}} div.font-weight-light.mb-3 {{$time.from(event.start_datetime)}} small(v-if='event.parentId') ({{$time.recurrentDetail(event)}}) .p-location.h-adr(itemprop="location" itemscope itemtype="https://schema.org/Place") v-icon(v-text='mdiMapMarker' small) nuxt-link.vcard.ml-2.p-name.text-decoration-none.text-uppercase(itemprop="name" :to='`/place/${encodeURIComponent(event.place.name)}`') {{event.place && event.place.name}} - .font-weight-light.p-street-address(itemprop='address') {{event.place && event.place.address}} + .font-weight-light.p-street-address(v-if='event.place.name !=="online"' itemprop='address') {{event.place && event.place.address}} //- tags, hashtags v-container.pt-0(v-if='event.tags && event.tags.length') @@ -35,20 +35,13 @@ v-container#event.pa-2.pa-sm-2(itemscope itemtype="https://schema.org/Event" v-t outlined :key='tag' :to='`/tag/${encodeURIComponent(tag)}`') {{tag}} //- online events - v-divider(v-if='onlineSectionEnabled && event.online_locations && event.online_locations.length') - div(v-if='onlineSectionEnabled && event.online_locations && event.online_locations.length') - v-card-text.text-caption.pb-0(v-text="event.place.name === 'online' && $t('event.event_only_online') || $t('event.event_also_online') ") - v-list-item(target='_blank' :href='`${event.online_locations[0]}`') + //- v-divider(v-if='hasOnlineLocations') + v-list(nav dense v-if='hasOnlineLocations') + v-list-item(v-for='(item, index) in event.online_locations' target='_blank' :href="`${item}`" :key="index") v-list-item-icon - v-icon.my-auto(v-text='mdiMonitorAccount') + v-icon(v-text='mdiMonitorAccount') v-list-item-content.py-0 - v-list-item-title.text-caption(v-text='`${event.online_locations[0]}`') - div(v-if='onlineSectionEnabled && event.online_locations && event.online_locations.length > 1') - v-card-text.text-caption.pt-0.pb-0(v-text="$t('event.online_locations_fallback_urls')") - v-list-item - v-list-item-content - v-chip(v-for='(item, index) in event.online_locations' v-if="index > 0" target='_blank' :href="`${item}`" - v-bind:key="index" small label v-text="`${item}`" outlined ) + v-list-item-title.text-caption(v-text='item') v-divider //- info & actions @@ -92,7 +85,7 @@ v-container#event.pa-2.pa-sm-2(itemscope itemtype="https://schema.org/Event" v-t v-list-item-content v-list-item-title(v-text="$t('event.download_flyer')") - v-divider + v-divider(v-if='is_mine') //- admin actions eventAdmin(v-if='is_mine' :event='event') @@ -229,8 +222,7 @@ export default { showEmbed: false, showResources: false, selectedResource: { data: { attachment: [] } }, - mapModal: false, - onlineSectionEnabled: $store.state.settings.allow_event_only_online || $store.state.settings.allow_event_also_online + mapModal: false } }, head () { @@ -311,6 +303,12 @@ export default { }, computed: { ...mapState(['settings']), + hasOnlineLocations () { + return this.event.online_locations && this.event.online_locations.length + }, + showMap () { + return this.settings.allow_geolocation && this.event.place.latitude && this.event.place.longitude + }, hasMedia () { return this.event.media && this.event.media.length }, diff --git a/pages/place/_place.vue b/pages/place/_place.vue index d37abde9..dfbbea1e 100644 --- a/pages/place/_place.vue +++ b/pages/place/_place.vue @@ -3,10 +3,10 @@

{{ place.name }}

- {{ place.address }} + {{ place.address }} -
+
diff --git a/server/api/controller/event.js b/server/api/controller/event.js index c82edc80..2cc30629 100644 --- a/server/api/controller/event.js +++ b/server/api/controller/event.js @@ -31,14 +31,14 @@ const eventController = { const place_name = body.place_name && body.place_name.trim() const place_address = body.place_address && body.place_address.trim() - if (!place_address || !place_name) { + if (!place_name || !place_address && place_name !== 'online') { throw new Error(`place_id or place_name and place_address are required`) } let place = await Place.findOne({ where: Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('name')), Sequelize.Op.eq, place_name.toLocaleLowerCase()) }) if (!place) { place = await Place.create({ name: place_name, - address: place_address, + address: place_address || '', latitude: Number(body.place_latitude) || null, longitude: Number(body.place_longitude) || null }) diff --git a/server/api/controller/settings.js b/server/api/controller/settings.js index 27896b86..28358e59 100644 --- a/server/api/controller/settings.js +++ b/server/api/controller/settings.js @@ -27,9 +27,8 @@ const defaultSettings = { allow_anon_event: true, allow_multidate_event: true, allow_recurrent_event: false, + allow_online_event: true, recurrent_event_visible: false, - allow_event_only_online: false, - allow_event_also_online: false, allow_geolocation: false, geocoding_provider_type: 'Nominatim', geocoding_provider: 'https://nominatim.openstreetmap.org/search', diff --git a/server/helpers.js b/server/helpers.js index 379fc9a0..3b2d59e5 100644 --- a/server/helpers.js +++ b/server/helpers.js @@ -79,6 +79,7 @@ module.exports = { allow_anon_event: settings.allow_anon_event, allow_recurrent_event: settings.allow_recurrent_event, allow_multidate_event: settings.allow_multidate_event, + allow_online_event: settings.allow_online_event, recurrent_event_visible: settings.recurrent_event_visible, enable_federation: settings.enable_federation, enable_resources: settings.enable_resources, @@ -99,8 +100,6 @@ module.exports = { tilelayer_provider_attribution: settings.tilelayer_provider_attribution, footerLinks: settings.footerLinks, about: settings.about, - allow_event_only_online: settings.allow_event_only_online, - allow_event_also_online: settings.allow_event_also_online } next() }, diff --git a/store/index.js b/store/index.js index f5442210..6c4069ff 100644 --- a/store/index.js +++ b/store/index.js @@ -10,10 +10,9 @@ export const state = () => ({ allow_anon_event: true, allow_multidate_event: true, allow_recurrent_event: true, - recurrent_event_visible: false, - allow_event_only_online: false, - allow_event_also_online: false, + allow_online_event: true, allow_geolocation: false, + recurrent_event_visible: false, geocoding_provider_type: '', geocoding_provider: '', geocoding_countrycodes: [], diff --git a/webcomponents/src/GancioEvents.svelte b/webcomponents/src/GancioEvents.svelte index 58a3e60c..9098a3ce 100644 --- a/webcomponents/src/GancioEvents.svelte +++ b/webcomponents/src/GancioEvents.svelte @@ -113,7 +113,7 @@
@{event.place.name} - {event.place.address} {event.place.address}{/if} {#if event.tags.length}