fix admin pager for links list

This commit is contained in:
Jean-Christian Denis 2021-08-28 23:17:13 +02:00
parent f13814ff5e
commit ab9b5e9b6b
2 changed files with 101 additions and 98 deletions

View file

@ -11,79 +11,86 @@
#
# -- END LICENSE BLOCK ------------------------------------
class kutrlLinkslist extends adminGenericList
class kutrlLinkslist
{
public function display($page, $nb_per_page, $url)
protected $core;
protected $rs;
protected $rs_count;
protected $html_prev;
protected $html_next;
public function __construct(dcCore $core, $rs, $rs_count)
{
$this->core = &$core;
$this->rs = &$rs;
$this->rs_count = $rs_count;
$this->html_prev = __('« prev.');
$this->html_next = __('next »');
}
public function display($page, $nb_per_page, $enclose_block, $filter = false)
{
if ($this->rs->isEmpty()) {
echo '<p><strong>' . __('No short link') . '</strong></p>';
} else {
$pager = new pager($page, $this->rs_count, $nb_per_page, 10);
$pager->base_url = $url;
$html_block =
'<table class="clear">' .
'<thead>' .
'<tr>' .
'<th class="nowrap" colspan="2">' . __('Hash') . '</th>' .
'<th class="maximal">' . __('Link') . '</th>' .
'<th class="nowrap">' . __('Date') . '</th>' .
'<th class="nowrap">' . __('Service') . '</th>' .
'</tr>' .
'</thead>' .
'<tbody>%s</tbody>' .
'</table>';
echo '<p>' . __('Page(s)') . ' : ' . $pager->getLinks() . '</p>';
$blocks = explode('%s', $html_block);
echo $blocks[0];
$this->rs->index(((integer)$page - 1) * $nb_per_page);
$iter = 0;
while ($iter < $nb_per_page) {
echo $this->line($url,$iter);
if ($this->rs->isEnd()) {
break;
} else {
$this->rs->moveNext();
}
$iter++;
if ($filter) {
echo '<p><strong>' . __('No short link matches the filter') . '</strong></p>';
} else {
echo '<p><strong>' . __('No short link') . '</strong></p>';
}
echo $blocks[1];
echo '<p>' . __('Page(s)') . ' : ' . $pager->getLinks() . '</p>';
} else {
$pager = new dcPager($page, $this->rs_count, $nb_per_page, 10);
$entries = [];
if (isset($_REQUEST['entries'])) {
foreach ($_REQUEST['entries'] as $v) {
$entries[(integer) $v] = true;
}
}
$blocks = explode('%s', sprintf($enclose_block,
'<div class="table-outer"><table>' .
($filter ?
'<caption>' . sprintf(__('List of %s links matching the filter.'), $this->rs_count) . '</caption>' :
'<caption>' . sprintf(__('List of links (%s)'), $this->rs_count) . '</caption>'
) .
'<tr>' .
'<th colspan="2" class="first">' . __('Hash') . '</th>' .
'<th scope="col">' . __('Link') . '</th>' .
'<th scope="col">' . __('Date') . '</th>' .
'<th scope="col">' . __('Service') . '</th>' .
'</tr>%s</table>%s</div>'
));
echo $pager->getLinks().$blocks[0];
while ($this->rs->fetch()) {
$type = $this->rs->kut_type;
$hash = $this->rs->kut_hash;
if (null !== ($o = kutrl::quickService($type))) {
$type = '<a href="' . $o->home . '" title="' . $o->name . '">' . $o->name . '</a>';
$hash = '<a href="' . $o->url_base . $hash . '" title="' . $o->url_base . $hash . '">' . $hash . '</a>';
}
echo
'<tr class="line">' .
'<td class="nowrap">' .
form::checkbox(['entries[]'], $this->rs->kut_id, ['checked' => isset($entries[$this->rs->kut_id])]) .
'</td>' .
'<td class="nowrap">' .
$hash .
'</td>' .
'<td class="maximal" scope="row">' .
'<a href="' . $this->rs->kut_url . '">' . $this->rs->kut_url . '</a>' .
'</td>' .
'<td class="nowrap count">' .
dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, $this->core->auth->getInfo('user_tz')) .
'</td>' .
'<td class="nowrap">' .
$type .
'</td>' .
'</tr>';
}
echo $blocks[1].$blocks[2].$pager->getLinks();
}
}
private function line($url, $loop)
{
$type = $this->rs->kut_type;
$hash = $this->rs->kut_hash;
if (null !== ($o = kutrl::quickService($this->rs->kut_type))) {
$type = '<a href="' . $o->home . '" title="' . $o->name . '">' . $o->name . '</a>';
$hash = '<a href="' . $o->url_base . $hash . '" title="' . $o->url_base . $hash . '">' . $hash . '</a>';
}
return
'<tr class="line">' . "\n" .
'<td class="nowrap">' .
form::checkbox(['entries[' . $loop . ']'], $this->rs->kut_id, 0) .
'</td>' .
'<td class="nowrap">' .
$hash .
"</td>\n" .
'<td class="maximal">' .
'<a href="' . $this->rs->kut_url . '">' . $this->rs->kut_url . '</a>' .
"</td>\n" .
'<td class="nowrap">' .
dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, $this->core->auth->getInfo('user_tz')) .
"</td>\n" .
'<td class="nowrap">' .
$type .
"</td>\n" .
'</tr>' . "\n";
}
}

View file

@ -237,14 +237,6 @@ if ($part == 'links') {
$show_filters = true;
}
$pager_base_url =
$p_url .
'&amp;urlsrv=' . $urlsrv .
'&amp;sortby=' . $sortby .
'&amp;order=' . $order .
'&amp;nb=' . $nb_per_page .
'&amp;page=%s';
try {
$list_all = $log->getLogs($params);
$list_counter = $log->getLogs($params, true)->f(0);
@ -532,30 +524,34 @@ if ($part == 'links') {
<p><input type="submit" value="' . __('Apply filters and display options') . '" />
<br class="clear" /></p>
</form>
<form action="' . $p_url . '&amp;part=links" method="post" id="form-actions">';
$list_current->display($page, $nb_per_page, $pager_base_url);
echo '
<div class="two-cols">
<p class="col checkboxes-helpers"></p>
<p class="col right">
<input type="submit" value="' . __('Delete selected short links') . '" />' .
form::hidden(['deletelinks'], 1) .
form::hidden(['urlsrv'], $urlsrv) .
form::hidden(['sortby'], $sortby) .
form::hidden(['order'], $order) .
form::hidden(['page'], $page) .
form::hidden(['nb'], $nb_per_page) .
form::hidden(['part'], 'links') .
$core->formNonce() . '
</p>
</div>
</form>';
$list_current->display(
$page,
$nb_per_page,
'<form action="' . $p_url . '&amp;part=links" method="post" id="form-actions">
%s
<div class="two-cols">
<p class="col checkboxes-helpers"></p>
<p class="col right">
<input type="submit" value="' . __('Delete selected short links') . '" />' .
form::hidden(['deletelinks'], 1) .
form::hidden(['urlsrv'], $urlsrv) .
form::hidden(['sortby'], $sortby) .
form::hidden(['order'], $order) .
form::hidden(['page'], $page) .
form::hidden(['nb'], $nb_per_page) .
form::hidden(['part'], 'links') .
$core->formNonce() . '
</p>
</div>
</form>',
$show_filters
);
}
# display footer
dcPage::helpBlock('kUtRL');