add geolocalization
This commit is contained in:
@@ -44,7 +44,7 @@ const eventController = {
|
||||
order: [[Sequelize.col('w'), 'DESC']],
|
||||
where: {
|
||||
tag: Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('tag')), 'LIKE', '%' + search + '%'),
|
||||
},
|
||||
},
|
||||
attributes: [['tag','label'], [Sequelize.cast(Sequelize.fn('COUNT', Sequelize.col('tag.tag')), 'INTEGER'), 'w']],
|
||||
include: [{ model: Event, where: { is_visible: true }, attributes: [], through: { attributes: [] }, required: true }],
|
||||
group: ['tag.tag'],
|
||||
@@ -110,7 +110,7 @@ const eventController = {
|
||||
attributes: ['tag'],
|
||||
through: { attributes: [] }
|
||||
},
|
||||
{ model: Place, required: true, attributes: ['id', 'name', 'address'] }
|
||||
{ model: Place, required: true, attributes: ['id', 'name', 'address', 'details'] }
|
||||
],
|
||||
replacements,
|
||||
limit: 30,
|
||||
@@ -192,7 +192,7 @@ const eventController = {
|
||||
},
|
||||
include: [
|
||||
{ model: Tag, required: false, attributes: ['tag'], through: { attributes: [] } },
|
||||
{ model: Place, attributes: ['name', 'address', 'id'] },
|
||||
{ model: Place, attributes: ['name', 'address', 'details', 'id'] },
|
||||
{
|
||||
model: Resource,
|
||||
where: !is_admin && { hidden: false },
|
||||
@@ -222,7 +222,7 @@ const eventController = {
|
||||
recurrent: null,
|
||||
[Op.or]: [
|
||||
{ start_datetime: { [Op.gt]: event.start_datetime } },
|
||||
{
|
||||
{
|
||||
start_datetime: event.start_datetime,
|
||||
id: { [Op.gt]: event.id }
|
||||
}
|
||||
@@ -239,7 +239,7 @@ const eventController = {
|
||||
recurrent: null,
|
||||
[Op.or]: [
|
||||
{ start_datetime: { [Op.lt]: event.start_datetime } },
|
||||
{
|
||||
{
|
||||
start_datetime: event.start_datetime,
|
||||
id: { [Op.lt]: event.id }
|
||||
}
|
||||
@@ -405,7 +405,8 @@ const eventController = {
|
||||
}
|
||||
place = await Place.create({
|
||||
name: body.place_name,
|
||||
address: body.place_address
|
||||
address: body.place_address,
|
||||
details: body.place_details
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -559,13 +560,14 @@ const eventController = {
|
||||
}
|
||||
place = await Place.create({
|
||||
name: body.place_name,
|
||||
address: body.place_address
|
||||
address: body.place_address,
|
||||
details: body.place_details
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
await event.setPlace(place)
|
||||
|
||||
|
||||
// create/assign tags
|
||||
let tags = []
|
||||
if (body.tags) {
|
||||
@@ -624,7 +626,7 @@ const eventController = {
|
||||
|
||||
/**
|
||||
* Method to search for events with pagination and filtering
|
||||
* @returns
|
||||
* @returns
|
||||
*/
|
||||
async _select ({
|
||||
start = dayjs().unix(),
|
||||
@@ -665,7 +667,7 @@ const eventController = {
|
||||
|
||||
const replacements = []
|
||||
if (tags && places) {
|
||||
where[Op.and] = [
|
||||
where[Op.and] = [
|
||||
{ placeId: places ? places.split(',') : []},
|
||||
Sequelize.fn('EXISTS', Sequelize.literal(`SELECT 1 FROM event_tags WHERE ${Col('event_tags.eventId')}=${Col('event.id')} AND LOWER(${Col('tagTag')}) in (?)`))
|
||||
]
|
||||
@@ -679,10 +681,10 @@ const eventController = {
|
||||
|
||||
let pagination = {}
|
||||
if (limit) {
|
||||
pagination = {
|
||||
pagination = {
|
||||
limit,
|
||||
offset: limit * page,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const events = await Event.findAll({
|
||||
@@ -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', 'details'] }
|
||||
],
|
||||
...pagination,
|
||||
replacements
|
||||
|
||||
@@ -5,6 +5,7 @@ const exportController = require('./export')
|
||||
|
||||
const log = require('../../log')
|
||||
const { Op, where, col, fn, cast } = require('sequelize')
|
||||
const NOMINATIM_URL = 'https://nominatim.openstreetmap.org/search?limit=3&format=geocodejson&accept-language=it&q='
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -60,7 +61,7 @@ module.exports = {
|
||||
{ address: where(fn('LOWER', col('address')), 'LIKE', '%' + search + '%')},
|
||||
]
|
||||
},
|
||||
attributes: ['name', 'address', 'id'],
|
||||
attributes: ['name', 'address', 'details', 'id'],
|
||||
include: [{ model: Event, where: { is_visible: true }, required: true, attributes: [] }],
|
||||
group: ['place.id'],
|
||||
raw: true,
|
||||
@@ -70,6 +71,16 @@ 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
|
||||
// const ret = await axios.get(`${NOMINATIM_URL}${details}`, { headers: { 'User-Agent': 'gancio 0.20' } })
|
||||
// debug(`${NOMINATIM_URL}${details}`)
|
||||
// debug(ret.status)
|
||||
// debug(ret.statusText)
|
||||
// debug(ret.data)
|
||||
// return ret
|
||||
// },
|
||||
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ const defaultSettings = {
|
||||
allow_anon_event: true,
|
||||
allow_recurrent_event: false,
|
||||
recurrent_event_visible: false,
|
||||
allow_geolocalization: false,
|
||||
enable_federation: true,
|
||||
enable_resources: false,
|
||||
hide_boosts: true,
|
||||
|
||||
@@ -89,16 +89,16 @@ 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)
|
||||
*/
|
||||
|
||||
api.get('/events', cors, eventController.select)
|
||||
api.get('/events', cors, eventController.select)
|
||||
|
||||
/**
|
||||
* Add a new event
|
||||
@@ -110,6 +110,7 @@ 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 {array} [place_details] - the details of the place
|
||||
* @param {integer} start_datetime - start timestamp
|
||||
* @param {integer} multidate - is a multidate event?
|
||||
* @param {array} tags - List of tags
|
||||
@@ -160,6 +161,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)
|
||||
|
||||
@@ -10,7 +10,8 @@ Place.init({
|
||||
index: true,
|
||||
allowNull: false
|
||||
},
|
||||
address: DataTypes.STRING
|
||||
address: DataTypes.STRING,
|
||||
details: DataTypes.JSON
|
||||
}, { sequelize, modelName: 'place' })
|
||||
|
||||
module.exports = Place
|
||||
|
||||
25
server/migrations/20220706090946-place-details.js
Normal file
25
server/migrations/20220706090946-place-details.js
Normal file
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
async up (queryInterface, Sequelize) {
|
||||
/**
|
||||
* Add altering commands here.
|
||||
*
|
||||
* Example:
|
||||
* await queryInterface.createTable('users', { id: Sequelize.INTEGER });
|
||||
*/
|
||||
return queryInterface.addColumn('places', 'details', { type: Sequelize.JSON })
|
||||
|
||||
},
|
||||
|
||||
async down (queryInterface, Sequelize) {
|
||||
/**
|
||||
* Add reverting commands here.
|
||||
*
|
||||
* Example:
|
||||
* await queryInterface.dropTable('users');
|
||||
*/
|
||||
return queryInterface.removeColumn('places', 'details')
|
||||
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user