diff options
-rw-r--r-- | lib/VNDB/DB/Chars.pm | 2 | ||||
-rw-r--r-- | lib/VNDB/Handler/Chars.pm | 12 | ||||
-rw-r--r-- | lib/VNDB/Util/FormHTML.pm | 4 | ||||
-rw-r--r-- | util/sql/schema.sql | 4 | ||||
-rw-r--r-- | util/updates/update_20190525.sql | 8 |
5 files changed, 19 insertions, 11 deletions
diff --git a/lib/VNDB/DB/Chars.pm b/lib/VNDB/DB/Chars.pm index 923d1e94..67fe2565 100644 --- a/lib/VNDB/DB/Chars.pm +++ b/lib/VNDB/DB/Chars.pm @@ -40,7 +40,7 @@ sub dbCharGet { defined $o{height_min} ? ( 'c.height >= ?' => $o{height_min} ) : (), defined $o{height_max} ? ( 'c.height <= ? AND c.height > 0' => $o{height_max} ) : (), defined $o{weight_min} ? ( 'c.weight >= ?' => $o{weight_min} ) : (), - defined $o{weight_max} ? ( 'c.weight <= ? AND c.weight > 0' => $o{weight_max} ) : (), + defined $o{weight_max} ? ( 'c.weight <= ?' => $o{weight_max} ) : (), $o{search} ? ( "(c.name ILIKE ? OR translate(c.original,' ','') ILIKE translate(?,' ','') OR c.alias ILIKE ?)", [ map '%'.$o{search}.'%', 1..3 ] ) : (), $o{char} ? ( diff --git a/lib/VNDB/Handler/Chars.pm b/lib/VNDB/Handler/Chars.pm index cce59f36..0312ae51 100644 --- a/lib/VNDB/Handler/Chars.pm +++ b/lib/VNDB/Handler/Chars.pm @@ -53,7 +53,7 @@ sub page { [ s_waist => 'Waist', serialize => sub { $_[0]||'[empty]' } ], [ s_hip => 'Hip', serialize => sub { $_[0]||'[empty]' } ], [ height => 'Height', serialize => sub { $_[0]||'[empty]' } ], - [ weight => 'Weight', serialize => sub { $_[0]||'[empty]' } ], + [ weight => 'Weight', serialize => sub { $_[0]//'[empty]' } ], [ bloodt => 'Blood type', serialize => sub { $self->{blood_types}{$_[0]} } ], [ main => 'Main character',htmlize => sub { $_[0] ? sprintf '<a href="/c%d">c%d</a>', $_[0], $_[0] : '[empty]' } ], [ main_spoil=> 'Spoiler', serialize => \&fmtspoil ], @@ -152,12 +152,12 @@ sub charTable { td $r->{alias}; end; } - if($r->{weight} || $r->{height} || $r->{s_bust} || $r->{s_waist} || $r->{s_hip}) { + if(defined($r->{weight}) || $r->{height} || $r->{s_bust} || $r->{s_waist} || $r->{s_hip}) { Tr; td class => 'key', 'Measurements'; td join ', ', $r->{height} ? "Height: $r->{height}cm" : (), - $r->{weight} ? "Weight: $r->{weight}kg" : (), + defined($r->{weight}) ? "Weight: $r->{weight}kg" : (), $r->{s_bust} || $r->{s_waist} || $r->{s_hip} ? sprintf 'Bust-Waist-Hips: %s-%s-%scm', $r->{s_bust}||'??', $r->{s_waist}||'??', $r->{s_hip}||'??' : (); end; @@ -307,7 +307,7 @@ sub edit { { post => 's_waist', required => 0, default => 0, template => 'uint', max => 32767 }, { post => 's_hip', required => 0, default => 0, template => 'uint', max => 32767 }, { post => 'height', required => 0, default => 0, template => 'uint', max => 32767 }, - { post => 'weight', required => 0, default => 0, template => 'uint', max => 32767 }, + { post => 'weight', required => 0, default => undef, template => 'uint', max => 32767 }, { post => 'bloodt', required => 0, default => 'unknown', enum => [ keys %{$self->{blood_types}} ] }, { post => 'main', required => 0, default => 0, template => 'id' }, { post => 'main_spoil', required => 0, default => 0, enum => [ 0..2 ] }, @@ -346,7 +346,7 @@ sub edit { @traits = grep $traits{$_->[0]}, @traits; # check for changes - my $same = $id && !grep $frm->{$_} ne $b4{$_}, keys %b4; + my $same = $id && !grep +($frm->{$_}//'') ne ($b4{$_}//''), keys %b4; return $self->resRedirect("/c$id", 'post') if !$copy && $same; $frm->{_err} = ["No changes, please don't create an entry that is fully identical to another"] if $copy && $same; } @@ -391,7 +391,7 @@ sub edit { [ input => name => 'Waist', short => 's_waist',width => 50, post => ' cm' ], [ input => name => 'Hips', short => 's_hip', width => 50, post => ' cm' ], [ input => name => 'Height', short => 'height', width => 50, post => ' cm' ], - [ input => name => 'Weight', short => 'weight', width => 50, post => ' kg' ], + [ input => name => 'Weight', short => 'weight', width => 50, post => ' kg', allow0 => 1 ], [ select => name => 'Blood type',short => 'bloodt', options => [ map [ $_, $self->{blood_types}{$_} ], keys %{$self->{blood_types}} ] ], [ static => content => '<br />' ], diff --git a/lib/VNDB/Util/FormHTML.pm b/lib/VNDB/Util/FormHTML.pm index 11de460b..e047dbd9 100644 --- a/lib/VNDB/Util/FormHTML.pm +++ b/lib/VNDB/Util/FormHTML.pm @@ -70,7 +70,7 @@ sub htmlFormError { # Type Options # hidden short, (value) # json short, (value) # Same as hidden, but value is passed through json_encode() -# input short, name, (width, pre, post) +# input short, name, (allow0, width, pre, post) # passwd short, name # static content, (label, nolabel) # check name, short, (value) @@ -135,7 +135,7 @@ sub htmlFormPart { if(/input/) { lit $o{pre} if $o{pre}; input type => 'text', class => 'text', name => $o{short}, id => $o{short}, tabindex => 10, - value => $frm->{$o{short}}||'', $o{width} ? (style => "width: $o{width}px") : (); + value => $o{allow0} ? $frm->{$o{short}}//'' : $frm->{$o{short}}||'', $o{width} ? (style => "width: $o{width}px") : (); lit $o{post} if $o{post}; } if(/passwd/) { diff --git a/util/sql/schema.sql b/util/sql/schema.sql index 9b031ae6..939e1d39 100644 --- a/util/sql/schema.sql +++ b/util/sql/schema.sql @@ -96,7 +96,7 @@ CREATE TABLE chars ( -- dbentry_type=c b_month smallint NOT NULL DEFAULT 0, b_day smallint NOT NULL DEFAULT 0, height smallint NOT NULL DEFAULT 0, - weight smallint NOT NULL DEFAULT 0, + weight smallint, bloodt blood_type NOT NULL DEFAULT 'unknown', main integer, -- chars.id main_spoil smallint NOT NULL DEFAULT 0 @@ -117,7 +117,7 @@ CREATE TABLE chars_hist ( b_month smallint NOT NULL DEFAULT 0, b_day smallint NOT NULL DEFAULT 0, height smallint NOT NULL DEFAULT 0, - weight smallint NOT NULL DEFAULT 0, + weight smallint, bloodt blood_type NOT NULL DEFAULT 'unknown', main integer, -- chars.id main_spoil smallint NOT NULL DEFAULT 0 diff --git a/util/updates/update_20190525.sql b/util/updates/update_20190525.sql new file mode 100644 index 00000000..d2f7ae16 --- /dev/null +++ b/util/updates/update_20190525.sql @@ -0,0 +1,8 @@ +-- Support a '0' weight. +ALTER TABLE chars ALTER COLUMN weight DROP DEFAULT; +ALTER TABLE chars ALTER COLUMN weight DROP NOT NULL; +ALTER TABLE chars_hist ALTER COLUMN weight DROP DEFAULT; +ALTER TABLE chars_hist ALTER COLUMN weight DROP NOT NULL; + +UPDATE chars SET weight = NULL WHERE weight = 0; +UPDATE chars_hist SET weight = NULL WHERE weight = 0; |