summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-06-26 11:44:19 +0200
committerYorhel <git@yorhel.nl>2020-06-29 09:31:31 +0200
commit6831c0b0de4c6581f7d5481e1df4e37754d64b63 (patch)
tree7d913d6a0d33d381bf6ec0b0975b3f1dcc2c617f
parentcbdcdab0ce2c5bb8e686f2ff18c4b886ea740cad (diff)
VN::Edit: Start rewrite of the VN edit form
This is mostly a copy-paste of the Char::Edit form.
-rw-r--r--elm/VNEdit.elm160
-rw-r--r--lib/VNDB/Handler/VNEdit.pm8
-rw-r--r--lib/VNWeb/HTML.pm5
-rw-r--r--lib/VNWeb/VN/Edit.pm71
4 files changed, 240 insertions, 4 deletions
diff --git a/elm/VNEdit.elm b/elm/VNEdit.elm
new file mode 100644
index 00000000..e6b50287
--- /dev/null
+++ b/elm/VNEdit.elm
@@ -0,0 +1,160 @@
+module VNEdit exposing (main)
+
+import Html exposing (..)
+import Html.Events exposing (..)
+import Html.Keyed as K
+import Html.Attributes exposing (..)
+import Browser
+import Browser.Navigation exposing (load)
+import Dict
+import Set
+import File exposing (File)
+import File.Select as FSel
+import Lib.Util exposing (..)
+import Lib.Html exposing (..)
+import Lib.TextPreview as TP
+import Lib.Autocomplete as A
+import Lib.Api as Api
+import Lib.Editsum as Editsum
+import Gen.VNEdit as GVE
+import Gen.Types as GT
+import Gen.Api as GApi
+
+
+main : Program GVE.Recv Model Msg
+main = Browser.element
+ { init = \e -> (init e, Cmd.none)
+ , view = view
+ , update = update
+ , subscriptions = always Sub.none
+ }
+
+
+type Tab
+ = General
+ | Image
+ | Staff
+ | Cast
+ | Relations
+ | Screenshots
+ | All
+
+type alias Model =
+ { state : Api.State
+ , tab : Tab
+ , editsum : Editsum.Model
+ , title : String
+ , original : String
+ , alias : String
+ , desc : TP.Model
+ , id : Maybe Int
+ }
+
+
+init : GVE.Recv -> Model
+init d =
+ { state = Api.Normal
+ , tab = General
+ , editsum = { authmod = d.authmod, editsum = TP.bbcode d.editsum, locked = d.locked, hidden = d.hidden }
+ , title = d.title
+ , original = d.original
+ , alias = d.alias
+ , desc = TP.bbcode d.desc
+ , id = d.id
+ }
+
+
+encode : Model -> GVE.Send
+encode model =
+ { id = model.id
+ , editsum = model.editsum.editsum.data
+ , hidden = model.editsum.hidden
+ , locked = model.editsum.locked
+ , title = model.title
+ , original = model.original
+ , alias = model.alias
+ , desc = model.desc.data
+ }
+
+type Msg
+ = Editsum Editsum.Msg
+ | Tab Tab
+ | Submit
+ | Submitted GApi.Response
+ | Title String
+ | Original String
+ | Alias String
+ | Desc TP.Msg
+
+
+update : Msg -> Model -> (Model, Cmd Msg)
+update msg model =
+ case msg of
+ Editsum m -> let (nm,nc) = Editsum.update m model.editsum in ({ model | editsum = nm }, Cmd.map Editsum nc)
+ Tab t -> ({ model | tab = t }, Cmd.none)
+ Title s -> ({ model | title = s }, Cmd.none)
+ 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)
+
+ 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)
+
+
+isValid : Model -> Bool
+isValid model = not
+ ( (model.title /= "" && model.title == model.original)
+ )
+
+
+view : Model -> Html Msg
+view model =
+ let
+ geninfo =
+ [ formField "title::Title (romaji)" [ inputText "title" model.title Title GVE.valTitle ]
+ , formField "original::Original title"
+ [ inputText "original" model.original Title GVE.valOriginal
+ , if model.title /= "" && model.title == model.original
+ then b [ class "standout" ] [ br [] [], text "Should not be the same as the Title (romaji). Leave blank is the original title is already in the latin alphabet" ]
+ else text ""
+ ]
+ , formField "alias::Aliases"
+ [ inputTextArea "alias" model.alias Alias (rows 3 :: GVE.valAlias)
+ , br [] []
+ , text "List of alternative titles or abbreviations. One line for each alias. Can include both official (japanese/english) titles and unofficial titles used around net."
+ , br [] []
+ , text "Titles that are listed in the releases should not be added here!"
+ -- TODO: Compare & warn when release title is listed as alias
+ ]
+ , formField "desc::Description"
+ [ 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."
+ ]
+ ]
+
+ in
+ form_ Submit (model.state == Api.Loading)
+ [ div [ class "maintabs left" ]
+ [ ul []
+ [ li [ classList [("tabselected", model.tab == General )] ] [ a [ href "#", onClickD (Tab General ) ] [ text "General info" ] ]
+ , li [ classList [("tabselected", model.tab == Image )] ] [ a [ href "#", onClickD (Tab Image ) ] [ text "Image" ] ]
+ , li [ classList [("tabselected", model.tab == Staff )] ] [ a [ href "#", onClickD (Tab Staff ) ] [ text "Staff" ] ]
+ , li [ classList [("tabselected", model.tab == Cast )] ] [ a [ href "#", onClickD (Tab Cast ) ] [ text "Cast" ] ]
+ , li [ classList [("tabselected", model.tab == Relations )] ] [ a [ href "#", onClickD (Tab Relations ) ] [ text "Relations" ] ]
+ , li [ classList [("tabselected", model.tab == Screenshots)] ] [ a [ href "#", onClickD (Tab Screenshots) ] [ text "Screenshots" ] ]
+ , li [ classList [("tabselected", model.tab == All )] ] [ a [ href "#", onClickD (Tab All ) ] [ text "All items" ] ]
+ ]
+ ]
+ , 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 /= 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" ] ]
+ , div [ class "mainbox", classList [("hidden", model.tab /= Screenshots && model.tab /= All)] ] [ h1 [] [ text "Screenshots" ] ]
+ , div [ class "mainbox" ] [ fieldset [ class "submit" ]
+ [ Html.map Editsum (Editsum.view model.editsum)
+ , submitButton "Submit" model.state (isValid model)
+ ]
+ ]
+ ]
diff --git a/lib/VNDB/Handler/VNEdit.pm b/lib/VNDB/Handler/VNEdit.pm
index 49e383a7..4c0a4737 100644
--- a/lib/VNDB/Handler/VNEdit.pm
+++ b/lib/VNDB/Handler/VNEdit.pm
@@ -10,9 +10,9 @@ use VNDB::Types;
TUWF::register(
- qr{v(?:([1-9]\d*)(?:\.([1-9]\d*))?/edit|/new)}
+ qr{old/v(?:([1-9]\d*)(?:\.([1-9]\d*))?/edit|/new)}
=> \&edit,
- qr{v/add} => \&addform,
+ qr{old/v/add} => \&addform,
qr{xml/vn\.xml} => \&vnxml,
qr{xml/screenshots\.xml} => \&scrxml,
);
@@ -69,7 +69,7 @@ sub addform {
end 'div';
}
- $self->htmlForm({ frm => $frm, action => '/v/add', continue => @$l ? 2 : 1 },
+ $self->htmlForm({ frm => $frm, action => '/old/v/add', continue => @$l ? 2 : 1 },
vn_add => [ 'Add a new visual novel',
[ input => short => 'title', name => 'Title (romaji)', width => 450 ],
[ input => short => 'original', name => 'Original title', width => 450 ],
@@ -255,7 +255,7 @@ sub _uploadimage {
sub _form {
my($self, $v, $frm, $r, $chars) = @_;
- $self->htmlForm({ frm => $frm, action => $v ? "/v$v->{id}/edit" : '/v/new', editsum => 1, upload => 1 },
+ $self->htmlForm({ frm => $frm, action => $v ? "/old/v$v->{id}/edit" : '/old/v/new', editsum => 1, upload => 1 },
vn_geninfo => [ 'General info',
[ input => short => 'title', name => 'Title (romaji)', width => 450 ],
[ input => short => 'original', name => 'Original title', width => 450 ],
diff --git a/lib/VNWeb/HTML.pm b/lib/VNWeb/HTML.pm
index 89a5fa6f..f411e3da 100644
--- a/lib/VNWeb/HTML.pm
+++ b/lib/VNWeb/HTML.pm
@@ -821,6 +821,11 @@ sub editmsg_ {
li_ 'Fields marked with (*) may cause other fields to become (un)available depending on the selection.' if $type eq 'r';
}
};
+ p_ class => 'center', sub {
+ txt_ "If you're having trouble using this new form, the ";
+ a_ href => '/old'.($obj ? "/v$obj->{id}/edit" : '/v/add'), 'old form';
+ txt_ ' is still available.';
+ } if $type eq 'v' && tuwf->reqPath() !~ m{^/old/};
}
}
diff --git a/lib/VNWeb/VN/Edit.pm b/lib/VNWeb/VN/Edit.pm
new file mode 100644
index 00000000..e71d77ae
--- /dev/null
+++ b/lib/VNWeb/VN/Edit.pm
@@ -0,0 +1,71 @@
+package VNWeb::VN::Edit;
+
+use VNWeb::Prelude;
+
+
+my $FORM = {
+ id => { required => 0, id => 1 },
+ title => { maxlength => 250 },
+ original => { required => 0, default => '', maxlength => 250 },
+ alias => { required => 0, default => '', maxlength => 500 },
+ desc => { required => 0, default => '', maxlength => 10240 },
+ hidden => { anybool => 1 },
+ locked => { anybool => 1 },
+
+ authmod => { _when => 'out', anybool => 1 },
+ editsum => { _when => 'in out', editsum => 1 },
+};
+
+my $FORM_OUT = form_compile out => $FORM;
+my $FORM_IN = form_compile in => $FORM;
+my $FORM_CMP = form_compile cmp => $FORM;
+
+
+TUWF::get qr{/$RE{vrev}/edit} => sub {
+ my $e = db_entry v => tuwf->capture('id'), tuwf->capture('rev') or return tuwf->resNotFound;
+ return tuwf->resDenied if !can_edit v => $e;
+
+ $e->{image_sex} = $e->{image_vio} = undef;
+ $e->{authmod} = auth->permDbmod;
+ $e->{editsum} = $e->{chrev} == $e->{maxrev} ? '' : "Reverted to revision v$e->{id}.$e->{chrev}";
+
+ framework_ title => "Edit $e->{title}", type => 'v', dbobj => $e, tab => 'edit',
+ sub {
+ editmsg_ v => $e, "Edit $e->{title}";
+ elm_ VNEdit => $FORM_OUT, $e;
+ };
+};
+
+
+# TODO: Make this work
+TUWF::get qr{/v/add}, sub {
+ return tuwf->resDenied if !can_edit v => undef;
+
+ my $e = elm_empty($FORM_OUT);
+
+ framework_ title => 'Add visual novel',
+ sub {
+ editmsg_ v => undef, 'Add visual novel';
+ elm_ VNEdit => $FORM_OUT, $e;
+ };
+};
+
+
+elm_api VNEdit => $FORM_OUT, $FORM_IN, sub {
+ my $data = shift;
+ my $new = !$data->{id};
+ my $e = $new ? { id => 0 } : db_entry v => $data->{id} or return tuwf->resNotFound;
+ return elm_Unauth if !can_edit v => $e;
+
+ if(!auth->permDbmod) {
+ $data->{hidden} = $e->{hidden}||0;
+ $data->{locked} = $e->{locked}||0;
+ }
+ $data->{desc} = bb_subst_links $data->{desc};
+
+ return elm_Unchanged if !$new && !form_changed $FORM_CMP, $data, $e;
+ my($id,undef,$rev) = db_edit v => $e->{id}, $data;
+ elm_Redirect "/v$id.$rev";
+};
+
+1;