diff options
author | Yorhel <git@yorhel.nl> | 2011-03-20 13:01:14 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2011-03-20 13:01:14 +0100 |
commit | f85a78f081b870dc98e08a62c1f5df7b21c9ac5b (patch) | |
tree | 0b177f38f5f681fde818697274a09c4d715c6551 | |
parent | e161985cfa8ffbd3e0b093acd70764295f4e3284 (diff) |
chardb: Added simple character browser + search
-rw-r--r-- | data/lang.txt | 32 | ||||
-rw-r--r-- | data/style.css | 9 | ||||
-rw-r--r-- | lib/VNDB/DB/Chars.pm | 17 | ||||
-rw-r--r-- | lib/VNDB/Handler/Chars.pm | 82 | ||||
-rw-r--r-- | lib/VNDB/Util/CommonHTML.pm | 1 |
5 files changed, 134 insertions, 7 deletions
diff --git a/data/lang.txt b/data/lang.txt index 17d926d4..60c8676e 100644 --- a/data/lang.txt +++ b/data/lang.txt @@ -2158,6 +2158,13 @@ cs : Producenti hu : Keszítők nl : Producenten +:_searchbox_chars +en : Characters +ru*: +cs*: +hu*: +nl : Karakters + :_searchbox_tags en : Tags ru : Теги @@ -5408,6 +5415,31 @@ hu*: nl : VN is al geselecteerd. +# Character browser (/c/*) + +:_charb_title +en : Browse characters +ru*: +cs*: +hu*: +nl : Browse karakters + +:_charb_noresults +en : No results +ru*: +cs*: +hu*: +nl : Geen resultaten + +:_charb_noresults_msg +en : No characters found that matched your criteria. +ru*: +cs*: +hu*: +nl : Geen karakters gevonden die aan je kriteria voldoen. + + + diff --git a/data/style.css b/data/style.css index 8b916fa2..0bc9973d 100644 --- a/data/style.css +++ b/data/style.css @@ -887,6 +887,15 @@ div.chardetails.charsep { padding-top: 5px; margin-top: 5px; border-top: 1px sol #jt_box_chare_vns td.tc_del { padding-left: 5px } #jt_box_chare_vns td.tc_vnadd input { width: 280px } +/***** Char browse *****/ + +div.charb table { table-layout: fixed } +div.charb td { white-space: nowrap } +div.charb td.tc1 { text-align: right; width: 40px; padding-left: 0!important; padding-bottom: 0 } +div.charb td.tc2 { overflow: hidden } +div.charb td.tc2 b { margin-left: 10px } +div.charb td.tc2 b a { color: $grayedout$!important } + /***** Documentation pages *****/ diff --git a/lib/VNDB/DB/Chars.pm b/lib/VNDB/DB/Chars.pm index 337d0ef8..8fb01ebf 100644 --- a/lib/VNDB/DB/Chars.pm +++ b/lib/VNDB/DB/Chars.pm @@ -8,7 +8,7 @@ use Exporter 'import'; our @EXPORT = qw|dbCharGet dbCharRevisionInsert dbCharImageId|; -# options: id rev instance traitspoil trait_inc trait_exc what results page +# options: id rev instance traitspoil trait_inc trait_exc char what results page # what: extended traits vns changes sub dbCharGet { my $self = shift; @@ -20,6 +20,8 @@ sub dbCharGet { @_ ); + $o{search} =~ s/%//g if $o{search}; + my %where = ( !$o{id} && !$o{rev} ? ( 'c.hidden = FALSE' => 1 ) : (), $o{id} ? ( 'c.id = ?' => $o{id} ) : (), @@ -27,6 +29,12 @@ sub dbCharGet { $o{notid} ? ( 'c.id <> ?' => $o{notid} ) : (), $o{instance} ? ( 'cr.main = ?' => $o{instance} ) : (), $o{vid} ? ( 'cr.id IN(SELECT cid FROM chars_vns WHERE vid = ?)' => $o{vid} ) : (), + $o{search} ? ( + '(cr.name ILIKE ? OR cr.original ILIKE ? OR cr.alias ILIKE ?)', [ map '%%'.$o{search}.'%%', 1..3 ] ) : (), + $o{char} ? ( + 'LOWER(SUBSTR(cr.name, 1, 1)) = ?' => $o{char} ) : (), + defined $o{char} && !$o{char} ? ( + '(ASCII(cr.name) < 97 OR ASCII(cr.name) > 122) AND (ASCII(cr.name) < 65 OR ASCII(cr.name) > 90)' => 1 ) : (), $o{trait_inc} ? ( 'c.id IN(SELECT cid FROM traits_chars WHERE tid IN(!l) AND spoil <= ? GROUP BY cid HAVING COUNT(tid) = ?)', [ ref $o{trait_inc} ? $o{trait_inc} : [$o{trait_inc}], $o{traitspoil}, ref $o{trait_inc} ? $#{$o{trait_inc}}+1 : 1 ]) : (), @@ -34,8 +42,8 @@ sub dbCharGet { 'c.id NOT IN(SELECT cid FROM traits_chars WHERE tid IN(!l))' => [ ref $o{trait_exc} ? $o{trait_exc} : [$o{trait_exc}] ] ) : (), ); - my @select = (qw|c.id cr.name cr.original|, 'cr.id AS cid'); - push @select, qw|c.hidden c.locked cr.alias cr.desc cr.image cr.b_month cr.b_day cr.s_bust cr.s_waist cr.s_hip cr.height cr.weight cr.bloodt cr.gender cr.main cr.main_spoil| if $o{what} =~ /extended/; + my @select = (qw|c.id cr.name cr.original cr.gender|, 'cr.id AS cid'); + push @select, qw|c.hidden c.locked cr.alias cr.desc cr.image cr.b_month cr.b_day cr.s_bust cr.s_waist cr.s_hip cr.height cr.weight cr.bloodt cr.main cr.main_spoil| if $o{what} =~ /extended/; push @select, qw|h.requester h.comments c.latest u.username h.rev h.ihid h.ilock|, "extract('epoch' from h.added) as added" if $o{what} =~ /changes/; my @join; @@ -47,7 +55,8 @@ sub dbCharGet { SELECT !s FROM chars_rev cr !s - !W|, + !W + ORDER BY cr.name|, join(', ', @select), join(' ', @join), \%where ); diff --git a/lib/VNDB/Handler/Chars.pm b/lib/VNDB/Handler/Chars.pm index f8c5a4e7..25be9487 100644 --- a/lib/VNDB/Handler/Chars.pm +++ b/lib/VNDB/Handler/Chars.pm @@ -3,7 +3,7 @@ package VNDB::Handler::Chars; use strict; use warnings; -use TUWF ':html'; +use TUWF ':html', 'uri_escape'; use Exporter 'import'; use VNDB::Func; @@ -13,6 +13,7 @@ TUWF::register( qr{c([1-9]\d*)(?:\.([1-9]\d*))?} => \&page, qr{c(?:([1-9]\d*)(?:\.([1-9]\d*))?/(edit|copy)|/new)} => \&edit, + qr{c/([a-z0]|all)} => \&list, ); @@ -187,11 +188,11 @@ sub charTable { # special case: all releases, no exceptions if(!$vn && @r == 1 && !$r[0]{rid}) { txt mt("_charrole_$r[0]{role}").' - '; - a href => "/v$r[0]{vid}", $r[0]{vntitle}; + a href => "/v$r[0]{vid}/chars", $r[0]{vntitle}; next; } # otherwise, print VN title and list releases separately - a href => "/v$r[0]{vid}", $r[0]{vntitle} if !$vn; + a href => "/v$r[0]{vid}/chars", $r[0]{vntitle} if !$vn; for(@r) { br if !$vn || $_ != $r[0]; b class => 'grayedout', '> '; @@ -424,5 +425,80 @@ sub _uploadimage { } +sub list { + my($self, $fch) = @_; + + my $f = $self->formValidate( + { get => 'p', required => 0, default => 1, template => 'int' }, + { get => 'q', required => 0, default => '' }, + ); + return $self->resNotFound if $f->{_err}; + + my($list, $np) = $self->dbCharGet( + $fch ne 'all' ? ( char => $fch ) : (), + $f->{q} ? ( search => $f->{q} ) : (), + results => 50, + page => $f->{p}, + what => 'vns', + ); + + $self->htmlHeader(title => mt '_charb_title'); + + my $quri = uri_escape($f->{q}); + div class => 'mainbox'; + h1 mt '_charb_title'; + form action => '/c/all', 'accept-charset' => 'UTF-8', method => 'get'; + $self->htmlSearchBox('c', $f->{q}); + end; + p class => 'browseopts'; + for ('all', 'a'..'z', 0) { + a href => "/c/$_?q=$quri", $_ eq $fch ? (class => 'optselected') : (), $_ eq 'all' ? mt('_char_all') : $_ ? uc $_ : '#'; + } + end; + end; + + if(!@$list) { + div class => 'mainbox'; + h1 mt '_charb_noresults'; + p mt '_charb_noresults_msg'; + end; + } + + my $uri = "/c/$fch?q=$quri"; + @$list && $self->htmlBrowse( + class => 'charb', + items => $list, + options => $f, + nextpage => $np, + pageurl => $uri, + sorturl => $uri, + header => [ [ '' ], [ '' ] ], + row => sub { + my($s, $n, $l) = @_; + Tr $n % 2 ? (class => 'odd') : (); + td class => 'tc1'; + cssicon "gen $l->{gender}", mt "_gender_$l->{gender}" if $l->{gender} ne 'unknown'; + end; + td class => 'tc2'; + a href => "/c$l->{id}", title => $l->{original}||$l->{name}, shorten $l->{name}, 50; + b class => 'grayedout'; + my $i = 1; + my %vns; + for (@{$l->{vns}}) { + next if $_->{spoil} || $vns{$_->{vid}}++; + last if $i++ > 4; + txt ', ' if $i > 2; + a href => "/v$_->{vid}/chars", title => $_->{vntitle}, shorten $_->{vntitle}, 30; + } + end; + end; + end; + } + ); + + $self->htmlFooter; +} + + 1; diff --git a/lib/VNDB/Util/CommonHTML.pm b/lib/VNDB/Util/CommonHTML.pm index a146a098..41370b4b 100644 --- a/lib/VNDB/Util/CommonHTML.pm +++ b/lib/VNDB/Util/CommonHTML.pm @@ -407,6 +407,7 @@ sub htmlSearchBox { a href => '/v/all', $sel eq 'v' ? (class => 'sel') : (), mt '_searchbox_vn'; a href => '/r', $sel eq 'r' ? (class => 'sel') : (), mt '_searchbox_releases'; a href => '/p/all', $sel eq 'p' ? (class => 'sel') : (), mt '_searchbox_producers'; + a href => '/c/all', $sel eq 'c' ? (class => 'sel') : (), mt '_searchbox_chars'; a href => '/g', $sel eq 'g' ? (class => 'sel') : (), mt '_searchbox_tags'; a href => '/i', $sel eq 'i' ? (class => 'sel') : (), mt '_searchbox_traits'; a href => '/u/all', $sel eq 'u' ? (class => 'sel') : (), mt '_searchbox_users'; |