summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-07-01 15:05:29 +0200
committerYorhel <git@yorhel.nl>2020-07-01 15:05:31 +0200
commit0a6254431d97a2f4de9429e738e58c4dca3bfaa5 (patch)
tree7e3cf1f7faadf7d8949d70f436ca41d577be6e43
parent8939317270f5facdd127c1b7640842a02a76e93c (diff)
VN::Edit: Add cover image changing/uploading
Pretty much a copy-paste from the character edit form now.
-rw-r--r--data/style.css7
-rw-r--r--elm/CharEdit.elm8
-rw-r--r--elm/VNEdit.elm40
-rw-r--r--lib/VNWeb/Chars/Edit.pm2
-rw-r--r--lib/VNWeb/VN/Edit.pm11
5 files changed, 59 insertions, 9 deletions
diff --git a/data/style.css b/data/style.css
index 60b1455b..d7de2cea 100644
--- a/data/style.css
+++ b/data/style.css
@@ -173,10 +173,9 @@ table.formtable tr.newpart td { padding-top: 20px; font-weight: bold; }
table.formtable td table td { padding: 1px 15px 1px 0px }
table.formtable td table { margin-bottom: 5px }
-div.formimage > div:nth-child(1) { width: 300px; height: 300px; text-align: center; float: left }
-div.formimage > div:nth-child(1) img { max-width: 290px; max-height: 300px }
-div.formimage > div:nth-child(2) { min-height: 330px }
-div.formimage h2 { margin: 0 }
+table.formimage > tr > td:nth-child(1) { width: 300px; height: 300px; text-align: center }
+table.formimage > tr > td:nth-child(1) img { max-width: 290px; max-height: 500px }
+table.formimage h2 { margin: 0 }
/* Format checkboxes and radio buttons as if they were normal links with unicode icons.
* Usage:
diff --git a/elm/CharEdit.elm b/elm/CharEdit.elm
index 75362ef0..8c9ae9c7 100644
--- a/elm/CharEdit.elm
+++ b/elm/CharEdit.elm
@@ -366,9 +366,9 @@ view model =
]
image =
- div [ class "formimage" ]
- [ div [] [ Img.viewImg model.image ]
- , div []
+ table [ class "formimage" ] [ tr []
+ [ td [] [ Img.viewImg model.image ]
+ , td []
[ h2 [] [ text "Image ID" ]
, input ([ type_ "text", class "text", tabindex 10, value (Maybe.withDefault "" model.image.id), onInputValidation ImageSet ] ++ GCE.valImage) []
, br [] []
@@ -387,7 +387,7 @@ view model =
, Html.map ImageMsg v
]
]
- ]
+ ] ]
traits =
let
diff --git a/elm/VNEdit.elm b/elm/VNEdit.elm
index 09ddabfb..6fa3aaaa 100644
--- a/elm/VNEdit.elm
+++ b/elm/VNEdit.elm
@@ -16,6 +16,7 @@ import Lib.TextPreview as TP
import Lib.Autocomplete as A
import Lib.Api as Api
import Lib.Editsum as Editsum
+import Lib.Image as Img
import Gen.VNEdit as GVE
import Gen.Types as GT
import Gen.Api as GApi
@@ -52,6 +53,7 @@ type alias Model =
, lRenai : String
, anime : List GVE.RecvAnime
, animeSearch : A.Model GApi.ApiAnimeResult
+ , image : Img.Image
, id : Maybe Int
}
@@ -70,6 +72,7 @@ init d =
, lRenai = d.l_renai
, anime = d.anime
, animeSearch = A.init ""
+ , image = Img.info d.image_info
, id = d.id
}
@@ -88,6 +91,7 @@ encode model =
, l_wikidata = model.lWikidata
, l_renai = model.lRenai
, anime = List.map (\a -> { aid = a.aid }) model.anime
+ , image = model.image.id
}
animeConfig : A.Config Msg GApi.ApiAnimeResult
@@ -107,6 +111,10 @@ type Msg
| LRenai String
| AnimeDel Int
| AnimeSearch (A.Msg GApi.ApiAnimeResult)
+ | ImageSet String Bool
+ | ImageSelect
+ | ImageSelected File
+ | ImageMsg Img.Msg
update : Msg -> Model -> (Model, Cmd Msg)
@@ -132,6 +140,11 @@ update msg model =
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)
+ ImageSet s b -> let (nm, nc) = Img.new b s in ({ model | image = nm }, Cmd.map ImageMsg nc)
+ ImageSelect -> (model, FSel.file ["image/png", "image/jpg"] ImageSelected)
+ ImageSelected f -> let (nm, nc) = Img.upload Api.Cv f in ({ model | image = nm }, Cmd.map ImageMsg nc)
+ ImageMsg m -> let (nm, nc) = Img.update m model.image in ({ model | image = nm }, Cmd.map ImageMsg nc)
+
Submit -> ({ model | state = Api.Loading }, GVE.send (encode model) Submitted)
Submitted (GApi.Redirect s) -> (model, load s)
Submitted r -> ({ model | state = Api.Error r }, Cmd.none)
@@ -140,6 +153,7 @@ update msg model =
isValid : Model -> Bool
isValid model = not
( (model.title /= "" && model.title == model.original)
+ || not (Img.isValid model.image)
)
@@ -181,6 +195,30 @@ view model =
]
]
+ image =
+ table [ class "formimage" ] [ tr []
+ [ td [] [ Img.viewImg model.image ]
+ , td []
+ [ h2 [] [ text "Image ID" ]
+ , input ([ type_ "text", class "text", tabindex 10, value (Maybe.withDefault "" model.image.id), onInputValidation ImageSet ] ++ GVE.valImage) []
+ , br [] []
+ , text "Use an image that already exists on the server or empty to remove the current image."
+ , br_ 2
+ , h2 [] [ text "Upload new image" ]
+ , inputButton "Browse image" ImageSelect []
+ , br [] []
+ , text "Preferably the cover of the CD/DVD/package. Image must be in JPEG or PNG format and at most 10 MiB. Images larger than 256x400 will automatically be resized."
+ , case Img.viewVote model.image of
+ Nothing -> text ""
+ Just v ->
+ div []
+ [ br [] []
+ , text "Please flag this image: (see the ", a [ href "/d19" ] [ text "image flagging guidelines" ], text " for guidance)"
+ , Html.map ImageMsg v
+ ]
+ ]
+ ] ]
+
in
form_ Submit (model.state == Api.Loading)
[ div [ class "maintabs left" ]
@@ -195,7 +233,7 @@ view model =
]
]
, div [ class "mainbox", classList [("hidden", model.tab /= General && model.tab /= All)] ] [ h1 [] [ text "General info" ], table [ class "formtable" ] geninfo ]
- , div [ class "mainbox", classList [("hidden", model.tab /= Image && model.tab /= All)] ] [ h1 [] [ text "Image" ] ]
+ , div [ class "mainbox", classList [("hidden", model.tab /= Image && model.tab /= All)] ] [ h1 [] [ text "Image" ], image ]
, div [ class "mainbox", classList [("hidden", model.tab /= Staff && model.tab /= All)] ] [ h1 [] [ text "Staff" ] ]
, div [ class "mainbox", classList [("hidden", model.tab /= Cast && model.tab /= All)] ] [ h1 [] [ text "Cast" ] ]
, div [ class "mainbox", classList [("hidden", model.tab /= Relations && model.tab /= All)] ] [ h1 [] [ text "Relations" ] ]
diff --git a/lib/VNWeb/Chars/Edit.pm b/lib/VNWeb/Chars/Edit.pm
index 355fcb4e..6fb6a494 100644
--- a/lib/VNWeb/Chars/Edit.pm
+++ b/lib/VNWeb/Chars/Edit.pm
@@ -147,6 +147,8 @@ elm_api CharEdit => $FORM_OUT, $FORM_IN, sub {
$data->{main} = undef if $data->{main} && !tuwf->dbVali('SELECT 1 FROM chars WHERE NOT hidden AND main IS NULL AND id =', \$data->{main});
$data->{main_spoil} = 0 if !$data->{main};
+ validate_dbid 'SELECT id FROM images WHERE id IN', $data->{image} if $data->{image};
+
# Allow non-applicable traits only when they were already applied to this character.
validate_dbid
sql('SELECT id FROM traits t WHERE state = 1+1 AND (applicable OR EXISTS(SELECT 1 FROM chars_traits ct WHERE ct.tid = t.id AND ct.id =', \$e->{id}, ')) AND id IN'),
diff --git a/lib/VNWeb/VN/Edit.pm b/lib/VNWeb/VN/Edit.pm
index 05b41668..322a7ba2 100644
--- a/lib/VNWeb/VN/Edit.pm
+++ b/lib/VNWeb/VN/Edit.pm
@@ -1,6 +1,7 @@
package VNWeb::VN::Edit;
use VNWeb::Prelude;
+use VNWeb::Images::Lib 'enrich_image';
my $FORM = {
@@ -17,6 +18,8 @@ my $FORM = {
title => { _when => 'out' },
original => { _when => 'out', required => 0, default => '' },
} },
+ image => { required => 0, vndbid => 'cv' },
+ image_info => { _when => 'out', required => 0, type => 'hash', keys => $VNWeb::Elm::apis{ImageResult}[0]{aoh} },
hidden => { anybool => 1 },
locked => { anybool => 1 },
@@ -37,6 +40,13 @@ TUWF::get qr{/$RE{vrev}/edit} => sub {
$e->{authmod} = auth->permDbmod;
$e->{editsum} = $e->{chrev} == $e->{maxrev} ? '' : "Reverted to revision v$e->{id}.$e->{chrev}";
+ if($e->{image}) {
+ $e->{image_info} = { id => $e->{image} };
+ enrich_image 0, [$e->{image_info}];
+ } else {
+ $e->{image_info} = undef;
+ }
+
enrich_merge aid => 'SELECT id AS aid, title_romaji AS title, title_kanji AS original FROM anime WHERE id IN', $e->{anime};
framework_ title => "Edit $e->{title}", type => 'v', dbobj => $e, tab => 'edit',
@@ -74,6 +84,7 @@ elm_api VNEdit => $FORM_OUT, $FORM_IN, sub {
$data->{desc} = bb_subst_links $data->{desc};
validate_dbid 'SELECT id FROM anime WHERE id IN', map $_->{aid}, $data->{anime}->@*;
+ validate_dbid 'SELECT id FROM images WHERE id IN', $data->{image} if $data->{image};
return elm_Unchanged if !$new && !form_changed $FORM_CMP, $data, $e;
my($id,undef,$rev) = db_edit v => $e->{id}, $data;