summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2008-11-14 16:42:30 +0100
committerYorhel <git@yorhel.nl>2008-11-14 16:42:30 +0100
commit549608b0091107973c6d25b2a45189b85663144c (patch)
tree56ae8281454d62e12d8cb35cfb7f82ef31955b9e
parent9476900ba8562fec588bc15435ca63b713c278ae (diff)
Added basic history browser
Doesn't work for r+ and v+ yet. Filter options pending...
-rw-r--r--lib/VNDB/DB/Misc.pm48
-rw-r--r--lib/VNDB/Handler/Misc.pm87
-rw-r--r--lib/VNDB/Util/CommonHTML.pm7
-rw-r--r--lib/VNDB/Util/LayoutHTML.pm2
-rw-r--r--static/f/style.css17
5 files changed, 154 insertions, 7 deletions
diff --git a/lib/VNDB/DB/Misc.pm b/lib/VNDB/DB/Misc.pm
index ced47084..2a88d756 100644
--- a/lib/VNDB/DB/Misc.pm
+++ b/lib/VNDB/DB/Misc.pm
@@ -6,7 +6,7 @@ use warnings;
use Exporter 'import';
our @EXPORT = qw|
- dbStats dbRevisionInsert dbItemInsert
+ dbStats dbRevisionInsert dbItemInsert dbRevisionGet
|;
@@ -82,5 +82,51 @@ sub dbItemInsert {
}
+# Options: type, iid, uid, page, results
+sub dbRevisionGet {
+ my($self, %o) = @_;
+ $o{results} ||= 10;
+ $o{page} ||= 1;
+
+ my %where = (
+ $o{type} ? (
+ 'c.type = ?' => { v=>0, r=>1, p=>2 }->{$o{type}} ) : (),
+ $o{iid} ? (
+ '!sr.!sid = ?' => [ $o{type}, $o{type}, $o{iid} ] ) : (),
+ $o{uid} ? (
+ 'c.requester = ?' => $o{uid} ) : (),
+ );
+
+ my @join = (
+ $o{iid} || $o{what} =~ /item/ ? (
+ 'LEFT JOIN vn_rev vr ON c.type = 0 AND c.id = vr.id',
+ 'LEFT JOIN releases_rev rr ON c.type = 1 AND c.id = rr.id',
+ 'LEFT JOIN producers_rev pr ON c.type = 2 AND c.id = pr.id',
+ ) : (),
+ $o{what} =~ /user/ ? 'JOIN users u ON c.requester = u.id' : (),
+ );
+
+ my @select = (
+ qw|c.id c.type c.added c.requester c.comments c.rev c.causedby|,
+ $o{what} =~ /user/ ? 'u.username' : (),
+ $o{what} =~ /item/ ? (
+ 'COALESCE(vr.vid, rr.rid, pr.pid) AS iid',
+ 'COALESCE(vr.title, rr.title, pr.name) AS ititle',
+ 'COALESCE(vr.original, rr.original, pr.original) AS ioriginal',
+ ) : (),
+ );
+
+ my($r, $np) = $self->dbPage(\%o, q|
+ SELECT !s
+ FROM changes c
+ !s
+ !W
+ ORDER BY c.id DESC|,
+ join(', ', @select), join(' ', @join), \%where
+ );
+ return wantarray ? ($r, $np) : $r;
+}
+
+
1;
diff --git a/lib/VNDB/Handler/Misc.pm b/lib/VNDB/Handler/Misc.pm
index 1124bac4..ce6d34a9 100644
--- a/lib/VNDB/Handler/Misc.pm
+++ b/lib/VNDB/Handler/Misc.pm
@@ -5,11 +5,13 @@ package VNDB::Handler::Misc;
use strict;
use warnings;
use YAWF ':html';
+use VNDB::Func;
YAWF::register(
- qr{}, \&homepage,
- qr{nospam}, \&nospam,
+ qr{}, \&homepage,
+ qr{(?:([upvr])([1-9]\d*)/)?hist}, \&history,
+ qr{nospam}, \&nospam,
);
@@ -25,6 +27,87 @@ sub homepage {
}
+sub history {
+ my($self, $type, $id) = @_;
+ $type ||= '';
+ $id ||= 0;
+
+ my $f = $self->formValidate(
+ { name => 'p', required => 0, default => 1, template => 'int' },
+ );
+ return 404 if $f->{_err};
+
+ # get item object and title
+ my $obj = $type eq 'u' ? $self->dbUserGet(id => $id)->[0] :
+ $type eq 'p' ? $self->dbProducerGet(id => $id)->[0] :
+ {};
+ my $title = $type ? 'Edit history of '.($obj->{title} || $obj->{name} || $obj->{username}) : 'Recent changes';
+ return 404 if $type && !$obj->{id};
+
+ # get the edit history
+ my($list, $np) = $self->dbRevisionGet(
+ what => 'item user',
+ $type && $type ne 'u' ? ( type => $type, iid => $id ) : (),
+ $type eq 'u' ? ( uid => $id ) : (),
+ page => $f->{p},
+ results => 50,
+ );
+
+ $self->htmlHeader(title => $title);
+ $self->htmlMainTabs($type, $obj, 'hist') if $type;
+
+ div class => 'mainbox';
+ h1 $title;
+ p class => 'center', 'Some filter or search options here';
+ end;
+
+ $self->htmlBrowse(
+ items => $list,
+ options => $f,
+ nextpage => $np,
+ pageurl => ($type ? "/$type$id" : '').'/hist',
+ class => 'history',
+ header => [
+ sub { td colspan => 2, class => 'tc1', 'Rev.' },
+ [ 'Date' ],
+ [ 'User' ],
+ [ 'Page' ],
+ #[ 'Edit summary' ],
+ ],
+ row => sub {
+ my($s, $n, $i) = @_;
+ my $tc = [qw|v r p|]->[$i->{type}];
+ my $revurl = "/$tc$i->{iid}.$i->{rev}";
+
+ Tr $n % 2 ? ( class => 'odd' ) : ();
+ td class => 'tc1_1';
+ a href => $revurl, "$tc$i->{iid}";
+ end;
+ td class => 'tc1_2';
+ a href => $revurl, ".$i->{rev}";
+ end;
+ td date $i->{added};
+ td;
+ a href => "/u$i->{requester}", $i->{username};
+ end;
+ td;
+ a href => $revurl, title => $i->{ioriginal}, shorten $i->{ititle}, 80;
+ end;
+ end;
+ if($i->{comments}) {
+ Tr $n % 2 ? ( class => 'odd' ) : ();
+ td colspan => 5, class => 'editsum';
+ lit bb2html $i->{comments}, 150;
+ end;
+ end;
+ }
+ },
+ );
+
+ $self->htmlFooter;
+}
+
+
sub nospam {
my $self = shift;
$self->htmlHeader(title => 'Could not send form');
diff --git a/lib/VNDB/Util/CommonHTML.pm b/lib/VNDB/Util/CommonHTML.pm
index 6771df75..f2c4d6ff 100644
--- a/lib/VNDB/Util/CommonHTML.pm
+++ b/lib/VNDB/Util/CommonHTML.pm
@@ -97,8 +97,9 @@ sub htmlDenied {
# items => arrayref with the list items
# options => hashref containing at least the keys s (sort key), o (order) and p (page)
# nextpage => whether there's a next page or not
-# sorturl => base URL to append the sort options to
+# sorturl => base URL to append the sort options to (if there are any sortable columns)
# pageurl => base URL to append the page option to
+# class => classname of the mainbox
# header =>
# can be either an arrayref or subroutine reference,
# in the case of a subroutine, it will be called when the header should be written,
@@ -111,12 +112,12 @@ sub htmlDenied {
sub htmlBrowse {
my($self, %opt) = @_;
- $opt{sorturl} .= $opt{sorturl} =~ /\?/ ? '&' : '?';
+ $opt{sorturl} .= $opt{sorturl} =~ /\?/ ? '&' : '?' if $opt{sorturl};
# top navigation
$self->htmlBrowseNavigate($opt{pageurl}, $opt{options}{p}, $opt{nextpage}, 't');
- div class => 'mainbox browse';
+ div class => 'mainbox browse'.($opt{class} ? ' '.$opt{class} : '');
table;
# header
diff --git a/lib/VNDB/Util/LayoutHTML.pm b/lib/VNDB/Util/LayoutHTML.pm
index 306668bf..383d63ee 100644
--- a/lib/VNDB/Util/LayoutHTML.pm
+++ b/lib/VNDB/Util/LayoutHTML.pm
@@ -49,7 +49,7 @@ sub _menu {
[ '#' => 'Visual Novels' ],
[ '/p/all' => 'Producers' ],
[ '/u/list/all' => 'Users' ],
- [ '#' => 'Recent Changes' ],
+ [ '/hist' => 'Recent Changes' ],
[ '#' => 'Discussion Board' ],
[ '#' => 'FAQ' ]) {
a href => $$_[0], $$_[1];
diff --git a/static/f/style.css b/static/f/style.css
index d78504a0..65dd432e 100644
--- a/static/f/style.css
+++ b/static/f/style.css
@@ -326,6 +326,23 @@ form.search .submit {
padding: 0 1px;
}
+/* history browser */
+div.mainbox.history td.tc1_1 {
+ text-align: right;
+ padding-left: 15px;
+ padding-right: 0;
+ width: 40px;
+}
+div.mainbox.history td.tc1_2 {
+ padding-left: 0;
+ width: 25px;
+}
+div.mainbox.history td.editsum {
+ color: #258;
+ padding-top: 0;
+ text-align: right;
+}
+