summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-08-31 10:41:53 +0200
committerYorhel <git@yorhel.nl>2020-08-31 10:41:53 +0200
commit261b52541f205915cfce63ca4fb183b14d8a5a45 (patch)
tree05618924b6d31b4773955228df25dcef83e32391
parentd4c11dddaf0ba52310afca84d26afcff182ee715 (diff)
Add review stats & tab to user page (re-using Reviews::List)
-rw-r--r--lib/VNWeb/HTML.pm1
-rw-r--r--lib/VNWeb/Reviews/List.pm24
-rw-r--r--lib/VNWeb/User/Page.pm9
3 files changed, 25 insertions, 9 deletions
diff --git a/lib/VNWeb/HTML.pm b/lib/VNWeb/HTML.pm
index e9f4ec72..1a4dc617 100644
--- a/lib/VNWeb/HTML.pm
+++ b/lib/VNWeb/HTML.pm
@@ -367,6 +367,7 @@ sub _maintabs_ {
t list => "/$id/ulist?vnlist=1", 'list';
t votes => "/$id/ulist?votes=1", 'votes';
t wish => "/$id/ulist?wishlist=1", 'wishlist';
+ t reviews => "/w?u=$o->{id}", 'reviews';
t posts => "/$id/posts", 'posts';
} if $t eq 'u';
diff --git a/lib/VNWeb/Reviews/List.pm b/lib/VNWeb/Reviews/List.pm
index 5ab5a133..f37dc375 100644
--- a/lib/VNWeb/Reviews/List.pm
+++ b/lib/VNWeb/Reviews/List.pm
@@ -13,7 +13,7 @@ sub tablebox_ {
div_ class => 'mainbox browse reviewlist', sub {
table_ class => 'stripe', sub {
thead_ sub { tr_ sub {
- td_ class => 'tc1', sub { txt_ 'Date'; sortable_ 'id', $opt, \&url };
+ td_ class => 'tc1', sub { txt_ 'Date'; sortable_ 'id', $opt, \&url; debug_ $lst };
td_ class => 'tc2', 'By';
td_ class => 'tc3', 'Vote';
td_ class => 'tc4', 'Type';
@@ -45,17 +45,19 @@ sub tablebox_ {
TUWF::get qr{/w}, sub {
return tuwf->resNotFound if !auth->permReview; #XXX:While in beta
- # TODO: User filter, so we can link from the user's page
- # TODO: Display full/short indicator
-
my $opt = tuwf->validate(get =>
p => { page => 1 },
s => { onerror => 'id', enum => [qw[id lastpost rating]] },
o => { onerror => 'd', enum => [qw[a d]] },
+ u => { onerror => 0, id => 1 },
)->data;
$opt->{s} = 'id' if $opt->{s} eq 'rating' && !auth->isMod;
- my $count = tuwf->dbVali('SELECT COUNT(*) FROM reviews');
+ my $u = $opt->{u} && tuwf->dbRowi('SELECT id, ', sql_user(), 'FROM users u WHERE id =', \$opt->{u});
+ return tuwf->resNotFound if $u && !$u->{id};
+
+ my $where = $u ? sql 'w.uid =', \$u->{id} : '1=1';
+ my $count = tuwf->dbVali('SELECT COUNT(*) FROM reviews w WHERE', $where);
my $lst = tuwf->dbPagei({results => 50, page => $opt->{p}}, '
SELECT w.id, w.vid, w.isfull, w.c_up, w.c_down, w.c_count, w.c_lastnum, v.title, uv.vote
, ', sql_user(), ',', sql_totime('w.date'), 'as date
@@ -66,15 +68,19 @@ TUWF::get qr{/w}, sub {
LEFT JOIN reviews_posts wp ON w.id = wp.id AND w.c_lastnum = wp.num
LEFT JOIN users wpu ON wpu.id = wp.uid
LEFT JOIN ulist_vns uv ON uv.uid = w.uid AND uv.vid = w.vid
+ WHERE', $where, '
ORDER BY', {id => 'w.id', lastpost => 'wp.date', rating => 'w.c_up-w.c_down'}->{$opt->{s}}, {a=>'ASC',d=>'DESC'}->{$opt->{o}}, 'NULLS LAST'
);
- framework_ title => 'Browse reviews', sub {
+ my $title = $u ? 'Reviews by '.user_displayname($u) : 'Browse reviews';
+ framework_ title => $title, $u ? (type => 'u', dbobj => $u, tab => 'reviews') : (), sub {
div_ class => 'mainbox', sub {
- h1_ 'Browse reviews';
- debug_ $lst;
+ h1_ $title;
+ if($u && !$count) {
+ p_ +(auth && $u->{id} == auth->uid ? 'You have' : user_displayname($u).' has').' not submitted any reviews yet.';
+ }
};
- tablebox_ $opt, $lst, $count;
+ tablebox_ $opt, $lst, $count if $count;
};
};
diff --git a/lib/VNWeb/User/Page.pm b/lib/VNWeb/User/Page.pm
index c1ff681d..b41be78e 100644
--- a/lib/VNWeb/User/Page.pm
+++ b/lib/VNWeb/User/Page.pm
@@ -66,6 +66,15 @@ sub _info_table_ {
};
};
tr_ sub {
+ my $stats = tuwf->dbRowi('SELECT COUNT(*) AS cnt, SUM(c_up) AS up, SUM(c_down) AS down FROM reviews WHERE uid =', \$u->{id});
+ td_ 'Reviews';
+ td_ !$stats->{cnt} ? '-' : sub {
+ txt_ sprintf '%d review%s', $stats->{cnt}, $stats->{cnt} == 1 ? '' : 's';
+ txt_ !$stats->{up} && !$stats->{down} ? '. ' : sprintf ', %.0f%% approval. ', $stats->{up}/($stats->{up}+$stats->{down})*100;
+ a_ href => "/w?u=$u->{id}", 'Browse reviews ยป';
+ };
+ };
+ tr_ sub {
my $stats = tuwf->dbRowi('SELECT COUNT(DISTINCT tag) AS tags, COUNT(DISTINCT vid) AS vns FROM tags_vn WHERE uid =', \$u->{id});
td_ 'Tags';
td_ !$u->{c_tags} ? '-' : !$stats->{tags} ? '-' : sub {