keep migrating to vuetify
This commit is contained in:
@@ -4,10 +4,11 @@ const config = require('config')
|
||||
const fs = require('fs')
|
||||
const { Op } = require('sequelize')
|
||||
const _ = require('lodash')
|
||||
const helpers = require('../../helpers')
|
||||
const linkifyHtml = require('linkifyjs/html')
|
||||
const Sequelize = require('sequelize')
|
||||
const dayjs = require('dayjs')
|
||||
const helpers = require('../../helpers')
|
||||
const settingsController = require('./settings')
|
||||
|
||||
const Event = require('../models/event')
|
||||
const Resource = require('../models/resource')
|
||||
@@ -417,19 +418,25 @@ const eventController = {
|
||||
}
|
||||
},
|
||||
|
||||
async _select ({ start, end, tags, places }) {
|
||||
async _select ({ start, end, tags, places, show_recurrent }) {
|
||||
const where = {
|
||||
// do not include parent recurrent event
|
||||
recurrent: null,
|
||||
|
||||
// confirmed event only
|
||||
is_visible: true,
|
||||
|
||||
[Op.or]: {
|
||||
start_datetime: { [Op.gt]: start },
|
||||
end_datetime: { [Op.gt]: start }
|
||||
start_datetime: { [Op.gte]: start },
|
||||
end_datetime: { [Op.gte]: start }
|
||||
}
|
||||
}
|
||||
|
||||
if (!show_recurrent) {
|
||||
where.parentId = null
|
||||
}
|
||||
if (end) {
|
||||
where.start_datetime = { [Op.lt]: end }
|
||||
where.start_datetime = { [Op.lte]: end }
|
||||
}
|
||||
|
||||
if (places) {
|
||||
@@ -470,9 +477,11 @@ const eventController = {
|
||||
const end = req.query.end
|
||||
const tags = req.query.tags
|
||||
const places = req.query.places
|
||||
const show_recurrent = settingsController.settings.allow_recurrent_event &&
|
||||
(typeof req.query.show_recurrent !== 'undefined' ? req.query.show_recurrent === 'true' : settingsController.settings.recurrent_event_visible)
|
||||
|
||||
res.json(await eventController._select({
|
||||
start, end, places, tags
|
||||
start, end, places, tags, show_recurrent
|
||||
}))
|
||||
},
|
||||
|
||||
@@ -497,20 +506,37 @@ const eventController = {
|
||||
const frequency = recurrent.frequency
|
||||
const type = recurrent.type
|
||||
|
||||
debug(`NOW IS ${cursor} while event is at ${start_date} (freq: ${frequency})`)
|
||||
|
||||
cursor = cursor.hour(start_date.hour()).minute(start_date.minute()).second(0)
|
||||
debug(`set cursor to correct date and hour => ${cursor}`)
|
||||
|
||||
// each week or 2
|
||||
if (frequency[1] === 'w') {
|
||||
cursor = cursor.day(start_date.day())
|
||||
debug(`Imposto il giorno della settimana ${cursor}`)
|
||||
if (cursor.isBefore(dayjs())) {
|
||||
cursor = cursor.add(7, 'day')
|
||||
}
|
||||
if (frequency[0] === 2) {
|
||||
if (frequency[0] === '2') {
|
||||
cursor = cursor.add(7, 'day')
|
||||
}
|
||||
} else if (frequency === '1m') {
|
||||
if (type === 'ordinal') {
|
||||
cursor = cursor.date(start_date.date())
|
||||
|
||||
if (cursor.isBefore(dayjs())) {
|
||||
cursor = cursor.add(1, 'month')
|
||||
}
|
||||
} else { // weekday
|
||||
const monthDay = start_date.format('D')
|
||||
const n = Math.floor((monthDay - 1) / 7) + 1
|
||||
cursor = cursor.startOf('month')
|
||||
cursor = cursor.add(n, 'week')
|
||||
cursor = cursor.day(start_date.day())
|
||||
if (cursor.isBefore(dayjs())) {
|
||||
cursor = cursor.add(1, 'month')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -529,7 +555,6 @@ const eventController = {
|
||||
include: [{ model: Event, as: 'child', required: false, where: { start_datetime: { [Op.gte]: start_datetime } } }],
|
||||
order: ['start_datetime']
|
||||
})
|
||||
|
||||
// filter events that as no instance in future yet
|
||||
const creations = events
|
||||
.filter(e => e.child.length === 0)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const ical = require('ical.js')
|
||||
const settingsController = require('./api/controller/settings')
|
||||
const acceptLanguage = require('accept-language')
|
||||
|
||||
@@ -114,31 +115,56 @@ module.exports = {
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* Import events from url
|
||||
* It does supports ICS and H-EVENT
|
||||
*/
|
||||
async importURL (req, res) {
|
||||
const URL = req.query.URL
|
||||
try {
|
||||
const response = await axios.get(URL)
|
||||
Microformats.get({ html: response.data, filter: ['h-event'] }, (err, data) => {
|
||||
if (err || !data.items.length || !data.items[0].properties) {
|
||||
return res.sendStatus(404)
|
||||
}
|
||||
const event = data.items[0].properties
|
||||
return res.json({
|
||||
title: get(event, 'name[0]', ''),
|
||||
description: get(event, 'content[0]', ''),
|
||||
place: get(event, 'location[0].properties.name', ''),
|
||||
address: get(event, 'location[0].properties.street-address'),
|
||||
start: get(event, 'start[0]', ''),
|
||||
end: get(event, 'end[0]', ''),
|
||||
tags: get(event, 'category', []),
|
||||
image: get(event, 'featured[0]')
|
||||
const contentType = response.headers['content-type']
|
||||
|
||||
if (contentType.includes('text/html')) {
|
||||
Microformats.get({ html: response.data, filter: ['h-event'] }, (err, data) => {
|
||||
if (err || !data.items.length || !data.items[0].properties) {
|
||||
return res.sendStatus(404)
|
||||
}
|
||||
const events = data.items.map(e => {
|
||||
const props = e.properties
|
||||
return {
|
||||
title: get(props, 'name[0]', ''),
|
||||
description: get(props, 'description[0]', ''),
|
||||
place: get(props, 'location[0].properties.name', ''),
|
||||
address: get(props, 'location[0].properties.street-address'),
|
||||
start: get(props, 'start[0]', ''),
|
||||
end: get(props, 'end[0]', ''),
|
||||
tags: get(props, 'category', []),
|
||||
image: get(props, 'featured[0]')
|
||||
}
|
||||
})
|
||||
return res.json(events)
|
||||
})
|
||||
})
|
||||
} else if (contentType.includes('text/calendar')) {
|
||||
const ret = ical.parse(response.data)
|
||||
const component = new ical.Component(ret)
|
||||
const events = component.getAllSubcomponents('vevent')
|
||||
return res.json(events.map(e => {
|
||||
const event = new ical.Event(e)
|
||||
return {
|
||||
title: get(event, 'summary', ''),
|
||||
description: get(event, 'description', ''),
|
||||
place: get(event, 'location', ''),
|
||||
start: get(event, 'dtstart', ''),
|
||||
end: get(event, 'dtend', '')
|
||||
}
|
||||
}))
|
||||
}
|
||||
// const event = dom.window.document.querySelected(".h-event")
|
||||
// console.error(event)
|
||||
// console.error(response)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
debug(e)
|
||||
}
|
||||
|
||||
// res.json('ok')
|
||||
|
||||
@@ -41,7 +41,6 @@ class Task {
|
||||
|
||||
class TaskManager {
|
||||
constructor () {
|
||||
this.interval = 60 * 1000
|
||||
this.tasks = []
|
||||
}
|
||||
|
||||
@@ -90,7 +89,7 @@ const TS = new TaskManager()
|
||||
TS.add(new Task({
|
||||
name: 'RECURRENT_EVENT',
|
||||
method: eventController._createRecurrent,
|
||||
repeatEach: 10 // check each 10 minutes
|
||||
repeatEach: 1 // check each 10 minutes
|
||||
}))
|
||||
|
||||
// daily morning notification
|
||||
|
||||
Reference in New Issue
Block a user