fix montly recurrent events
This commit is contained in:
@@ -27,7 +27,7 @@ v-col(cols=12)
|
|||||||
|
|
||||||
div.text-center.mb-2(v-if='type === "recurrent"')
|
div.text-center.mb-2(v-if='type === "recurrent"')
|
||||||
span(v-if='value.recurrent.frequency !== "1m" && value.recurrent.frequency !== "2m"') {{whenPatterns}}
|
span(v-if='value.recurrent.frequency !== "1m" && value.recurrent.frequency !== "2m"') {{whenPatterns}}
|
||||||
v-btn-toggle.mt-1.flex-column.flex-sm-row(v-else :value='value.recurrent.type' color='primary' @change='fq => change("", fq)')
|
v-btn-toggle.mt-1.flex-column.flex-sm-row(v-else :value='value.recurrent.type' color='primary' @change='fq => change("recurrentType", fq)')
|
||||||
v-btn(v-for='whenPattern in whenPatterns' :value='whenPattern.key' :key='whenPatterns.key' small) {{whenPattern.label}}
|
v-btn(v-for='whenPattern in whenPatterns' :value='whenPattern.key' :key='whenPatterns.key' small) {{whenPattern.label}}
|
||||||
|
|
||||||
v-row.mt-3.col-md-6.mx-auto
|
v-row.mt-3.col-md-6.mx-auto
|
||||||
@@ -133,27 +133,26 @@ export default {
|
|||||||
// { label: this.$tc(`event.recurrent_${freq}_ordinal`, { n, days: weekDay }), key: 'weekday' }
|
// { label: this.$tc(`event.recurrent_${freq}_ordinal`, { n, days: weekDay }), key: 'weekday' }
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if (n < 5) {
|
||||||
|
patterns.push(
|
||||||
|
{
|
||||||
|
label: this.$t(`event.recurrent_${freq}_ordinal`, { n: this.$t(`ordinal.${n}`), days: weekDay }),
|
||||||
|
key: n
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// if selected day is in last week, propose also this type of selection
|
// if selected day is in last week, propose also this type of selection
|
||||||
const lastWeek = date.daysInMonth() - monthDay < 7
|
const lastWeek = date.daysInMonth() - monthDay < 7
|
||||||
if (lastWeek) {
|
if (lastWeek) {
|
||||||
patterns.push(
|
patterns.push(
|
||||||
{
|
{
|
||||||
label: this.$t(`event.recurrent_${freq}_ordinal`,
|
label: this.$t(`event.recurrent_${freq}_ordinal`, { n: this.$t('ordinal.-1'), days: weekDay }),
|
||||||
{ n: this.$t('ordinal.-1'), days: weekDay }),
|
key: -1
|
||||||
key: 'weekday'
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n < 5) {
|
|
||||||
patterns.push(
|
|
||||||
{
|
|
||||||
label: this.$t(`event.recurrent_${freq}_ordinal`,
|
|
||||||
{ n: this.$t(`ordinal.${n}`), days: weekDay }),
|
|
||||||
key: 'weekday'
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return patterns
|
return patterns
|
||||||
} else if (freq === '1d') {
|
} else if (freq === '1d') {
|
||||||
return this.$t('event.recurrent_each_day')
|
return this.$t('event.recurrent_each_day')
|
||||||
@@ -198,6 +197,8 @@ export default {
|
|||||||
}
|
}
|
||||||
} else if (what === 'frequency') {
|
} else if (what === 'frequency') {
|
||||||
this.$emit('input', { ...this.value, recurrent: { ...this.value.recurrent, frequency: value } })
|
this.$emit('input', { ...this.value, recurrent: { ...this.value.recurrent, frequency: value } })
|
||||||
|
} else if (what === 'recurrentType') {
|
||||||
|
this.$emit('input', { ...this.value, recurrent: { ...this.value.recurrent, type: value } })
|
||||||
} else if (what === 'fromHour') {
|
} else if (what === 'fromHour') {
|
||||||
if (value) {
|
if (value) {
|
||||||
const [hour, minute] = value.split(':')
|
const [hour, minute] = value.split(':')
|
||||||
@@ -221,6 +222,7 @@ export default {
|
|||||||
} else {
|
} else {
|
||||||
this.$emit('input', { ...this.value, dueHour: false })
|
this.$emit('input', { ...this.value, dueHour: false })
|
||||||
}
|
}
|
||||||
|
// change date in calendar (could be a range or a recurrent event...)
|
||||||
} else if (what === 'date') {
|
} else if (what === 'date') {
|
||||||
if (value === null) {
|
if (value === null) {
|
||||||
this.$emit('input', { ...this.value, from: null, fromHour: false })
|
this.$emit('input', { ...this.value, from: null, fromHour: false })
|
||||||
|
|||||||
@@ -44,7 +44,12 @@ export default ({ app, store }) => {
|
|||||||
recurrent = app.i18n.t(`event.recurrent_${frequency}_days`, { days: dayjs.unix(parent.start_datetime).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' ? dayjs.unix(parent.start_datetime).date() : dayjs.unix(parent.start_datetime).format('dddd')
|
const d = type === 'ordinal' ? dayjs.unix(parent.start_datetime).date() : dayjs.unix(parent.start_datetime).format('dddd')
|
||||||
recurrent = app.i18n.tc(`event.recurrent_${frequency}_${type}`, d)
|
if (type === 'ordinal') {
|
||||||
|
recurrent = app.i18n.t(`event.recurrent_${frequency}_days`, { days: d })
|
||||||
|
} else {
|
||||||
|
recurrent = app.i18n.t(`event.recurrent_${frequency}_ordinal`,
|
||||||
|
{ n: app.i18n.t('ordinal.' + type), days: d })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return recurrent
|
return recurrent
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -496,7 +496,7 @@ const eventController = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure we have the next instances of recurrent events
|
* Ensure we have the next instance of a recurrent event
|
||||||
*/
|
*/
|
||||||
_createRecurrentOccurrence (e) {
|
_createRecurrentOccurrence (e) {
|
||||||
log.debug(`Create recurrent event [${e.id}] ${e.title}"`)
|
log.debug(`Create recurrent event [${e.id}] ${e.title}"`)
|
||||||
@@ -541,17 +541,24 @@ const eventController = {
|
|||||||
cursor = cursor.add(1, 'month')
|
cursor = cursor.add(1, 'month')
|
||||||
}
|
}
|
||||||
} else { // weekday
|
} else { // weekday
|
||||||
const monthDay = start_date.format('D')
|
// get weekday
|
||||||
const n = Math.floor((monthDay - 1) / 7) + 1
|
log.info(type)
|
||||||
cursor = cursor.startOf('month')
|
// get recurrent freq details
|
||||||
cursor = cursor.add(n, 'week')
|
if (type === -1) {
|
||||||
cursor = cursor.day(start_date.day())
|
cursor = cursor.endOf('month')
|
||||||
if (cursor.isBefore(dayjs())) {
|
cursor = cursor.subtract(1, 'week')
|
||||||
cursor = cursor.add(1, 'month')
|
cursor = cursor.day(start_date.day())
|
||||||
|
} else {
|
||||||
|
cursor = cursor.startOf('month')
|
||||||
|
cursor = cursor.add(type, 'week')
|
||||||
|
cursor = cursor.day(start_date.day())
|
||||||
|
if (cursor.isBefore(dayjs())) {
|
||||||
|
cursor = cursor.add(1, 'month')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.info(cursor)
|
||||||
event.start_datetime = cursor.unix()
|
event.start_datetime = cursor.unix()
|
||||||
event.end_datetime = event.start_datetime + duration
|
event.end_datetime = event.start_datetime + duration
|
||||||
Event.create(event)
|
Event.create(event)
|
||||||
|
|||||||
Reference in New Issue
Block a user