minor on recurrent events
This commit is contained in:
parent
3d83c8e1a0
commit
a52ca3c3d5
4 changed files with 33 additions and 105 deletions
|
@ -6,7 +6,7 @@ div
|
|||
div(v-if='event.is_visible' @click='toggle(false)') <i class='el-icon-open'/> {{$t('common.hide')}}
|
||||
div(v-else @click='toggle(false)') <i class='el-icon-turn-off'/> {{$t('common.confirm')}}
|
||||
el-menu-item(@click='$router.replace(`/add/${event.id}`)') <i class='el-icon-edit'/> {{$t('common.edit')}}
|
||||
el-menu-item(v-if='!event.parentId' @click='remove(false)') <i class='el-icon-delete'/> {{$t('common.remove')}}
|
||||
el-menu-item(@click='remove(false)') <i class='el-icon-delete'/> {{$t('common.remove')}}
|
||||
div(v-if='event.parentId')
|
||||
el-divider {{$t('event.recurrent')}}
|
||||
el-menu-item(v-if='event.parent.is_visible' @click='toggle(true)') <i class='el-icon-video-pause'/> {{$t('common.pause')}}
|
||||
|
@ -30,7 +30,7 @@ export default {
|
|||
...mapActions(['delEvent']),
|
||||
async remove (parent = false) {
|
||||
try {
|
||||
await MessageBox.confirm(this.$t('event.remove_confirmation'), this.$t('common.confirm'), {
|
||||
await MessageBox.confirm(this.$t(`event.remove_${parent ? 'recurrent_' : ''}confirmation`), this.$t('common.confirm'), {
|
||||
confirmButtonText: this.$t('common.ok'),
|
||||
cancelButtonText: this.$t('common.cancel'),
|
||||
type: 'error'
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
<template lang='pug'>
|
||||
div
|
||||
p(v-html="$t('event.follow_me_description', { title: settings.title, account: `@${settings.instance_name}@${domain}`})")
|
||||
el-input(v-model='instance_hostname' ref='instance')
|
||||
a(slot='append' :href='link' target='_blank')
|
||||
el-button(:disabled='(!couldGo || !proceed)' plain type="primary" icon='el-icon-document') {{$t("common.follow")}}
|
||||
p.mt-2 <img class='instance_thumb' :src="instance.thumbnail"/> {{instance.title}}
|
||||
</template>
|
||||
<script>
|
||||
import { mapState } from 'vuex'
|
||||
import debounce from 'lodash/debounce'
|
||||
import url from 'url'
|
||||
|
||||
export default {
|
||||
|
||||
name: 'EmbedEvent',
|
||||
data () {
|
||||
return {
|
||||
instance_hostname: '',
|
||||
proceed: false,
|
||||
instance: {},
|
||||
get_instance_info: debounce(this.getInstanceInfo, 500)
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
...mapState(['settings']),
|
||||
domain () {
|
||||
const URL = url.parse(this.settings.baseurl)
|
||||
return URL.hostname
|
||||
},
|
||||
couldGo () {
|
||||
console.error(this.instance_hostname)
|
||||
// check if is mastodon
|
||||
this.get_instance_info()
|
||||
return true
|
||||
},
|
||||
link () {
|
||||
// check if exists
|
||||
return `https://${this.instance_hostname}/authorize_interaction?uri=${this.settings.instance_name}@${this.domain}`
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getInstanceInfo () {
|
||||
const instance_url = `https://${this.instance_hostname}/api/v1/instance`
|
||||
this.$axios.$get(instance_url)
|
||||
.then(ret => {
|
||||
this.instance = ret
|
||||
this.proceed = true
|
||||
})
|
||||
.catch(e => {
|
||||
this.proceed = false
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style lang="less">
|
||||
.instance_thumb {
|
||||
height: 20px;
|
||||
}
|
||||
</style>
|
|
@ -25,10 +25,10 @@ export default ({ app, store }) => {
|
|||
|
||||
const normal = `${start.format('dddd, D MMMM (HH:mm-')}${end.format('HH:mm) ')}`
|
||||
// recurrent event
|
||||
if (event.recurrent && where !== 'home') {
|
||||
const { frequency, days, type } = event.recurrent
|
||||
if (event.parent && where !== 'home') {
|
||||
const { frequency, days, type } = event.parent.recurrent
|
||||
if (frequency === '1w' || frequency === '2w') {
|
||||
const recurrent = app.i18n.tc(`event.recurrent_${frequency}_days`, days.length, { days: days.map(d => moment().day(d - 1).format('dddd')) })
|
||||
const recurrent = app.i18n.tc(`event.recurrent_${frequency}_days`, days.length, { days: days.map(d => moment().day(d).format('dddd')) })
|
||||
return `${normal} - ${recurrent}`
|
||||
} else if (frequency === '1m' || frequency === '2m') {
|
||||
const d = type === 'ordinal' ? days : days.map(d => moment().day(d - 1).format('dddd'))
|
||||
|
|
|
@ -105,7 +105,7 @@ const eventController = {
|
|||
required: false,
|
||||
attributes: ['id', 'activitypub_id', 'data', 'hidden']
|
||||
},
|
||||
{ model: Event, required: false, as: 'parent' }
|
||||
{ model: Event, required: false, as: 'parent', attributes: ['id', 'recurrent'] }
|
||||
],
|
||||
order: [[Resource, 'id', 'DESC']]
|
||||
})
|
||||
|
@ -113,7 +113,7 @@ const eventController = {
|
|||
return res.sendStatus(400)
|
||||
}
|
||||
if (event && (event.is_visible || is_admin)) {
|
||||
event = event.toJSON()
|
||||
event = event.get()
|
||||
event.tags = event.tags.map(t => t.tag)
|
||||
if (format === 'json') {
|
||||
res.json(event)
|
||||
|
@ -272,7 +272,7 @@ const eventController = {
|
|||
|
||||
// send notification (mastodon/email)
|
||||
// only if user is authenticated
|
||||
if (req.user) {
|
||||
if (req.user && !event.recurrent) {
|
||||
const notifier = require('../../notifier')
|
||||
notifier.notifyEvent('Create', event.id)
|
||||
}
|
||||
|
@ -362,7 +362,7 @@ const eventController = {
|
|||
where,
|
||||
limit,
|
||||
attributes: {
|
||||
exclude: ['slug', 'likes', 'boost', 'userId', 'is_visible', 'description', 'createdAt', 'updatedAt', 'placeId']
|
||||
exclude: ['slug', 'likes', 'boost', 'userId', 'is_visible', 'createdAt', 'updatedAt', 'placeId']
|
||||
// include: [[Sequelize.fn('COUNT', Sequelize.col('activitypub_id')), 'ressources']]
|
||||
},
|
||||
order: ['start_datetime', [Tag, 'weigth', 'DESC']],
|
||||
|
@ -373,7 +373,7 @@ const eventController = {
|
|||
]
|
||||
})
|
||||
|
||||
return _(events).map(e => {
|
||||
return events.map(e => {
|
||||
e = e.get()
|
||||
e.tags = e.tags ? e.tags.map(t => t && t.tag) : []
|
||||
return e
|
||||
|
@ -390,7 +390,7 @@ const eventController = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Ensure we have at least 3 instances of recurrent events
|
||||
* Ensure we have the next instances of recurrent events
|
||||
*/
|
||||
_createRecurrentOccurrence (e) {
|
||||
const event = {
|
||||
|
@ -398,15 +398,14 @@ const eventController = {
|
|||
title: e.title,
|
||||
description: e.description,
|
||||
image_path: e.image_path,
|
||||
is_visible: e.is_visible,
|
||||
is_visible: true,
|
||||
userId: e.userId,
|
||||
placeId: e.placeId
|
||||
}
|
||||
|
||||
const recurrent = e.recurrent
|
||||
let left = 3 - e.child.length
|
||||
const start = e.child.length ? moment.unix(e.child[e.child.length - 1].start_datetime) : moment()
|
||||
let cursor = start.startOf('week')
|
||||
const cursor = moment()
|
||||
// let cursor = start.startOf('week')
|
||||
const start_date = moment.unix(e.start_datetime)
|
||||
const duration = moment.unix(e.end_datetime).diff(start_date, 's')
|
||||
const frequency = recurrent.frequency
|
||||
|
@ -418,7 +417,7 @@ const eventController = {
|
|||
|
||||
// each week or 2 (search for the first specified day)
|
||||
if (frequency === '1w' || frequency === '2w') {
|
||||
cursor.add(days[0] - 1, 'day')
|
||||
// cursor.add(days[0] - 1, 'day')
|
||||
if (frequency === '2w') {
|
||||
const nWeeks = cursor.diff(e.start_datetime, 'w') % 2
|
||||
if (!nWeeks) { cursor.add(1, 'week') }
|
||||
|
@ -442,45 +441,36 @@ const eventController = {
|
|||
}
|
||||
|
||||
// add event at specified frequency
|
||||
while (true) {
|
||||
if (!left) { break }
|
||||
left -= 1
|
||||
const first_event_of_week = cursor.clone()
|
||||
days.forEach(d => {
|
||||
debug(cursor)
|
||||
if (type === 'ordinal') {
|
||||
cursor.date(d)
|
||||
} else {
|
||||
cursor.day(d - 1)
|
||||
}
|
||||
event.start_datetime = cursor.unix()
|
||||
event.end_datetime = event.start_datetime + duration
|
||||
Event.create(event)
|
||||
cursor.set('hour', start_date.hour()).set('minute', start_date.minutes())
|
||||
})
|
||||
cursor = first_event_of_week.add(toAdd.n, toAdd.unit)
|
||||
}
|
||||
// const first_event_of_week = cursor.clone()
|
||||
days.forEach(d => {
|
||||
if (type === 'ordinal') {
|
||||
cursor.date(d)
|
||||
} else {
|
||||
cursor.day(d - 1)
|
||||
}
|
||||
event.start_datetime = cursor.unix()
|
||||
event.end_datetime = event.start_datetime + duration
|
||||
Event.create(event)
|
||||
cursor.set('hour', start_date.hour()).set('minute', start_date.minutes())
|
||||
})
|
||||
// cursor = first_event_of_week.add(toAdd.n, toAdd.unit)
|
||||
},
|
||||
|
||||
/**
|
||||
* Create instances of recurrent events
|
||||
* Remove old
|
||||
* @param {*} start_datetime
|
||||
* @param {Number} start_datetime
|
||||
*/
|
||||
async _createRecurrent (start_datetime = moment().unix()) {
|
||||
// select recurrent events
|
||||
const events = await Event.findAll({
|
||||
where: { is_visible: true, recurrent: { [Op.ne]: null } },
|
||||
include: [{ model: Event, as: 'child', required: false, where: { start_datetime: { [Op.gt]: start_datetime } } }],
|
||||
include: [{ model: Event, as: 'child', required: false, where: { start_datetime: { [Op.gte]: start_datetime } } }],
|
||||
order: ['start_datetime']
|
||||
})
|
||||
|
||||
const creations = []
|
||||
events
|
||||
.filter(e => e.child && e.child.length < 3)
|
||||
.forEach(e => {
|
||||
eventController._createRecurrentOccurrence(e)
|
||||
})
|
||||
const creations = events
|
||||
.filter(e => e.child.length === 0)
|
||||
.map(eventController._createRecurrentOccurrence)
|
||||
|
||||
return Promise.all(creations)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue