summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-09-11 17:05:27 +0200
committerYorhel <git@yorhel.nl>2019-09-11 17:05:44 +0200
commit04e92a4ef886c141783efcb1c62de12722511cc4 (patch)
tree71e1cce07de6bb8760d62a7d197a6b34cab15e67
parent82ade4157f86891c3d90336155a942976e1df934 (diff)
VNDB::Types: Convert (wishlist|rlist|vnlist)_status
I did create a function to export arrays, but ended up exporting them as hashes. That ought to simplify a conversion to an enum type. Which will likely never happen because I'd rather switch to dynamic user-defined statuses, but that's quite a step further...
-rw-r--r--data/global.pl3
-rw-r--r--data/js/vnreldropdown.js8
-rw-r--r--lib/VN3/ElmGen.pm2
-rw-r--r--lib/VN3/Types.pm4
-rw-r--r--lib/VN3/User/Page.pm2
-rw-r--r--lib/VN3/User/VNList.pm10
-rw-r--r--lib/VN3/Validation.pm2
-rw-r--r--lib/VNDB/Handler/Releases.pm6
-rw-r--r--lib/VNDB/Handler/ULists.pm43
-rw-r--r--lib/VNDB/Handler/VNPage.pm10
-rw-r--r--lib/VNDB/Types.pm30
-rw-r--r--lib/VNDB/Util/BrowseHTML.pm2
-rwxr-xr-xutil/jsgen.pl2
13 files changed, 74 insertions, 50 deletions
diff --git a/data/global.pl b/data/global.pl
index 333fab14..cf23b9c2 100644
--- a/data/global.pl
+++ b/data/global.pl
@@ -130,9 +130,6 @@ our %S;
icons_ero_animated => [ 'unknown', 'ero_not_animated', 'ero_simple_animated', 'ero_some_fully_animated', 'ero_all_fully_animated' ],
voiced => [ 'Unknown', 'Not voiced', 'Only ero scenes voiced', 'Partially voiced', 'Fully voiced' ],
icons_voiced => [ 'unknown', 'not_voiced', 'ero_voiced', 'partially_voiced', 'fully_voiced' ],
- wishlist_status => [ 'high', 'medium', 'low', 'blacklist' ],
- rlist_status => [ 'Unknown', 'Pending', 'Obtained', 'On loan', 'Deleted' ], # 0 = hardcoded "unknown", 2 = hardcoded 'OK'
- vnlist_status => [ 'Unknown', 'Playing', 'Finished', 'Stalled', 'Dropped' ],
blood_types => ordhash(qw{unknown Unknown o O a A b B ab AB}),
genders => ordhash(unknown => 'Unknown or N/A', qw{m Male f Female b Both}),
char_roles => ordhash(
diff --git a/data/js/vnreldropdown.js b/data/js/vnreldropdown.js
index 3b8cdf04..16a1dbcd 100644
--- a/data/js/vnreldropdown.js
+++ b/data/js/vnreldropdown.js
@@ -7,9 +7,9 @@ function dropdown(lnk) {
var o = tag('ul', null);
for(var i=0; i<VARS.rlist_status.length; i++) {
var val = VARS.rlist_status[i];
- o.appendChild(tag('li', st == val
- ? tag('i', val)
- : tag('a', {href:'#', rl_rid:relid, rl_act:i, onclick:change}, val)));
+ o.appendChild(tag('li', st == val[1]
+ ? tag('i', val[1])
+ : tag('a', {href:'#', rl_rid:relid, rl_act:val[0], onclick:change}, val[1])));
}
if(st != '--')
o.appendChild(tag('li', tag('a', {href:'#', rl_rid:relid, rl_act:-1, onclick:change}, 'Remove from list')));
@@ -24,7 +24,7 @@ function change() {
ddHide();
setContent(lnk, tag('b', {'class': 'grayedout'}, 'Loading...'));
ajax('/xml/rlist.xml?formcode='+code+';id='+this.rl_rid+';e='+act, function(hr) {
- setText(lnk, act == -1 ? '--' : VARS.rlist_status[act]);
+ setText(lnk, act == -1 ? '--' : VARS.rlist_status[act][1]);
});
return false;
}
diff --git a/lib/VN3/ElmGen.pm b/lib/VN3/ElmGen.pm
index accef5e8..202b72fd 100644
--- a/lib/VN3/ElmGen.pm
+++ b/lib/VN3/ElmGen.pm
@@ -181,7 +181,7 @@ def animated => 'List String' => list map string($_), @ANIMAT
def genders => 'List (String, String)' => list map tuple(string $_, string gender_display $_), keys %GENDERS;
def bloodTypes => 'List (String, String)' => list map tuple(string $_, string blood_type_display $_), keys %BLOOD_TYPES;
def charRoles => 'List (String, String)' => list map tuple(string $_, string char_role_display $_), keys %CHAR_ROLES;
-def vnlistStatus => 'List (Int, String)' => list map tuple($_, string $VNLIST_STATUS[$_]), 0..$#VNLIST_STATUS;
+def vnlistStatus => 'List (Int, String)' => list map tuple($_, string $VNLIST_STATUS{$_}), keys %VNLIST_STATUS;
def emailPattern => String => string { tuwf->compile({ email => 1 })->analyze->html5_validation() }->{pattern};
def weburlPattern => String => string { tuwf->compile({ weburl => 1 })->analyze->html5_validation() }->{pattern};
diff --git a/lib/VN3/Types.pm b/lib/VN3/Types.pm
index e458c085..b8fb3ca0 100644
--- a/lib/VN3/Types.pm
+++ b/lib/VN3/Types.pm
@@ -33,7 +33,6 @@ our @EXPORT = qw/
@ANIMATED
%GENDERS gender_display gender_icon
%BLOOD_TYPES blood_type_display
- @VNLIST_STATUS @RLIST_STATUS
/;
@@ -271,7 +270,4 @@ tie %BLOOD_TYPES, 'Tie::IxHash', qw/unknown Unknown o O a A b B ab AB/;
sub blood_type_display { $BLOOD_TYPES{$_[0]} }
-our @VNLIST_STATUS = ('Unknown', 'Playing', 'Finished', 'Stalled', 'Dropped');
-our @RLIST_STATUS = ('Unknown', 'Pending', 'Obtained', 'On loan', 'Deleted');
-
1;
diff --git a/lib/VN3/User/Page.pm b/lib/VN3/User/Page.pm
index b89c51fb..886ad39a 100644
--- a/lib/VN3/User/Page.pm
+++ b/lib/VN3/User/Page.pm
@@ -103,7 +103,7 @@ sub List {
A href => "/v$i->{vid}", title => $i->{original}||$i->{title}, $i->{title};
};
Td vote_display $i->{vote};
- Td $i->{status} ? $VNLIST_STATUS[$i->{status}] : '';
+ Td $i->{status} ? $VNLIST_STATUS{$i->{status}} : '';
};
}
};
diff --git a/lib/VN3/User/VNList.pm b/lib/VN3/User/VNList.pm
index 71ebd1f3..922f81d6 100644
--- a/lib/VN3/User/VNList.pm
+++ b/lib/VN3/User/VNList.pm
@@ -20,11 +20,11 @@ sub SideBar {
Div class => 'fixed-size-left-sidebar-xl', sub {
Div class => 'vertical-selector-label', 'Status';
Div class => 'vertical-selector', sub {
- for (-1..$#VNLIST_STATUS) {
+ for (-1, keys %VNLIST_STATUS) {
A href => mkurl($opt, t => $_, p => 1), mkclass(
'vertical-selector__item' => 1,
'vertical-selector__item--active' => $_ == $opt->{t}
- ), $_ < 0 ? 'All' : $VNLIST_STATUS[$_];
+ ), $_ < 0 ? 'All' : $VNLIST_STATUS{$_};
}
};
};
@@ -100,11 +100,11 @@ sub VNTable {
Td class => 'table-edit-overlay-base', sub {
Div 'data-elm-module' => 'UVNList.Status',
'data-elm-flags' => JSON::XS->new->encode({uid => int $u->{id}, vid => int $l->{id}, status => int $l->{status}||0}),
- $VNLIST_STATUS[$l->{status}||0];
+ $VNLIST_STATUS{$l->{status}||0};
};
} else {
Td vote_display $l->{vote};
- Td $VNLIST_STATUS[$l->{status}||0];
+ Td $VNLIST_STATUS{$l->{status}||0};
}
# Release info
@@ -140,7 +140,7 @@ sub VNTable {
A href => "/v$r->{rid}", title => $r->{original}||$r->{title}, $r->{title};
};
# TODO: Editabe
- Td width => '20%', $RLIST_STATUS[$l->{status}];
+ Td width => '20%', $RLIST_STATUS{$l->{status}};
Td width => '15%', ''; # TODO: Edit menu
}
}
diff --git a/lib/VN3/Validation.pm b/lib/VN3/Validation.pm
index 1c9a1807..91f09e68 100644
--- a/lib/VN3/Validation.pm
+++ b/lib/VN3/Validation.pm
@@ -40,7 +40,7 @@ TUWF::set custom_validations => {
voiced => { uint => 1, range => [ 0, $#VOICED ] },
rdate => { uint => 1, func => \&_validate_rdate },
spoiler => { uint => 1, range => [ 0, 2 ] },
- vnlist_status=>{ uint => 1, range => [ 0, $#VNLIST_STATUS ] },
+ vnlist_status=>{ enum => \%VNLIST_STATUS },
# Accepts a user-entered vote string (or '-' or empty) and converts that into a DB vote number (or undef)
vnvote => { regex => qr/^(?:|-|[1-9]|10|[1-9]\.[0-9]|10\.0)$/, required => 0, func => sub { $_[0] = $_[0] eq '-' ? undef : 10*$_[0]; 1 } },
# Sort an array by the listed hash keys, using string comparison on each key
diff --git a/lib/VNDB/Handler/Releases.pm b/lib/VNDB/Handler/Releases.pm
index ed9d4627..ff687dec 100644
--- a/lib/VNDB/Handler/Releases.pm
+++ b/lib/VNDB/Handler/Releases.pm
@@ -287,10 +287,10 @@ sub _infotable {
td 'User options';
td;
Select id => 'listsel', name => $self->authGetCode("/r$r->{id}/list");
- option value => -2, !$rl ? 'not on your list' : "Status: $self->{rlist_status}[$rl->{status}]";
+ option value => -2, !$rl ? 'not on your list' : "Status: $RLIST_STATUS{$rl->{status}}";
optgroup label => 'Set status';
- option value => $_, $self->{rlist_status}[$_]
- for (0..$#{$self->{rlist_status}});
+ option value => $_, $RLIST_STATUS{$_}
+ for (keys %RLIST_STATUS);
end;
option value => -1, 'remove from list' if $rl;
end;
diff --git a/lib/VNDB/Handler/ULists.pm b/lib/VNDB/Handler/ULists.pm
index 7f4d1ed6..b66d0419 100644
--- a/lib/VNDB/Handler/ULists.pm
+++ b/lib/VNDB/Handler/ULists.pm
@@ -5,6 +5,7 @@ use strict;
use warnings;
use TUWF ':html', ':xml';
use VNDB::Func;
+use VNDB::Types;
TUWF::register(
@@ -47,7 +48,7 @@ sub vnwish {
return if !$self->authCheckCode;
my $f = $self->formValidate(
- { get => 's', enum => [ -1..$#{$self->{wishlist_status}} ] },
+ { get => 's', enum => [ -1, keys %WISHLIST_STATUS ] },
{ get => 'ref', required => 0, default => "/v$id" }
);
return $self->resNotFound if $f->{_err};
@@ -67,7 +68,7 @@ sub vnlist_e {
return if !$self->authCheckCode;
my $f = $self->formValidate(
- { get => 'e', enum => [ -1..$#{$self->{vnlist_status}} ] },
+ { get => 'e', enum => [ -1, keys %VNLIST_STATUS ] },
{ get => 'ref', required => 0, default => "/v$id" }
);
return $self->resNotFound if $f->{_err};
@@ -94,7 +95,7 @@ sub rlist_e {
return if !$self->authCheckCode;
my $f = $self->formValidate(
- { get => 'e', required => 1, enum => [ -1..$#{$self->{rlist_status}} ] },
+ { get => 'e', required => 1, enum => [ -1, keys %RLIST_STATUS ] },
{ get => 'ref', required => 0, default => "/r$rid" }
);
return $self->resNotFound if $f->{_err};
@@ -238,7 +239,7 @@ sub wishlist {
{ get => 'p', required => 0, default => 1, template => 'page' },
{ get => 'o', required => 0, default => 'd', enum => [ 'a', 'd' ] },
{ get => 's', required => 0, default => 'wstat', enum => [qw|title added wstat|] },
- { get => 'f', required => 0, default => -1, enum => [ -1..$#{$self->{wishlist_status}} ] },
+ { get => 'f', required => 0, default => -1, enum => [ -1, keys %WISHLIST_STATUS ] },
);
return $self->resNotFound if $f->{_err};
@@ -246,7 +247,7 @@ sub wishlist {
return if !$self->authCheckCode;
my $frm = $self->formValidate(
{ post => 'sel', required => 0, default => 0, multi => 1, template => 'id' },
- { post => 'batchedit', required => 1, enum => [ -1..$#{$self->{wishlist_status}} ] },
+ { post => 'batchedit', required => 1, enum => [ -1, keys %WISHLIST_STATUS ] },
);
$frm->{sel} = [ grep $_, @{$frm->{sel}} ]; # weed out "select all" checkbox
if(!$frm->{_err} && @{$frm->{sel}} && $frm->{sel}[0]) {
@@ -276,8 +277,8 @@ sub wishlist {
}
p class => 'browseopts';
a $f->{f} == $_ ? (class => 'optselected') : (), href => "/u$uid/wish?f=$_",
- $_ == -1 ? 'All priorities' : $self->{wishlist_status}[$_]
- for (-1..$#{$self->{wishlist_status}});
+ $_ == -1 ? 'All priorities' : $WISHLIST_STATUS{$_}
+ for (-1, keys %WISHLIST_STATUS);
end;
end 'div';
@@ -306,7 +307,7 @@ sub wishlist {
if $own;
a href => "/v$i->{vid}", title => $i->{original}||$i->{title}, ' '.shorten $i->{title}, 70;
end;
- td class => 'tc2', $self->{wishlist_status}[$i->{wstat}];
+ td class => 'tc2', $WISHLIST_STATUS{$i->{wstat}};
td class => 'tc3', fmtdate $i->{added}, 'compact';
end;
},
@@ -318,8 +319,8 @@ sub wishlist {
Select name => 'batchedit', id => 'batchedit';
option '-- with selected --';
optgroup label => 'Change priority';
- option value => $_, $self->{wishlist_status}[$_]
- for (0..$#{$self->{wishlist_status}});
+ option value => $_, $WISHLIST_STATUS{$_}
+ for (keys %WISHLIST_STATUS);
end;
option value => -1, 'remove from wishlist';
end;
@@ -345,7 +346,7 @@ sub vnlist {
{ get => 's', required => 0, default => 'title', enum => [ 'title', 'vote' ] },
{ get => 'c', required => 0, default => 'all', enum => [ 'all', 'a'..'z', 0 ] },
{ get => 'v', required => 0, default => 0, enum => [ -1..1 ] },
- { get => 't', required => 0, default => -1, enum => [ -1..$#{$self->{vnlist_status}} ] },
+ { get => 't', required => 0, default => -1, enum => [ -1, keys %VNLIST_STATUS ] },
);
return $self->resNotFound if $f->{_err};
@@ -355,8 +356,8 @@ sub vnlist {
{ post => 'vid', required => 0, default => 0, multi => 1, template => 'id' },
{ post => 'rid', required => 0, default => 0, multi => 1, template => 'id' },
{ post => 'not', required => 0, default => '', maxlength => 2000 },
- { post => 'vns', required => 1, enum => [ -2..$#{$self->{vnlist_status}}, 999 ] },
- { post => 'rel', required => 1, enum => [ -2..$#{$self->{rlist_status}} ] },
+ { post => 'vns', required => 1, enum => [ -2, -1, keys %VNLIST_STATUS, 999 ] },
+ { post => 'rel', required => 1, enum => [ -2, -1, keys %RLIST_STATUS ] },
);
my @vid = grep $_ > 0, @{$frm->{vid}};
my @rid = grep $_ > 0, @{$frm->{rid}};
@@ -414,7 +415,7 @@ sub vnlist {
end;
p class => 'browseopts';
a href => $url->(t => -1), -1 == $f->{t} ? (class => 'optselected') : (), 'All';
- a href => $url->(t => $_), $_ == $f->{t} ? (class => 'optselected') : (), $self->{vnlist_status}[$_] for 0..$#{$self->{vnlist_status}};
+ a href => $url->(t => $_), $_ == $f->{t} ? (class => 'optselected') : (), $VNLIST_STATUS{$_} for keys %VNLIST_STATUS;
end;
end 'div';
@@ -460,7 +461,7 @@ sub _vnlist_browse {
a href => "/v$i->{vid}", title => $i->{original}||$i->{title}, shorten $i->{title}, 70;
b class => 'grayedout', $i->{notes} if $i->{notes};
end;
- td class => 'tc6', $i->{status} ? $self->{vnlist_status}[$i->{status}] : '';
+ td class => 'tc6', $i->{status} ? $VNLIST_STATUS{$i->{status}} : '';
td class => 'tc7';
my $obtained = grep $_->{status}==2, @{$i->{rels}};
my $total = scalar @{$i->{rels}};
@@ -482,13 +483,13 @@ sub _vnlist_browse {
lit fmtdatestr $_->{released};
end;
td class => 'tc4';
- cssicon "lang $_", $self->{languages}{$_} for @{$_->{languages}};
+ cssicon "lang $_", $LANGUAGE{$_} for @{$_->{languages}};
cssicon "rt$_->{type}", $_->{type};
end;
td class => 'tc5';
a href => "/r$_->{rid}", title => $_->{original}||$_->{title}, shorten $_->{title}, 50;
end;
- td class => 'tc6', $_->{status} ? $self->{rlist_status}[$_->{status}] : '';
+ td class => 'tc6', $_->{status} ? $RLIST_STATUS{$_->{status}} : '';
td class => 'tc7_8', colspan => 2, '';
end 'tr';
}
@@ -502,8 +503,8 @@ sub _vnlist_browse {
Select id => 'vns', name => 'vns';
option value => -2, '-- with selected VNs --';
optgroup label => 'Change status';
- option value => $_, $self->{vnlist_status}[$_]
- for (0..$#{$self->{vnlist_status}});
+ option value => $_, $VNLIST_STATUS{$_}
+ for (keys %VNLIST_STATUS);
end;
option value => 999, 'Set note';
option value => -1, 'remove from list';
@@ -511,8 +512,8 @@ sub _vnlist_browse {
Select id => 'rel', name => 'rel';
option value => -2, '-- with selected releases --';
optgroup label => 'Change status';
- option value => $_, $self->{rlist_status}[$_]
- for (0..$#{$self->{rlist_status}});
+ option value => $_, $RLIST_STATUS{$_}
+ for (keys %RLIST_STATUS);
end;
option value => -1, 'remove from list';
end;
diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm
index b130ddc9..d8e0840e 100644
--- a/lib/VNDB/Handler/VNPage.pm
+++ b/lib/VNDB/Handler/VNPage.pm
@@ -730,9 +730,9 @@ sub _useroptions {
}
Select id => 'listsel', name => $self->authGetCode("/v$v->{id}/list");
- option $list ? "VN list: $self->{vnlist_status}[$list->{status}]" : 'not on your VN list';
+ option $list ? "VN list: $VNLIST_STATUS{$list->{status}}" : 'not on your VN list';
optgroup label => $list ? 'Change status' : 'Add to VN list';
- option value => $_, $self->{vnlist_status}[$_] for (0..$#{$self->{vnlist_status}});
+ option value => $_, $VNLIST_STATUS{$_} for (keys %VNLIST_STATUS);
end;
option value => -1, 'remove from VN list' if $list;
end;
@@ -740,9 +740,9 @@ sub _useroptions {
if(!$vote || $wish) {
Select id => 'wishsel', name => $self->authGetCode("/v$v->{id}/wish");
- option $wish ? "wishlist: $self->{wishlist_status}[$wish->{wstat}]" : 'not on your wishlist';
+ option $wish ? "wishlist: $WISHLIST_STATUS{$wish->{wstat}}" : 'not on your wishlist';
optgroup label => $wish ? 'Change status' : 'Add to wishlist';
- option value => $_, $self->{wishlist_status}[$_] for (0..$#{$self->{wishlist_status}});
+ option value => $_, $WISHLIST_STATUS{$_} for (keys %WISHLIST_STATUS);
end;
option value => -1, 'remove from wishlist' if $wish;
end;
@@ -834,7 +834,7 @@ sub _releases {
td class => 'tc5';
if($self->authInfo->{id}) {
a href => "/r$rel->{id}", id => "rlsel_$rel->{id}", class => 'vnrlsel',
- $rel->{ulist} ? $self->{rlist_status}[ $rel->{ulist}{status} ] : '--';
+ $rel->{ulist} ? $RLIST_STATUS{ $rel->{ulist}{status} } : '--';
} else {
txt ' ';
}
diff --git a/lib/VNDB/Types.pm b/lib/VNDB/Types.pm
index 2d87b88a..8c29df3b 100644
--- a/lib/VNDB/Types.pm
+++ b/lib/VNDB/Types.pm
@@ -14,6 +14,12 @@ sub hash {
push @EXPORT, "%$name";
}
+sub array {
+ my $name = shift;
+ $name->@* = @_;
+ push @EXPORT, "\@$name";
+}
+
sub fun($&) {
my($name, $code) = @_;
*$name = $code;
@@ -141,3 +147,27 @@ hash CREDIT_TYPE =>
songs => 'Vocals',
director => 'Director',
staff => 'Staff';
+
+
+
+
+hash WISHLIST_STATUS =>
+ 0 => 'High',
+ 1 => 'Medium',
+ 2 => 'Low',
+ 3 => 'Blacklist';
+
+# 0 = hardcoded "unknown", 2 = hardcoded 'OK'
+hash RLIST_STATUS =>
+ 0 => 'Unknown',
+ 1 => 'Pending',
+ 2 => 'Obtained',
+ 3 => 'On loan',
+ 4 => 'Deleted';
+
+hash VNLIST_STATUS =>
+ 0 => 'Unknown',
+ 1 => 'Playing',
+ 2 => 'Finished',
+ 3 => 'Stalled',
+ 4 => 'Dropped';
diff --git a/lib/VNDB/Util/BrowseHTML.pm b/lib/VNDB/Util/BrowseHTML.pm
index ee2dbbf1..09bf55b2 100644
--- a/lib/VNDB/Util/BrowseHTML.pm
+++ b/lib/VNDB/Util/BrowseHTML.pm
@@ -197,7 +197,7 @@ sub htmlBrowseVN {
lit sprintf '<b class="%s">%d/%d</b>', $l->{userlist_obtained} == $l->{userlist_all} ? 'done' : 'todo', $l->{userlist_obtained}, $l->{userlist_all} if $l->{userlist_all};
end 'td';
}
- td class => 'tc8', defined($l->{wstat}) ? $self->{wishlist_status}[$l->{wstat}] : '' if $f->{wish};
+ td class => 'tc8', defined($l->{wstat}) ? $WISHLIST_STATUS{$l->{wstat}} : '' if $f->{wish};
td class => 'tc2';
$_ ne 'oth' && cssicon $_, $PLATFORM{$_}
for (sort @{$l->{c_platforms}});
diff --git a/util/jsgen.pl b/util/jsgen.pl
index 3fb58b06..7228276f 100755
--- a/util/jsgen.pl
+++ b/util/jsgen.pl
@@ -36,7 +36,7 @@ sub resolutions {
sub vars {
my %vars = (
- rlist_status => $S{rlist_status},
+ rlist_status => [ map [ $_, $RLIST_STATUS{$_} ], keys %RLIST_STATUS ],
cookie_prefix => $O{cookie_prefix},
age_ratings => [ map [ $_, $_ == -1 ? 'Unknown' : $_ == 0 ? 'All ages' : "$_+" ], @{$S{age_ratings}} ],
languages => [ map [ $_, $LANGUAGE{$_} ], keys %LANGUAGE ],