summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2021-06-24 16:25:09 +0200
committerYorhel <git@yorhel.nl>2021-06-24 16:25:09 +0200
commit98f9b76a9ec342e7cc4512e8de1b3d669eee7ec1 (patch)
tree17f9da160db57f48ff47e452b558630adefa6ad8 /lib
parent32b11b261fe79491dfb73139487c259e0d041e2b (diff)
VN::List: Bad attempt at a grid mode
Diffstat (limited to 'lib')
-rw-r--r--lib/VNWeb/Chars/List.pm6
-rw-r--r--lib/VNWeb/Images/Lib.pm32
-rw-r--r--lib/VNWeb/VN/List.pm87
3 files changed, 76 insertions, 49 deletions
diff --git a/lib/VNWeb/Chars/List.pm b/lib/VNWeb/Chars/List.pm
index 2f935c7c..462eeedf 100644
--- a/lib/VNWeb/Chars/List.pm
+++ b/lib/VNWeb/Chars/List.pm
@@ -57,12 +57,8 @@ sub listing_ {
div_ class => 'mainbox charbgrid', sub {
- # XXX: This logic is repeated in Images::Lib (and possibly elsewhere), might want to abstract it.
- my $sexp = auth->pref('max_sexual')||0;
- my $viop = auth->pref('max_violence')||0;
a_ href => "/$_->{id}", title => $_->{original}||$_->{name},
- !$_->{image} || $sexp < 0 || $_->{image}{sexual} > $sexp || $_->{image}{violence} > $viop || (!$_->{image}{votecount} && ($sexp < 2 || $viop < 2))
- ? () : (style => 'background-image: url("'.imgurl($_->{image}{id}).'")'),
+ !$_->{image} || image_hidden($_->{image}) ? () : (style => 'background-image: url("'.imgurl($_->{image}{id}).'")'),
sub {
span_ $_->{name};
} for @$list;
diff --git a/lib/VNWeb/Images/Lib.pm b/lib/VNWeb/Images/Lib.pm
index a5d42386..3adb142d 100644
--- a/lib/VNWeb/Images/Lib.pm
+++ b/lib/VNWeb/Images/Lib.pm
@@ -3,7 +3,7 @@ package VNWeb::Images::Lib;
use VNWeb::Prelude;
use Exporter 'import';
-our @EXPORT = qw/enrich_image validate_token image_flagging_display image_ enrich_image_obj/;
+our @EXPORT = qw/enrich_image validate_token image_flagging_display image_hidden image_ enrich_image_obj/;
my @SEX = qw/Safe Suggestive Explicit/;
@@ -75,6 +75,24 @@ sub image_flagging_display {
}
+# Returns whether the image is hidden according to the user's preferences.
+# Return values:
+# 0 -> visible
+# 1 -> hidden because of sexual flag
+# 2 -> hidden because of violence flag
+# 3 -> hidden because both
+sub image_hidden {
+ my($img) = @_;
+ my($sex,$vio) = $img->@{'sexual', 'violence'};
+ my $sexp = auth->pref('max_sexual')||0;
+ my $viop = auth->pref('max_violence')||0;
+ my $sexh = $sex > $sexp && $sexp >= 0 if $img->{votecount};
+ my $vioh = $vio > $viop if $img->{votecount};
+ my $hidden = $sexp < 0 || $sexh || $vioh || (!$img->{votecount} && ($sexp < 2 || $viop < 2));
+ $hidden ? ($sexh?1:0)+($vioh?2:0) : 0;
+}
+
+
# Display (or not) an image with preference toggle and hover-information.
# Given $img is assumed to be an object generated by enrich_image_obj().
# %opt:
@@ -90,12 +108,8 @@ sub image_ {
my($sex,$vio) = $img->@{'sexual', 'violence'};
my($w,$h) = $opt{width} ? @opt{'width','height'} : @{$img}{'width', 'height'};
- my $sexp = auth->pref('max_sexual')||0;
- my $viop = auth->pref('max_violence')||0;
- my $sexh = $sex > $sexp && $sexp >= 0 if $img->{votecount};
- my $vioh = $vio > $viop if $img->{votecount};
- my $hidden = $sexp < 0 || $sexh || $vioh || (!$img->{votecount} && ($sexp < 2 || $viop < 2));
- my $hide_on_click = $opt{url} ? $hidden : $sexp < 0 || $sex || $vio || !$img->{votecount};
+ my $hidden = image_hidden $img;
+ my $hide_on_click = $opt{url} ? $hidden : $sex || $vio || !$img->{votecount} || (auth->pref('max_sexual')||0) < 0;
my $small = $w*$h < 20000;
label_ class => 'imghover', style => "width: ${w}px; height: ${h}px", sub {
@@ -116,9 +130,9 @@ sub image_ {
txt_ 'This image has been flagged as:';
br_; br_;
}
- txt_ 'Sexual: '; $sexh ? b_ class => 'standout', $SEX[$sex] : txt_ $SEX[$sex];
+ txt_ 'Sexual: '; $hidden & 1 ? b_ class => 'standout', $SEX[$sex] : txt_ $SEX[$sex];
br_;
- txt_ 'Violence: '; $vioh ? b_ class => 'standout', $VIO[$vio] : txt_ $VIO[$vio];
+ txt_ 'Violence: '; $hidden & 2 ? b_ class => 'standout', $VIO[$vio] : txt_ $VIO[$vio];
} else {
txt_ 'This image has not yet been flagged';
}
diff --git a/lib/VNWeb/VN/List.pm b/lib/VNWeb/VN/List.pm
index e6fec701..d5ba588f 100644
--- a/lib/VNWeb/VN/List.pm
+++ b/lib/VNWeb/VN/List.pm
@@ -10,7 +10,7 @@ use VNWeb::TT::Lib 'tagscore_';
sub TABLEOPTS {
my($tags) = @_;
tableopts _pref => $tags ? 'tableopts_vt' : 'tableopts_v',
- _views => ['rows', 'cards'],
+ _views => ['rows', 'cards', 'grid'],
$tags ? (tagscore => {
name => 'Tag score',
compat => 'tagscore',
@@ -117,6 +117,47 @@ sub listing_ {
}
} if $opt->{s}->rows;
+ # Contents of the grid & card modes are the same
+ my sub infoblock_ {
+ my($canlink) = @_; # grid contains an outer <a>, so may not contain links itself.
+ my sub lnk_ {
+ my($url, $title, $label) = @_;
+ a_ href => $url, $title, $label if $canlink;
+ span_ $label if !$canlink;
+ }
+ lnk_ "/$_->{id}", $_->{original}||$_->{title}, $_->{title};
+ br_;
+ join_ '', sub { platform_ $_ if $_ ne 'unk' }, sort $_->{platforms}->@*;
+ join_ '', sub { abbr_ class => "icons lang $_", title => $LANGUAGE{$_}, '' }, reverse sort $_->{lang}->@*;
+ rdate_ $_->{c_released};
+ if($opt->{s}->vis('developer')) {
+ br_;
+ join_ ' & ', sub {
+ lnk_ "/$_->{id}", $_->{original}||$_->{name}, $_->{name};
+ }, sort { $a->{name} cmp $b->{name} || $a->{id} <=> $b->{id} } $_->{developers}->@*;
+ }
+ table_ sub {
+ tr_ sub {
+ td_ 'Popularity:';
+ td_ sprintf '%.2f', ($_->{c_popularity}||0)/100;
+ } if $opt->{s}->vis('popularity');
+ tr_ sub {
+ td_ 'Rating:';
+ td_ sub {
+ txt_ sprintf '%.2f', ($_->{c_rating}||0)/100;
+ b_ class => 'grayedout', sprintf ' (%d)', $_->{c_votecount};
+ };
+ } if $opt->{s}->vis('rating');
+ tr_ sub {
+ td_ 'Average:';
+ td_ sub {
+ txt_ sprintf '%.2f', ($_->{c_average}||0)/100;
+ b_ class => 'grayedout', sprintf ' (%d)', $_->{c_votecount} if !$opt->{s}->vis('rating');
+ };
+ } if $opt->{s}->vis('average');
+ }
+ }
+
div_ class => 'mainbox vncards', sub {
my($w,$h) = (90,120);
div_ sub {
@@ -128,42 +169,18 @@ sub listing_ {
txt_ 'no image';
}
};
- div_ sub {
- a_ href => "/$_->{id}", title => $_->{original}||$_->{title}, $_->{title};
- br_;
- join_ '', sub { platform_ $_ if $_ ne 'unk' }, sort $_->{platforms}->@*;
- join_ '', sub { abbr_ class => "icons lang $_", title => $LANGUAGE{$_}, '' }, reverse sort $_->{lang}->@*;
- rdate_ $_->{c_released};
- if($opt->{s}->vis('developer')) {
- br_;
- join_ ' & ', sub {
- a_ href => "/$_->{id}", title => $_->{original}||$_->{name}, $_->{name};
- }, sort { $a->{name} cmp $b->{name} || $a->{id} <=> $b->{id} } $_->{developers}->@*;
- }
- table_ sub {
- tr_ sub {
- td_ 'Popularity:';
- td_ sprintf '%.2f', ($_->{c_popularity}||0)/100;
- } if $opt->{s}->vis('popularity');
- tr_ sub {
- td_ 'Rating:';
- td_ sub {
- txt_ sprintf '%.2f', ($_->{c_rating}||0)/100;
- b_ class => 'grayedout', sprintf ' (%d)', $_->{c_votecount};
- };
- } if $opt->{s}->vis('rating');
- tr_ sub {
- td_ 'Average:';
- td_ sub {
- txt_ sprintf '%.2f', ($_->{c_average}||0)/100;
- b_ class => 'grayedout', sprintf ' (%d)', $_->{c_votecount} if !$opt->{s}->vis('rating');
- };
- } if $opt->{s}->vis('average');
- }
- };
+ div_ sub { infoblock_ 1 };
} for @$list;
} if $opt->{s}->cards;
+ div_ class => 'mainbox vngrid', sub {
+ a_ href => "/$_->{id}", title => $_->{original}||$_->{title},
+ !$_->{image} || image_hidden($_->{image}) ? (class => 'noimage') : (style => 'background-image: url("'.imgurl($_->{image}{id}).'")'),
+ sub {
+ div_ sub { infoblock_ 0 };
+ } for @$list;
+ } if $opt->{s}->grid;
+
paginate_ \&url, $opt->{p}, [$count, $opt->{s}->results], 'b';
}
@@ -179,7 +196,7 @@ sub enrich_listing {
WHERE p.id = vp.id AND v.id IN', $_[0], 'ORDER BY p.name, p.id'
}, @_ if $opt->{s}->vis('developer');
- enrich_image_obj image => @_ if $opt->{s}->cards;
+ enrich_image_obj image => @_ if !$opt->{s}->rows;
enrich_merge id => sub { sql '
SELECT irv.vid AS id