keep going with recurrent event

This commit is contained in:
lesion
2019-07-13 01:02:11 +02:00
parent c929c314a9
commit 03b563971b
15 changed files with 109 additions and 72 deletions

View File

@@ -43,7 +43,7 @@ export default {
...mapState(['tags', 'filters']),
attributes () {
const colors = ['indigo', 'orange', 'yellow', 'green', 'teal', 'blue', 'red', 'purple', 'pink', 'grey']
const tags = take(this.tags, 10).map(t=>t.tag)
const tags = take(this.tags, 10)//.map(t=>t.tag)
// const tags = [this.tags[0].tag, this.tags[1].tag, this.tags[2].tag, this.tags[3].tag, this.tags[4].tag, this.tags[5].tag ]
let attributes = []
attributes.push ({ key: 'today', dates: new Date(), highlight: { color: 'green' }})
@@ -51,7 +51,7 @@ export default {
const that = this
function getColor(event) {
const color = { class: event.past && !that.filters.show_past_events ? 'past-event vc-rounded-full' : 'vc-rounded-full', color: 'blue' }
const tag = get(event, 'tags[0].tag')
const tag = get(event, 'tags[0]')
if (!tag) return color
const idx = tags.indexOf(tag)
if (idx<0) return color
@@ -64,12 +64,12 @@ export default {
.map(e => ({
key: e.id,
dot: getColor(e),
dates: new Date(e.start_datetime*1000)})))
dates: new Date(e.start_datetime)})))
attributes = attributes.concat(this.filteredEventsWithPast
.filter(e => e.multidate)
.map( e => ({ key: e.id, highlight: getColor(e), dates: {
start: new Date(e.start_datetime*1000), end: new Date(e.end_datetime*1000) }})))
start: new Date(e.start_datetime), end: new Date(e.end_datetime) }})))
return attributes
}

View File

@@ -21,7 +21,7 @@
//- span {{event.comments.length}} {{$t('common.comments')}}
ul.tags(v-if='showTags && event.tags')
li(v-for='tag in event.tags' :key='tag.tag') {{tag.tag}}
li(v-for='tag in event.tags' :key='tag') {{tag}}
</template>
<script>
import { mapState, mapActions } from 'vuex'

View File

@@ -13,6 +13,7 @@
a(:id='event.newDay' v-if='event.newDay')
.d-block.d-sm-none
el-divider {{event.start_datetime|day}}
//- p(style='color: white;') {{event}}
Event(
:id='event.start_datetime'
:key='event.id'

View File

@@ -185,16 +185,26 @@ export default {
error({ statusCode: 404, message: 'Event not found!'})
return {}
}
data.event.place.name = event.place.name
data.event.place.address = event.place.address || ''
data.event.multidate = event.multidate
if (event.multidate) {
data.date = { start: new Date(event.start_datetime*1000), end: new Date(event.end_datetime*1000) }
data.date = { start: new Date(event.start_datetime), end: new Date(event.end_datetime) }
data.event.type = 'multidate'
} else {
data.date = new Date(event.start_datetime*1000)
data.event.type = 'normal'
data.date = new Date(event.start_datetime)
}
data.time.start = moment(event.start_datetime*1000).format('HH:mm')
data.time.end = moment(event.end_datetime*1000).format('HH:mm')
if (event.recurrent) {
data.event.type = 'recurrent'
const recurrent = JSON.parse(event.recurrent)
data.event.rec_frequency = recurrent.frequency
}
data.time.start = moment(event.start_datetime).format('HH:mm')
data.time.end = moment(event.end_datetime).format('HH:mm')
data.event.title = event.title
data.event.description = event.description.replace(/(<([^>]+)>)/ig, '')
data.event.id = event.id
@@ -239,17 +249,17 @@ export default {
const date_end = moment(this.date.end)
return this.events.filter(e =>
!e.multidate ?
date_start.isSame(e.start_datetime*1000, 'day') ||
date_start.isBefore(e.start_datime*1000) && date_end.isAfter(e.start_datetime*1000) :
date_start.isSame(e.start_datetime*1000, 'day') || date_start.isSame(e.end_datetime*1000) ||
date_start.isAfter(e.start_datetime*1000) && date_start.isBefore(e.end_datetime*1000))
date_start.isSame(e.start_datetime, 'day') ||
date_start.isBefore(e.start_datime) && date_end.isAfter(e.start_datetime) :
date_start.isSame(e.start_datetime, 'day') || date_start.isSame(e.end_datetime) ||
date_start.isAfter(e.start_datetime) && date_start.isBefore(e.end_datetime))
} else {
const date = moment(this.date)
return this.events.filter(e =>
!e.multidate ?
date.isSame(moment(e.start_datetime*1000), 'day') :
moment(e.start_datetime*1000).isSame(date, 'day') ||
moment(e.start_datetime*1000).isBefore(date) && moment(e.end_datetime*1000).isAfter(date)
date.isSame(moment(e.start_datetime), 'day') :
moment(e.start_datetime).isSame(date, 'day') ||
moment(e.start_datetime).isBefore(date) && moment(e.end_datetime).isAfter(date)
)
}
},
@@ -260,12 +270,12 @@ export default {
attributes = attributes.concat(this.filteredEvents
.filter(e => !e.multidate)
.map(e => ({ key: e.id, dot: {}, dates: new Date(e.start_datetime*1000)})))
.map(e => ({ key: e.id, dot: {}, dates: new Date(e.start_datetime)})))
attributes = attributes.concat(this.filteredEvents
.filter(e => e.multidate)
.map( e => ({ key: e.id, highlight: {}, dates: {
start: new Date(e.start_datetime*1000), end: new Date(e.end_datetime*1000) }})))
start: new Date(e.start_datetime), end: new Date(e.end_datetime) }})))
if (this.event.type==='recurrent' && this.event.rec_frequency && Array.isArray(this.date)) {
const recurrent = {}
@@ -286,6 +296,13 @@ export default {
recurrent.start = new Date(this.date[0])
}
if (this.event.rec_frequency === '2m') {
// recurrent.weeks = 1
// recurrent.ordinalWeekdays = { 1: this.date.map(d => moment(d).day()+1) }
recurrent.days = this.date.map(d => moment(d).date())
recurrent.monthlyInterval = 2
recurrent.start = new Date(this.date[0])
}
if (this.event.rec_frequency === '1d') {
}
attributes.push({name: 'recurrent', dates: recurrent, dot: { color: 'red'}})
}
@@ -372,10 +389,11 @@ export default {
if (this.event.type === 'recurrent') {
const recurrent = {
frequency: this.rec_frequency,
days: this.rec_when,
ordinal: this.rec_ordinal,
frequency: this.event.rec_frequency,
days: this.event.rec_when,
ordinal: this.event.rec_ordinal,
}
console.error('sono qui dentro type recurrent bella storia,', recurrent)
formData.append('recurrent', JSON.stringify(recurrent))
}

View File

@@ -102,6 +102,9 @@
el-form-item(:label="$t('admin.allow_recurrent_event')")
el-switch(v-model='allow_recurrent_event')
el-form-item(v-show='allow_recurrent_event' :label="$t('admin.recurrent_event_visible')")
el-switch(v-model='recurrent_event_visible')
el-divider {{$t('admin.federation')}}
el-form(inline @submit.native.prevent='associate_mastondon_instance' label-width='240px')
p {{$t('admin.mastodon_description')}}
@@ -172,6 +175,18 @@ export default {
get () { return this.settings.allow_anon_event },
set (value) { this.setSetting({ key: 'allow_anon_event', value })}
},
allow_recurrent_event: {
get () { return this.settings.allow_recurrent_event },
set (value) { this.setSetting({ key: 'allow_recurrent_event', value })}
},
recurrent_event_visible: {
get () { return this.settings.recurrent_event_visible },
set (value) { this.setSetting({ key: 'recurrent_event_visible', value })}
},
allow_comments: {
get () { return this.settings.allow_comments },
set (value) { this.setSetting({ key: 'allow_comments', value })}
},
paginatedEvents () {
return this.events.slice((this.eventPage-1) * this.perPage,
this.eventPage * this.perPage)

View File

@@ -8,12 +8,12 @@ export default ({ app, store }) => {
Vue.filter('datetime', value => moment(value).format('ddd, D MMMM HH:mm'))
Vue.filter('short_datetime', value => moment(value).format('D/MM HH:mm'))
Vue.filter('hour', value => moment(value).format('HH:mm'))
Vue.filter('day', value => moment(value*1000).format('dddd, D MMMM'))
Vue.filter('day', value => moment(value).format('dddd, D MMMM'))
Vue.filter('month', value => moment(value).format('MMM'))
Vue.filter('event_when', event => {
const start = moment(event.start_datetime*1000)
const end = moment(event.end_datetime*1000)
const start = moment(event.start_datetime)
const end = moment(event.end_datetime)
if (event.multidate) {
return `${start.format('ddd, D MMMM (HH:mm)')} - ${end.format('ddd, D MMMM')}`
} else if (event.end_datetime && event.end_datetime !== event.start_datetime)

View File

@@ -22,7 +22,7 @@ const botController = {
listener.on('error', botController.error)
},
async post(event) {
const status = `${event.title} @${event.place.name} ${moment(event.start_datetime*1000).format('ddd, D MMMM HH:mm')} -
const status = `${event.title} @${event.place.name} ${moment(event.start_datetime).format('ddd, D MMMM HH:mm')} -
${event.description.length > 200 ? event.description.substr(0, 200) + '...' : event.description} - ${event.tags.map(t => '#' + t.tag).join(' ')} ${config.baseurl}/event/${event.id}`
let media

View File

@@ -194,53 +194,55 @@ const eventController = {
let events = await Event.findAll({
where: {
// return only confirmed events
is_visible: true,
[Op.and]: [
Sequelize.literal(`start_datetime >= ${start.unix()}`),
Sequelize.literal(`start_datetime <= ${end.unix()}`)
[Op.or]: [
// return all recurrent events
{recurrent: { [Op.ne]: null }},
// and events in specified range
{ start_datetime: { [Op.between]: [start.unix(), end.unix()] }}
]
},
order: [
['start_datetime', 'ASC'],
[Tag, 'weigth', 'DESC']
],
attributes: { exclude: ['createdAt', 'updatedAt', 'placeId' ] },
order: [[Tag, 'weigth', 'DESC']],
include: [
{ model: Tag, required: false, attributes: ['tag', 'weigth'] },
{ model: Tag, required: false },
{ model: Place, required: false, attributes: ['id', 'name', 'address'] }
]
})
events = events.map(e => {
events = events.map(e => e.get()).map(e => {
e.start_datetime = e.start_datetime*1000
e.end_datetime = e.end_datetime*1000
e.tags = e.tags.map(t => t.tag)
return e
})
// build singular events from a recurrent pattern from today due to
// specified parameters
function createEventsFromRecurrent(e, dueTo=null, maxEvents=20) {
// build singular events from a recurrent pattern
function createEventsFromRecurrent(e, dueTo=null, maxEvents=8) {
const events = []
const cursor = moment()
const recurrent = JSON.parse(e.recurrent)
if (!recurrent.frequency) return false
const cursor = moment(start)
const start_date = moment(e.start_datetime)
const frequency = e.recurrent.frequency
const days = e.recurrent.days
const ordinal = e.recurrent.ordinal
const frequency = recurrent.frequency
const days = [start_date.day()]
const ordinal = recurrent.ordinal
// EACH WEEK
if (frequency === '1w') {
while(true) {
const found = days.indexOf(cursor.day())
if (found) break
if (found!==-1) break
cursor.add(1, 'day')
}
e.start_datetime = cursor.set('hour', e.start_datetime.hour()).set('minute', e.start_datetime.minutes())
cursor.set('hour', start_date.hour()).set('minute', start_date.minutes())
while (true) {
if ((dueTo && cursor.isAfter(dueTo)) || events.length>maxEvents) break
e.start_datetime = cursor.unix()
events.push(e)
cursors.add(1, 'week')
e.start_datetime = cursor.unix()*1000
events.push( Object.assign({}, e) )
cursor.add(1, 'week')
}
}
@@ -249,10 +251,15 @@ const eventController = {
return events
}
const normalEvents = events.filter(e => !e.recurrent)
const recurrentEvents = events.filter(e => e.recurrent).map(createEventsFromRecurrent)
let allEvents = events.filter(e => !e.recurrent)
events.filter(e => e.recurrent).forEach(e => {
const events = createEventsFromRecurrent(e, end)
if (events)
allEvents = allEvents.concat(events)
})
res.json(normalEvents.concat(recurrentEvents))
// allEvents.sort((a,b) => a.start_datetime-b.start_datetime)
res.json(allEvents.sort((a,b) => a.start_datetime-b.start_datetime))
}
}

View File

@@ -25,8 +25,8 @@ const settingsController = {
await Setting.findOrCreate({
where: { key },
defaults: { value, is_secret }
}).spread((settings, created) => {
if (!created) return settings.update({ value, is_secret })
}).spread((setting, created) => {
if (!created) return setting.update({ value, is_secret })
})
settingsController[is_secret?'secretSettings':'settings'][key]=value
return true

View File

@@ -82,7 +82,8 @@ const userController = {
start_datetime: body.start_datetime,
end_datetime: body.end_datetime,
// publish this event if authenticated
recurrent: body.recurrent,
// publish this event only if authenticated
is_visible: !!req.user
}

View File

@@ -1,6 +1,6 @@
h3 #{event.title}
p Dove: #{event.place.name} - #{event.place.address}
p Quando: #{datetime(event.start_datetime*1000)}
p Quando: #{datetime(event.start_datetime)}
br
if event.image_path
<center>

View File

@@ -1 +1 @@
= `[${config.title}] ${event.title} @${event.place.name} ${datetime(event.start_datetime*1000)}`
= `[${config.title}] ${event.title} @${event.place.name} ${datetime(event.start_datetime)}`

View File

@@ -17,14 +17,13 @@ const notifier = {
case 'admin_email':
return mail.send([config.smtp.auth.user, config.admin_email], 'event', { event, to_confirm: !event.is_visible, config, notification })
case 'mastodon':
console.error('mando le cose')
// instance publish
if (bot.bot) {
const b = bot.post(event).then(b => {
event.activitypub_id = String(b.data.id)
return event.save()
}).catch(e => {
console.error("ERRORE !! ", e)
console.error("ERROR !! ", e)
})
promises.push(b)
}
@@ -53,9 +52,7 @@ const notifier = {
await notifier.sendNotification(notification, event)
e.status = 'sent'
} catch (err) {
// console.error(err)
e.status = 'error'
// e.error = err
}
return e.save()
})
@@ -84,12 +81,4 @@ const notifier = {
}
}
// let interval
// function startLoop(seconds) {
// interval = setInterval(notify, seconds * 1000)
// }
// startLoop(26000)
module.exports = notifier
// export default notifier
module.exports = notifier

View File

@@ -9,7 +9,13 @@ export const state = () => ({
events: [],
tags: [],
places: [],
settings: {},
settings: {
allow_registration: true,
allow_anon_event: true,
allow_recurrent_event: true,
recurrent_event_visible: false,
allow_comments: false,
},
filters: {
tags: [],
places: [],
@@ -83,7 +89,7 @@ export const mutations = {
// set`past` and `newDay` flags to event
let lastDay = null
state.events = events.map((e) => {
const currentDay = moment(e.start_datetime*1000).date()
const currentDay = moment(e.start_datetime).date()
e.newDay = (!lastDay || lastDay !== currentDay) && currentDay
lastDay = currentDay
const end_datetime = e.end_datetime || e.start_datetime+3600*2

View File

@@ -9,13 +9,13 @@ rss(version='2.0')
lastBuildDate= new Date(posts[0].publishedAt).toUTCString()
each event in events
item
title [#{moment(event.start_datetime*1000).format("D-MM-YY")}] #{event.title} @#{event.place.name}
title [#{moment(event.start_datetime).format("D-MM-YY")}] #{event.title} @#{event.place.name}
link #{config.baseurl}/event/#{event.id}
description
| <![CDATA[
| <h4>#{event.title}</h4>
| <strong>#{event.place.name} - #{event.place.address}</strong>
| #{moment(event.start_datetime*1000).format("dddd, D MMMM HH:mm")}<br/>
| #{moment(event.start_datetime).format("dddd, D MMMM HH:mm")}<br/>
| <img src="#{config.apiurl}/media/#{event.image_path}"/>
| <pre>!{event.description}</pre>
| ]]>