* Calendar: Fix changing the recurrence end date did not add/remove the events in the UI

This commit is contained in:
nathan 2021-10-15 14:03:29 -06:00
parent a7ec8c002d
commit c01df39342
3 changed files with 61 additions and 14 deletions

View File

@ -642,13 +642,17 @@ class calendar_ui
* *
* @param int $event_id * @param int $event_id
* @param Api\DateTime $recurrence_date * @param Api\DateTime $recurrence_date
* @param array $old_event
* *
* @return boolean True if the event was updated, false if it could not be * @return boolean True if the event was updated, false if it could not be
* updated or was removed. * updated or was removed.
*/ */
public function update_client($event_id, Api\DateTime $recurrence_date = null) public function update_client($event_id, Api\DateTime $recurrence_date = null, array $old_event = array())
{ {
if(!$event_id) return false; if(!$event_id)
{
return false;
}
if(is_string($event_id) && strpos($event_id, ':') !== FALSE) if(is_string($event_id) && strpos($event_id, ':') !== FALSE)
{ {
list($event_id, $date) = explode(':', $event_id); list($event_id, $date) = explode(':', $event_id);
@ -698,6 +702,21 @@ class calendar_ui
else if($event['recur_type'] ) else if($event['recur_type'] )
{ {
$this_month = new Api\DateTime('next month'); $this_month = new Api\DateTime('next month');
$data = [];
if($old_event && ($old_event['start'] != $event['start'] || $old_event['recur_enddate'] != $event['recur_enddate']))
{
// Set up to clear old events in case recurrence start/end date changed
$old_rrule = calendar_rrule::event2rrule($old_event, true);
$old_rrule->rewind();
do
{
$occurrence = $old_rrule->current();
$data['calendar::' . $old_event['id'] . ':' . $occurrence->format('ts')] = null;
$old_rrule->next();
}
while($old_rrule->valid() && $occurrence <= $this_month);
}
$rrule = calendar_rrule::event2rrule($event, true); $rrule = calendar_rrule::event2rrule($event, true);
$rrule->rewind(); $rrule->rewind();
do do
@ -705,10 +724,17 @@ class calendar_ui
$occurrence = $rrule->current(); $occurrence = $rrule->current();
$converted = $this->bo->read($event['id'], $occurrence); $converted = $this->bo->read($event['id'], $occurrence);
$this->to_client($converted); $this->to_client($converted);
$response->generic('data', array('uid' => 'calendar::'.$converted['row_id'], 'data' => $converted)); $data['calendar::' . $converted['row_id']] = $converted;
$rrule->next(); $rrule->next();
} }
while($rrule->valid() && $occurrence <= $this_month); while($rrule->valid() && $occurrence <= $this_month);
// Now we have to go through and send each one individually, since client side data can't handle more than one
foreach($data as $uid => $cal_data)
{
$response->apply('egw.dataStoreUID', [$uid, $cal_data]);
}
$response->apply('app.calendar.update_events', [array_keys($data)]);
} }
return true; return true;
} }

View File

@ -1007,7 +1007,7 @@ class calendar_uiforms extends calendar_ui
$response = Api\Json\Response::get(); $response = Api\Json\Response::get();
if($response && $update_type != 'delete' && !$client_updated) if($response && $update_type != 'delete' && !$client_updated)
{ {
$client_updated = $this->update_client($event['id']); $client_updated = $this->update_client($event['id'], null, $old_event);
} }
$msg = $message . ($msg ? ', ' . $msg : ''); $msg = $message . ($msg ? ', ' . $msg : '');

View File

@ -657,16 +657,28 @@ export class CalendarApp extends EgwApp
// Update directly // Update directly
this._update_events(this.state, ['calendar::' + pushData.id]); this._update_events(this.state, ['calendar::' + pushData.id]);
return; return;
}; }
;
// Ask for the real data, we don't have it // Ask for the real data, we don't have it
egw.request("calendar.calendar_ui.ajax_get", [[pushData.id]]).then((data) => let process_data = (data) =>
{ {
// Store it, which will call all registered listeners // Store it, which will call all registered listeners
egw.dataStoreUID(data.uid, data.data); egw.dataStoreUID(data.uid, data.data);
// Any existing events were updated. Run this to catch new events or events moved into view // Any existing events were updated. Run this to catch new events or events moved into view
this._update_events(this.state, [data.uid]); this._update_events(this.state, [data.uid]);
}
egw.request("calendar.calendar_ui.ajax_get", [[pushData.id]]).then((data) =>
{
if(typeof data.uid !== "undefined")
{
return process_data(data)
}
for(let e of data)
{
process_data(e);
}
}); });
} }
@ -3743,6 +3755,15 @@ export class CalendarApp extends EgwApp
); );
} }
/**
* We have a list of calendar UIDs of events that need updating.
* Public wrapper for _update_events so we can call it from server
*/
update_events(uids : string[])
{
return this._update_events(this.state, uids);
}
/** /**
* We have a list of calendar UIDs of events that need updating. * We have a list of calendar UIDs of events that need updating.
* *