From b298aad2332fac0e5360fc20cac2f9cca0969429 Mon Sep 17 00:00:00 2001 From: Sunik Kupfer Date: Sun, 28 Jul 2024 18:48:10 +0200 Subject: [PATCH] Allow for daily frequency to be set --- src/models/task.js | 9 +++++---- src/store/tasks.js | 31 ++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/models/task.js b/src/models/task.js index 0b7c2d80a..d2d116350 100644 --- a/src/models/task.js +++ b/src/models/task.js @@ -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) @@ -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 } /** diff --git a/src/store/tasks.js b/src/store/tasks.js index 18019afd3..15a866432 100644 --- a/src/store/tasks.js +++ b/src/store/tasks.js @@ -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: {}, @@ -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 },