diff options
-rw-r--r-- | elm/Lib/Api.elm | 1 | ||||
-rw-r--r-- | elm/Lib/Autocomplete.elm | 15 | ||||
-rw-r--r-- | elm/ReleaseEdit.elm | 49 | ||||
-rw-r--r-- | lib/VNWeb/Elm.pm | 4 | ||||
-rw-r--r-- | lib/VNWeb/Releases/Edit.pm | 25 | ||||
-rw-r--r-- | lib/VNWeb/Releases/Elm.pm | 8 |
6 files changed, 44 insertions, 58 deletions
diff --git a/elm/Lib/Api.elm b/elm/Lib/Api.elm index a598b9d3..3e69a4e1 100644 --- a/elm/Lib/Api.elm +++ b/elm/Lib/Api.elm @@ -48,6 +48,7 @@ showResponse res = DupNames _ -> "Name or alias already in the database." Releases _ -> unexp Resolutions _ -> unexp + Engines _ -> unexp BoardResult _ -> unexp TagResult _ -> unexp TraitResult _ -> unexp diff --git a/elm/Lib/Autocomplete.elm b/elm/Lib/Autocomplete.elm index aea614db..d1d974b1 100644 --- a/elm/Lib/Autocomplete.elm +++ b/elm/Lib/Autocomplete.elm @@ -13,6 +13,7 @@ module Lib.Autocomplete exposing , charSource , animeSource , resolutionSource + , engineSource , init , clear , refocus @@ -43,6 +44,7 @@ import Gen.Staff as GS import Gen.Chars as GC import Gen.Anime as GA import Gen.Resolutions as GR +import Gen.Engines as GE type alias Config m a = @@ -212,6 +214,19 @@ resolutionSource = } +engineSource : SourceConfig m GApi.ApiEngines +engineSource = + { source = LazyList + (GE.send {}) + (\x -> case x of + GApi.Engines e -> Just e + _ -> Nothing) + (\s l -> List.filter (\v -> String.contains (String.toLower s) (String.toLower v.engine)) l |> List.take 10) + , view = \i -> [ text i.engine, b [ class "grayedout" ] [ text <| " (" ++ String.fromInt i.count ++ ")" ] ] + , key = \i -> i.engine + } + + type alias Model a = { visible : Bool , value : String diff --git a/elm/ReleaseEdit.elm b/elm/ReleaseEdit.elm index e29d2848..f21c6eff 100644 --- a/elm/ReleaseEdit.elm +++ b/elm/ReleaseEdit.elm @@ -52,14 +52,12 @@ type alias Model = , uncensored : Bool , resoX : Int , resoY : Int - , resoConf : A.Config Msg GRE.RecvResolutions - , reso : A.Model GRE.RecvResolutions + , reso : A.Model GApi.ApiResolutions , voiced : Int , ani_story : Int , ani_ero : Int , website : String - , engineConf : A.Config Msg GRE.RecvEngines - , engine : A.Model GRE.RecvEngines + , engine : A.Model GApi.ApiEngines , extlinks : EL.Model GRE.RecvExtlinks , vn : List GRE.RecvVn , vnAdd : A.Model GApi.ApiVNResult @@ -71,29 +69,6 @@ type alias Model = } -engineConf : List GRE.RecvEngines -> A.Config Msg GRE.RecvEngines -engineConf lst = - { wrap = Engine - , id = "engine" - , source = - { source = A.Func (\s -> List.filter (\e -> String.contains (String.toLower s) (String.toLower e.engine)) lst |> List.take 10) - , view = \i -> [ text i.engine, b [ class "grayedout" ] [ text <| " (" ++ String.fromInt i.count ++ ")" ] ] - , key = \i -> i.engine - } - } - - -resoConf : List GRE.RecvResolutions -> A.Config Msg GRE.RecvResolutions -resoConf lst = - { wrap = Resolution - , id = "resolution" - , source = - { source = A.Func (\s -> List.filter (\e -> String.contains (String.toLower s) (String.toLower e.resolution)) lst |> List.take 10) - , view = \i -> [ text i.resolution, b [ class "grayedout" ] [ text <| " (" ++ String.fromInt i.count ++ ")" ] ] - , key = \i -> i.resolution - } - } - init : GRE.Recv -> Model init d = { state = Api.Normal @@ -117,13 +92,11 @@ init d = , uncensored = d.uncensored , resoX = d.reso_x , resoY = d.reso_y - , resoConf = resoConf d.resolutions , reso = A.init (resoFmt True d.reso_x d.reso_y) , voiced = d.voiced , ani_story = d.ani_story , ani_ero = d.ani_ero , website = d.website - , engineConf = engineConf d.engines , engine = A.init d.engine , extlinks = EL.new d.extlinks GEL.releaseSites , vn = d.vn @@ -176,6 +149,12 @@ vnConfig = { wrap = VNSearch, id = "vnadd", source = A.vnSource } producerConfig : A.Config Msg GApi.ApiProducerResult producerConfig = { wrap = ProdSearch, id = "prodadd", source = A.producerSource } +resoConfig : A.Config Msg GApi.ApiResolutions +resoConfig = { wrap = Resolution, id = "resolution", source = A.resolutionSource } + +engineConfig : A.Config Msg GApi.ApiEngines +engineConfig = { wrap = Engine, id = "engine", source = A.engineSource } + sub : Model -> Sub Msg sub m = Sub.batch [ DD.sub m.langDd, DD.sub m.platDd ] @@ -199,12 +178,12 @@ type Msg | Released D.RDate | Minage Int | Uncensored Bool - | Resolution (A.Msg GRE.RecvResolutions) + | Resolution (A.Msg GApi.ApiResolutions) | Voiced Int | AniStory Int | AniEro Int | Website String - | Engine (A.Msg GRE.RecvEngines) + | Engine (A.Msg GApi.ApiEngines) | ExtLinks (EL.Msg GRE.RecvExtlinks) | VNDel Int | VNSearch (A.Msg GApi.ApiVNResult) @@ -240,7 +219,7 @@ update msg model = Minage i -> ({ model | minage = i }, Cmd.none) Uncensored b->({ model | uncensored = b }, Cmd.none) Resolution m-> - let (nm, c, en) = A.update model.resoConf m model.reso + let (nm, c, en) = A.update resoConfig m model.reso nmod = { model | reso = Maybe.withDefault nm <| Maybe.map (\e -> A.clear nm e.resolution) en } n2mod = case resoParse True nmod.reso.value of Just (x,y) -> { nmod | resoX = x, resoY = y } @@ -251,7 +230,7 @@ update msg model = AniEro i -> ({ model | ani_ero = i }, Cmd.none) Website s -> ({ model | website = s }, Cmd.none) Engine m -> - let (nm, c, en) = A.update model.engineConf m model.engine + let (nm, c, en) = A.update engineConfig m model.engine nmod = case en of Just e -> A.clear nm e.engine Nothing -> nm @@ -358,10 +337,10 @@ viewGen model = ] , if model.patch then text "" else - formField "engine::Engine" [ A.view model.engineConf model.engine [] ] + formField "engine::Engine" [ A.view engineConfig model.engine [] ] , if model.patch then text "" else formField "resolution::Resolution" - [ A.view model.resoConf model.reso [] + [ A.view resoConfig model.reso [] , if resoParse True model.reso.value == Nothing then b [ class "standout" ] [ text " Invalid resolution" ] else text "" ] , if model.patch then text "" else diff --git a/lib/VNWeb/Elm.pm b/lib/VNWeb/Elm.pm index 1dd2e93f..0fd24d36 100644 --- a/lib/VNWeb/Elm.pm +++ b/lib/VNWeb/Elm.pm @@ -70,6 +70,10 @@ our %apis = ( resolution => {}, count => { uint => 1 }, } } ], + Engines => [ { aoh => { # Response to 'Engines' + engine => {}, + count => { uint => 1 }, + } } ], BoardResult => [ { aoh => { # Response to 'Boards' btype => {}, iid => { required => 0, default => 0, id => 1 }, diff --git a/lib/VNWeb/Releases/Edit.pm b/lib/VNWeb/Releases/Edit.pm index ebdb9850..839c42c5 100644 --- a/lib/VNWeb/Releases/Edit.pm +++ b/lib/VNWeb/Releases/Edit.pm @@ -45,14 +45,6 @@ my $FORM = { hidden => { anybool => 1 }, locked => { anybool => 1 }, - engines => { _when => 'out', aoh => { - engine => {}, - count => { uint => 1 }, - } }, - resolutions=> { _when => 'out', aoh => { - resolution => {}, - count => { uint => 1 }, - } }, authmod => { _when => 'out', anybool => 1 }, editsum => { _when => 'in out', editsum => 1 }, }; @@ -63,19 +55,6 @@ my $FORM_CMP = form_compile cmp => $FORM; sub to_extlinks { $_[0]{extlinks} = { map +($_, delete $_[0]{$_}), grep /^l_/, keys $_[0]->%* } } -sub enrich_form { - my($e) = @_; - $e->{authmod} = auth->permDbmod; - $e->{engines} = tuwf->dbAlli(q{ - SELECT engine, count(*) AS count FROM releases WHERE NOT hidden AND engine <> '' - GROUP BY engine ORDER BY count(*) DESC, engine - }); - $e->{resolutions} = [ map +{ resolution => resolution($_), count => $_->{count} }, tuwf->dbAlli(q{ - SELECT reso_x, reso_y, count(*) AS count FROM releases WHERE NOT hidden AND NOT (reso_x = 0 AND reso_y = 0) - GROUP BY reso_x, reso_y ORDER BY count(*) DESC - })->@* ]; -} - TUWF::get qr{/$RE{rrev}/(?<action>edit|copy)} => sub { my $e = db_entry r => tuwf->capture('id'), tuwf->capture('rev') or return tuwf->resNotFound; @@ -84,8 +63,8 @@ TUWF::get qr{/$RE{rrev}/(?<action>edit|copy)} => sub { $e->{rtype} = delete $e->{type}; $e->{editsum} = $copy ? "Copied from r$e->{id}.$e->{chrev}" : $e->{chrev} == $e->{maxrev} ? '' : "Reverted to revision r$e->{id}.$e->{chrev}"; + $e->{authmod} = auth->permDbmod; - enrich_form $e; to_extlinks $e; enrich_merge vid => 'SELECT id AS vid, title FROM vn WHERE id IN', $e->{vn}; @@ -117,7 +96,7 @@ TUWF::get qr{/$RE{vid}/add}, sub { vn => [{vid => $v->{id}, title => $v->{title}}], official => 1, }; - enrich_form $e; + $e->{authmod} = auth->permDbmod; framework_ title => "Add release to $v->{title}", sub { diff --git a/lib/VNWeb/Releases/Elm.pm b/lib/VNWeb/Releases/Elm.pm index 7f0578e4..40e6bfad 100644 --- a/lib/VNWeb/Releases/Elm.pm +++ b/lib/VNWeb/Releases/Elm.pm @@ -18,4 +18,12 @@ elm_api Resolutions => undef, {}, sub { })->@* ]; }; + +elm_api Engines => undef, {}, sub { + elm_Engines tuwf->dbAlli(q{ + SELECT engine, count(*) AS count FROM releases WHERE NOT hidden AND engine <> '' + GROUP BY engine ORDER BY count(*) DESC, engine + }); +}; + 1; |