summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-05-25 14:29:03 +0200
committerYorhel <git@yorhel.nl>2020-05-25 14:29:28 +0200
commitfbe2b482ff4cf19b25941a70bb72bb23a15c11d1 (patch)
treefdf2b58a31a39413624eca472e23f1fbacb1b27d
parent71d8fb65059288d6f312bf6c61b21c8bb2dea82f (diff)
Chars::Edit: Character creation + copying
This removes the 'Add character' link from the main menu, need some data to see if it's used.
-rw-r--r--elm/CharEdit.elm2
-rw-r--r--lib/VNDB/Handler/Chars.pm2
-rw-r--r--lib/VNWeb/Chars/Edit.pm55
-rw-r--r--lib/VNWeb/HTML.pm1
-rw-r--r--lib/VNWeb/VN/Page.pm2
5 files changed, 36 insertions, 26 deletions
diff --git a/elm/CharEdit.elm b/elm/CharEdit.elm
index 56aadb81..6b964117 100644
--- a/elm/CharEdit.elm
+++ b/elm/CharEdit.elm
@@ -269,7 +269,7 @@ update msg model =
isValid : Model -> Bool
isValid model = not
- ( model.name == model.original
+ ( (model.name /= "" && model.name == model.original)
|| hasDuplicates (List.map (\v -> (v.vid, Maybe.withDefault 0 v.rid)) model.vns)
)
diff --git a/lib/VNDB/Handler/Chars.pm b/lib/VNDB/Handler/Chars.pm
index 781a5507..55936775 100644
--- a/lib/VNDB/Handler/Chars.pm
+++ b/lib/VNDB/Handler/Chars.pm
@@ -126,7 +126,7 @@ sub edit {
$self->htmlHeader(title => $title, noindex => 1);
$self->htmlMainTabs('c', $r, $copy ? 'copy' : 'edit') if $r;
$self->htmlEditMessage('c', $r, $title, $copy);
- $self->htmlForm({ frm => $frm, action => $r ? "/c$id/".($copy ? 'copy' : 'edit') : '/c/new', editsum => 1, upload => 1 },
+ $self->htmlForm({ frm => $frm, action => $r ? "/old/c$id/".($copy ? 'copy' : 'edit') : '/old/c/new', editsum => 1, upload => 1 },
chare_geninfo => [ 'General info',
[ input => name => 'Name (romaji)', short => 'name' ],
[ input => name => 'Original name', short => 'original' ],
diff --git a/lib/VNWeb/Chars/Edit.pm b/lib/VNWeb/Chars/Edit.pm
index ae8fb564..6aae944c 100644
--- a/lib/VNWeb/Chars/Edit.pm
+++ b/lib/VNWeb/Chars/Edit.pm
@@ -56,18 +56,8 @@ my $FORM_IN = form_compile in => $FORM;
my $FORM_CMP = form_compile cmp => $FORM;
-TUWF::get qr{/$RE{crev}/edit} => sub {
- my $e = db_entry c => tuwf->capture('id'), tuwf->capture('rev') or return tuwf->resNotFound;
- return tuwf->resDenied if !can_edit c => $e;
-
- $e->{main_name} = $e->{main} ? tuwf->dbVali('SELECT name FROM chars WHERE id =', \$e->{main}) : '';
- $e->{main_ref} = tuwf->dbVali('SELECT 1 FROM chars WHERE main =', \$e->{id})||0;
-
- enrich_merge tid => 'SELECT t.id AS tid, t.name, t.applicable, g.name AS group, g.order AS order, false AS new FROM traits t LEFT JOIN traits g ON g.id = t.group WHERE t.id IN', $e->{traits};
- $e->{traits} = [ sort { ($a->{order}//99) <=> ($b->{order}//99) || $a->{name} cmp $b->{name} } $e->{traits}->@* ];
-
- enrich_merge vid => 'SELECT id AS vid, title FROM vn WHERE id IN', $e->{vns};
- $e->{vns} = [ sort { $a->{title} cmp $b->{title} || $a->{vid} <=> $b->{vid} || ($a->{rid}||0) <=> ($b->{rid}||0) } $e->{vns}->@* ];
+sub enrich_releases {
+ my($e) = @_;
my %vns;
$e->{releases} = [ map !$vns{$_->{vid}}++ ? { id => $_->{vid} } : (), $e->{vns}->@* ];
@@ -80,28 +70,49 @@ TUWF::get qr{/$RE{crev}/edit} => sub {
}, $e->{releases};
enrich_flatten lang => id => id => sub { sql('SELECT id, lang FROM releases_lang WHERE id IN', $_, 'ORDER BY lang') }, map $_->{rels}, $e->{releases}->@*;
enrich_flatten platforms => id => id => sub { sql('SELECT id, platform FROM releases_platforms WHERE id IN', $_, 'ORDER BY platform') }, map $_->{rels}, $e->{releases}->@*;
+}
+
+
+TUWF::get qr{/$RE{crev}/(?<action>edit|copy)} => sub {
+ my $e = db_entry c => tuwf->capture('id'), tuwf->capture('rev') or return tuwf->resNotFound;
+ my $copy = tuwf->capture('action') eq 'copy';
+ return tuwf->resDenied if !can_edit c => $copy ? {} : $e;
+
+ $e->{main_name} = $e->{main} ? tuwf->dbVali('SELECT name FROM chars WHERE id =', \$e->{main}) : '';
+ $e->{main_ref} = tuwf->dbVali('SELECT 1 FROM chars WHERE main =', \$e->{id})||0;
+
+ enrich_merge tid => 'SELECT t.id AS tid, t.name, t.applicable, g.name AS group, g.order AS order, false AS new FROM traits t LEFT JOIN traits g ON g.id = t.group WHERE t.id IN', $e->{traits};
+ $e->{traits} = [ sort { ($a->{order}//99) <=> ($b->{order}//99) || $a->{name} cmp $b->{name} } $e->{traits}->@* ];
+
+ enrich_merge vid => 'SELECT id AS vid, title FROM vn WHERE id IN', $e->{vns};
+ $e->{vns} = [ sort { $a->{title} cmp $b->{title} || $a->{vid} <=> $b->{vid} || ($a->{rid}||0) <=> ($b->{rid}||0) } $e->{vns}->@* ];
+ enrich_releases $e;
$e->{authmod} = auth->permDbmod;
- $e->{editsum} = $e->{chrev} == $e->{maxrev} ? '' : "Reverted to revision c$e->{id}.$e->{chrev}";
+ $e->{editsum} = $copy ? "Copied from c$e->{id}.$e->{chrev}" : $e->{chrev} == $e->{maxrev} ? '' : "Reverted to revision c$e->{id}.$e->{chrev}";
- framework_ title => "Edit $e->{name}", type => 'c', dbobj => $e, tab => 'edit',
+ my $title = ($copy ? 'Copy ' : 'Edit ').$e->{name};
+ framework_ title => $title, type => 'c', dbobj => $e, tab => tuwf->capture('action'),
sub {
- editmsg_ c => $e, "Edit $e->{name}";
- elm_ CharEdit => $FORM_OUT, $e;
+ editmsg_ c => $e, $title, $copy;
+ elm_ CharEdit => $FORM_OUT, $copy ? {%$e, id=>undef} : $e;
};
};
-# XXX: Require VN
-# TODO: Copy.
-TUWF::get qr{/c/new}, sub {
+TUWF::get qr{/$RE{vid}/addchar}, sub {
return tuwf->resDenied if !can_edit c => undef;
+ my $v = tuwf->dbRowi('SELECT id, title FROM vn WHERE NOT hidden AND id =', \tuwf->capture('id'));
+ return tuwf->resNotFound if !$v->{id};
+
+ my $e = elm_empty($FORM_OUT);
+ $e->{vns} = [{ vid => $v->{id}, title => $v->{title}, rid => undef, spoil => 0, role => 'primary' }];
+ enrich_releases $e;
+
framework_ title => 'Add character',
sub {
editmsg_ c => undef, 'Add character';
- elm_ CharEdit => $FORM_OUT, {
- elm_empty($FORM_OUT)->%*,
- };
+ elm_ CharEdit => $FORM_OUT, $e;
};
};
diff --git a/lib/VNWeb/HTML.pm b/lib/VNWeb/HTML.pm
index 369db474..81e649d8 100644
--- a/lib/VNWeb/HTML.pm
+++ b/lib/VNWeb/HTML.pm
@@ -241,7 +241,6 @@ sub _menu_ {
a_ href => '/v/add', 'Add Visual Novel'; br_;
a_ href => '/p/add', 'Add Producer'; br_;
a_ href => '/s/new', 'Add Staff'; br_;
- a_ href => '/c/new', 'Add Character'; br_;
}
br_;
form_ action => "$uid/logout", method => 'post', sub {
diff --git a/lib/VNWeb/VN/Page.pm b/lib/VNWeb/VN/Page.pm
index 5fe84698..c3feac4a 100644
--- a/lib/VNWeb/VN/Page.pm
+++ b/lib/VNWeb/VN/Page.pm
@@ -413,7 +413,7 @@ sub tabs_ {
ul_ sub {
if(auth->permEdit) {
li_ sub { a_ href => "/v$v->{id}/add", 'add release' };
- li_ sub { a_ href => "/c/new?vid=$v->{id}", 'add character' };
+ li_ sub { a_ href => "/v$v->{id}/addchar", 'add character' };
}
};
}