summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-02-28 12:53:44 +0100
committerYorhel <git@yorhel.nl>2020-02-28 12:55:40 +0100
commitccc121634fec7d7aa3a36564eeab2330e543e970 (patch)
treee427f45ceeda01c55260950e2844b22548735586
parent03106135b8d4f0c2c0387991133cc3205957d68b (diff)
v2rw/RelEdit: Add producers relation editing
Lots of copy-pasting going on here. Meh. Also added a couple of overdue server-side validations.
-rw-r--r--elm/Lib/Api.elm1
-rw-r--r--elm/Lib/Autocomplete.elm15
-rw-r--r--elm/ReleaseEdit/General.elm32
-rw-r--r--elm/ReleaseEdit/Main.elm1
-rw-r--r--lib/VNWeb/Elm.pm5
-rw-r--r--lib/VNWeb/Producers/Elm.pm24
-rw-r--r--lib/VNWeb/Releases/Edit.pm12
7 files changed, 88 insertions, 2 deletions
diff --git a/elm/Lib/Api.elm b/elm/Lib/Api.elm
index a7dd18d8..d8cb1315 100644
--- a/elm/Lib/Api.elm
+++ b/elm/Lib/Api.elm
@@ -46,6 +46,7 @@ showResponse res =
BoardResult _ -> unexp
TagResult _ -> unexp
VNResult _ -> unexp
+ ProducerResult _ -> unexp
expectResponse : (Response -> msg) -> Http.Expect msg
diff --git a/elm/Lib/Autocomplete.elm b/elm/Lib/Autocomplete.elm
index fa18efc4..0dd0e9fc 100644
--- a/elm/Lib/Autocomplete.elm
+++ b/elm/Lib/Autocomplete.elm
@@ -7,6 +7,7 @@ module Lib.Autocomplete exposing
, boardSource
, tagSource
, vnSource
+ , producerSource
, init
, clear
, update
@@ -30,6 +31,7 @@ import Gen.Api as GApi
import Gen.Boards as GB
import Gen.Tags as GT
import Gen.VN as GV
+import Gen.Producers as GP
type alias Config m a =
@@ -110,6 +112,19 @@ vnSource =
}
+producerSource : SourceConfig m GApi.ApiProducerResult
+producerSource =
+ { source = Endpoint (\s -> GP.send { search = s })
+ <| \x -> case x of
+ GApi.ProducerResult e -> Just e
+ _ -> Nothing
+ , view = \i ->
+ [ b [ class "grayedout" ] [ text <| "p" ++ String.fromInt i.id ++ ": " ]
+ , text i.name ]
+ , key = \i -> String.fromInt i.id
+ }
+
+
type alias Model a =
{ visible : Bool
, value : String
diff --git a/elm/ReleaseEdit/General.elm b/elm/ReleaseEdit/General.elm
index e88532a0..446639d6 100644
--- a/elm/ReleaseEdit/General.elm
+++ b/elm/ReleaseEdit/General.elm
@@ -17,8 +17,6 @@ import Gen.Types as GT
import Gen.ReleaseEdit as GRE
import Gen.ExtLinks as GEL
--- TODO: producers
-
type alias Model =
{ title : String
@@ -48,6 +46,8 @@ type alias Model =
, extlinks : EL.Model GRE.RecvExtlinks
, vn : List GRE.RecvVn
, vnAdd : A.Model GApi.ApiVNResult
+ , prod : List GRE.RecvProducers
+ , prodAdd : A.Model GApi.ApiProducerResult
, notes : TP.Model
}
@@ -86,6 +86,8 @@ init d =
, extlinks = EL.new d.extlinks GEL.releaseLinks
, vn = d.vn
, vnAdd = A.init ""
+ , prod = d.producers
+ , prodAdd = A.init ""
, notes = TP.bbcode d.notes
}
@@ -93,6 +95,9 @@ init d =
vnConfig : A.Config Msg GApi.ApiVNResult
vnConfig = { wrap = VNSearch, id = "vnadd", source = A.vnSource }
+producerConfig : A.Config Msg GApi.ApiProducerResult
+producerConfig = { wrap = ProdSearch, id = "prodadd", source = A.producerSource }
+
sub : Model -> Sub Msg
sub model = Sub.batch [ DD.sub model.langDd, DD.sub model.platDd ]
@@ -126,6 +131,9 @@ type Msg
| ExtLinks (EL.Msg GRE.RecvExtlinks)
| VNDel Int
| VNSearch (A.Msg GApi.ApiVNResult)
+ | ProdDel Int
+ | ProdRole Int (Bool, Bool)
+ | ProdSearch (A.Msg GApi.ApiProducerResult)
| Notes (TP.Msg)
@@ -174,6 +182,16 @@ update msg model =
if List.any (\vn -> vn.vid == v.id) model.vn
then ({ model | vnAdd = nm }, c)
else ({ model | vnAdd = A.clear nm "", vn = model.vn ++ [{ vid = v.id, title = v.title}] }, c)
+ ProdDel i -> mod { model | vn = delidx i model.vn }
+ ProdRole i (d,p) -> mod { model | prod = modidx i (\e -> { e | developer = d, publisher = p }) model.prod }
+ ProdSearch m ->
+ let (nm, c, res) = A.update producerConfig m model.prodAdd
+ in case res of
+ Nothing -> ({ model | prodAdd = nm }, c)
+ Just p ->
+ if List.any (\e -> e.pid == p.id) model.prod
+ then ({ model | prodAdd = nm }, c)
+ else ({ model | prodAdd = A.clear nm "", prod = model.prod ++ [{ pid = p.id, name = p.name, developer = False, publisher = True}] }, c)
Notes m -> let (nm, nc) = TP.update m model.notes in ({ model | notes = nm }, Cmd.map Notes nc)
@@ -277,6 +295,16 @@ view model =
) model.vn
, A.view vnConfig model.vnAdd [placeholder "Add visual novel..."]
]
+ , formField "Producers"
+ [ table [ class "compact" ] <| List.indexedMap (\i p -> tr []
+ [ td [ style "text-align" "right" ] [ b [ class "grayedout" ] [ text <| "p" ++ String.fromInt p.pid ++ ":" ] ]
+ , td [] [ a [ href <| "/p" ++ String.fromInt p.pid ] [ text p.name ] ]
+ , td [] [ inputSelect "" (p.developer, p.publisher) (ProdRole i) [style "width" "100px"] [((True,False), "Developer"), ((False,True), "Publisher"), ((True,True), "Both")] ]
+ , td [] [ a [ href "#", onClickD (ProdDel i) ] [ text "remove" ] ]
+ ]
+ ) model.prod
+ , A.view producerConfig model.prodAdd [placeholder "Add producer..."]
+ ]
, tr [ class "newpart" ] [ td [ colspan 2 ] [] ]
, formField "notes::Notes"
diff --git a/elm/ReleaseEdit/Main.elm b/elm/ReleaseEdit/Main.elm
index 1b028124..df10a942 100644
--- a/elm/ReleaseEdit/Main.elm
+++ b/elm/ReleaseEdit/Main.elm
@@ -72,6 +72,7 @@ encode model =
, extlinks = model.general.extlinks.links
, vn = List.map (\l -> {vid=l.vid}) model.general.vn
, notes = model.general.notes.data
+ , producers = List.map (\l -> {pid=l.pid, developer=l.developer, publisher=l.publisher}) model.general.prod
}
diff --git a/lib/VNWeb/Elm.pm b/lib/VNWeb/Elm.pm
index 4a5269dc..cf6409cb 100644
--- a/lib/VNWeb/Elm.pm
+++ b/lib/VNWeb/Elm.pm
@@ -75,6 +75,11 @@ my %apis = (
title => {},
original => { required => 0, default => '' },
} } ],
+ ProducerResult => [ { aoh => { # Response to 'Producers'
+ id => { id => 1 },
+ name => {},
+ original => { required => 0, default => '' },
+ } } ],
);
diff --git a/lib/VNWeb/Producers/Elm.pm b/lib/VNWeb/Producers/Elm.pm
new file mode 100644
index 00000000..181729c3
--- /dev/null
+++ b/lib/VNWeb/Producers/Elm.pm
@@ -0,0 +1,24 @@
+package VNWeb::Producers::Elm;
+
+use VNWeb::Prelude;
+
+elm_api Producers => undef, { search => {} }, sub {
+ my $q = shift->{search};
+ my $qs = $q =~ s/[%_]//gr;
+
+ elm_ProducerResult tuwf->dbPagei({ results => 15, page => 1 },
+ 'SELECT p.id, p.name, p.original
+ FROM (',
+ sql_join('UNION ALL',
+ $q =~ /^$RE{pid}$/ ? sql('SELECT 1, id FROM producers WHERE id =', \"$+{id}") : (),
+ sql('SELECT 1+substr_score(lower(name),' , \$qs, '), id FROM producers WHERE name ILIKE', \"$qs%"),
+ sql('SELECT 10+substr_score(lower(original),', \$qs, '), id FROM producers WHERE original ILIKE', \"$qs%"),
+ ), ') x(prio, id)
+ JOIN producers p ON p.id = x.id
+ WHERE NOT p.hidden
+ GROUP BY p.id, p.name, p.original
+ ORDER BY MIN(x.prio), p.name
+ ');
+};
+
+1;
diff --git a/lib/VNWeb/Releases/Edit.pm b/lib/VNWeb/Releases/Edit.pm
index 21563c34..a292261d 100644
--- a/lib/VNWeb/Releases/Edit.pm
+++ b/lib/VNWeb/Releases/Edit.pm
@@ -34,6 +34,12 @@ my $FORM = {
vid => { id => 1 },
title => { _when => 'out' },
} },
+ producers => { sort_keys => 'pid', aoh => {
+ pid => { id => 1 },
+ developer => { anybool => 1 },
+ publisher => { anybool => 1 },
+ name => { _when => 'out' },
+ } },
hidden => { anybool => 1 },
locked => { anybool => 1 },
@@ -67,6 +73,7 @@ TUWF::get qr{/$RE{rrev}/(?<action>edit|copy)} => sub {
to_extlinks $e;
enrich_merge vid => 'SELECT id AS vid, title FROM vn WHERE id IN', $e->{vn};
+ enrich_merge pid => 'SELECT id AS pid, name FROM producers WHERE id IN', $e->{producers};
my $title = ($copy ? 'Copy ' : 'Edit ').$e->{title};
framework_ title => $title, type => 'r', dbobj => $e, tab => tuwf->capture('action'),
@@ -98,7 +105,12 @@ elm_api ReleaseEdit => $FORM_OUT, $FORM_IN, sub {
$data->{hidden} = $e->{hidden}||0;
$data->{locked} = $e->{locked}||0;
}
+ $data->{doujin} = $data->{voiced} = $data->{ani_story} = $data->{ani_ero} = 0 if $data->{patch};
+ $data->{resolution} = 'unknown' if $data->{patch};
+ $data->{uncensored} = 0 if $data->{minage} != 18;
$_->{qty} = $MEDIUM{$_->{medium}}{qty} ? $_->{qty}||1 : 0 for $data->{media}->@*;
+ $data->{notes} = bb_subst_links $data->{notes};
+ die "No VNs selected" if !$data->{vn}->@*;
to_extlinks $e;
$e->{rtype} = delete $e->{type};