summaryrefslogtreecommitdiff
path: root/elm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-06-29 11:34:34 +0200
committerYorhel <git@yorhel.nl>2020-06-29 11:34:36 +0200
commitd5b13e58abee0b2edbe16705451d498e39235d77 (patch)
tree222c4a0db15ed205bc894d703065300c8e9b94e7 /elm
parent6831c0b0de4c6581f7d5481e1df4e37754d64b63 (diff)
VN::Edit: Add length/wikidata/renai/anime fields
Completing the "General info" tab. This makes use of the new anime titles import for validation and autocomplete. It does have a bug, though, as it also autocompletes deleted AniDB entries that happen to have been linked to old VN revisions. Need to find a way to mark those for exclusion.
Diffstat (limited to 'elm')
-rw-r--r--elm/Lib/Api.elm1
-rw-r--r--elm/Lib/Autocomplete.elm15
-rw-r--r--elm/VNEdit.elm48
3 files changed, 64 insertions, 0 deletions
diff --git a/elm/Lib/Api.elm b/elm/Lib/Api.elm
index 4af28ea6..3ad3f3aa 100644
--- a/elm/Lib/Api.elm
+++ b/elm/Lib/Api.elm
@@ -53,6 +53,7 @@ showResponse res =
VNResult _ -> unexp
ProducerResult _ -> unexp
CharResult _ -> unexp
+ AnimeResult _ -> unexp
ImageResult _ -> unexp
diff --git a/elm/Lib/Autocomplete.elm b/elm/Lib/Autocomplete.elm
index 738f6008..7f44ccae 100644
--- a/elm/Lib/Autocomplete.elm
+++ b/elm/Lib/Autocomplete.elm
@@ -10,6 +10,7 @@ module Lib.Autocomplete exposing
, vnSource
, producerSource
, charSource
+ , animeSource
, init
, clear
, update
@@ -36,6 +37,7 @@ import Gen.Traits as GTR
import Gen.VN as GV
import Gen.Producers as GP
import Gen.Chars as GC
+import Gen.Anime as GA
type alias Config m a =
@@ -164,6 +166,19 @@ charSource =
}
+animeSource : SourceConfig m GApi.ApiAnimeResult
+animeSource =
+ { source = Endpoint (\s -> GA.send { search = s })
+ <| \x -> case x of
+ GApi.AnimeResult e -> Just e
+ _ -> Nothing
+ , view = \i ->
+ [ b [ class "grayedout" ] [ text <| "a" ++ String.fromInt i.id ++ ": " ]
+ , text i.title ]
+ , key = \i -> String.fromInt i.id
+ }
+
+
type alias Model a =
{ visible : Bool
, value : String
diff --git a/elm/VNEdit.elm b/elm/VNEdit.elm
index e6b50287..09ddabfb 100644
--- a/elm/VNEdit.elm
+++ b/elm/VNEdit.elm
@@ -47,6 +47,11 @@ type alias Model =
, original : String
, alias : String
, desc : TP.Model
+ , length : Int
+ , lWikidata : Maybe Int
+ , lRenai : String
+ , anime : List GVE.RecvAnime
+ , animeSearch : A.Model GApi.ApiAnimeResult
, id : Maybe Int
}
@@ -60,6 +65,11 @@ init d =
, original = d.original
, alias = d.alias
, desc = TP.bbcode d.desc
+ , length = d.length
+ , lWikidata = d.l_wikidata
+ , lRenai = d.l_renai
+ , anime = d.anime
+ , animeSearch = A.init ""
, id = d.id
}
@@ -74,8 +84,15 @@ encode model =
, original = model.original
, alias = model.alias
, desc = model.desc.data
+ , length = model.length
+ , l_wikidata = model.lWikidata
+ , l_renai = model.lRenai
+ , anime = List.map (\a -> { aid = a.aid }) model.anime
}
+animeConfig : A.Config Msg GApi.ApiAnimeResult
+animeConfig = { wrap = AnimeSearch, id = "animeadd", source = A.animeSource }
+
type Msg
= Editsum Editsum.Msg
| Tab Tab
@@ -85,6 +102,11 @@ type Msg
| Original String
| Alias String
| Desc TP.Msg
+ | Length Int
+ | LWikidata (Maybe Int)
+ | LRenai String
+ | AnimeDel Int
+ | AnimeSearch (A.Msg GApi.ApiAnimeResult)
update : Msg -> Model -> (Model, Cmd Msg)
@@ -96,6 +118,19 @@ update msg model =
Original s -> ({ model | original = s }, Cmd.none)
Alias s -> ({ model | alias = s }, Cmd.none)
Desc m -> let (nm,nc) = TP.update m model.desc in ({ model | desc = nm }, Cmd.map Desc nc)
+ Length n -> ({ model | length = n }, Cmd.none)
+ LWikidata n-> ({ model | lWikidata = n }, Cmd.none)
+ LRenai s -> ({ model | lRenai = s }, Cmd.none)
+
+ AnimeDel i -> ({ model | anime = delidx i model.anime }, Cmd.none)
+ AnimeSearch m ->
+ let (nm, c, res) = A.update animeConfig m model.animeSearch
+ in case res of
+ Nothing -> ({ model | animeSearch = nm }, c)
+ Just a ->
+ if List.any (\l -> l.aid == a.id) model.anime
+ then ({ model | animeSearch = A.clear nm "" }, c)
+ else ({ model | animeSearch = A.clear nm "", anime = model.anime ++ [{ aid = a.id, title = a.title, original = a.original }] }, Cmd.none)
Submit -> ({ model | state = Api.Loading }, GVE.send (encode model) Submitted)
Submitted (GApi.Redirect s) -> (model, load s)
@@ -131,6 +166,19 @@ view model =
[ TP.view "desc" model.desc Desc 600 (style "height" "180px" :: GVE.valDesc) [ b [ class "standout" ] [ text "English please!" ] ]
, text "Short description of the main story. Please do not include spoilers, and don't forget to list the source in case you didn't write the description yourself."
]
+ , formField "length::Length" [ inputSelect "length" model.length Length [] GT.vnLengths ]
+ , formField "l_wikidata::Wikidata ID" [ inputWikidata "l_wikidata" model.lWikidata LWikidata ]
+ , formField "l_renai::Renai.us link" [ text "http://renai.us/game/", inputText "l_renai" model.lRenai LRenai [], text ".shtml" ]
+ , formField "Related anime"
+ [ if List.isEmpty model.anime then text ""
+ else table [] <| List.indexedMap (\i e -> tr []
+ [ td [ style "text-align" "right" ] [ b [ class "grayedout" ] [ text <| "a" ++ String.fromInt e.aid ++ ":" ] ]
+ , td [] [ a [ href <| "https://anidb.net/anime/" ++ String.fromInt e.aid ] [ text e.title ] ]
+ , td [] [ inputButton "remove" (AnimeDel i) [] ]
+ ]
+ ) model.anime
+ , A.view animeConfig model.animeSearch [placeholder "Add anime..."]
+ ]
]
in