diff options
author | Yorhel <git@yorhel.nl> | 2020-11-24 10:36:04 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2020-11-24 10:36:04 +0100 |
commit | 3cfbd795f0cd8756edc1bb69e9248fed72fe59f7 (patch) | |
tree | 51fa98ebd572119137abb2da25702b5a003d1c00 /elm | |
parent | f127e412285bbdc5009368acd8eec1a8fb63cf5c (diff) |
AdvSearch: Add character subquery and role/bloodtype/sex filters
Diffstat (limited to 'elm')
-rw-r--r-- | elm/AdvSearch/Fields.elm | 45 | ||||
-rw-r--r-- | elm/AdvSearch/Query.elm | 2 | ||||
-rw-r--r-- | elm/AdvSearch/Set.elm | 81 |
3 files changed, 123 insertions, 5 deletions
diff --git a/elm/AdvSearch/Fields.elm b/elm/AdvSearch/Fields.elm index e188fbea..a18fdf76 100644 --- a/elm/AdvSearch/Fields.elm +++ b/elm/AdvSearch/Fields.elm @@ -17,7 +17,7 @@ import AdvSearch.Query exposing (..) -- "Nested" fields are a container for other fields. -- The code for nested fields is tightly coupled with the generic 'Field' abstraction below. -type NestType = NAnd | NOr | NRel | NRelNeg +type NestType = NAnd | NOr | NRel | NRelNeg | NChar | NCharNeg type alias NestModel = { ntype : NestType @@ -85,6 +85,8 @@ nestToQuery model = (_, [] ) -> Nothing (NRel, [x]) -> Just (QQuery 50 Eq x) (NRelNeg, [x]) -> Just (QQuery 50 Ne x) + (NChar, [x]) -> Just (QQuery 51 Eq x) + (NCharNeg,[x]) -> Just (QQuery 51 Ne x) (_, [x]) -> Just x (NAnd, xs ) -> Just (QAnd xs) (NOr, xs ) -> Just (QOr xs) @@ -103,7 +105,8 @@ nestFromQuery ntype qtype dat q = Ne -> Just (init ntNeg qt [val]) _ -> Nothing in case (qtype, ntype, q) of - (V, NRel, QQuery 50 op r) -> initSub op NRel NRelNeg R r + (V, NRel, QQuery 50 op r) -> initSub op NRel NRelNeg R r + (V, NChar, QQuery 51 op r) -> initSub op NChar NCharNeg C r (_, NAnd, QAnd l) -> Just (init NAnd qtype l) (_, NOr, QOr l) -> Just (init NOr qtype l) _ -> Nothing @@ -149,6 +152,8 @@ nestView dat model = NOr -> "Or" NRel -> "Rel" NRelNeg -> "¬Rel" + NChar -> "Char" + NCharNeg-> "¬Char" cont () = [ ul [] <| @@ -156,9 +161,13 @@ nestView dat model = then [ li [] [ linkRadio (model.ntype == NAnd) (NType NAnd) [ text "And: All filters must match" ] ] , li [] [ linkRadio (model.ntype == NOr ) (NType NOr ) [ text "Or: At least one filter must match" ] ] ] - else [ li [] [ linkRadio (model.ntype == NRel) (NType NRel) [ text "Has a release that matches these filters" ] ] + else if model.ntype == NRel || model.ntype == NRelNeg + then [ li [] [ linkRadio (model.ntype == NRel) (NType NRel) [ text "Has a release that matches these filters" ] ] , li [] [ linkRadio (model.ntype == NRelNeg) (NType NRelNeg) [ text "Does not have a release that matches these filters" ] ] ] + else [ li [] [ linkRadio (model.ntype == NChar) (NType NChar) [ text "Has a character that matches these filters" ] ] + , li [] [ linkRadio (model.ntype == NCharNeg) (NType NCharNeg) [ text "Does not have a character that matches these filters" ] ] + ] ] body = div [] @@ -188,6 +197,10 @@ type FieldModel | FMOLang (AS.Model String) | FMPlatform (AS.Model String) | FMLength (AS.Model Int) + | FMRole (AS.Model String) + | FMBlood (AS.Model String) + | FMSexChar (AS.Model String) + | FMSexSpoil (AS.Model String) | FMDeveloper AP.Model | FMRDate AR.Model | FMTag AG.Model @@ -199,6 +212,10 @@ type FieldMsg | FSOLang (AS.Msg String) | FSPlatform (AS.Msg String) | FSLength (AS.Msg Int) + | FSRole (AS.Msg String) + | FSBlood (AS.Msg String) + | FSSexChar (AS.Msg String) + | FSSexSpoil (AS.Msg String) | FSDeveloper AP.Msg | FSRDate AR.Msg | FSTag AG.Msg @@ -236,6 +253,8 @@ fields = , f V "Or" Nothing FMNest (nestInit NOr V []) (nestFromQuery NOr V) , f R "And" Nothing FMNest (nestInit NAnd R []) (nestFromQuery NAnd R) , f R "Or" Nothing FMNest (nestInit NOr R []) (nestFromQuery NOr R) + , f C "And" Nothing FMNest (nestInit NAnd C []) (nestFromQuery NAnd C) + , f C "Or" Nothing FMNest (nestInit NOr C []) (nestFromQuery NOr C) , f V "Language" (Just 1) FMLang AS.init AS.langFromQuery , f V "Original language" (Just 2) FMOLang AS.init AS.olangFromQuery @@ -246,13 +265,19 @@ fields = , f V "" Nothing FMTag AG.init (AG.fromQuery 2) , f V "Length" Nothing FMLength AS.init AS.lengthFromQuery , f V "Developer" Nothing FMDeveloper AP.init AP.devFromQuery - , f V "Release" Nothing FMNest (nestInit NRel R []) (nestFromQuery NRel V) , f V "Release date" Nothing FMRDate AR.init AR.fromQuery + , f V "Release" Nothing FMNest (nestInit NRel R []) (nestFromQuery NRel V) + , f V "Character" Nothing FMNest (nestInit NChar C []) (nestFromQuery NChar V) , f R "Language" (Just 1) FMLang AS.init AS.langFromQuery , f R "Platform" (Just 2) FMPlatform AS.init AS.platformFromQuery , f R "Developer" Nothing FMDeveloper AP.init AP.devFromQuery , f R "Release date" Nothing FMRDate AR.init AR.fromQuery + + , f C "Role" (Just 1) FMRole AS.init AS.roleFromQuery + , f C "Blood type" Nothing FMBlood AS.init AS.bloodFromQuery + , f C "Sex" (Just 2) FMSexChar AS.init (AS.sexFromQuery AS.SexChar) + , f C "Sex (spoiler)" Nothing FMSexSpoil AS.init (AS.sexFromQuery AS.SexSpoil) ] @@ -285,6 +310,10 @@ fieldUpdate dat msg_ (num, dd, model) = (FSOLang msg, FMOLang m) -> maps FMOLang (AS.update msg m) (FSPlatform msg, FMPlatform m) -> maps FMPlatform (AS.update msg m) (FSLength msg, FMLength m) -> maps FMLength (AS.update msg m) + (FSRole msg, FMRole m) -> maps FMRole (AS.update msg m) + (FSBlood msg, FMBlood m) -> maps FMBlood (AS.update msg m) + (FSSexChar msg, FMSexChar m) -> maps FMSexChar (AS.update msg m) + (FSSexSpoil msg, FMSexSpoil m) -> maps FMSexSpoil (AS.update msg m) (FSDeveloper msg,FMDeveloper m)-> mapf FMDeveloper FSDeveloper (AP.update dat msg m) (FSRDate msg, FMRDate m) -> maps FMRDate (AR.update msg m) (FSTag msg, FMTag m) -> mapf FMTag FSTag (AG.update dat msg m) @@ -317,6 +346,10 @@ fieldView dat (_, dd, model) = FMOLang m -> vs FSOLang (AS.langView True m) FMPlatform m -> vs FSPlatform (AS.platformView m) FMLength m -> vs FSLength (AS.lengthView m) + FMRole m -> vs FSRole (AS.roleView m) + FMBlood m -> vs FSBlood (AS.bloodView m) + FMSexChar m -> vs FSSexChar (AS.sexView AS.SexChar m) + FMSexSpoil m -> vs FSSexSpoil (AS.sexView AS.SexSpoil m) FMDeveloper m-> vs FSDeveloper(AP.devView dat m) FMRDate m -> vs FSRDate (AR.view m) FMTag m -> vs FSTag (AG.view dat m) @@ -331,6 +364,10 @@ fieldToQuery (_, _, model) = FMOLang m -> AS.toQuery (QStr 3) m FMPlatform m -> AS.toQuery (QStr 4) m FMLength m -> AS.toQuery (QInt 5) m + FMRole m -> AS.toQuery (QStr 2) m + FMBlood m -> AS.toQuery (QStr 3) m + FMSexChar m -> AS.toQuery (QStr 4) m + FMSexSpoil m -> AS.toQuery (QStr 5) m FMDeveloper m-> AP.toQuery (QInt 6) m FMRDate m -> AR.toQuery m FMTag m -> AG.toQuery m diff --git a/elm/AdvSearch/Query.elm b/elm/AdvSearch/Query.elm index 6b8f30ba..0edb6065 100644 --- a/elm/AdvSearch/Query.elm +++ b/elm/AdvSearch/Query.elm @@ -8,7 +8,7 @@ import Gen.Api as GApi -- Generic dynamically typed representation of a query. -- Used only as an intermediate format to help with encoding/decoding. -- Corresponds to the compact JSON form. -type QType = V | R +type QType = V | R | C type Op = Eq | Ne | Ge | Gt | Le | Lt type Query = QAnd (List Query) diff --git a/elm/AdvSearch/Set.elm b/elm/AdvSearch/Set.elm index 00e995e6..1e3ad18e 100644 --- a/elm/AdvSearch/Set.elm +++ b/elm/AdvSearch/Set.elm @@ -174,3 +174,84 @@ lengthFromQuery = fromQuery (\q -> case q of QInt 5 op v -> Just (op, v) _ -> Nothing) + + + + +-- Character role + +roleView model = + ( case Set.toList model.sel of + [] -> b [ class "grayedout" ] [ text "Role" ] + [v] -> span [ class "nowrap" ] [ lblPrefix model, text <| Maybe.withDefault "" (lookup v GT.charRoles) ] + l -> span [] [ lblPrefix model, text <| "Role (" ++ String.fromInt (List.length l) ++ ")" ] + , \() -> + [ div [ class "advheader" ] + [ h3 [] [ text "Role" ] + , opts model True True ] + , ul [] <| List.map (\(l,t) -> li [] [ linkRadio (Set.member l model.sel) (Sel l) [ text t ] ]) GT.charRoles + ] + ) + +roleFromQuery = fromQuery (\q -> + case q of + QStr 2 op v -> Just (op, v) + _ -> Nothing) + + + + +-- Blood type + +bloodView model = + ( case Set.toList model.sel of + [] -> b [ class "grayedout" ] [ text "Blood type" ] + [v] -> span [ class "nowrap" ] [ lblPrefix model, text <| "Blood type " ++ Maybe.withDefault "" (lookup v GT.bloodTypes) ] + l -> span [] [ lblPrefix model, text <| "Blood type (" ++ String.fromInt (List.length l) ++ ")" ] + , \() -> + [ div [ class "advheader" ] + [ h3 [] [ text "Blood type" ] + , opts model False True ] + , ul [] <| List.map (\(l,t) -> li [] [ linkRadio (Set.member l model.sel) (Sel l) [ text t ] ]) GT.bloodTypes + ] + ) + +bloodFromQuery = fromQuery (\q -> + case q of + QStr 3 op v -> Just (op, v) + _ -> Nothing) + + + + +-- Sex / gender + +type SexType + = SexChar -- chars sex + | SexSpoil -- chars sex-spoil + | SexGender -- staff gender + +sexView stype model = + let lbl = case stype of + SexChar -> "Sex" + SexSpoil -> "Spoiler-sex" + SexGender -> "Gender" + in + ( case Set.toList model.sel of + [] -> b [ class "grayedout" ] [ text lbl ] + [v] -> span [ class "nowrap" ] [ lblPrefix model, text <| lbl ++ ": " ++ Maybe.withDefault "" (lookup v GT.genders) ] + l -> span [] [ lblPrefix model, text <| lbl ++ " (" ++ String.fromInt (List.length l) ++ ")" ] + , \() -> + [ div [ class "advheader" ] + [ h3 [] [ text lbl ] + , opts model False True ] + , ul [] <| List.map (\(l,t) -> if stype == SexGender && l == "b" then text "" else li [] [ linkRadio (Set.member l model.sel) (Sel l) [ text t ] ]) GT.genders + ] + ) + +sexFromQuery stype = fromQuery (\q -> + case (stype, q) of + (SexChar, QStr 4 op v) -> Just (op, v) + (SexSpoil, QStr 5 op v) -> Just (op, v) + -- TODO: SexGender + _ -> Nothing) |