summaryrefslogtreecommitdiff
path: root/www
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2016-10-26 19:25:23 +0200
committerYorhel <git@yorhel.nl>2016-10-26 19:25:23 +0200
commit25a39c6fe4d389fdd43e2e46b86aa70b61936f34 (patch)
tree3ce5cb8f3312de23a3cffac31734ec4e8bd2cabc /www
parent965aa9a2f646ceff3b017a33cc8719fa482c336f (diff)
Improved pagination on package info pages
Diffstat (limited to 'www')
-rwxr-xr-xwww/index.pl60
-rw-r--r--www/man.css15
2 files changed, 52 insertions, 23 deletions
diff --git a/www/index.pl b/www/index.pl
index 967ef0a..fa80b32 100755
--- a/www/index.pl
+++ b/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;
}
diff --git a/www/man.css b/www/man.css
index 9c62c52..e752c73 100644
--- a/www/man.css
+++ b/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 }