Skip to content

Commit

Permalink
Allow for daily frequency to be set
Browse files Browse the repository at this point in the history
  • Loading branch information
sunkup committed Jul 28, 2024
1 parent 4f25191 commit b298aad
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/models/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,10 @@ export default class Task {
*
* @readonly
* @memberof Task
* @return {object}
*/
get recurrenceRuleObject() {
if (this._recurrence === undefined || this._recurrence === null) {
if (this._recurrence == null) {
return getDefaultRecurrenceRuleObject()
}
return mapRecurrenceRuleValueToRecurrenceRuleObject(this._recurrence.getFirstValue(), this._start)
Expand All @@ -356,13 +357,13 @@ export default class Task {
set recurrenceRuleObject(rruleObject) {
if (rruleObject === null) {
this.vtodo.removeProperty('rrule')
this._recurrence = null
} else {
// FIXME: rruleObject.recurrenceRuleValue should not be null
this.vtodo.updatePropertyWithValue('rrule', rruleObject.recurrenceRuleValue)
this.vtodo.updatePropertyWithValue('rrule', rruleObject.recurrenceRuleValue.toICALJs())
}
this.todoComponent = ToDoComponent.fromICALJs(this.vtodo)
this._recurrence = this.todoComponent.getPropertyIterator('RRULE').next().value
this.updateLastModified()
this._recurrence = this.todoComponent.getPropertyIterator('RRULE').next().value
}

/**
Expand Down
31 changes: 30 additions & 1 deletion src/store/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { translate as t } from '@nextcloud/l10n'
import moment from '@nextcloud/moment'

import ICAL from 'ical.js'
import { RecurValue } from '@nextcloud/calendar-js'

const state = {
tasks: {},
Expand Down Expand Up @@ -501,9 +502,37 @@ const mutations = {
* @param {object} state The store data
* @param {object} data Destructuring object
* @param {Task} data.task The task
* @param {string} data.rruleObject The recurrence rule object from NC calendar-js
* @param {object} data.rruleObject The recurrence rule object from NC calendar-js
*/
setRecurrence(state, { task, rruleObject }) {
if (rruleObject == null) {
task.recurrenceRuleObject = null
return
}
// Set the ICAL recur value from changed params
const data = {}
if (rruleObject.frequency != null) { data.freq = rruleObject.frequency }
if (rruleObject.interval != null) { data.interval = rruleObject.interval }
// wkst
if (rruleObject.until != null) { data.until = rruleObject.until }
if (rruleObject.count != null) { data.count = rruleObject.count }
// bysecond
// byminute
// byhour
if (rruleObject.byDay != null) { data.byday = rruleObject.byDay }
if (rruleObject.bymonthday != null) { data.bymonthday = rruleObject.bymonthday }
// byyearday
// byweekno
if (rruleObject.byMonth != null) { data.bymonth = rruleObject.byMonth }
if (rruleObject.bySetPosition != null) { data.bysetpos = rruleObject.bySetPosition }

rruleObject.recurrenceRuleValue = RecurValue.fromData(data)
if (!rruleObject.recurrenceRuleValue.isRuleValid()) {
// Don't save an invalid RRULE (For development, remove after)
// console.log('Invalid rrule')
// console.log(rruleObject.recurrenceRuleValue.toICALJs().toString())
return
}
task.recurrenceRuleObject = rruleObject
},

Expand Down

0 comments on commit b298aad

Please sign in to comment.