Merge remote-tracking branch 'sedum/feat/allowgeoloc' into dev_geo
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -90,12 +90,12 @@ if (config.status !== 'READY') {
|
||||
* @param {integer} [end] - end timestamp (optional)
|
||||
* @param {array} [tags] - List of tags
|
||||
* @param {array} [places] - List of places id
|
||||
* @param {integer} [max] - Limit events
|
||||
* @param {integer} [max] - Limit events
|
||||
* @param {boolean} [show_recurrent] - Show also recurrent events (default: as choosen in admin settings)
|
||||
* @param {integer} [page] - Pagination
|
||||
* @param {boolean} [older] - select <= start instead of >=
|
||||
* @example ***Example***
|
||||
* [https://demo.gancio.org/api/events](https://demo.gancio.org/api/events)
|
||||
* @example ***Example***
|
||||
* [https://demo.gancio.org/api/events](https://demo.gancio.org/api/events)
|
||||
* [usage example](https://framagit.org/les/gancio/-/blob/master/webcomponents/src/GancioEvents.svelte#L18-42)
|
||||
*/
|
||||
|
||||
@@ -111,6 +111,8 @@ if (config.status !== 'READY') {
|
||||
* @param {string} description - event's description (html accepted and sanitized)
|
||||
* @param {string} place_name - the name of the place
|
||||
* @param {string} [place_address] - the address of the place
|
||||
* @param {float} [place_latitude] - the latitude of the place
|
||||
* @param {float} [place_longitude] - the longitude of the place
|
||||
* @param {integer} start_datetime - start timestamp
|
||||
* @param {integer} multidate - is a multidate event?
|
||||
* @param {array} tags - List of tags
|
||||
@@ -163,6 +165,7 @@ if (config.status !== 'READY') {
|
||||
api.get('/place/all', isAdmin, placeController.getAll)
|
||||
api.get('/place/:placeName', cors, placeController.getEvents)
|
||||
api.get('/place', cors, placeController.search)
|
||||
api.get('/placeNominatim/:place_details', cors, placeController._nominatim)
|
||||
api.put('/place', isAdmin, placeController.updatePlace)
|
||||
|
||||
api.get('/tag', cors, tagController.search)
|
||||
|
||||
@@ -105,7 +105,9 @@ Event.prototype.toAP = function (username, locale, to = []) {
|
||||
endTime: this.end_datetime ? dayjs.unix(this.end_datetime).tz().locale(locale).format() : null,
|
||||
location: {
|
||||
name: this.place.name,
|
||||
address: this.place.address
|
||||
address: this.place.address,
|
||||
latitude: this.place.latitude,
|
||||
longitude: this.place.longitude
|
||||
},
|
||||
attachment,
|
||||
tag: tags && tags.map(tag => ({
|
||||
|
||||
@@ -10,7 +10,9 @@ Place.init({
|
||||
index: true,
|
||||
allowNull: false
|
||||
},
|
||||
address: DataTypes.STRING
|
||||
address: DataTypes.STRING,
|
||||
latitude: DataTypes.FLOAT,
|
||||
longitude: DataTypes.FLOAT,
|
||||
}, { sequelize, modelName: 'place' })
|
||||
|
||||
module.exports = Place
|
||||
|
||||
@@ -90,6 +90,7 @@ module.exports = {
|
||||
'theme.primary': settings['theme.primary'],
|
||||
hide_thumbs: settings.hide_thumbs,
|
||||
hide_calendar: settings.hide_calendar,
|
||||
allow_geolocation: settings.allow_geolocation,
|
||||
footerLinks: settings.footerLinks,
|
||||
about: settings.about
|
||||
}
|
||||
|
||||
31
server/migrations/20220706090946-place-details.js
Normal file
31
server/migrations/20220706090946-place-details.js
Normal file
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
async up (queryInterface, Sequelize) {
|
||||
/**
|
||||
* Add altering commands here.
|
||||
*
|
||||
* Example:
|
||||
* await queryInterface.createTable('users', { id: Sequelize.INTEGER });
|
||||
*/
|
||||
return Promise.all(
|
||||
[
|
||||
await queryInterface.addColumn('places', 'latitude', { type: Sequelize.FLOAT }),
|
||||
await queryInterface.addColumn('places', 'longitude', { type: Sequelize.FLOAT })
|
||||
])
|
||||
},
|
||||
|
||||
async down (queryInterface, Sequelize) {
|
||||
/**
|
||||
* Add reverting commands here.
|
||||
*
|
||||
* Example:
|
||||
* await queryInterface.dropTable('users');
|
||||
*/
|
||||
return Promise.all(
|
||||
[
|
||||
await queryInterface.removeColumn('places', 'latitude'),
|
||||
await queryInterface.removeColumn('places', 'longitude')
|
||||
])
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user