Improved pagination on package info pages
This commit is contained in:
parent
965aa9a2f6
commit
25a39c6fe4
2 changed files with 52 additions and 23 deletions
60
www/index.pl
60
www/index.pl
|
|
@ -4,6 +4,7 @@ use strict;
|
|||
use warnings;
|
||||
use TUWF ':html', 'html_escape', ':xml';
|
||||
use JSON::XS;
|
||||
use POSIX 'ceil';
|
||||
|
||||
use Cwd 'abs_path';
|
||||
our $ROOT;
|
||||
|
|
@ -443,6 +444,27 @@ sub pkg_frompath {
|
|||
}
|
||||
|
||||
|
||||
sub paginate {
|
||||
my($url, $count, $perpage, $p) = @_;
|
||||
return if $count <= $perpage;
|
||||
|
||||
my $l = sub {
|
||||
my $c = shift;
|
||||
a href => sprintf('%s%d', $url, $c), $c if $c != $p;
|
||||
b $c if $c == $p;
|
||||
};
|
||||
|
||||
my $lp = ceil($count/$perpage);
|
||||
p class => 'paginate';
|
||||
$l->(1) if $p > 1+4;
|
||||
b '...' if $p > 1+5;
|
||||
$l->($_) for (($p > 4 ? $p-4 : 1)..($p+4 > $lp ? $lp : $p+4));
|
||||
b '...' if $p < $lp-5;
|
||||
$l->($lp) if $p < $lp-4;
|
||||
end;
|
||||
}
|
||||
|
||||
|
||||
sub pkg_info {
|
||||
my($self, $short, $path) = @_;
|
||||
|
||||
|
|
@ -457,11 +479,12 @@ sub pkg_info {
|
|||
my $sel = $ver ? (grep $_->{version} eq $ver, @$vers)[0] : $vers->[0];
|
||||
return $self->resNotFound if !$sel;
|
||||
|
||||
my $f = $self->formValidate({ get => 's', required => 0});
|
||||
my $f = $self->formValidate({ get => 'p', required => 0, default => 1, template => 'uint', min => 1, max => 100});
|
||||
return $self->resNotFound if $f->{_err};
|
||||
|
||||
my $mans = $self->dbManInfo(package => $sel->{id}, results => 201, start => $f->{s}, sort => 'syspkgname');
|
||||
my $more = @$mans > 200 && pop @$mans;
|
||||
my $mans = $self->dbManInfo(package => $sel->{id}, results => 200, page => $f->{p}, sort => 'syspkgname');
|
||||
my $more = 1;
|
||||
my $count = $self->dbManInfo(package => $sel->{id}, countonly => 1)->[0]{count};
|
||||
|
||||
# Latest version of this package determines last modification date of the page.
|
||||
$self->setLastMod($vers->[0]{released});
|
||||
|
|
@ -485,6 +508,7 @@ sub pkg_info {
|
|||
|
||||
div id => 'pkgmans';
|
||||
h2 "Manuals for version $sel->{version}";
|
||||
paginate "/pkg/$sys->{short}/$pkg->{category}/$pkg->{name}/$sel->{version}?p=", $count, 200, $f->{p};
|
||||
ul;
|
||||
for(@$mans) {
|
||||
li;
|
||||
|
|
@ -494,12 +518,7 @@ sub pkg_info {
|
|||
end;
|
||||
}
|
||||
end;
|
||||
if($more) {
|
||||
use utf8;
|
||||
p class => 'pagination';
|
||||
a href => "/pkg/$sys->{short}/$pkg->{category}/$pkg->{name}/$sel->{version}?s=$mans->[199]{name}", 'next »';
|
||||
end;
|
||||
}
|
||||
paginate "/pkg/$sys->{short}/$pkg->{category}/$pkg->{name}/$sel->{version}?p=", $count, 200, $f->{p};
|
||||
end;
|
||||
|
||||
$self->htmlFooter;
|
||||
|
|
@ -759,7 +778,7 @@ sub htmlHeader {
|
|||
|
||||
html;
|
||||
head;
|
||||
Link rel => 'stylesheet', type => 'text/css', href => '/man.css?2';
|
||||
Link rel => 'stylesheet', type => 'text/css', href => '/man.css?4';
|
||||
title $o{title}.' - manned.org';
|
||||
end 'head';
|
||||
body;
|
||||
|
|
@ -824,10 +843,15 @@ sub dbManContent {
|
|||
}
|
||||
|
||||
|
||||
# Options: name, section, shorthash, package, start, results, sort
|
||||
# Options: name, section, shorthash, package, start, results, sort, countonly
|
||||
sub dbManInfo {
|
||||
my $s = shift;
|
||||
my %o = @_;
|
||||
my %o = (
|
||||
sort => '',
|
||||
page => 1,
|
||||
results => 10_000,
|
||||
@_
|
||||
);
|
||||
|
||||
my %where = (
|
||||
$o{name} ? ('m.name = ?' => $o{name}) : (),
|
||||
|
|
@ -840,20 +864,22 @@ sub dbManInfo {
|
|||
$o{start} ? ('m.name > ?' => $o{start}) : (),
|
||||
);
|
||||
|
||||
$o{sort} ||= '';
|
||||
my $order =
|
||||
$o{sort} eq 'syspkgname' ? 'ORDER BY s.name, s.relorder DESC, p.name, v.released DESC, m.name, m.locale NULLS FIRST, m.filename' : '';
|
||||
|
||||
return $s->dbAll(q{
|
||||
SELECT p.system, p.category, p.name AS package, v.version, v.released, m.name, m.section, m.filename, m.locale, encode(m.hash, 'hex') AS hash
|
||||
my $select = $o{countonly} ? 'COUNT(*) as count'
|
||||
: "p.system, p.category, p.name AS package, v.version, v.released, m.name, m.section, m.filename, m.locale, encode(m.hash, 'hex') AS hash";
|
||||
|
||||
my($r, $np) = $s->dbPage(\%o, q{
|
||||
SELECT !s
|
||||
FROM man m
|
||||
JOIN package_versions v ON v.id = m.package
|
||||
JOIN packages p ON p.id = v.package
|
||||
JOIN systems s ON s.id = p.system
|
||||
!W
|
||||
!s
|
||||
LIMIT ?
|
||||
}, \%where, $order, $o{results}||10000);
|
||||
}, $select, \%where, $order);
|
||||
wantarray ? ($r, $np) : $r;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
15
www/man.css
15
www/man.css
|
|
@ -25,10 +25,15 @@ code { font-family: "Lucida Console", Monospace; font-size: 12px; background-col
|
|||
#body { padding: 10px 10px 20px 10px; background: #fff }
|
||||
|
||||
#systems a,
|
||||
#charselect a { color: #048; font-family: "Verdana"; font-weight: normal; text-decoration: none; padding: 3px 5px; border-radius: 4px; }
|
||||
#charselect a,
|
||||
.paginate a { color: #048; font-family: "Verdana"; font-weight: normal; text-decoration: none; padding: 3px 5px; border-radius: 4px; }
|
||||
|
||||
#charselect b,
|
||||
.paginate b { font-family: "Verdana"; padding: 3px }
|
||||
|
||||
#systems a:hover,
|
||||
#charselect a:hover { background: #cde; }
|
||||
#charselect a:hover,
|
||||
.paginate a:hover { background: #cde; }
|
||||
|
||||
i.grayedout { color: #aaa; font-size: 13px; }
|
||||
|
||||
|
|
@ -43,11 +48,8 @@ i.grayedout { color: #aaa; font-size: 13px; }
|
|||
#systems b { font-size: 24px; display: block }
|
||||
|
||||
#charselect { float: right }
|
||||
#charselect b { padding: 3px }
|
||||
.pagination { display: block; margin: 10px; width: 100%; text-align: center }
|
||||
|
||||
#external { list-style-type: none }
|
||||
|
||||
#packages { margin: 20px 0; -webkit-column-width: 300px; -moz-column-width: 300px; column-width: 300px }
|
||||
#packages li { display: block; }
|
||||
#packages i { color: #aaa; font-size: 13px; }
|
||||
|
|
@ -69,8 +71,9 @@ i.grayedout { color: #aaa; font-size: 13px; }
|
|||
#pkgmans { margin-top: 10px }
|
||||
#pkgmans h2 { margin: 0 }
|
||||
#pkgmans { float: left }
|
||||
#pkgmans .paginate { margin: 10px 0 }
|
||||
#pkgmans ul { margin: 10px 0 }
|
||||
#pkgmans li { display: block; }
|
||||
#pkgmans li { display: block }
|
||||
#pkgmans i { color: #aaa; font-size: 13px; }
|
||||
|
||||
#manbuttons h1 { display: inline; margin: 0 20px 0 0; vertical-align: middle }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue