diff options
author | Yorhel <git@yorhel.nl> | 2021-01-18 16:15:39 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2021-01-18 16:15:54 +0100 |
commit | 512e82ef617f66f941811c1419ec14dc2313c83a (patch) | |
tree | 30b985470192214bfd78834e625531743f189690 /lib/VNWeb | |
parent | 074bf602f896ebd9eb3c8b2c130eca05299a44dc (diff) |
Staff::List: Convert to new AdvSearch system
Mostly copy-paste, nothing special going on here.
Diffstat (limited to 'lib/VNWeb')
-rw-r--r-- | lib/VNWeb/Filters.pm | 13 | ||||
-rw-r--r-- | lib/VNWeb/HTML.pm | 4 | ||||
-rw-r--r-- | lib/VNWeb/Staff/List.pm | 102 |
3 files changed, 116 insertions, 3 deletions
diff --git a/lib/VNWeb/Filters.pm b/lib/VNWeb/Filters.pm index 26cd9265..73f37e99 100644 --- a/lib/VNWeb/Filters.pm +++ b/lib/VNWeb/Filters.pm @@ -7,7 +7,7 @@ package VNWeb::Filters; use VNWeb::Prelude; use Exporter 'import'; -our @EXPORT = qw/filter_parse filter_vn_query filter_release_query filter_vn_adv filter_release_adv filter_char_adv/; +our @EXPORT = qw/filter_parse filter_vn_query filter_release_query filter_vn_adv filter_release_adv filter_char_adv filter_staff_adv/; my $VN = form_compile any => { @@ -285,4 +285,15 @@ sub filter_char_adv { ] } + +# 'truename' filter is ignored, not part of the AdvSearch interface +sub filter_staff_adv { + my($fil) = @_; + [ 'and', + defined $fil->{gender} ? [ 'or', map [ 'gender', '=', $_ ], $fil->{gender}->@* ] : (), + defined $fil->{role} ? [ 'or', map [ 'role', '=', $_ ], $fil->{role}->@* ] : (), + defined $fil->{lang} ? [ 'or', map [ 'lang', '=', $_ ], $fil->{lang}->@* ] : (), + ] +} + 1; diff --git a/lib/VNWeb/HTML.pm b/lib/VNWeb/HTML.pm index 059a103c..a52aacce 100644 --- a/lib/VNWeb/HTML.pm +++ b/lib/VNWeb/HTML.pm @@ -207,7 +207,7 @@ sub _menu_ { b_ class => 'grayedout', '> '; a_ href => '/g', 'Tags'; br_; a_ href => '/r', 'Releases'; br_; a_ href => '/p/all', 'Producers'; br_; - a_ href => '/s/all', 'Staff'; br_; + a_ href => '/s', 'Staff'; br_; a_ href => '/c', 'Characters'; br_; b_ class => 'grayedout', '> '; a_ href => '/i', 'Traits'; br_; a_ href => '/u/all', 'Users'; br_; @@ -807,7 +807,7 @@ sub searchbox_ { a_ href => '/v', $sel eq 'v' ? (class => 'sel') : (), 'Visual novels'; a_ href => '/r', $sel eq 'r' ? (class => 'sel') : (), 'Releases'; a_ href => '/p/all', $sel eq 'p' ? (class => 'sel') : (), 'Producers'; - a_ href => '/s/all', $sel eq 's' ? (class => 'sel') : (), 'Staff'; + a_ href => '/s', $sel eq 's' ? (class => 'sel') : (), 'Staff'; a_ href => '/c', $sel eq 'c' ? (class => 'sel') : (), 'Characters'; a_ href => '/g', $sel eq 'g' ? (class => 'sel') : (), 'Tags'; a_ href => '/i', $sel eq 'i' ? (class => 'sel') : (), 'Traits'; diff --git a/lib/VNWeb/Staff/List.pm b/lib/VNWeb/Staff/List.pm new file mode 100644 index 00000000..654fd766 --- /dev/null +++ b/lib/VNWeb/Staff/List.pm @@ -0,0 +1,102 @@ +package VNWeb::Staff::List; + +use VNWeb::Prelude; +use VNWeb::AdvSearch; +use VNWeb::Filters; + + +sub listing_ { + my($opt, $list, $count) = @_; + my sub url { '?'.query_encode %$opt, @_ } + paginate_ \&url, $opt->{p}, [$count, 150], 't'; + div_ class => 'mainbox staffbrowse', sub { + h1_ 'Staff list'; + ul_ sub { + li_ sub { + abbr_ class => "icons lang $_->{lang}", title => $LANGUAGE{$_->{lang}}, ''; + a_ href => "/s$_->{id}", title => $_->{original}||$_->{name}, $_->{name}; + } for @$list; + }; + }; + paginate_ \&url, $opt->{p}, [$count, 150], 'b'; +} + + +TUWF::get qr{/s(?:/(?<char>all|[a-z0]))?}, sub { + my $opt = tuwf->validate(get => + q => { onerror => undef }, + p => { upage => 1 }, + f => { advsearch_err => 's' }, + n => { onerror => [], type => 'array', scalar => 1, values => { anybool => 1 } }, + ch=> { onerror => [], type => 'array', scalar => 1, values => { onerror => undef, enum => ['0', 'a'..'z'] } }, + fil => { required => 0 }, + )->data; + $opt->{ch} = $opt->{ch}[0]; + $opt->{n} = $opt->{n}[0]; + + # compat with old URLs + my $oldch = tuwf->capture('char'); + $opt->{ch} //= $oldch if defined $oldch && $oldch ne 'all'; + + # URL compatibility with old filters + if(!$opt->{f}->{query} && $opt->{fil}) { + my $q = eval { + my $f = filter_parse s => $opt->{fil}; + $opt->{n} = $f->{truename} if defined $f->{truename}; + $f = filter_staff_adv $f; + tuwf->compile({ advsearch => 's' })->validate(@$f > 1 ? $f : undef)->data; + }; + if(!$q) { + warn "Filter compatibility conversion failed\n$@"; + } else { + return tuwf->resRedirect(tuwf->reqPath().'?'.query_encode(%$opt, fil => undef, f => $q), 'temp'); + } + } + + $opt->{f} = advsearch_default 's' if !$opt->{f}{query} && !defined tuwf->reqGet('f'); + + my @search = map { + my $l = '%'.sql_like($_).'%'; + length $_ > 0 ? sql '(sa.name ILIKE', \$l, "OR translate(sa.original,' ','') ILIKE", \$l, ')' : (); + } split /[ -,._]/, $opt->{q}||''; + + my $where = sql_and + $opt->{n} ? 's.aid = sa.aid' : (), + 'NOT s.hidden', $opt->{f}->sql_where(), @search, + defined($opt->{ch}) && $opt->{ch} ? sql('LOWER(SUBSTR(sa.name, 1, 1)) =', \$opt->{ch}) : (), + defined($opt->{ch}) && !$opt->{ch} ? sql('(ASCII(sa.name) <', \97, 'OR ASCII(sa.name) >', \122, ') AND (ASCII(sa.name) <', \65, 'OR ASCII(sa.name) >', \90, ')') : (); + + my $time = time; + my($count, $list); + db_maytimeout { + $count = tuwf->dbVali('SELECT count(*) FROM staff s JOIN staff_alias sa ON sa.id = s.id WHERE', $where); + $list = $count ? tuwf->dbPagei({results => 150, page => $opt->{p}}, ' + SELECT s.id, sa.name, sa.original, s.lang FROM staff s JOIN staff_alias sa ON sa.id = s.id WHERE', $where, 'ORDER BY sa.name, sa.aid' + ) : []; + } || (($count, $list) = (undef, [])); + $time = time - $time; + + framework_ title => 'Browse staff', sub { + div_ class => 'mainbox', sub { + h1_ 'Browse staff'; + form_ action => '/s', method => 'get', sub { + searchbox_ s => $opt->{q}//''; + p_ class => 'browseopts', sub { + button_ type => 'submit', name => 'ch', value => ($_//''), ($_//'') eq ($opt->{ch}//'') ? (class => 'optselected') : (), !defined $_ ? 'ALL' : $_ ? uc $_ : '#' + for (undef, 'a'..'z', 0); + }; + p_ class => 'browseopts', sub { + button_ type => 'submit', name => 'n', value => 0, !$opt->{n} ? (class => 'optselected') : (), 'Display aliases'; + button_ type => 'submit', name => 'n', value => 1, $opt->{n} ? (class => 'optselected') : (), 'Hide aliases'; + }; + input_ type => 'hidden', name => 'ch', value => $opt->{ch}//''; + input_ type => 'hidden', name => 'n', value => $opt->{n}; + $opt->{f}->elm_; + advsearch_msg_ $count, $time; + }; + }; + listing_ $opt, $list, $count if $count; + }; +}; + +1; |