feat: improve collections export adding max, start_at parameter

This commit is contained in:
lesion 2023-12-15 16:39:56 +01:00
parent 582cef3714
commit c472e87676
No known key found for this signature in database
GPG key ID: 352918250B012177
8 changed files with 15 additions and 24 deletions

View file

@ -462,7 +462,7 @@ function He(t, e, i) {
const h = [];
r && h.push(`max=${r}`);
let p = "/api/events";
o ? p = `/api/collections/${o}` : (f && h.push(`tags=${f}`), s && h.push(`places=${s}`)), h.push(`show_recurrent=${w ? "true" : "false"}`), fetch(`${l}${p}?${h.join("&")}`).then((v) => v.json()).then((v) => {
o ? p = `/feed/json/collection/${o}` : (f && h.push(`tags=${f}`), s && h.push(`places=${s}`)), h.push(`show_recurrent=${w ? "true" : "false"}`), fetch(`${l}${p}?${h.join("&")}`).then((v) => v.json()).then((v) => {
i(5, E = v.events || v);
}).catch((v) => {
console.error("Error loading Gancio API -> ", v);

View file

@ -101,7 +101,6 @@ export default {
},
search: debounce(async function(search) {
this.items = await this.$axios.$get(`/event/meta?search=${search.target.value}`)
console.error('items ', this.items.length)
}, 100),
remove (item) {
// const filters = {

View file

@ -462,7 +462,7 @@ function He(t, e, i) {
const h = [];
r && h.push(`max=${r}`);
let p = "/api/events";
o ? p = `/api/collections/${o}` : (f && h.push(`tags=${f}`), s && h.push(`places=${s}`)), h.push(`show_recurrent=${w ? "true" : "false"}`), fetch(`${l}${p}?${h.join("&")}`).then((v) => v.json()).then((v) => {
o ? p = `/feed/json/collection/${o}` : (f && h.push(`tags=${f}`), s && h.push(`places=${s}`)), h.push(`show_recurrent=${w ? "true" : "false"}`), fetch(`${l}${p}?${h.join("&")}`).then((v) => v.json()).then((v) => {
i(5, E = v.events || v);
}).catch((v) => {
console.error("Error loading Gancio API -> ", v);

View file

@ -42,20 +42,13 @@ const collectionController = {
async getEvents (req, res) {
const name = req.params.name
const format = req.params.format || 'json'
const max = req.query.max || 10
const start_at = req.query.start_at || DateTime.local().toUnixInteger()
try {
const events = await collectionController._getEvents(name)
switch (format) {
case 'rss':
return exportController.feed(req, res, events,
`${res.locals.settings.title} - Collection @${name}`,
`${res.locals.settings.baseurl}/feed/rss/collection/${name}`)
case 'ics':
return exportController.ics(req, res, events)
default:
const events = await collectionController._getEvents({ name, start_at, max })
log.debug(`[COLLECTION] (${name}) events: ${events?.length}`)
return res.json(events)
}
} catch (e) {
log.error(e)
return res.sendStatus(404)
@ -63,7 +56,7 @@ const collectionController = {
},
// return events from collection
async _getEvents (name) {
async _getEvents ({ name, start_at, max = 10 }) {
const collection = await Collection.findOne({ where: { name } })
if (!collection) {
@ -74,7 +67,7 @@ const collectionController = {
if (!filters.length) {
return []
}
const start = DateTime.local().toUnixInteger()
const where = {
// do not include parent recurrent event
recurrent: null,
@ -82,7 +75,7 @@ const collectionController = {
// confirmed event only
is_visible: true,
start_datetime: { [Op.gte]: start },
start_datetime: { [Op.gte]: start_at },
}
const replacements = []
@ -118,7 +111,7 @@ const collectionController = {
},
{ model: Place, required: true, attributes: ['id', 'name', 'address'] }
],
// limit: max,
limit: max,
replacements
}).catch(e => {
log.error('[EVENT]', e)

View file

@ -49,8 +49,7 @@ const exportController = {
let events = []
if (collection) {
events = await collectionController._getEvents(collection)
console.error(events.map(e => e))
events = await collectionController._getEvents({ name: collection })
} else {
events = await Event.findAll({
order: ['start_datetime'],

View file

@ -462,7 +462,7 @@ function He(t, e, i) {
const h = [];
r && h.push(`max=${r}`);
let p = "/api/events";
o ? p = `/api/collections/${o}` : (f && h.push(`tags=${f}`), s && h.push(`places=${s}`)), h.push(`show_recurrent=${w ? "true" : "false"}`), fetch(`${l}${p}?${h.join("&")}`).then((v) => v.json()).then((v) => {
o ? p = `/feed/json/collection/${o}` : (f && h.push(`tags=${f}`), s && h.push(`places=${s}`)), h.push(`show_recurrent=${w ? "true" : "false"}`), fetch(`${l}${p}?${h.join("&")}`).then((v) => v.json()).then((v) => {
i(5, E = v.events || v);
}).catch((v) => {
console.error("Error loading Gancio API -> ", v);

View file

@ -27,7 +27,7 @@
let api = '/api/events'
if (collection) {
api = `/api/collections/${collection}`
api = `/feed/json/collection/${collection}`
} else {
if (tags) {
params.push(`tags=${tags}`)

View file

@ -462,7 +462,7 @@ function He(t, e, i) {
const h = [];
r && h.push(`max=${r}`);
let p = "/api/events";
o ? p = `/api/collections/${o}` : (f && h.push(`tags=${f}`), s && h.push(`places=${s}`)), h.push(`show_recurrent=${w ? "true" : "false"}`), fetch(`${l}${p}?${h.join("&")}`).then((v) => v.json()).then((v) => {
o ? p = `/feed/json/collection/${o}` : (f && h.push(`tags=${f}`), s && h.push(`places=${s}`)), h.push(`show_recurrent=${w ? "true" : "false"}`), fetch(`${l}${p}?${h.join("&")}`).then((v) => v.json()).then((v) => {
i(5, E = v.events || v);
}).catch((v) => {
console.error("Error loading Gancio API -> ", v);