diff options
author | Yorhel <git@yorhel.nl> | 2021-01-06 16:49:33 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2021-01-06 16:51:07 +0100 |
commit | 54742f26bbcf9f41c4bf6ed198f60e243388b723 (patch) | |
tree | 04ab78a1c4a121651fec9b03f78abbcff49af9a4 | |
parent | 38c25d78f5705312d7a6e1815d5eec251284e675 (diff) |
AdvSearch: Add VN subquery filter for releases + convert old "olang" filters
The UI does not allow nesting queries of the same type, like
"VN has a release which has a VN ..", but the server doesn't really
enforce this limitation at the moment.
(I mean, it would probably work, but such queries are going to be slow
and wouldn't be useful anyway)
-rw-r--r-- | elm/AdvSearch/Fields.elm | 19 | ||||
-rw-r--r-- | elm/AdvSearch/Lib.elm | 2 | ||||
-rw-r--r-- | elm/AdvSearch/Main.elm | 2 | ||||
-rw-r--r-- | lib/VNWeb/AdvSearch.pm | 1 | ||||
-rw-r--r-- | lib/VNWeb/Filters.pm | 2 |
5 files changed, 22 insertions, 4 deletions
diff --git a/elm/AdvSearch/Fields.elm b/elm/AdvSearch/Fields.elm index b51edda5..7d13dba3 100644 --- a/elm/AdvSearch/Fields.elm +++ b/elm/AdvSearch/Fields.elm @@ -3,6 +3,7 @@ module AdvSearch.Fields exposing (..) import Html exposing (..) import Html.Attributes exposing (..) import Array +import Set import Lib.Util exposing (..) import Lib.Html exposing (..) import Lib.DropDown as DD @@ -104,6 +105,7 @@ nestToQuery dat model = (V, C) -> wrap (QQuery 51 op) (V, S) -> wrap (QQuery 52 op) (C, S) -> wrap (QQuery 52 op) + (R, V) -> wrap (QQuery 53 op) _ -> wrap identity @@ -127,6 +129,7 @@ nestFromQuery ptype qtype dat q = (V, C, QQuery 51 op r) -> initSub op r (V, S, QQuery 52 op r) -> initSub op r (C, S, QQuery 52 op r) -> initSub op r + (R, V, QQuery 53 op r) -> initSub op r (_, _, QAnd l) -> if ptype == qtype then Just (init True l) else Nothing (_, _, QOr l) -> if ptype == qtype then Just (init False l) else Nothing _ -> Nothing @@ -140,8 +143,13 @@ nestView dat dd model = FMNest _ -> True _ -> False hasNest = List.any isNest model.fields + filterDat = + { dat + | level = if model.ptype /= model.qtype then 1 else dat.level+1 + , parentTypes = if model.ptype /= model.qtype then Set.insert (showQType model.ptype) dat.parentTypes else dat.parentTypes + } filters = List.indexedMap (\i f -> - Html.map (FSNest << NField i) <| fieldView { dat | level = if model.ptype /= model.qtype then 1 else dat.level+1 } f + Html.map (FSNest << NField i) <| fieldView filterDat f ) model.fields add = @@ -153,15 +161,17 @@ nestView dat dd model = let opts = case model.qtype of V -> [ V, R, C, S ] C -> [ C, S ] - R -> [] + R -> [ R, V ] S -> [] + fopts = List.filter (\t -> (not (Set.member (showQType t) filterDat.parentTypes))) opts f t = case t of V -> "VN" R -> "Release" C -> "Character" S -> if model.qtype == C then "Seiyuu" else "Staff" - in List.map (\t -> if t == model.addtype then b [] [ text (f t) ] else a [ href "#", onClickD (FSNest <| NAddType t) ] [ text (f t) ]) opts + in List.map (\t -> if t == model.addtype then b [] [ text (f t) ] else a [ href "#", onClickD (FSNest <| NAddType t) ] [ text (f t) ]) fopts ] + -- TODO: "Staff"/"Seiyuu" subquery filters should not be visible when S is in parentTypes , let lst = Array.toIndexedList fields |> List.filter (\(_,f) -> f.qtype == model.addtype && f.title /= "") in ul (if List.length lst > 6 then [ style "columns" "2" ] else []) <| List.map (\(n,f) -> @@ -185,6 +195,7 @@ nestView dat dd model = case (model.ptype, model.qtype) of (_, C) -> ("Has a character that matches these filters", "Does not have a character that matches these filters") (_, R) -> ("Has a release that matches these filters", "Does not have a release that matches these filters") + (_, V) -> ("Has a visual novel that matches these filters", "Does not have a visual novel that matches these filters") (V, S) -> ("Has staff that matches these filters", "Does not have staff that matches these filters") (C, S) -> ("Has a voice actor that matches these filters", "Does not have a voice actor that matches these filters") _ -> ("","") @@ -197,6 +208,7 @@ nestView dat dd model = case (model.ptype, model.qtype) of (_, C) -> "Char" (_, R) -> "Rel" + (_, V) -> "VN" (V, S) -> "Staff" (C, S) -> "Seiyuu" _ -> "" @@ -407,6 +419,7 @@ fields = , f R "Ero animation " 0 FMAniEro AS.init (AS.animatedFromQuery False) , f R "Story animation" 0 FMAniStory AS.init (AS.animatedFromQuery True) , f R "Engine" 0 FMEngine AEng.init AEng.fromQuery + , f R "" 0 FMNest (nestInit True R V []) (nestFromQuery R V) -- VN subtype , f C "Role" 1 FMRole AS.init AS.roleFromQuery , f C "Age" 0 FMAge AR.ageInit AR.ageFromQuery diff --git a/elm/AdvSearch/Lib.elm b/elm/AdvSearch/Lib.elm index 36373ede..51aa2882 100644 --- a/elm/AdvSearch/Lib.elm +++ b/elm/AdvSearch/Lib.elm @@ -6,6 +6,7 @@ import Html import Html.Attributes import Lib.Html import Dict +import Set import Gen.Api as GApi -- Generic dynamically typed representation of a query. @@ -171,6 +172,7 @@ inputOp onlyEq val msg = type alias Data = { objid : Int -- Incremental integer for global identifiers , level : Int -- Nesting level of the field being processed + , parentTypes : Set.Set String -- Only used for 'view' functions: query types that the current field is a subquery of , uid : Maybe Int , labels : List (Int, String) , defaultSpoil : Int diff --git a/elm/AdvSearch/Main.elm b/elm/AdvSearch/Main.elm index 23ec58f6..3149e375 100644 --- a/elm/AdvSearch/Main.elm +++ b/elm/AdvSearch/Main.elm @@ -92,6 +92,7 @@ loadQuery : Data -> GApi.ApiAdvSearchQuery -> (QType, Field, Data) loadQuery odat arg = let dat = { objid = 0 , level = 0 + , parentTypes = Set.empty , uid = odat.uid , labels = odat.labels , defaultSpoil = odat.defaultSpoil @@ -120,6 +121,7 @@ init : Recv -> Model init arg = let dat = { objid = 0 , level = 0 + , parentTypes = Set.empty , uid = arg.uid , labels = (0, "Unlabeled") :: List.map (\e -> (e.id, e.label)) arg.labels , defaultSpoil = arg.defaultSpoil diff --git a/lib/VNWeb/AdvSearch.pm b/lib/VNWeb/AdvSearch.pm index 6266a2f2..9637670a 100644 --- a/lib/VNWeb/AdvSearch.pm +++ b/lib/VNWeb/AdvSearch.pm @@ -375,6 +375,7 @@ f r => 62 => 'freeware', { uint => 1, range => [1,1] }, '=' => sub { 'r.freeware f r => 63 => 'doujin', { uint => 1, range => [1,1] }, '=' => sub { 'r.doujin' }; f r => 64 => 'uncensored',{uint => 1, range => [1,1] }, '=' => sub { 'r.uncensored' }; f r => 65 => 'official', { uint => 1, range => [1,1] }, '=' => sub { 'r.official' }; +f r => 53 => 'vn', 'v', '=' => sub { sql 'r.id IN(SELECT rv.id FROM releases_vn rv JOIN vn v ON v.id = rv.vid WHERE NOT v.hidden AND', $_, ')' }; diff --git a/lib/VNWeb/Filters.pm b/lib/VNWeb/Filters.pm index e38f7a06..923c3ff2 100644 --- a/lib/VNWeb/Filters.pm +++ b/lib/VNWeb/Filters.pm @@ -246,7 +246,7 @@ sub filter_release_adv { defined $fil->{released} ? [ 'released', $fil->{released} ? '<=' : '>', 1 ] : (), defined $fil->{minage} ? [ 'or', map [ 'minage', '=', $_ == -1 ? undef : $_ ], $fil->{minage}->@* ] : (), defined $fil->{lang} ? [ 'or', map [ 'lang', '=', $_ ], $fil->{lang}->@* ] : (), - defined $fil->{olang} ? () : (), # TODO: This isn't supported (yet? it's more like a VN filter). + defined $fil->{olang} ? [ 'vn', '=', [ 'or', map [ 'olang', '=', $_ ], $fil->{olang}->@* ] ] : (), defined $fil->{resolution} ? [ 'or', map [ 'resolution', '=', $_ eq 'unknown' ? [0,0] : $_ eq 'nonstandard' ? [0,1] : [split /x/] ], $fil->{resolution}->@* ] : (), defined $fil->{plat} ? [ 'or', map [ 'platform', '=', $_ eq 'unk' ? '' : $_ ], $fil->{plat}->@* ] : (), defined $fil->{prod_inc} ? [ 'or', map [ 'producer-id', '=', $_ ], $fil->{prod_inc}->@* ] : (), |