dayjs / restart with recurrent
This commit is contained in:
@@ -1,5 +1,16 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
v-row
|
v-row
|
||||||
|
|
||||||
|
v-btn-toggle.col-md-4(@change='changeType' color='primary' :value='value.type')
|
||||||
|
v-btn(value='normal') {{$t('event.normal')}}
|
||||||
|
v-btn(value='multidate') {{$t('event.multidate')}}
|
||||||
|
v-menu(v-if='settings.allow_recurrent_event' offset-y open-on-hover)
|
||||||
|
template(v-slot:activator="{ on, attrs }")
|
||||||
|
v-btn(value='recurrent' v-on='on') {{$t('event.recurrent')}}
|
||||||
|
v-list
|
||||||
|
v-list-item(v-for='f in frequencies' :key='f.value'
|
||||||
|
@click='selectFrequency(f.value)') {{f.text}}
|
||||||
|
|
||||||
v-menu(
|
v-menu(
|
||||||
v-model="datePickerMenu"
|
v-model="datePickerMenu"
|
||||||
:close-on-content-click="false"
|
:close-on-content-click="false"
|
||||||
@@ -19,21 +30,11 @@ v-row
|
|||||||
v-on="on")
|
v-on="on")
|
||||||
v-date-picker(
|
v-date-picker(
|
||||||
:min='today'
|
:min='today'
|
||||||
v-model="value.date"
|
:value="value.date"
|
||||||
:range="value.type === 'multidate'"
|
:range="value.type === 'multidate'"
|
||||||
:locale='settings.locale'
|
:locale='settings.locale'
|
||||||
@input="pick")
|
@input="pick")
|
||||||
|
|
||||||
v-btn-toggle.col-md-4(@change='changeType' color='primary' :value='value.type')
|
|
||||||
v-btn(value='normal') {{$t('event.normal')}}
|
|
||||||
v-btn(value='multidate') {{$t('event.multidate')}}
|
|
||||||
v-menu(v-if='settings.allow_recurrent_event' offset-y open-on-hover)
|
|
||||||
template(v-slot:activator="{ on, attrs }")
|
|
||||||
v-btn(value='recurrent' v-on='on') {{$t('event.recurrent')}}
|
|
||||||
v-list
|
|
||||||
v-list-item(v-for='f in frequencies' :key='f.value'
|
|
||||||
@click='selectFrequency(f.value)') {{f.text}}
|
|
||||||
|
|
||||||
p.col-12 {{$t(`event.${value.type}_description`)}}
|
p.col-12 {{$t(`event.${value.type}_description`)}}
|
||||||
//- v-btn-toggle(v-if="type === 'recurrent'" v-model='value.recurrent.frequency' color='primary')
|
//- v-btn-toggle(v-if="type === 'recurrent'" v-model='value.recurrent.frequency' color='primary')
|
||||||
//- v-btn(v-for='f in frequencies' :value='f.value') {{f.text}}
|
//- v-btn(v-for='f in frequencies' :value='f.value') {{f.text}}
|
||||||
@@ -59,7 +60,6 @@ v-row
|
|||||||
|
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
// import VInput from 'vuetify/es5/components/VInput'
|
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import { mapState } from 'vuex'
|
import { mapState } from 'vuex'
|
||||||
import List from '@/components/List'
|
import List from '@/components/List'
|
||||||
@@ -223,10 +223,11 @@ export default {
|
|||||||
selectFrequency (f) {
|
selectFrequency (f) {
|
||||||
this.$emit('input', { recurrent: { frequency: f }, date: null, type: 'recurrent' })
|
this.$emit('input', { recurrent: { frequency: f }, date: null, type: 'recurrent' })
|
||||||
},
|
},
|
||||||
pick (value) {
|
pick (date) {
|
||||||
if (this.value.type === 'normal' || this.value.type === 'recurrent' || this.value.date.length === 2) {
|
if (this.value.type === 'normal' || this.value.type === 'recurrent' || this.value.date.length === 2) {
|
||||||
this.datePickerMenu = false
|
this.datePickerMenu = false
|
||||||
}
|
}
|
||||||
|
this.$emit('input', { date, type: this.value.type, recurrent: this.value.recurrent })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,25 +180,19 @@ export default {
|
|||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
|
|
||||||
if (this.date.type === 'multidate') {
|
if (this.date.type === 'multidate') {
|
||||||
console.error('sono in multidate!')
|
|
||||||
start_datetime = dayjs(this.date.date[0])
|
start_datetime = dayjs(this.date.date[0])
|
||||||
.set('hour', start_hour).set('minute', start_minute)
|
.hour(start_hour).minute(start_minute)
|
||||||
end_datetime = dayjs(this.date.date[1])
|
end_datetime = dayjs(this.date.date[1])
|
||||||
.set('hour', end_hour).set('minute', end_minute)
|
.hour(end_hour).minute(end_minute)
|
||||||
} else if (this.date.type === 'normal') {
|
} else if (this.date.type === 'normal') {
|
||||||
start_datetime = dayjs(this.date.date).set('hour', start_hour).set('minute', start_minute)
|
start_datetime = dayjs(this.date.date).hour(start_hour).minute(start_minute)
|
||||||
end_datetime = dayjs(this.date.date).set('hour', end_hour).set('minute', end_minute)
|
end_datetime = dayjs(this.date.date).hour(end_hour).minute(end_minute)
|
||||||
if (end_hour < start_hour) {
|
if (end_hour < start_hour) {
|
||||||
end_datetime = end_datetime.add(1, 'day')
|
end_datetime = end_datetime.add(1, 'day')
|
||||||
}
|
}
|
||||||
} else if (this.date.type === 'recurrent') {
|
} else if (this.date.type === 'recurrent') {
|
||||||
start_datetime = dayjs().set('hour', start_hour).set('minute', start_minute)
|
start_datetime = dayjs(this.date.date).set('hour', start_hour).set('minute', start_minute)
|
||||||
end_datetime = dayjs().set('hour', end_hour).set('minute', end_minute)
|
end_datetime = dayjs(this.date.date).set('hour', end_hour).set('minute', end_minute)
|
||||||
// const recurrent = {
|
|
||||||
// frequency: this.event.recurrent.frequency,
|
|
||||||
// days: this.event.recurrent.type === 'ordinal' ? _.map(this.date, d => dayjs(d).date()) : _.map(this.date, d => dayjs(d).day() + 1),
|
|
||||||
// type: this.event.recurrent.type
|
|
||||||
// }
|
|
||||||
if (end_hour < start_hour) {
|
if (end_hour < start_hour) {
|
||||||
end_datetime = end_datetime.add(1, 'day')
|
end_datetime = end_datetime.add(1, 'day')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,10 +37,11 @@ export default ({ app, store }) => {
|
|||||||
Vue.filter('from', timestamp => dayjs.unix(timestamp).fromNow())
|
Vue.filter('from', timestamp => dayjs.unix(timestamp).fromNow())
|
||||||
|
|
||||||
Vue.filter('recurrentDetail', event => {
|
Vue.filter('recurrentDetail', event => {
|
||||||
const { frequency, days, type } = event.parent.recurrent
|
const parent = event.parent
|
||||||
|
const { frequency, days, type } = parent.recurrent
|
||||||
let recurrent
|
let recurrent
|
||||||
if (frequency === '1w' || frequency === '2w') {
|
if (frequency === '1w' || frequency === '2w') {
|
||||||
recurrent = app.i18n.tc(`event.recurrent_${frequency}_days`, days.length, { days: days.map(d => dayjs().day(d - 1).format('dddd')) })
|
recurrent = app.i18n.t(`event.recurrent_${frequency}_days`, { days: dayjs.unix(parent.start_datetime).format('dddd') })
|
||||||
} else if (frequency === '1m' || frequency === '2m') {
|
} else if (frequency === '1m' || frequency === '2m') {
|
||||||
const d = type === 'ordinal' ? days : days.map(d => dayjs().day(d - 1).format('dddd'))
|
const d = type === 'ordinal' ? days : days.map(d => dayjs().day(d - 1).format('dddd'))
|
||||||
recurrent = app.i18n.tc(`event.recurrent_${frequency}_${type}`, days.length, { days: d })
|
recurrent = app.i18n.tc(`event.recurrent_${frequency}_${type}`, days.length, { days: d })
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
const crypto = require('crypto')
|
const crypto = require('crypto')
|
||||||
// const moment = require('moment-timezone')
|
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const config = require('config')
|
const config = require('config')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
@@ -107,7 +106,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', attributes: ['id', 'recurrent', 'is_visible'] }
|
{ model: Event, required: false, as: 'parent', attributes: ['id', 'recurrent', 'is_visible', 'start_datetime'] }
|
||||||
],
|
],
|
||||||
order: [[Resource, 'id', 'DESC']]
|
order: [[Resource, 'id', 'DESC']]
|
||||||
})
|
})
|
||||||
@@ -493,72 +492,46 @@ const eventController = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const recurrent = e.recurrent
|
const recurrent = e.recurrent
|
||||||
const cursor = dayjs()
|
let cursor = dayjs()
|
||||||
// let cursor = start.startOf('week')
|
|
||||||
const start_date = dayjs.unix(e.start_datetime)
|
const start_date = dayjs.unix(e.start_datetime)
|
||||||
const duration = dayjs.unix(e.end_datetime).diff(start_date, 's')
|
const duration = dayjs.unix(e.end_datetime).diff(start_date, 's')
|
||||||
const frequency = recurrent.frequency
|
const frequency = recurrent.frequency
|
||||||
const days = recurrent.days
|
|
||||||
const type = recurrent.type
|
const type = recurrent.type
|
||||||
|
|
||||||
// default frequency is '1d' => each day
|
cursor = cursor.hour(start_date.hour()).minute(start_date.minute()).second(0)
|
||||||
const toAdd = { n: 1, unit: 'day' }
|
|
||||||
|
|
||||||
// each week or 2 (search for the first specified day)
|
// each week or 2
|
||||||
if (frequency === '1w' || frequency === '2w') {
|
if (frequency[1] === 'w') {
|
||||||
// cursor.add(days[0] - 1, 'day')
|
cursor = cursor.day(start_date.day())
|
||||||
if (frequency === '2w') {
|
if (cursor.isBefore(dayjs())) {
|
||||||
const nWeeks = cursor.diff(e.start_datetime, 'w') % 2
|
cursor = cursos.add(7, 'day')
|
||||||
if (!nWeeks) { cursor.add(1, 'week') }
|
|
||||||
}
|
}
|
||||||
toAdd.n = Number(frequency[0])
|
if (frequency[0] === 2) {
|
||||||
toAdd.unit = 'week'
|
cursor = cursor.add(7, 'day')
|
||||||
}
|
|
||||||
|
|
||||||
cursor.set('hour', start_date.hour()).set('minute', start_date.minutes())
|
|
||||||
|
|
||||||
// each month or 2
|
|
||||||
if (frequency === '1m' || frequency === '2m') {
|
|
||||||
// find first match
|
|
||||||
toAdd.n = 1
|
|
||||||
toAdd.unit = 'month'
|
|
||||||
if (type === 'weekday') {
|
|
||||||
|
|
||||||
} else if (type === 'ordinal') {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
} else if (frequency === '1m') {
|
||||||
|
|
||||||
// add event at specified frequency
|
|
||||||
// const first_event_of_week = cursor.clone()
|
|
||||||
days.forEach(d => {
|
|
||||||
if (type === 'ordinal') {
|
if (type === 'ordinal') {
|
||||||
cursor.date(d)
|
cursor = cursor.date(start_date.date())
|
||||||
} else {
|
|
||||||
cursor.day(d - 1)
|
|
||||||
if (cursor.isBefore(dayjs())) {
|
|
||||||
cursor.day(d - 1 + 7)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
event.start_datetime = cursor.unix()
|
}
|
||||||
event.end_datetime = event.start_datetime + duration
|
|
||||||
Event.create(event)
|
event.start_datetime = cursor.unix()
|
||||||
cursor.set('hour', start_date.hour()).set('minute', start_date.minutes())
|
event.end_datetime = event.start_datetime + duration
|
||||||
})
|
Event.create(event)
|
||||||
// cursor = first_event_of_week.add(toAdd.n, toAdd.unit)
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create instances of recurrent events
|
* Create instances of recurrent events
|
||||||
*/
|
*/
|
||||||
async _createRecurrent (start_datetime = dayjs().unix()) {
|
async _createRecurrent (start_datetime = dayjs().unix()) {
|
||||||
// select recurrent events
|
// select recurrent events and its childs
|
||||||
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.gte]: start_datetime } } }],
|
include: [{ model: Event, as: 'child', required: false, where: { start_datetime: { [Op.gte]: start_datetime } } }],
|
||||||
order: ['start_datetime']
|
order: ['start_datetime']
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// filter events that as no instance in future yet
|
||||||
const creations = events
|
const creations = events
|
||||||
.filter(e => e.child.length === 0)
|
.filter(e => e.child.length === 0)
|
||||||
.map(eventController._createRecurrentOccurrence)
|
.map(eventController._createRecurrentOccurrence)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ const Place = require('../models/place')
|
|||||||
const Tag = require('../models/tag')
|
const Tag = require('../models/tag')
|
||||||
|
|
||||||
const { Op } = require('sequelize')
|
const { Op } = require('sequelize')
|
||||||
const moment = require('moment-timezone')
|
const moment = require('dayjs')
|
||||||
const ics = require('ics')
|
const ics = require('ics')
|
||||||
|
|
||||||
const exportController = {
|
const exportController = {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const OAuthCode = require('../models/oauth_code')
|
|||||||
const User = require('../models/user')
|
const User = require('../models/user')
|
||||||
|
|
||||||
const debug = require('debug')('oauth')
|
const debug = require('debug')('oauth')
|
||||||
const moment = require('moment')
|
const moment = require('dayjs')
|
||||||
|
|
||||||
async function randomString (len = 16) {
|
async function randomString (len = 16) {
|
||||||
const bytes = await randomBytes(len * 8)
|
const bytes = await randomBytes(len * 8)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const Email = require('email-templates')
|
const Email = require('email-templates')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const moment = require('moment-timezone')
|
const moment = require('dayjs')
|
||||||
const config = require('config')
|
const config = require('config')
|
||||||
const settingsController = require('./controller/settings')
|
const settingsController = require('./controller/settings')
|
||||||
const debug = require('debug')('email')
|
const debug = require('debug')('email')
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const config = require('config')
|
const config = require('config')
|
||||||
const moment = require('moment-timezone')
|
const moment = require('dayjs')
|
||||||
const htmlToText = require('html-to-text')
|
const htmlToText = require('html-to-text')
|
||||||
|
|
||||||
const { Model, DataTypes } = require('sequelize')
|
const { Model, DataTypes } = require('sequelize')
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
const settingsController = require('./api/controller/settings')
|
const settingsController = require('./api/controller/settings')
|
||||||
const acceptLanguage = require('accept-language')
|
const acceptLanguage = require('accept-language')
|
||||||
|
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
|
const timezone = require('dayjs/plugin/timezone')
|
||||||
|
dayjs.extend(timezone)
|
||||||
|
|
||||||
const config = require('config')
|
const config = require('config')
|
||||||
const debug = require('debug')('helpers')
|
const debug = require('debug')('helpers')
|
||||||
const pkg = require('../package.json')
|
const pkg = require('../package.json')
|
||||||
|
|||||||
Reference in New Issue
Block a user