diff options
Diffstat (limited to 'elm3/RelEdit')
-rw-r--r-- | elm3/RelEdit/General.elm | 272 | ||||
-rw-r--r-- | elm3/RelEdit/Main.elm | 137 | ||||
-rw-r--r-- | elm3/RelEdit/New.elm | 19 | ||||
-rw-r--r-- | elm3/RelEdit/Producers.elm | 92 | ||||
-rw-r--r-- | elm3/RelEdit/Vn.elm | 77 |
5 files changed, 0 insertions, 597 deletions
diff --git a/elm3/RelEdit/General.elm b/elm3/RelEdit/General.elm deleted file mode 100644 index 698c9f99..00000000 --- a/elm3/RelEdit/General.elm +++ /dev/null @@ -1,272 +0,0 @@ -module RelEdit.General exposing (..) - -import Html exposing (..) -import Html.Attributes exposing (..) -import Html.Events exposing (..) -import Lib.Html exposing (..) -import Lib.Gen exposing (..) -import Lib.Util exposing (..) -import Lib.RDate as RDate - - -type alias Model = - { aniEro : Int - , aniStory : Int - , catalog : String - , doujin : Bool - , freeware : Bool - , gtinInput : String - , gtinVal : Maybe Int - , lang : List { lang : String } - , media : List { medium : String, qty : Int } - , minage : Maybe Int - , notes : String - , original : String - , patch : Bool - , platforms : List { platform : String } - , released : RDate.RDate - , resolution : String - , rtype : String - , title : String - , uncensored : Bool - , voiced : Int - , website : String - } - - -init : RelEdit -> Model -init d = - { aniEro = d.ani_ero - , aniStory = d.ani_story - , catalog = d.catalog - , doujin = d.doujin - , freeware = d.freeware - , gtinInput = formatGtin d.gtin - , gtinVal = Just d.gtin - , lang = d.lang - , media = d.media - , minage = d.minage - , notes = d.notes - , original = d.original - , patch = d.patch - , platforms = d.platforms - , released = d.released - , resolution = d.resolution - , rtype = d.rtype - , title = d.title - , uncensored = d.uncensored - , voiced = d.voiced - , website = d.website - } - - -new : String -> String -> Model -new title orig = - { aniEro = 0 - , aniStory = 0 - , catalog = "" - , doujin = False - , freeware = False - , gtinInput = "" - , gtinVal = Just 0 - , lang = [{lang = "ja"}] - , media = [] - , minage = Nothing - , notes = "" - , original = orig - , patch = False - , platforms = [] - , released = 99999999 - , resolution = "unknown" - , rtype = "complete" - , title = title - , uncensored = False - , voiced = 0 - , website = "" - } - - -type Msg - = Title String - | Original String - | RType String - | Patch Bool - | Freeware Bool - | Doujin Bool - | LangDel Int - | LangAdd String - | Notes String - | Released RDate.Msg - | Gtin String - | Catalog String - | Website String - | Minage String - | Uncensored Bool - | Resolution String - | Voiced String - | AniStory String - | AniEro String - | PlatDel Int - | PlatAdd String - | MedDel Int - | MedQty Int String - | MedAdd String - - -update : Msg -> Model -> Model -update msg model = - case msg of - Title s -> { model | title = s } - Original s -> { model | original = s } - RType s -> { model | rtype = s } - Patch b -> { model | patch = b } - Freeware b -> { model | freeware = b } - Doujin b -> { model | doujin = b } - LangDel n -> { model | lang = delidx n model.lang } - LangAdd s -> if s == "" then model else { model | lang = model.lang ++ [{ lang = s }] } - Notes s -> { model | notes = s } - Released m -> { model | released = RDate.update m model.released } - Gtin s -> { model | gtinInput= s, gtinVal = if s == "" then Just 0 else validateGtin s } - Catalog s -> { model | catalog = s } - Website s -> { model | website = s } - Minage s -> { model | minage = String.toInt s } - Uncensored b -> { model | uncensored = b } - Resolution s -> { model | resolution = s } - Voiced s -> { model | voiced = Maybe.withDefault model.voiced <| String.toInt s } - AniStory s -> { model | aniStory = Maybe.withDefault model.aniStory <| String.toInt s } - AniEro s -> { model | aniEro = Maybe.withDefault model.aniEro <| String.toInt s } - PlatDel n -> { model | platforms = delidx n model.platforms } - PlatAdd s -> if s == "" then model else { model | platforms = model.platforms ++ [{ platform = s }] } - MedDel n -> { model | media = delidx n model.media } - MedQty i s -> { model | media = modidx i (\e -> { e | qty = Maybe.withDefault 0 (String.toInt s) }) model.media } - MedAdd s -> if s == "" then model else { model | media = model.media ++ [{ medium = s, qty = 1 }] } - - -general : Model -> Html Msg -general model = card "general" "General info" [] - - [ cardRow "Title" Nothing <| formGroups - [ [ label [for "title"] [text "Title (romaji)"] - , inputText "title" model.title Title [required True, maxlength 250] - ] - , [ label [for "original"] [text "Original"] - , inputText "original" model.original Original [maxlength 250] - , div [class "form-group__help"] [text "The original title of this release, leave blank if it already is in the Latin alphabet."] - ] - ] - - , cardRow "Type" Nothing <| formGroups <| - [ [ inputSelect [id "type", onInput RType] model.rtype <| List.map (\s -> (s, toUpperFirst s)) releaseTypes ] - , [ label [class "checkbox"] [ inputCheck "" model.patch Patch , text " This release is a patch to another release" ] ] - , [ label [class "checkbox"] [ inputCheck "" model.freeware Freeware, text " Freeware (i.e. available at no cost)" ] ] - ] ++ if model.patch - then [] - else [ [ label [class "checkbox"] [ inputCheck "" model.doujin Doujin, text " Doujin (self-published, not by a company)" ] ] ] - - , cardRow "Languages" Nothing <| formGroups - [ editList <| List.indexedMap (\n l -> - editListRow "" - [ editListField 3 "" [ iconLanguage l.lang, text <| " " ++ (Maybe.withDefault l.lang <| lookup l.lang languages) ] - , editListField 0 "" [ removeButton (LangDel n) ] - ] - ) model.lang - , [ if List.isEmpty model.lang - then div [class "invalid-feedback"] [ text "No language selected." ] - else text "" - , label [for "addlang"] [ text "Add language" ] - -- TODO: Move selection back to "" when a new language has been added - , inputSelect [id "addlang", onInput LangAdd] "" - <| ("", "-- Add language --") - :: List.filter (\(n,_) -> not <| List.any (\l -> l.lang == n) model.lang) languages - ] - ] - - , cardRow "Meta" Nothing <| formGroups <| - [ [ label [for "released"] [text "Release date"] - , Html.map Released <| RDate.view model.released False - , div [class "form-group__help"] [text "Leave month or day blank if they are unknown"] - ] - , [ label [for "gtin"] [text "JAN/EAN/UPC"] - , inputText "gtin" model.gtinInput Gtin [pattern "[0-9]+"] - , if model.gtinVal == Nothing - then div [class "invalid-feedback"] [ text "Invalid bar code." ] - else text "" - ] - , [ label [for "catalog"] [text "Catalog number"] - , inputText "catalog" model.catalog Catalog [maxlength 50] - ] - , [ label [for "website"] [text "Official website"] - , inputText "website" model.website Website [pattern weburlPattern] - ] - , [ label [for "minage"] [text "Age rating"] - , inputSelect [id "minage", onInput Minage] (Maybe.withDefault "" (Maybe.map String.fromInt model.minage)) (List.map (\(a,b) -> (String.fromInt a, b)) minAges) - ] - ] ++ if model.minage /= Just 18 - then [] - else [ [ label [class "checkbox"] [ inputCheck "" model.uncensored Uncensored, text " No mosaic or other optical censoring (only check if this release has erotic content)" ] ] ] - - , cardRow "Notes" (Just "English please!") <| formGroup - [ inputTextArea "" model.notes Notes [rows 5, maxlength 10240] - , div [class "form-group__help"] - [ text "Miscellaneous notes/comments, information that does not fit in the other fields." - , text " For example, types of censoring or for which other releases this patch applies." - ] - ] - ] - - -format : Model -> Html Msg -format model = card "format" "Format" [] <| - - (if model.patch then [] else [ cardRow "Technical" Nothing <| formGroups - [ [ label [for "resolution"] [text "Native screen resolution"] - , inputSelect [id "resolution", onInput Resolution] model.resolution resolutions - ] - , [ label [for "voiced"] [text "Voiced"] - , inputSelect [id "voiced", onInput Voiced] (String.fromInt model.voiced) <| List.map (\(a,b) -> (String.fromInt a, b)) voiced - ] - , [ label [for "ani_story"] [text "Story animation"] - , inputSelect [id "ani_story", onInput AniStory] (String.fromInt model.aniStory) <| List.map (\(a,b) -> (String.fromInt a, b)) animated - ] - , [ label [for "ani_ero"] [text "Ere scene animation"] - , inputSelect [id "ani_ero", onInput AniEro] (String.fromInt model.aniEro) <| List.map (\(a,b) -> (String.fromInt a, if a == 0 then "Unknown / no ero scenes" else b)) animated - ] - ] - ]) ++ - - [ cardRow "Platforms" Nothing <| formGroups - [ editList <| List.indexedMap (\n p -> - editListRow "" - [ editListField 3 "" [ iconPlatform p.platform, text <| " " ++ (Maybe.withDefault p.platform <| lookup p.platform platforms) ] - , editListField 0 "" [ removeButton (PlatDel n) ] - ] - ) model.platforms - , [ label [for "addplat"] [ text "Add platform" ] - -- TODO: Move selection back to "" when a new platform has been added - , inputSelect [id "addplat", onInput PlatAdd] "" - <| ("", "-- Add platform --") - :: List.filter (\(n,_) -> not <| List.any (\p -> p.platform == n) model.platforms) platforms - ] - ] - - , cardRow "Media" Nothing <| formGroups - [ editList <| List.indexedMap (\n m -> - let md = Maybe.withDefault { qty = False, single = "", plural = "" } <| lookup m.medium Lib.Gen.media - in editListRow "" - [ editListField 2 "" [ text md.single ] -- TODO: Add icon - , editListField 2 "" - [ if md.qty - then inputSelect [ onInput (MedQty n) ] (String.fromInt m.qty) <| List.map (\i -> (String.fromInt i, String.fromInt i)) <| List.range 1 20 - else text "" - ] - , editListField 0 "" [ removeButton (MedDel n) ] - ] - ) model.media - , [ label [for "addmed"] [ text "Add medium" ] - -- TODO: Move selection back to "" when a new medium has been added - , inputSelect [id "addmed", onInput MedAdd] "" - <| ("", "-- Add medium --") - :: List.map (\(n,m) -> (n,m.single)) Lib.Gen.media - ] - ] - ] diff --git a/elm3/RelEdit/Main.elm b/elm3/RelEdit/Main.elm deleted file mode 100644 index 16e317f0..00000000 --- a/elm3/RelEdit/Main.elm +++ /dev/null @@ -1,137 +0,0 @@ -module RelEdit.Main exposing (..) - -import Html exposing (..) -import Browser -import Browser.Navigation exposing (load) -import Lib.Html exposing (..) -import Lib.Gen as Gen -import Lib.Api as Api -import Lib.Editsum as Editsum -import RelEdit.General as General -import RelEdit.Producers as Producers -import RelEdit.Vn as Vn - - -main : Program Gen.RelEdit Model Msg -main = Browser.element - { init = \e -> (init e, Cmd.none) - , view = view - , update = update - , subscriptions = always Sub.none - } - - -type alias Model = - { state : Api.State - , editsum : Editsum.Model - , general : General.Model - , producers : Producers.Model - , vn : Vn.Model - , id : Maybe Int - } - - -init : Gen.RelEdit -> Model -init d = - { state = Api.Normal - , editsum = { authmod = d.authmod, editsum = d.editsum, locked = d.locked, hidden = d.hidden } - , general = General.init d - , producers = Producers.init d.producers - , vn = Vn.init d.vn - , id = d.id - } - - -new : Int -> String -> String -> Model -new vid title orig = - { state = Api.Normal - , editsum = Editsum.new - , general = General.new title orig - , producers = Producers.init [] - , vn = Vn.init [{vid = vid, title = title}] - , id = Nothing - } - - -encode : Model -> Gen.RelEditSend -encode model = - { editsum = model.editsum.editsum - , hidden = model.editsum.hidden - , locked = model.editsum.locked - , catalog = model.general.catalog - , doujin = model.general.doujin - , freeware = model.general.freeware - , gtin = Maybe.withDefault 0 model.general.gtinVal - , lang = model.general.lang - , minage = model.general.minage - , notes = model.general.notes - , original = model.general.original - , patch = model.general.patch - , rtype = model.general.rtype - , released = model.general.released - , title = model.general.title - , uncensored = model.general.uncensored - , website = model.general.website - , resolution = model.general.resolution - , voiced = model.general.voiced - , ani_story = model.general.aniStory - , ani_ero = model.general.aniEro - , platforms = model.general.platforms - , media = model.general.media - , producers = List.map (\e -> { pid = e.pid, developer = e.developer, publisher = e.publisher }) model.producers.producers - , vn = List.map (\e -> { vid = e.vid }) model.vn.vn - } - - -type Msg - = Editsum Editsum.Msg - | General General.Msg - | Producers Producers.Msg - | Vn Vn.Msg - | Submit - | Submitted Api.Response - - -update : Msg -> Model -> (Model, Cmd Msg) -update msg model = - case msg of - Editsum m -> ({ model | editsum = Editsum.update m model.editsum }, Cmd.none) - General m -> ({ model | general = General.update m model.general }, Cmd.none) - Producers m -> let (nm, c) = Producers.update m model.producers in ({ model | producers = nm }, Cmd.map Producers c) - Vn m -> let (nm, c) = Vn.update m model.vn in ({ model | vn = nm }, Cmd.map Vn c) - - Submit -> - let - path = - case model.id of - Just id -> "/r" ++ String.fromInt id ++ "/edit" - Nothing -> "/r/add" - body = Gen.releditSendEncode (encode model) - in ({ model | state = Api.Loading }, Api.post path body Submitted) - - Submitted (Gen.Changed id rev) -> (model, load <| "/r" ++ String.fromInt id ++ "." ++ String.fromInt rev) - Submitted r -> ({ model | state = Api.Error r }, Cmd.none) - - -isValid : Model -> Bool -isValid model = not - ( List.isEmpty model.general.lang - || model.general.gtinVal == Nothing - || model.producers.duplicates - || model.vn.duplicates - || List.isEmpty model.vn.vn - ) - - -view : Model -> Html Msg -view model = - form_ Submit (model.state == Api.Loading) - [ Html.map General <| General.general model.general - , Html.map General <| General.format model.general - , card "relations" "Relations" [] - [ Html.map Producers <| Producers.view model.producers - , Html.map Vn <| Vn.view model.vn - ] - , Html.map Editsum <| Editsum.view model.editsum - , submitButton "Submit" model.state (isValid model) False - ] diff --git a/elm3/RelEdit/New.elm b/elm3/RelEdit/New.elm deleted file mode 100644 index 699e3c29..00000000 --- a/elm3/RelEdit/New.elm +++ /dev/null @@ -1,19 +0,0 @@ -module RelEdit.New exposing (main) - -import Browser -import RelEdit.Main as Main - - -type alias Flags = - { id : Int - , title : String - , original : String - } - -main : Program Flags Main.Model Main.Msg -main = Browser.element - { init = \f -> (Main.new f.id f.title f.original, Cmd.none) - , view = Main.view - , update = Main.update - , subscriptions = always Sub.none - } diff --git a/elm3/RelEdit/Producers.elm b/elm3/RelEdit/Producers.elm deleted file mode 100644 index 1af1f2ba..00000000 --- a/elm3/RelEdit/Producers.elm +++ /dev/null @@ -1,92 +0,0 @@ -module RelEdit.Producers exposing (Model, Msg, init, update, view) - -import Html exposing (..) -import Html.Attributes exposing (..) -import Html.Events exposing (..) -import Lib.Html exposing (..) -import Lib.Autocomplete as A -import Lib.Gen as Gen -import Lib.Util exposing (..) - - -type alias Model = - { producers : List Gen.RelEditProducers - , search : A.Model Gen.ApiProducerResult - , duplicates : Bool - } - - -init : List Gen.RelEditProducers -> Model -init l = - { producers = l - , search = A.init - , duplicates = False - } - - -type Msg - = Del Int - | SetRole Int String - | Search (A.Msg Gen.ApiProducerResult) - - -searchConfig : A.Config Msg Gen.ApiProducerResult -searchConfig = { wrap = Search, id = "add-producer", source = A.producerSource } - - -validate : Model -> Model -validate model = { model | duplicates = hasDuplicates <| List.map .pid model.producers } - - -update : Msg -> Model -> (Model, Cmd Msg) -update msg model = - case msg of - Del i -> (validate { model | producers = delidx i model.producers }, Cmd.none) - SetRole i s -> (validate { model | producers = modidx i (\e -> { e | developer = s == "d" || s == "b", publisher = s == "p" || s == "b" }) model.producers } - , Cmd.none ) - - Search m -> - let (nm, c, res) = A.update searchConfig m model.search - in case res of - Nothing -> ({ model | search = nm }, c) - Just r -> - let nrow = { pid = r.id, name = r.name, developer = False, publisher = True } - in (validate { model | search = A.clear nm, producers = model.producers ++ [nrow] }, c) - - - -view : Model -> Html Msg -view model = - let - role e = - case (e.developer, e.publisher) of - (True, False) -> "d" - (False, True) -> "p" - _ -> "b" - - roles = - [ ("d", "Developer") - , ("p", "Publisher") - , ("b", "Both") - ] - - entry n e = editListRow "" - [ editListField 1 "col-form-label single-line" - [ a [href <| "/p" ++ String.fromInt e.pid, title e.name, target "_blank" ] [text e.name ] ] - , editListField 1 "" - [ inputSelect [onInput (SetRole n)] (role e) roles ] - , editListField 0 "" [ removeButton (Del n) ] - ] - - in cardRow "Producers" Nothing - <| editList (List.indexedMap entry model.producers) - ++ formGroups ( - (if model.duplicates - then [ [ div [ class "invalid-feedback" ] - [ text "The producers list contains duplicates." ] ] ] - else [] - ) ++ - [ label [for "add-producer"] [text "Add producer"] - :: A.view searchConfig model.search [placeholder "Producer", style "max-width" "400px"] - ] - ) diff --git a/elm3/RelEdit/Vn.elm b/elm3/RelEdit/Vn.elm deleted file mode 100644 index 9f32aff4..00000000 --- a/elm3/RelEdit/Vn.elm +++ /dev/null @@ -1,77 +0,0 @@ -module RelEdit.Vn exposing (Model, Msg, init, update, view) - -import Html exposing (..) -import Html.Attributes exposing (..) -import Lib.Html exposing (..) -import Lib.Gen as Gen -import Lib.Util exposing (..) -import Lib.Autocomplete as A - - -type alias Model = - { vn : List Gen.RelEditVn - , search : A.Model Gen.ApiVNResult - , duplicates : Bool - } - - -init : List Gen.RelEditVn -> Model -init l = - { vn = l - , search = A.init - , duplicates = False - } - - -type Msg - = Del Int - | Search (A.Msg Gen.ApiVNResult) - - -searchConfig : A.Config Msg Gen.ApiVNResult -searchConfig = { wrap = Search, id = "add-vn", source = A.vnSource } - - -validate : Model -> Model -validate model = { model | duplicates = hasDuplicates <| List.map .vid model.vn } - - -update : Msg -> Model -> (Model, Cmd Msg) -update msg model = - case msg of - Del i -> (validate { model | vn = delidx i model.vn }, Cmd.none) - Search m -> - let (nm, c, res) = A.update searchConfig m model.search - in case res of - Nothing -> ({ model | search = nm }, c) - Just r -> - let nrow = { vid = r.id, title = r.title } - in (validate { model | search = A.clear nm, vn = model.vn ++ [nrow] }, c) - - -view : Model -> Html Msg -view model = - let - entry n e = editListRow "row--ai-center" - [ editListField 1 "col-form-label single-line" - [ a [href <| "/v" ++ String.fromInt e.vid, title e.title, target "_blank" ] [text e.title ] ] - , editListField 0 "" [ removeButton (Del n) ] - ] - - in cardRow "Visual Novels" Nothing - <| editList (List.indexedMap entry model.vn) - ++ formGroups ( - (if model.duplicates - then [ [ div [ class "invalid-feedback" ] - [ text "The list contains duplicates. Make sure that the same visual novel is not listed multiple times." ] ] ] - else [] - ) ++ - (if List.isEmpty model.vn - then [ [ div [ class "invalid-feedback" ] - [ text "Please make sure that at least one visual novel is selected." ] ] ] - else [] - ) ++ - [ label [for "add-vn"] [text "Add visual novel"] - :: A.view searchConfig model.search [placeholder "Visual Novel...", style "max-width" "400px"] - ] - ) |