summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2008-12-11 16:47:39 +0100
committerYorhel <git@yorhel.nl>2008-12-11 16:47:39 +0100
commit739327d3d50b7cae9f9cb938fa25129ae34e78cb (patch)
tree526eb94147223f1aedc70e873b273f0ab3e15d80 /lib
parent0514545451f9955cbdcdfed3137ac7e7888d6269 (diff)
Basic userpage + recent votes to VN pages + long-object-float bugfix
These changes are all pretty much related, so couldn't really do that in multiple commits.
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/DB/ULists.pm2
-rw-r--r--lib/VNDB/Func.pm9
-rw-r--r--lib/VNDB/Handler/Producers.pm2
-rw-r--r--lib/VNDB/Handler/Users.pm64
-rw-r--r--lib/VNDB/Handler/VNBrowse.pm2
-rw-r--r--lib/VNDB/Handler/VNPage.pm27
-rw-r--r--lib/VNDB/Util/CommonHTML.pm61
-rw-r--r--lib/VNDB/Util/LayoutHTML.pm3
8 files changed, 138 insertions, 32 deletions
diff --git a/lib/VNDB/DB/ULists.pm b/lib/VNDB/DB/ULists.pm
index c47af8e5..212388d0 100644
--- a/lib/VNDB/DB/ULists.pm
+++ b/lib/VNDB/DB/ULists.pm
@@ -137,7 +137,7 @@ sub dbVoteGet {
my %where = (
$o{uid} ? ( 'n.uid = ?' => $o{uid} ) : (),
$o{vid} ? ( 'n.vid = ?' => $o{vid} ) : (),
- $o{hide} ? ( 'u.show_list = FALSE' => 1 ) : (),
+ $o{hide} ? ( 'u.show_list = TRUE' => 1 ) : (),
);
my($r, $np) = $self->dbPage(\%o, q|
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm
index 52aa16a4..0fb0e6a1 100644
--- a/lib/VNDB/Func.pm
+++ b/lib/VNDB/Func.pm
@@ -3,9 +3,10 @@ package VNDB::Func;
use strict;
use warnings;
+use YAWF ':html';
use Exporter 'import';
use POSIX 'strftime';
-our @EXPORT = qw| shorten date datestr monthstr userstr bb2html gtintype liststat |;
+our @EXPORT = qw| shorten date datestr monthstr userstr bb2html gtintype liststat clearfloat |;
# I would've done this as a #define if this was C...
@@ -186,5 +187,11 @@ sub liststat {
}
+# Clears a float, to make sure boxes always have the correct height
+sub clearfloat {
+ div class => 'clearfloat', '';
+}
+
+
1;
diff --git a/lib/VNDB/Handler/Producers.pm b/lib/VNDB/Handler/Producers.pm
index c857aa74..d28a4746 100644
--- a/lib/VNDB/Handler/Producers.pm
+++ b/lib/VNDB/Handler/Producers.pm
@@ -199,7 +199,7 @@ sub list {
end;
}
}
- br style => 'clear: left';
+ clearfloat;
end;
$self->htmlBrowseNavigate($pageurl, $f->{p}, $np, 'b');
$self->htmlFooter;
diff --git a/lib/VNDB/Handler/Users.pm b/lib/VNDB/Handler/Users.pm
index b2ecc841..80bc11ec 100644
--- a/lib/VNDB/Handler/Users.pm
+++ b/lib/VNDB/Handler/Users.pm
@@ -27,11 +27,73 @@ sub userpage {
my $u = $self->dbUserGet(uid => $uid)->[0];
return 404 if !$u->{id};
+ my $votes = $u->{c_votes} && $self->dbVoteStats(uid => $uid);
+
$self->htmlHeader(title => ucfirst($u->{username})."'s Profile");
$self->htmlMainTabs('u', $u);
- div class => 'mainbox';
+ div class => 'mainbox userpage';
h1 ucfirst($u->{username})."'s Profile";
+
+ table;
+ Tr;
+ td class => 'key', ' ';
+ td ' ';
+ end;
+ my $i = 0;
+
+ Tr ++$i % 2 ? (class => 'odd') : ();
+ td 'Username';
+ td;
+ txt ucfirst($u->{username}).' (';
+ a href => "/u$uid", "u$uid";
+ txt ')';
+ end;
+ end;
+
+ Tr ++$i % 2 ? (class => 'odd') : ();
+ td 'Registered';
+ td date $u->{registered};
+ end;
+
+ Tr ++$i % 2 ? (class => 'odd') : ();
+ td 'Edits';
+ td;
+ if($u->{c_changes}) {
+ a href => "/u$uid/hist", $u->{c_changes};
+ } else {
+ txt '-';
+ }
+ end;
+ end;
+
+ Tr ++$i % 2 ? (class => 'odd') : ();
+ td 'Votes';
+ td;
+ if(!$u->{show_list}) {
+ txt 'hidden';
+ } elsif($votes) {
+ my($total, $count) = (0, 0);
+ for (1..@$votes) {
+ $total += $_*$votes->[$_-1];
+ $count += $votes->[$_-1];
+ }
+ a href => "/u$uid/list?v=1", $count;
+ txt sprintf ' (%.2f average)', $total/$count;
+ } else {
+ txt '-';
+ }
+ end;
+ end;
+
+ end;
end;
+
+ if($u->{show_list} && $votes) {
+ div class => 'mainbox';
+ h1 'Vote statistics';
+ $self->htmlVoteStats(u => $u, $votes);
+ end;
+ }
$self->htmlFooter;
}
diff --git a/lib/VNDB/Handler/VNBrowse.pm b/lib/VNDB/Handler/VNBrowse.pm
index c0c3754e..dd79990e 100644
--- a/lib/VNDB/Handler/VNBrowse.pm
+++ b/lib/VNDB/Handler/VNBrowse.pm
@@ -172,7 +172,7 @@ sub _filters {
end;
}
- br style => 'clear: left';
+ clearfloat;
end;
end;
end;
diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm
index 2bfe4eac..57773839 100644
--- a/lib/VNDB/Handler/VNPage.pm
+++ b/lib/VNDB/Handler/VNPage.pm
@@ -467,35 +467,12 @@ sub _stats {
my($self, $v) = @_;
my $stats = $self->dbVoteStats(vid => $v->{id});
- my($max, $count, $total) = (0, 0);
- for (0..$#$stats) {
- $max = $stats->[$_] if $stats->[$_] > $max;
- $count += $stats->[$_];
- $total += $stats->[$_]*($_+1);
- }
-
div class => 'mainbox';
h1 'User stats';
- if(!$max) {
+ if(!grep $_ > 0, @$stats) {
p "Nobody has voted on this visual novel yet...";
} else {
- table class => 'votegraph';
- thead; Tr;
- td colspan => 2, 'Vote graph';
- end; end;
- for (reverse 0..$#$stats) {
- Tr;
- td class => 'number', $_+1;
- td class => 'graph';
- div style => 'width: '.($stats->[$_] ? $stats->[$_]/$max*250 : 0).'px', ' ';
- txt $stats->[$_];
- end;
- end;
- }
- tfoot; Tr;
- td colspan => 2, sprintf '%d votes total, average %.2f (%s)', $count, $total/$count, $self->{votes}[sprintf '%.0f', $total/$count-1];
- end; end;
- end;
+ $self->htmlVoteStats(v => $v, $stats);
}
end;
}
diff --git a/lib/VNDB/Util/CommonHTML.pm b/lib/VNDB/Util/CommonHTML.pm
index 5cf3d729..df114cd7 100644
--- a/lib/VNDB/Util/CommonHTML.pm
+++ b/lib/VNDB/Util/CommonHTML.pm
@@ -9,7 +9,10 @@ use Algorithm::Diff::XS 'compact_diff';
use VNDB::Func;
use Encode 'encode_utf8', 'decode_utf8';
-our @EXPORT = qw|htmlMainTabs htmlDenied htmlHiddenMessage htmlBrowse htmlBrowseNavigate htmlRevision htmlEditMessage htmlItemMessage|;
+our @EXPORT = qw|
+ htmlMainTabs htmlDenied htmlHiddenMessage htmlBrowse htmlBrowseNavigate
+ htmlRevision htmlEditMessage htmlItemMessage htmlVoteStats
+|;
# generates the "main tabs". These are the commonly used tabs for
@@ -383,4 +386,60 @@ sub htmlItemMessage {
}
+# generates two tables, one with a vote graph, other with recent votes
+sub htmlVoteStats {
+ my($self, $type, $obj, $stats) = @_;
+
+ my($max, $count, $total) = (0, 0);
+ for (0..$#$stats) {
+ $max = $stats->[$_] if $stats->[$_] > $max;
+ $count += $stats->[$_];
+ $total += $stats->[$_]*($_+1);
+ }
+ div class => 'votestats';
+ table class => 'votegraph';
+ thead; Tr;
+ td colspan => 2, 'Vote graph';
+ end; end;
+ for (reverse 0..$#$stats) {
+ Tr;
+ td class => 'number', $_+1;
+ td class => 'graph';
+ div style => 'width: '.($stats->[$_] ? $stats->[$_]/$max*250 : 0).'px', ' ';
+ txt $stats->[$_];
+ end;
+ end;
+ }
+ tfoot; Tr;
+ td colspan => 2, sprintf '%d votes total, average %.2f%s', $count, $total/$count,
+ $type eq 'v' ? ' ('.$self->{votes}[sprintf '%.0f', $total/$count-1].')' : '';
+ end; end;
+ end;
+
+ my $recent = $self->dbVoteGet(
+ $type.'id' => $obj->{id}, results => 8, order => 'date DESC', hide => 1,
+ );
+ table class => 'recentvotes';
+ thead; Tr;
+ td colspan => 3, 'Recent votes';
+ end; end;
+ for (0..$#$recent) {
+ Tr $_ % 2 == 0 ? (class => 'odd') : ();
+ td;
+ if($type eq 'u') {
+ a href => "/v$recent->[$_]{vid}", title => $recent->[$_]{original}||$recent->[$_]{title}, shorten $recent->[$_]{title}, 40;
+ } else {
+ a href => "/u$recent->[$_]{uid}", $recent->[$_]{username};
+ }
+ end;
+ td $recent->[$_]{vote};
+ td date $recent->[$_]{date};
+ end;
+ }
+ end;
+ clearfloat;
+ end;
+}
+
+
1;
diff --git a/lib/VNDB/Util/LayoutHTML.pm b/lib/VNDB/Util/LayoutHTML.pm
index 061c4b16..ad0be091 100644
--- a/lib/VNDB/Util/LayoutHTML.pm
+++ b/lib/VNDB/Util/LayoutHTML.pm
@@ -5,6 +5,7 @@ use strict;
use warnings;
use YAWF ':html';
use Exporter 'import';
+use VNDB::Func;
our @EXPORT = qw|htmlHeader htmlFooter|;
@@ -125,7 +126,7 @@ sub _menu {
dd $stats->{$$_[0]};
}
end;
- br style => 'clear: left';
+ clearfloat;
end;
end;
end;