summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-08-19 14:12:36 +0200
committerYorhel <git@yorhel.nl>2020-08-19 14:13:03 +0200
commitcae561ee7e13c2ba238995468b5fe614d7ec15e0 (patch)
tree719467868e41d8aa8efdf375622e72b7cd5babe8
parent51e430fdfc5df05b7ee49d6955e2cfc8e4205b88 (diff)
reviews: Add quick and dirty review browser
Primarily intended as a feed for recent reviews or recent comments, much like the discussion board equivalent.
-rw-r--r--data/style.css10
-rw-r--r--lib/VNWeb/Reviews/List.pm78
2 files changed, 88 insertions, 0 deletions
diff --git a/data/style.css b/data/style.css
index d15391d6..1fc5c431 100644
--- a/data/style.css
+++ b/data/style.css
@@ -625,6 +625,16 @@ div.producerbrowse { padding-bottom: 10px }
#reviewspoil:checked ~ .fullreview .reviewnotspoil { display: none }
+/***** Review browser *****/
+
+.reviewlist td.tc1 { width: 90px }
+.reviewlist td.tc2 { width: 110px; }
+.reviewlist td.tc4 { width: 50px; text-align: right }
+.reviewlist td.tc5 { width: 80px; padding-left: 15px }
+.reviewlist td.tc6 { width: 30px; text-align: right }
+.reviewlist td.tc7 { width: 250px; text-align: right }
+
+
/***** Release browser *****/
.relbrowse .tc1 { width: 80px }
diff --git a/lib/VNWeb/Reviews/List.pm b/lib/VNWeb/Reviews/List.pm
new file mode 100644
index 00000000..fcd0ed03
--- /dev/null
+++ b/lib/VNWeb/Reviews/List.pm
@@ -0,0 +1,78 @@
+package VNWeb::Reviews::List;
+
+use VNWeb::Prelude;
+
+
+sub tablebox_ {
+ my($opt, $lst, $count) = @_;
+
+ my sub url { '?'.query_encode %$opt, @_ }
+
+ paginate_ \&url, $opt->{p}, [$count, 50], 't';
+ 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 => 'tc2', 'By';
+ td_ class => 'tc3', 'Review';
+ td_ class => 'tc4', 'Vote';
+ td_ class => 'tc5', sub { txt_ 'Score'; sortable_ 'rating', $opt, \&url if auth->isMod };
+ td_ class => 'tc6', 'C#';
+ td_ class => 'tc7', sub { txt_ 'Last comment'; sortable_ 'lastpost', $opt, \&url };
+ } };
+ tr_ sub {
+ td_ class => 'tc1', fmtdate $_->{date}, 'compact';
+ td_ class => 'tc2', sub { user_ $_ };
+ td_ class => 'tc3', sub { a_ href => "/$_->{id}", $_->{title} };
+ td_ class => 'tc4', fmtvote $_->{vote};
+ td_ class => 'tc5', sprintf '👍 %d 👎 %d', $_->{c_up}, $_->{c_down};
+ td_ class => 'tc6', $_->{c_count};
+ td_ class => 'tc7', $_->{c_lastnum} ? sub {
+ user_ $_, 'lu_';
+ txt_ ' @ ';
+ a_ href => "/$_->{id}.$_->{c_lastnum}#last", fmtdate $_->{ldate}, 'full';
+ } : '';
+ } for @$lst;
+ };
+ };
+ paginate_ \&url, $opt->{p}, [$count, 50], 'b';
+}
+
+
+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]] },
+ )->data;
+ $opt->{s} = 'id' if $opt->{s} eq 'rating' && !auth->isMod;
+
+ my $count = tuwf->dbVali('SELECT COUNT(*) FROM reviews');
+ my $lst = tuwf->dbPagei({results => 50, page => $opt->{p}}, '
+ SELECT w.id, w.vid, w.c_up, w.c_down, w.c_count, w.c_lastnum, v.title, uv.vote
+ , ', sql_user(), ',', sql_totime('w.date'), 'as date
+ , ', sql_user('wpu','lu_'), ',', sql_totime('wp.date'), 'as ldate
+ FROM reviews w
+ JOIN vn v ON v.id = w.vid
+ LEFT JOIN users u ON u.id = w.uid
+ 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
+ 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 {
+ div_ class => 'mainbox', sub {
+ h1_ 'Browse reviews';
+ debug_ $lst;
+ };
+ tablebox_ $opt, $lst, $count;
+ };
+};
+
+1;