Fix recurrence rule update issues

This commit is contained in:
yflory 2022-10-11 16:11:53 +02:00
parent c11b83dd5a
commit 16cdf2ccdc
2 changed files with 34 additions and 10 deletions

View File

@ -604,7 +604,17 @@ define([
var nextRule = nextRules.shift();
if (_start >= _endMonth) { return; }
if (rule.until < _startMonth) { return; }
// Check the "until" date of the latest rule we can use and stop now
// if the recurrence ends before the current month
var until = rule.until;
var _nextRules = nextRules.slice();
var _nextRule = nextRule;
while (_nextRule && _nextRule._start && _nextRule._start < _startMonth) {
until = nextRule.until;
_nextRule = _nextRules.shift();
}
if (until < _startMonth) { return; }
var endData = getEndData(_start, _end);
@ -626,7 +636,8 @@ define([
rule.freq = 'yearly';
rule.count = 10;
*/
debug('Iterate over', obj);
debug('Iterate over', obj.title, obj);
debug('Use rule', rule);
var count = rule.count;
var c = 1;
@ -671,6 +682,19 @@ define([
newrule = true;
}
var useNewRule = function () {
if (!newrule) { return; }
debug('Use new rule', nextRule);
_ev._count = c;
count = nextRule.count;
c = 1;
evS = +_evS;
obj = _ev;
rule = nextRule;
nextRule = nextRules.shift();
};
if (c >= count) { // Limit reached
debug(_evS.toLocaleDateString(), 'count');
stop = true;
@ -694,6 +718,7 @@ define([
if (_evE < _startMonth) { // Ended before the current month
// Nothing to display but continue the recurrence
debug(_evS.toLocaleDateString(), 'startMonth');
if (newrule) { useNewRule(); }
return;
}
// If a recurring event start and end in different months, make sure
@ -712,13 +737,7 @@ define([
// Add this event
toAdd.push(_ev);
if (newrule) {
_ev._count = c;
count = nextRule.count;
c = 1;
evS = +_evS;
obj = _ev;
rule = nextRule;
nextRule = nextRules.shift();
useNewRule();
return true;
}
});

View File

@ -841,6 +841,8 @@ define([
var ev = c.proxy.content[data.ev.id];
if (!ev) { return void cb({error: "EINVAL"}); }
data.rawData = data.rawData || {};
// update the event
var changes = data.changes || {};
var type = data.type || {};
@ -893,7 +895,7 @@ define([
if (['one','from'].includes(type.which) && !data.rawData.isOrigin) {
cleanAfter(type.when);
} else {
ev.recUpdate = RECUPDATE;
update = ev.recUpdate = RECUPDATE;
}
}
@ -954,6 +956,9 @@ define([
Object.keys(changes).forEach(function (key) {
if (!alwaysAll.includes(key) && type.which === "one") {
if (key === "recurrenceRule") {
if (data.rawData && data.rawData.isOrigin) {
return (ev[key] = changes[key]);
}
// Always "from", never "one" for recurrence rules
update.from[type.when] = update.from[type.when] || {};
return (update.from[type.when][key] = changes[key]);