mirror of
https://framagit.org/les/gancio.git
synced 2025-01-31 16:42:22 +01:00
fix montly recurrent events
This commit is contained in:
parent
563bed45ee
commit
f4ab613671
3 changed files with 37 additions and 23 deletions
|
@ -27,7 +27,7 @@ v-col(cols=12)
|
|||
|
||||
div.text-center.mb-2(v-if='type === "recurrent"')
|
||||
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-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' }
|
||||
]
|
||||
|
||||
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
|
||||
const lastWeek = date.daysInMonth() - monthDay < 7
|
||||
if (lastWeek) {
|
||||
patterns.push(
|
||||
{
|
||||
label: this.$t(`event.recurrent_${freq}_ordinal`,
|
||||
{ n: this.$t('ordinal.-1'), days: weekDay }),
|
||||
key: 'weekday'
|
||||
label: this.$t(`event.recurrent_${freq}_ordinal`, { n: this.$t('ordinal.-1'), days: weekDay }),
|
||||
key: -1
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (n < 5) {
|
||||
patterns.push(
|
||||
{
|
||||
label: this.$t(`event.recurrent_${freq}_ordinal`,
|
||||
{ n: this.$t(`ordinal.${n}`), days: weekDay }),
|
||||
key: 'weekday'
|
||||
}
|
||||
)
|
||||
}
|
||||
return patterns
|
||||
} else if (freq === '1d') {
|
||||
return this.$t('event.recurrent_each_day')
|
||||
|
@ -198,6 +197,8 @@ export default {
|
|||
}
|
||||
} else if (what === 'frequency') {
|
||||
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') {
|
||||
if (value) {
|
||||
const [hour, minute] = value.split(':')
|
||||
|
@ -221,6 +222,7 @@ export default {
|
|||
} else {
|
||||
this.$emit('input', { ...this.value, dueHour: false })
|
||||
}
|
||||
// change date in calendar (could be a range or a recurrent event...)
|
||||
} else if (what === 'date') {
|
||||
if (value === null) {
|
||||
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') })
|
||||
} else if (frequency === '1m' || frequency === '2m') {
|
||||
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
|
||||
})
|
||||
|
|
|
@ -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) {
|
||||
log.debug(`Create recurrent event [${e.id}] ${e.title}"`)
|
||||
|
@ -541,17 +541,24 @@ const eventController = {
|
|||
cursor = cursor.add(1, 'month')
|
||||
}
|
||||
} else { // weekday
|
||||
const monthDay = start_date.format('D')
|
||||
const n = Math.floor((monthDay - 1) / 7) + 1
|
||||
cursor = cursor.startOf('month')
|
||||
cursor = cursor.add(n, 'week')
|
||||
cursor = cursor.day(start_date.day())
|
||||
if (cursor.isBefore(dayjs())) {
|
||||
cursor = cursor.add(1, 'month')
|
||||
// get weekday
|
||||
log.info(type)
|
||||
// get recurrent freq details
|
||||
if (type === -1) {
|
||||
cursor = cursor.endOf('month')
|
||||
cursor = cursor.subtract(1, 'week')
|
||||
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.end_datetime = event.start_datetime + duration
|
||||
Event.create(event)
|
||||
|
|
Loading…
Reference in a new issue