minor on recurrent events
This commit is contained in:
@@ -6,7 +6,7 @@ div
|
|||||||
div(v-if='event.is_visible' @click='toggle(false)') <i class='el-icon-open'/> {{$t('common.hide')}}
|
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')}}
|
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(@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')
|
div(v-if='event.parentId')
|
||||||
el-divider {{$t('event.recurrent')}}
|
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')}}
|
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']),
|
...mapActions(['delEvent']),
|
||||||
async remove (parent = false) {
|
async remove (parent = false) {
|
||||||
try {
|
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'),
|
confirmButtonText: this.$t('common.ok'),
|
||||||
cancelButtonText: this.$t('common.cancel'),
|
cancelButtonText: this.$t('common.cancel'),
|
||||||
type: 'error'
|
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) ')}`
|
const normal = `${start.format('dddd, D MMMM (HH:mm-')}${end.format('HH:mm) ')}`
|
||||||
// recurrent event
|
// recurrent event
|
||||||
if (event.recurrent && where !== 'home') {
|
if (event.parent && where !== 'home') {
|
||||||
const { frequency, days, type } = event.recurrent
|
const { frequency, days, type } = event.parent.recurrent
|
||||||
if (frequency === '1w' || frequency === '2w') {
|
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}`
|
return `${normal} - ${recurrent}`
|
||||||
} else if (frequency === '1m' || frequency === '2m') {
|
} else if (frequency === '1m' || frequency === '2m') {
|
||||||
const d = type === 'ordinal' ? days : days.map(d => moment().day(d - 1).format('dddd'))
|
const d = type === 'ordinal' ? days : days.map(d => moment().day(d - 1).format('dddd'))
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ const eventController = {
|
|||||||
required: false,
|
required: false,
|
||||||
attributes: ['id', 'activitypub_id', 'data', 'hidden']
|
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']]
|
order: [[Resource, 'id', 'DESC']]
|
||||||
})
|
})
|
||||||
@@ -113,7 +113,7 @@ const eventController = {
|
|||||||
return res.sendStatus(400)
|
return res.sendStatus(400)
|
||||||
}
|
}
|
||||||
if (event && (event.is_visible || is_admin)) {
|
if (event && (event.is_visible || is_admin)) {
|
||||||
event = event.toJSON()
|
event = event.get()
|
||||||
event.tags = event.tags.map(t => t.tag)
|
event.tags = event.tags.map(t => t.tag)
|
||||||
if (format === 'json') {
|
if (format === 'json') {
|
||||||
res.json(event)
|
res.json(event)
|
||||||
@@ -272,7 +272,7 @@ const eventController = {
|
|||||||
|
|
||||||
// send notification (mastodon/email)
|
// send notification (mastodon/email)
|
||||||
// only if user is authenticated
|
// only if user is authenticated
|
||||||
if (req.user) {
|
if (req.user && !event.recurrent) {
|
||||||
const notifier = require('../../notifier')
|
const notifier = require('../../notifier')
|
||||||
notifier.notifyEvent('Create', event.id)
|
notifier.notifyEvent('Create', event.id)
|
||||||
}
|
}
|
||||||
@@ -362,7 +362,7 @@ const eventController = {
|
|||||||
where,
|
where,
|
||||||
limit,
|
limit,
|
||||||
attributes: {
|
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']]
|
// include: [[Sequelize.fn('COUNT', Sequelize.col('activitypub_id')), 'ressources']]
|
||||||
},
|
},
|
||||||
order: ['start_datetime', [Tag, 'weigth', 'DESC']],
|
order: ['start_datetime', [Tag, 'weigth', 'DESC']],
|
||||||
@@ -373,7 +373,7 @@ const eventController = {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
return _(events).map(e => {
|
return events.map(e => {
|
||||||
e = e.get()
|
e = e.get()
|
||||||
e.tags = e.tags ? e.tags.map(t => t && t.tag) : []
|
e.tags = e.tags ? e.tags.map(t => t && t.tag) : []
|
||||||
return e
|
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) {
|
_createRecurrentOccurrence (e) {
|
||||||
const event = {
|
const event = {
|
||||||
@@ -398,15 +398,14 @@ const eventController = {
|
|||||||
title: e.title,
|
title: e.title,
|
||||||
description: e.description,
|
description: e.description,
|
||||||
image_path: e.image_path,
|
image_path: e.image_path,
|
||||||
is_visible: e.is_visible,
|
is_visible: true,
|
||||||
userId: e.userId,
|
userId: e.userId,
|
||||||
placeId: e.placeId
|
placeId: e.placeId
|
||||||
}
|
}
|
||||||
|
|
||||||
const recurrent = e.recurrent
|
const recurrent = e.recurrent
|
||||||
let left = 3 - e.child.length
|
const cursor = moment()
|
||||||
const start = e.child.length ? moment.unix(e.child[e.child.length - 1].start_datetime) : moment()
|
// let cursor = start.startOf('week')
|
||||||
let cursor = start.startOf('week')
|
|
||||||
const start_date = moment.unix(e.start_datetime)
|
const start_date = moment.unix(e.start_datetime)
|
||||||
const duration = moment.unix(e.end_datetime).diff(start_date, 's')
|
const duration = moment.unix(e.end_datetime).diff(start_date, 's')
|
||||||
const frequency = recurrent.frequency
|
const frequency = recurrent.frequency
|
||||||
@@ -418,7 +417,7 @@ const eventController = {
|
|||||||
|
|
||||||
// each week or 2 (search for the first specified day)
|
// each week or 2 (search for the first specified day)
|
||||||
if (frequency === '1w' || frequency === '2w') {
|
if (frequency === '1w' || frequency === '2w') {
|
||||||
cursor.add(days[0] - 1, 'day')
|
// cursor.add(days[0] - 1, 'day')
|
||||||
if (frequency === '2w') {
|
if (frequency === '2w') {
|
||||||
const nWeeks = cursor.diff(e.start_datetime, 'w') % 2
|
const nWeeks = cursor.diff(e.start_datetime, 'w') % 2
|
||||||
if (!nWeeks) { cursor.add(1, 'week') }
|
if (!nWeeks) { cursor.add(1, 'week') }
|
||||||
@@ -442,45 +441,36 @@ const eventController = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add event at specified frequency
|
// add event at specified frequency
|
||||||
while (true) {
|
// const first_event_of_week = cursor.clone()
|
||||||
if (!left) { break }
|
days.forEach(d => {
|
||||||
left -= 1
|
if (type === 'ordinal') {
|
||||||
const first_event_of_week = cursor.clone()
|
cursor.date(d)
|
||||||
days.forEach(d => {
|
} else {
|
||||||
debug(cursor)
|
cursor.day(d - 1)
|
||||||
if (type === 'ordinal') {
|
}
|
||||||
cursor.date(d)
|
event.start_datetime = cursor.unix()
|
||||||
} else {
|
event.end_datetime = event.start_datetime + duration
|
||||||
cursor.day(d - 1)
|
Event.create(event)
|
||||||
}
|
cursor.set('hour', start_date.hour()).set('minute', start_date.minutes())
|
||||||
event.start_datetime = cursor.unix()
|
})
|
||||||
event.end_datetime = event.start_datetime + duration
|
// cursor = first_event_of_week.add(toAdd.n, toAdd.unit)
|
||||||
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
|
* Create instances of recurrent events
|
||||||
* Remove old
|
* @param {Number} start_datetime
|
||||||
* @param {*} start_datetime
|
|
||||||
*/
|
*/
|
||||||
async _createRecurrent (start_datetime = moment().unix()) {
|
async _createRecurrent (start_datetime = moment().unix()) {
|
||||||
// select recurrent events
|
// select recurrent events
|
||||||
const events = await Event.findAll({
|
const events = await Event.findAll({
|
||||||
where: { is_visible: true, recurrent: { [Op.ne]: null } },
|
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']
|
order: ['start_datetime']
|
||||||
})
|
})
|
||||||
|
|
||||||
const creations = []
|
const creations = events
|
||||||
events
|
.filter(e => e.child.length === 0)
|
||||||
.filter(e => e.child && e.child.length < 3)
|
.map(eventController._createRecurrentOccurrence)
|
||||||
.forEach(e => {
|
|
||||||
eventController._createRecurrentOccurrence(e)
|
|
||||||
})
|
|
||||||
|
|
||||||
return Promise.all(creations)
|
return Promise.all(creations)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user