summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/style.css7
-rw-r--r--lib/VNDB/DB/Tags.pm53
-rw-r--r--lib/VNDB/Handler/Tags.pm88
-rw-r--r--lib/VNDB/Util/CommonHTML.pm4
-rw-r--r--lib/VNDB/Util/LayoutHTML.pm1
-rw-r--r--static/f/script.js2
6 files changed, 140 insertions, 15 deletions
diff --git a/data/style.css b/data/style.css
index d9413d39..9386b0fa 100644
--- a/data/style.css
+++ b/data/style.css
@@ -935,8 +935,8 @@ ul#catselect li li.exc { background-position: 0px -33px; color: $statnok$; }
/***** User VN list browser ******/
-.rlist .relhid { }
-.rlist .relhid_but, #relhidall { cursor: pointer }
+.relhid_but, #relhidall { cursor: pointer }
+.relhid_but i, #relhidall i { font-style: normal }
.browse.rlist .tc2 { width: 100px; }
.browse.rlist .tc3 { width: 70px; }
.browse.rlist .relhid .tc1 { padding-left: 40px; width: 70px; }
@@ -975,6 +975,9 @@ ul#catselect li li.exc { background-position: 0px -33px; color: $statnok$; }
.tagvnlist .tc4 { padding: 0; }
.tagvnlist .tc6 { text-align: right; padding-right: 10px; }
+/***** User tag list *****/
+.browse.tagstats .tc1 { width: 80px }
+.browse.tagstats .tc1_2 { padding-left: 15px }
/***** VN tagmod *****/
diff --git a/lib/VNDB/DB/Tags.pm b/lib/VNDB/DB/Tags.pm
index 3e06d1b8..27485229 100644
--- a/lib/VNDB/DB/Tags.pm
+++ b/lib/VNDB/DB/Tags.pm
@@ -5,7 +5,7 @@ use strict;
use warnings;
use Exporter 'import';
-our @EXPORT = qw|dbTagGet dbTagEdit dbTagAdd dbTagDel dbTagLinks dbTagLinkEdit dbVNTags dbTagVNs|;
+our @EXPORT = qw|dbTagGet dbTagEdit dbTagAdd dbTagDel dbTagLinks dbTagLinkEdit dbTagStats dbTagVNs|;
# %options->{ id name search page results order what }
@@ -114,18 +114,51 @@ sub dbTagLinkEdit {
}
-# Fetch all tags related to a VN
-# Argument: vid
-sub dbVNTags {
- my($self, $vid) = @_;
- return $self->dbAll(q|
- SELECT t.id, t.name, count(tv.uid) as users, avg(tv.vote) as rating, COALESCE(avg(tv.spoiler), 0) as spoiler
+# Fetch all tags related to a VN or User
+# Argument: %options->{ uid vid results what page order }
+# what: vns
+sub dbTagStats {
+ my($self, %o) = @_;
+ $o{results} ||= 10;
+ $o{page} ||= 1;
+ $o{order} ||= 't.name ASC';
+ $o{what} ||= '';
+
+ my %where = (
+ $o{uid} ? (
+ 'tv.uid = ?' => $o{uid} ) : (),
+ $o{vid} ? (
+ 'tv.vid = ?' => $o{vid} ) : (),
+ );
+ my($r, $np) = $self->dbPage(\%o, q|
+ SELECT t.id, t.name, count(*) as cnt, avg(tv.vote) as rating, COALESCE(avg(tv.spoiler), 0) as spoiler
FROM tags t
JOIN tags_vn tv ON tv.tag = t.id
- WHERE tv.vid = ?
- GROUP BY t.id, t.name|,
- $vid
+ !W
+ GROUP BY t.id, t.name
+ ORDER BY !s|,
+ \%where, $o{order}
);
+
+ if(@$r && $o{what} =~ /vns/ && $o{uid}) {
+ my %r = map {
+ $_->{vns} = [];
+ ($_->{id}, $_->{vns})
+ } @$r;
+
+ push @{$r{$_->{tag}}}, $_ for (@{$self->dbAll(q|
+ SELECT tv.tag, tv.vote, tv.spoiler, vr.vid, vr.title, vr.original
+ FROM tags_vn tv
+ JOIN vn v ON v.id = tv.vid
+ JOIN vn_rev vr ON vr.id = v.latest
+ WHERE tv.uid = ?
+ AND tv.tag IN(!l)
+ ORDER BY vr.title ASC|,
+ $o{uid}, [ keys %r ]
+ )});
+ }
+
+ return wantarray ? ($r, $np) : $r;
}
diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm
index 55f8fe7a..84a049e5 100644
--- a/lib/VNDB/Handler/Tags.pm
+++ b/lib/VNDB/Handler/Tags.pm
@@ -15,6 +15,7 @@ YAWF::register(
qr{g([1-9]\d*)/del(/o)?}, \&tagdel,
qr{g/new}, \&tagedit,
qr{v([1-9]\d*)/tagmod}, \&vntagmod,
+ qr{u([1-9]\d*)/tags}, \&usertags,
qr{g}, \&tagtree,
qr{xml/tags\.xml}, \&tagxml,
);
@@ -297,7 +298,7 @@ sub vntagmod {
}
my $my = $self->dbTagLinks(vid => $vid, uid => $self->authInfo->{id});
- my $tags = $self->dbVNTags($vid);
+ my $tags = $self->dbTagStats(vid => $vid, result => 9999);
my $frm;
@@ -343,8 +344,8 @@ sub vntagmod {
a href => "/g$t->{id}", $t->{name};
end;
td class => 'tc2';
- tagscore !$m->{vote} ? $t->{rating} : $t->{users} == 1 ? 0 : ($t->{rating}*$t->{users} - $m->{vote}) / ($t->{users}-1);
- i ' ('.($t->{users} - ($m->{vote} ? 1 : 0)).')';
+ tagscore !$m->{vote} ? $t->{rating} : $t->{cnt} == 1 ? 0 : ($t->{rating}*$t->{cnt} - $m->{vote}) / ($t->{cnt}-1);
+ i ' ('.($t->{cnt} - ($m->{vote} ? 1 : 0)).')';
end;
td class => 'tc3', sprintf '%.2f', $t->{spoiler};
td class => 'tc4', $m->{vote}||0;
@@ -359,6 +360,87 @@ sub vntagmod {
}
+sub usertags {
+ my($self, $uid) = @_;
+
+ my $u = $self->dbUserGet(uid => $uid)->[0];
+ return 404 if !$u;
+
+ my $f = $self->formValidate(
+ { name => 's', required => 0, default => 'cnt', enum => [ qw|cnt name| ] },
+ { name => 'o', required => 0, default => 'd', enum => [ 'a','d' ] },
+ { name => 'p', required => 0, default => 1, template => 'int' },
+ );
+ return 404 if $f->{_err};
+
+ # TODO: might want to use AJAX to load the VN list on request
+ my($list, $np) = $self->dbTagStats(
+ uid => $uid,
+ page => $f->{p},
+ order => ($f->{s}eq'cnt'?'COUNT(*)':'name').($f->{o}eq'a'?' ASC':' DESC'),
+ what => 'vns',
+ );
+
+ $self->htmlHeader(title => "Tags by $u->{username}");
+ $self->htmlMainTabs('u', $u, 'tags');
+ div class => 'mainbox';
+ h1 "Tags by $u->{username}";
+ if(@$list) {
+ p 'Warning: spoilery tags are not hidden in this list!';
+ } else {
+ p "$u->{username} doesn't seem to have used the tagging system yet...";
+ }
+ end;
+
+ if(@$list) {
+ $self->htmlBrowse(
+ class => 'tagstats',
+ options => $f,
+ nextpage => $np,
+ items => $list,
+ pageurl => "/u$u->{id}/tags?s=$f->{s};o=$f->{o}",
+ sorturl => "/u$u->{id}/tags",
+ header => [
+ sub {
+ td class => 'tc1';
+ b id => 'relhidall';
+ lit '<i>&#9656;</i> #VNs ';
+ end;
+ lit $f->{s} eq 'cnt' && $f->{o} eq 'a' ? "\x{25B4}" : qq|<a href="/u$u->{id}/tags?o=a;s=cnt">\x{25B4}</a>|;
+ lit $f->{s} eq 'cnt' && $f->{o} eq 'd' ? "\x{25BE}" : qq|<a href="/u$u->{id}/tags?o=d;s=cnt">\x{25BE}</a>|;
+ end;
+ },
+ [ 'Tag', 'name' ],
+ [ ' ', '' ],
+ ],
+ row => sub {
+ my($s, $n, $l) = @_;
+ Tr $n % 2 ? (class => 'odd') : ();
+ td class => 'tc1 relhid_but', id => "tag$l->{id}";
+ lit "<i>&#9656;</i> $l->{cnt}";
+ end;
+ td class => 'tc2', colspan => 2;
+ a href => "/g$l->{id}", $l->{name};
+ end;
+ end;
+ for(@{$l->{vns}}) {
+ Tr class => "relhid tag$l->{id}";
+ td class => 'tc1_1';
+ tagscore $_->{vote};
+ end;
+ td class => 'tc1_2';
+ a href => "/v$_->{vid}", title => $_->{original}||$_->{title}, shorten $_->{title}, 50;
+ end;
+ td class => 'tc1_3', !defined $_->{spoiler} ? ' ' : ['No spoiler', 'Minor spoiler', 'Major spoiler']->[$_->{spoiler}];
+ end;
+ }
+ },
+ );
+ }
+ $self->htmlFooter;
+}
+
+
sub tagtree {
my $self = shift;
diff --git a/lib/VNDB/Util/CommonHTML.pm b/lib/VNDB/Util/CommonHTML.pm
index ca87e599..0abc9cfc 100644
--- a/lib/VNDB/Util/CommonHTML.pm
+++ b/lib/VNDB/Util/CommonHTML.pm
@@ -47,6 +47,10 @@ sub htmlMainTabs {
li $sel eq 'list' ? (class => 'tabselected') : ();
a href => "/$id/list", 'list';
end;
+
+ li $sel eq 'tags' ? (class => 'tabselected') : ();
+ a href => "/$id/tags", 'tags';
+ end;
}
if($type eq 'v' && $self->authCan('tag')) {
diff --git a/lib/VNDB/Util/LayoutHTML.pm b/lib/VNDB/Util/LayoutHTML.pm
index f2a63c7b..de87bcaa 100644
--- a/lib/VNDB/Util/LayoutHTML.pm
+++ b/lib/VNDB/Util/LayoutHTML.pm
@@ -88,6 +88,7 @@ sub _menu {
a href => "$uid/wish", 'My Wishlist'; br;
a href => "/t$uid", 'My Messages'; br;
a href => "$uid/hist", 'My Recent Changes'; br;
+ a href => "$uid/tags", 'My Tags'; br;
br;
a href => '/v/new', 'Add Visual Novel'; br;
a href => '/p/new', 'Add Producer'; br;
diff --git a/static/f/script.js b/static/f/script.js
index 25dbeca4..7c28f060 100644
--- a/static/f/script.js
+++ b/static/f/script.js
@@ -394,7 +394,9 @@ DOMLoad(function() {
if(this.selectedIndex != 0)
location.href = location.href.replace(/\.[0-9]+/, '')+'/list?e='+this.options[this.selectedIndex].value;
};
+
// User VN list
+ // (might want to make this a bit more generic, as it's now also used for the user tag list)
i = x('relhidall');
if(i) {
var l = document.getElementsByTagName('tr');