allow to paginate through CalDAV/CardDAV autoindex start-page with accounts

This commit is contained in:
ralf 2022-11-07 20:50:45 +01:00
parent be16565cc4
commit 6a51e56961
2 changed files with 39 additions and 4 deletions

View File

@ -387,6 +387,15 @@ class CalDAV extends HTTP_WebDAV_Server
// make options (readonly) available to all class methods, eg. prop_requested // make options (readonly) available to all class methods, eg. prop_requested
$this->propfind_options = $options; $this->propfind_options = $options;
$nresults = null;
foreach($options['other'] ?? [] as $option)
{
if ($option['name'] === 'nresults' && (int)$option['data'] > 0)
{
$nresults = (int)$option['data'];
}
}
// parse path in form [/account_lid]/app[/more] // parse path in form [/account_lid]/app[/more]
$id = $app = $user = $user_prefix = null; $id = $app = $user = $user_prefix = null;
if (!self::_parse_path($options['path'],$id,$app,$user,$user_prefix) && $app && !$user && $user !== 0) if (!self::_parse_path($options['path'],$id,$app,$user,$user_prefix) && $app && !$user && $user !== 0)
@ -421,10 +430,24 @@ class CalDAV extends HTTP_WebDAV_Server
$files['files'][] = $this->add_collection('/principals/', array( $files['files'][] = $this->add_collection('/principals/', array(
'displayname' => lang('Accounts'), 'displayname' => lang('Accounts'),
)); ));
foreach($this->accounts->search(array('type' => 'both','order'=>'account_lid')) as $account) foreach($this->accounts->search([
'type' => 'both',
'order' =>'account_lid',
'start' => $_GET['start'] ?? 0,
'offset' => $nresults,
]) as $account)
{ {
$this->add_home($files, $path.$account['account_lid'].'/', $account['account_id'], $options['depth'] == 'infinity' ? 'infinity' : $options['depth']-1); $this->add_home($files, $path.$account['account_lid'].'/', $account['account_id'], $options['depth'] == 'infinity' ? 'infinity' : $options['depth']-1);
} }
// if nresults-limit is set respond correct
if (isset($nresults) && $this->accounts->total > ($_GET['start'] ?? 0)+$nresults)
{
$handler = new CalDAV\Principals('calendar', $this);
$handler->sync_collection_toke = '?start='.(($_GET['start'] ?? 0)+$nresults);
$files['sync-token'] = [$handler, 'get_sync_collection_token'];
$files['sync-token-parameters'] = ['/', '', true];
}
} }
return true; return true;
} }
@ -1239,9 +1262,11 @@ class CalDAV extends HTTP_WebDAV_Server
*/ */
protected function autoindex($options) protected function autoindex($options)
{ {
$chunk_size = 500;
$propfind_options = array( $propfind_options = array(
'path' => $options['path'], 'path' => $options['path'],
'depth' => 1, 'depth' => 1,
'other' => [['name' => 'nresults', 'data' => $chunk_size]],
); );
$files = array(); $files = array();
if (($ret = $this->PROPFIND($propfind_options,$files)) !== true) if (($ret = $this->PROPFIND($propfind_options,$files)) !== true)
@ -1328,6 +1353,16 @@ class CalDAV extends HTTP_WebDAV_Server
} }
else else
{ {
if (!empty($files['sync-token-parameters'][2]) || !empty($_GET['start']))
{
echo "\t<tr class='th'><td colspan='".(2+count($props2show))."'>".
(empty($_GET['start']) ? '' :
Html::a_href('<<< '.lang('Previous %1 accounts', $chunk_size), '/groupdav.php'.$options['path'].'?start='.max(0, $_GET['start']-$chunk_size))).
(!empty($_GET['start']) && !empty($files['sync-token-parameters'][2]) ? ' | ' : '').
(empty($files['sync-token-parameters'][2]) ? '' :
Html::a_href(lang('Next %1 accounts', $chunk_size).' >>>', '/groupdav.php'.$options['path'].'?start='.(($_GET['start'] ?? 0)+$chunk_size))).
"</td></tr></tr>\n";
}
echo "</table>\n"; echo "</table>\n";
} }
echo '<h3>'.lang('Properties')."</h3>\n"; echo '<h3>'.lang('Properties')."</h3>\n";
@ -2531,4 +2566,4 @@ class CalDAV extends HTTP_WebDAV_Server
return $_appName.'-'.$_eventID.'-'.$GLOBALS['egw_info']['server']['install_id']; return $_appName.'-'.$_eventID.'-'.$GLOBALS['egw_info']['server']['install_id'];
} }
} }

View File

@ -754,10 +754,10 @@ abstract class Handler
if (!isset($token)) $token = $this->getctag($path, $user); if (!isset($token)) $token = $this->getctag($path, $user);
// never return current time, as more modifications might happen due to second granularity --> return 1sec less // never return current time, as more modifications might happen due to second granularity --> return 1sec less
if ($token >= (int)$GLOBALS['egw_info']['flags']['page_start_time']) if (is_numeric($token) && $token >= (int)$GLOBALS['egw_info']['flags']['page_start_time'])
{ {
$token = (int)$GLOBALS['egw_info']['flags']['page_start_time'] - 1; $token = (int)$GLOBALS['egw_info']['flags']['page_start_time'] - 1;
} }
return $this->base_uri().$path.$token; return $this->base_uri().$path.$token;
} }
} }