Merge remote-tracking branch 'sedum/feat/allowgeoloc' into dev_geo

This commit is contained in:
lesion
2022-11-15 17:37:13 +01:00
37 changed files with 663 additions and 107 deletions

View File

@@ -41,7 +41,9 @@ const eventController = {
if (!place) {
place = await Place.create({
name: place_name,
address: place_address
address: place_address,
latitude: body.place_latitude,
longitude: body.place_longitude
})
}
return place
@@ -58,7 +60,7 @@ const eventController = {
Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('address')), 'LIKE', '%' + search + '%')
]
},
attributes: [['name', 'label'], 'address', 'id', [Sequelize.cast(Sequelize.fn('COUNT', Sequelize.col('events.placeId')), 'INTEGER'), 'w']],
attributes: [['name', 'label'], 'address', 'latitude', 'longitude', 'id', [Sequelize.cast(Sequelize.fn('COUNT', Sequelize.col('events.placeId')), 'INTEGER'), 'w']],
include: [{ model: Event, where: { is_visible: true }, required: true, attributes: [] }],
group: ['place.id'],
raw: true
@@ -134,7 +136,7 @@ const eventController = {
attributes: ['tag'],
through: { attributes: [] }
},
{ model: Place, required: true, attributes: ['id', 'name', 'address'] }
{ model: Place, required: true, attributes: ['id', 'name', 'address', 'latitude', 'longitude'] }
],
replacements,
limit: 30,
@@ -216,7 +218,7 @@ const eventController = {
},
include: [
{ model: Tag, required: false, attributes: ['tag'], through: { attributes: [] } },
{ model: Place, attributes: ['name', 'address', 'id'] },
{ model: Place, attributes: ['name', 'address', 'latitude', 'longitude', 'id'] },
{
model: Resource,
where: !is_admin && { hidden: false },
@@ -513,7 +515,7 @@ const eventController = {
description: helpers.sanitizeHTML(linkifyHtml(body.description || '', { target: '_blank' })) || event.description,
multidate: body.multidate,
start_datetime: body.start_datetime || event.start_datetime,
end_datetime: body.end_datetime,
end_datetime: body.end_datetime || null,
recurrent
}
@@ -624,7 +626,7 @@ const eventController = {
/**
* Method to search for events with pagination and filtering
* @returns
* @returns
*/
async _select({
start = dayjs().unix(),
@@ -698,7 +700,7 @@ const eventController = {
attributes: ['tag'],
through: { attributes: [] }
},
{ model: Place, required: true, attributes: ['id', 'name', 'address'] }
{ model: Place, required: true, attributes: ['id', 'name', 'address', 'latitude', 'longitude'] }
],
...pagination,
replacements

View File

@@ -5,6 +5,8 @@ const exportController = require('./export')
const log = require('../../log')
const { Op, where, col, fn, cast } = require('sequelize')
const NOMINATIM_URL = 'https://nominatim.openstreetmap.org/search'
const axios = require('axios')
module.exports = {
@@ -60,7 +62,7 @@ module.exports = {
{ address: where(fn('LOWER', col('address')), 'LIKE', '%' + search + '%')},
]
},
attributes: ['name', 'address', 'id'],
attributes: ['name', 'address', 'latitude', 'longitude', 'id'],
include: [{ model: Event, where: { is_visible: true }, required: true, attributes: [] }],
group: ['place.id'],
raw: true,
@@ -70,6 +72,23 @@ module.exports = {
// TOFIX: don't know why limit does not work
return res.json(places.slice(0, 10))
}
},
}
async _nominatim (req, res) {
const details = req.params.place_details
// ?limit=3&format=json&namedetails=1&addressdetails=1&q=
const ret = await axios.get(`${NOMINATIM_URL}`, {
params: {
q: details,
limit: 3,
format: 'json',
addressdetails: 1,
namedetails: 1
},
headers: { 'User-Agent': 'gancio 1.6.0' }
})
return res.json(ret.data)
},
}

View File

@@ -29,6 +29,7 @@ const defaultSettings = {
allow_anon_event: true,
allow_recurrent_event: false,
recurrent_event_visible: false,
allow_geolocation: true,
enable_federation: true,
enable_resources: false,
hide_boosts: true,