diff options
author | Yorhel <git@yorhel.nl> | 2009-05-10 14:48:34 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2009-05-10 14:48:34 +0200 |
commit | d3e270d6987cfe696ee2c2e25bb344f242f53a1e (patch) | |
tree | 11343e05596afea0ba795c913d68d247eaa336ee | |
parent | 31c7f61c58686e39645a45fa2feeb435ac023e7f (diff) |
Added search field on release browser
-rw-r--r-- | data/style.css | 4 | ||||
-rw-r--r-- | lib/VNDB/DB/Releases.pm | 20 | ||||
-rw-r--r-- | lib/VNDB/Handler/Producers.pm | 4 | ||||
-rw-r--r-- | lib/VNDB/Handler/Releases.pm | 11 | ||||
-rw-r--r-- | lib/VNDB/Handler/Tags.pm | 8 | ||||
-rw-r--r-- | lib/VNDB/Handler/VNBrowse.pm | 4 |
6 files changed, 36 insertions, 15 deletions
diff --git a/data/style.css b/data/style.css index 3b478cca..6f643b97 100644 --- a/data/style.css +++ b/data/style.css @@ -429,13 +429,13 @@ table thead td { font-weight: bold; background-color: $secbg$; } -form.search { +fieldset.search { display: block; width: 100%; text-align: center; margin: 0 0 10px 0; } -form.search .submit { +fieldset.search .submit { padding: 0 1px; } diff --git a/lib/VNDB/DB/Releases.pm b/lib/VNDB/DB/Releases.pm index da50a6d8..4aa844a8 100644 --- a/lib/VNDB/DB/Releases.pm +++ b/lib/VNDB/DB/Releases.pm @@ -9,7 +9,7 @@ use Exporter 'import'; our @EXPORT = qw|dbReleaseGet dbReleaseAdd dbReleaseEdit|; -# Options: id vid rev order unreleased page results what date platforms languages type minage +# Options: id vid rev order unreleased page results what date platforms languages type minage search # What: extended changes vn producers platforms media sub dbReleaseGet { my($self, %o) = @_; @@ -18,7 +18,7 @@ sub dbReleaseGet { $o{what} ||= ''; $o{order} ||= 'rr.released ASC'; - my %where = ( + my @where = ( !$o{id} && !$o{rev} ? ( 'r.hidden = FALSE' => 0 ) : (), $o{id} ? ( @@ -44,6 +44,20 @@ sub dbReleaseGet { 'rr.patch = ?', $o{patch} == 1 ? 1 : 0) : (), ); + if($o{search}) { + for (split /[ -,._]/, $o{search}) { + s/%//g; + next if length($_) < 2; + if(/^\d+$/ && gtintype($_)) { + push @where, 'rr.gtin = ?', $_; + } else { + $_ = "%$_%"; + push @where, '(rr.title ILIKE ? OR rr.original ILIKE ? OR rr.catalog = ?)', + [ $_, $_, $_ ]; + } + } + } + my @join = ( $o{rev} ? 'JOIN releases r ON r.id = rr.rid' : 'JOIN releases r ON rr.id = r.latest', $o{vid} ? 'JOIN releases_vn rv ON rv.rid = rr.id' : (), @@ -66,7 +80,7 @@ sub dbReleaseGet { !s !W ORDER BY !s|, - join(', ', @select), join(' ', @join), \%where, $o{order} + join(', ', @select), join(' ', @join), \@where, $o{order} ); if(@$r && $o{what} =~ /(vn|producers|platforms|media)/) { diff --git a/lib/VNDB/Handler/Producers.pm b/lib/VNDB/Handler/Producers.pm index 7f43dd78..2aaa241d 100644 --- a/lib/VNDB/Handler/Producers.pm +++ b/lib/VNDB/Handler/Producers.pm @@ -171,8 +171,8 @@ sub list { div class => 'mainbox'; h1 'Browse producers'; - form class => 'search', action => '/p/all', 'accept-charset' => 'UTF-8', method => 'get'; - fieldset; + form action => '/p/all', 'accept-charset' => 'UTF-8', method => 'get'; + fieldset class => 'search'; input type => 'text', name => 'q', id => 'q', class => 'text', value => $f->{q}; input type => 'submit', class => 'submit', value => 'Search!'; end; diff --git a/lib/VNDB/Handler/Releases.pm b/lib/VNDB/Handler/Releases.pm index 8ad8396a..2a2ea21b 100644 --- a/lib/VNDB/Handler/Releases.pm +++ b/lib/VNDB/Handler/Releases.pm @@ -431,6 +431,7 @@ sub browse { { name => 'p', required => 0, default => 1, template => 'int' }, { name => 's', required => 0, default => 'title', enum => [qw|released minage title|] }, { name => 'o', required => 0, default => 'a', enum => ['a', 'd'] }, + { name => 'q', required => 0, default => '', maxlength => 500 }, #{ name => 't', required => 0, default => ((gmtime)[5]+1900)*100+(gmtime)[4]+1, template => 'int' }, { name => 'ln', required => 0, multi => 1, default => '', enum => [ keys %{$self->{languages}} ] }, { name => 'pl', required => 0, multi => 1, default => '', enum => [ keys %{$self->{platforms}} ] }, @@ -447,6 +448,7 @@ sub browse { page => $f->{p}, results => 50, #date => $f->{t}, + $f->{q} ? (search => $f->{q}) : (), $f->{pl}[0] ? (platforms => $f->{pl}) : (), $f->{ln}[0] ? (languages => $f->{ln}) : (), $f->{tp} >= 0 ? (type => $f->{tp}) : (), @@ -455,7 +457,7 @@ sub browse { what => 'platforms', ); - my $url = "/r?tp=$f->{tp};pa=$f->{pa};ma_m=$f->{ma_m};ma_a=$f->{ma_a}"; + my $url = "/r?tp=$f->{tp};pa=$f->{pa};ma_m=$f->{ma_m};ma_a=$f->{ma_a};q=$f->{q}"; $_&&($url .= ";ln=$_") for @{$f->{ln}}; $_&&($url .= ";pl=$_") for @{$f->{pl}}; @@ -500,10 +502,15 @@ sub browse { sub _filters { my($self, $f) = @_; - form method => 'get', action => '/r'; + form method => 'get', action => '/r', 'accept-charset' => 'UTF-8'; div class => 'mainbox'; h1 'Browse releases'; + fieldset class => 'search'; + input type => 'text', name => 'q', id => 'q', class => 'text', value => $f->{q}; + input type => 'submit', class => 'submit', value => 'Search!'; + end; + #p class => 'center'; # # you know, date calculation on strangely formatted integers really isn't so bad :-) # my $t = $f->{t}; diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm index d10de195..6838e7c7 100644 --- a/lib/VNDB/Handler/Tags.pm +++ b/lib/VNDB/Handler/Tags.pm @@ -367,8 +367,8 @@ sub taglist { $self->htmlHeader(title => $title); div class => 'mainbox'; h1 $title; - form class => 'search', action => '/g/list', 'accept-charset' => 'UTF-8', method => 'get'; - fieldset; + form action => '/g/list', 'accept-charset' => 'UTF-8', method => 'get'; + fieldset class => 'search'; input type => 'hidden', name => 't', value => $f->{t}; input type => 'text', name => 'q', id => 'q', class => 'text', value => $f->{q}; input type => 'submit', class => 'submit', value => 'Search!'; @@ -589,8 +589,8 @@ sub tagindex { div class => 'mainbox'; a class => 'addnew', href => "/g/new", ($self->authCan('tagmod')?'Create':'Request').' new tag' if $self->authCan('tag'); h1 'Search tags'; - form class => 'search', action => '/g/list', 'accept-charset' => 'UTF-8', method => 'get'; - fieldset; + form action => '/g/list', 'accept-charset' => 'UTF-8', method => 'get'; + fieldset class => 'search'; input type => 'text', name => 'q', id => 'q', class => 'text'; input type => 'submit', class => 'submit', value => 'Search!'; end; diff --git a/lib/VNDB/Handler/VNBrowse.pm b/lib/VNDB/Handler/VNBrowse.pm index f50a8500..03c4a8ce 100644 --- a/lib/VNDB/Handler/VNBrowse.pm +++ b/lib/VNDB/Handler/VNBrowse.pm @@ -117,8 +117,8 @@ sub _filters { div class => 'mainbox'; h1 'Browse visual novels'; - form class => 'search', action => '/v/all', 'accept-charset' => 'UTF-8', method => 'get'; - fieldset; + form action => '/v/all', 'accept-charset' => 'UTF-8', method => 'get'; + fieldset class => 'search'; input type => 'text', name => 'q', id => 'q', class => 'text', value => $f->{q}; input type => 'submit', class => 'submit', value => 'Search!'; end; |