diff options
author | Yorhel <git@yorhel.nl> | 2020-01-28 09:23:45 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2020-01-28 16:42:44 +0100 |
commit | 915ea70075d6ffced641ac52cf567acc747aa7eb (patch) | |
tree | 1f0955db45b2f6048b35165eddf7a1e3e3f1e781 /lib/VNDB | |
parent | 495e03c42b378bfd5ee9bb0c431bac45c5e2b330 (diff) |
v2rw: Convert the VN tagmod interface
This also changes the voting interface a little bit:
- Spoiler options are a bit more concise
- Mouse-over a button indicates what it does
- The -1 and -2 options are not available anymore
- Downvoted tags are hidden by default
- Moderators can now vote-and-overrule in a single go
Diffstat (limited to 'lib/VNDB')
-rw-r--r-- | lib/VNDB/DB/Tags.pm | 34 | ||||
-rw-r--r-- | lib/VNDB/Handler/Tags.pm | 161 |
2 files changed, 1 insertions, 194 deletions
diff --git a/lib/VNDB/DB/Tags.pm b/lib/VNDB/DB/Tags.pm index 875ff6e9..ed3ea9fe 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 dbTTTree dbTagEdit dbTagAdd dbTagMerge dbTagLinks dbTagLinkEdit dbTagStats dbTagWipeVotes|; +our @EXPORT = qw|dbTagGet dbTTTree dbTagEdit dbTagAdd dbTagMerge dbTagLinks dbTagStats dbTagWipeVotes|; # %options->{ id noid name search state searchable applicable page results what sort reverse } @@ -211,38 +211,6 @@ sub dbTagLinks { } -# Change a user's tags for a VN entry -sub dbTagLinkEdit { - my($self, $uid, $vid, $insert, $update, $delete, $overrule) = @_; - - # overrule - # 1. set ignore flag for everyone except $uid - $self->dbExec('UPDATE tags_vn SET ignore = ? WHERE tag = ? AND vid = ? AND uid <> ?', - $overrule->{$_}?1:0, $_, $vid, $uid) for(keys %$overrule); - # 2. make sure $uid isn't ignored when others are set to ignore - # (this happens when a mod takes over an other mods' overrule) - $self->dbExec('UPDATE tags_vn SET ignore = false WHERE tag = ? AND vid = ? AND uid = ?', - $_, $vid, $uid) for(grep $overrule->{$_}, keys %$overrule); - - # delete - $self->dbExec('DELETE FROM tags_vn WHERE vid = ? AND uid = ? AND tag IN(!l)', - $vid, $uid, [ keys %$delete ]) if keys %$delete; - - # insert - my $val = join ',', map '(?,?,?,?,?,?)', keys %$insert; - $self->dbExec("INSERT INTO tags_vn (tag, vid, uid, vote, spoiler, ignore) VALUES $val", map - +($_, $vid, $uid, $insert->{$_}[0], $insert->{$_}[1]<0?undef:$insert->{$_}[1], $insert->{$_}[2]?1:0), - keys %$insert) if keys %$insert; - - # update - $self->dbExec('UPDATE tags_vn SET vote = ?, spoiler = ?, date = NOW() WHERE tag = ? AND vid = ? AND uid = ?', - $update->{$_}[0], $update->{$_}[1]<0?undef:$update->{$_}[1], $_, $vid, $uid) for (keys %$update); - - # Update cache - $self->dbExec('SELECT tag_vn_calc(?)', $vid); -} - - # Fetch all tags related to a VN # Argument: %options->{ vid minrating state results what page sort reverse } # sort: name, rating diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm index 5acc948f..c44529cf 100644 --- a/lib/VNDB/Handler/Tags.pm +++ b/lib/VNDB/Handler/Tags.pm @@ -15,7 +15,6 @@ TUWF::register( qr{g([1-9]\d*)/(add)}, \&tagedit, qr{g/new}, \&tagedit, qr{g/list}, \&taglist, - qr{v([1-9]\d*)/tagmod}, \&vntagmod, qr{u([1-9]\d*)/tags}, \&usertags, qr{g}, \&tagindex, qr{g/debug}, \&fulltree, @@ -379,166 +378,6 @@ sub taglist { } -sub vntagmod { - my($self, $vid) = @_; - - my $v = $self->dbVNGet(id => $vid)->[0]; - return $self->resNotFound if !$v || $v->{hidden}; - - return $self->htmlDenied if !$self->authCan('tag'); - - my $tags = $self->dbTagStats(vid => $vid, results => 9999); - my $my = $self->dbTagLinks(vid => $vid, uid => $self->authInfo->{id}); - - if($self->reqMethod eq 'POST') { - return if !$self->authCheckCode; - my $frm = $self->formValidate( - { post => 'taglinks', required => 0, default => '', maxlength => 10240, regex => [ qr/^[1-9][0-9]*,-?[1-3],-?[0-2]( [1-9][0-9]*,-?[1-3],-?[0-2])*$/, 'meh' ] }, - { post => 'overrule', required => 0, multi => 1, template => 'id' }, - ); - return $self->resNotFound if $frm->{_err}; - - # convert some data in a more convenient structure for faster lookup - my %tags = map +($_->{id} => $_), @$tags; - my %old = map +($_->{tag} => $_), @$my; - my %new = map { my($tag, $vote, $spoiler) = split /,/; ($tag => [ $vote, $spoiler ]) } split / /, $frm->{taglinks}; - my %over = !$self->authCan('tagmod') || !$frm->{overrule}[0] ? () : (map $new{$_} ? ($_ => 1) : (), @{$frm->{overrule}}); - - # hashes which need to be filled, indicating what should be changed to the DB - my %delete; # tag => 1 - my %update; # tag => [ vote, spoiler ] (ignore flag is untouched) - my %insert; # tag => [ vote, spoiler, ignore ] - my %overrule; # tag => 0/1 - - # remove tags in the deleted state - delete $new{$_->{id}} for(keys %new ? @{$self->dbTagGet(id => [ keys %new ], state => 1)} : ()); - # and not-applicable tags - delete $new{$_->{id}} for(keys %new ? @{$self->dbTagGet(id => [ keys %new ], applicable => 0)} : ()); - - for my $t (keys %old, keys %new) { - my $prev_over = $old{$t} && !$old{$t}{ignore} && $tags{$t}{overruled}; - - # overrule checkbox has changed? make sure to (de-)overrule the tag votes - $overrule{$t} = $over{$t}?1:0 if (!$prev_over && $over{$t}) || ($prev_over && !$over{$t}); - - # tag deleted? - if($old{$t} && !$new{$t}) { - $delete{$t} = 1; - next; - } - - # and insert or update the vote - if(!$old{$t} && $new{$t}) { - # determine whether this vote is going to be ignored or not - my $ign = $tags{$t}{overruled} && !$prev_over && !$over{$t}; - $insert{$t} = [ $new{$t}[0], $new{$t}[1], $ign ]; - } elsif($old{$t}{vote} != $new{$t}[0] || (defined $old{$t}{spoiler} ? $old{$t}{spoiler} : -1) != $new{$t}[1]) { - $update{$t} = [ $new{$t}[0], $new{$t}[1] ]; - } - } - - $self->dbTagLinkEdit($self->authInfo->{id}, $vid, \%insert, \%update, \%delete, \%overrule); - - # need to re-fetch the tags and tag links, as these have been modified - $tags = $self->dbTagStats(vid => $vid, results => 9999); - $my = $self->dbTagLinks(vid => $vid, uid => $self->authInfo->{id}); - } - - - my $title = "Add/remove tags for $v->{title}"; - $self->htmlHeader(title => $title, noindex => 1); - $self->htmlMainTabs('v', $v, 'tagmod'); - div class => 'mainbox'; - h1 $title; - div class => 'notice'; - h2 'Tagging'; - ul; - li; txt 'Make sure you have read the '; a href => '/d10', 'guidelines'; txt '!'; end; - li 'Don\'t forget to hit the submit button on the bottom of the page to make your changes permanent.'; - end; - end; - end 'div'; - $self->htmlForm({ action => "/v$vid/tagmod", nosubmit => 1 }, tagmod => [ 'Tags', - [ hidden => short => 'taglinks', value => '' ], - [ static => nolabel => 1, content => sub { - table class => 'tgl stripe'; - thead; - Tr; - td ''; - td colspan => $self->authCan('tagmod') ? 3 : 2, class => 'tc_you', 'You'; - td colspan => 3, class => 'tc_others', 'Others'; - end; - Tr; - td class => 'tc_tagname', 'Tag'; - td class => 'tc_myvote', 'Rating'; - td class => 'tc_myover', 'O' if $self->authCan('tagmod'); - td class => 'tc_myspoil', 'Spoiler'; - td class => 'tc_allvote', 'Rating'; - td class => 'tc_allspoil', 'Spoiler'; - td class => 'tc_allwho', ''; - end; - end 'thead'; - tfoot; Tr; - td colspan => 6; - input type => 'submit', class => 'submit', value => 'Save changes', style => 'float: right'; - input id => 'tagmod_tag', type => 'text', class => 'text', value => ''; - input id => 'tagmod_add', type => 'button', class => 'submit', value => 'Add tag'; - br; - p; - txt 'Check the '; a href => '/g', 'tag list'; txt ' to browse all available tags.'; - br; - txt 'Can\'t find what you\'re looking for? '; a href => '/g/new', 'Request a new tag'; txt '.'; - end; - end; - end; end 'tfoot'; - tbody id => 'tagtable'; - _tagmod_list($self, $vid, $tags, $my); - end 'tbody'; - end 'table'; - } ], - ]); - $self->htmlFooter; -} - -sub _tagmod_list { - my($self, $vid, $tags, $my) = @_; - - my %my = map +($_->{tag} => $_), @$my; - - for my $cat (keys %TAG_CATEGORY) { - my @tags = grep $_->{cat} eq $cat, @$tags; - next if !@tags; - Tr class => 'tagmod_cat'; - td colspan => 7, $TAG_CATEGORY{$cat}; - end; - for my $t (@tags) { - my $m = $my{$t->{id}}; - Tr id => "tgl_$t->{id}"; - td class => 'tc_tagname'; a href => "/g$t->{id}", $t->{name}; end; - td class => 'tc_myvote', $m->{vote}||0; - if($self->authCan('tagmod')) { - td class => 'tc_myover'; - input type => 'checkbox', name => 'overrule', value => $t->{id}, - $m->{vote} && !$m->{ignore} && $t->{overruled} ? (checked => 'checked') : () - if $t->{cnt} > 1; - end; - } - td class => 'tc_myspoil', defined $m->{spoiler} ? $m->{spoiler} : -1; - td class => 'tc_allvote'; - VNWeb::Tags::Lib::tagscore_($t->{rating}); - i $t->{overruled} ? (class => 'grayedout') : (), " ($t->{cnt})"; - b class => 'standout', style => 'font-weight: bold', title => 'Tag overruled. All votes other than that of the moderator who overruled it will be ignored.', ' !' if $t->{overruled}; - end; - td class => 'tc_allspoil', sprintf '%.2f', $t->{spoiler}; - td class => 'tc_allwho'; - a href => "/g/links?v=$vid;t=$t->{id}", 'Who?'; - end; - end; - } - } -} - - sub tagindex { my $self = shift; |