summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-03-20 13:51:41 +0100
committerYorhel <git@yorhel.nl>2020-03-20 13:51:42 +0100
commit00af3fbc612063547e5da40484d89b4b23ecfaaf (patch)
treeb44a5afde248bc5a28f0b876f83e1cf64b2771cf
parentb87a1ed17a35fbe136a9f817b696362a6441ac2b (diff)
imgflag: Support displaying unreferenced images
I conveniently avoided this problem earlier on by not including unreferenced images in the history, but this should still be supported if we're to allow directly linking to the voting UI for a particular image.
-rw-r--r--elm/ImageFlagging.elm13
-rw-r--r--lib/VNWeb/Elm.pm7
-rw-r--r--lib/VNWeb/Misc/ImageFlagging.pm14
3 files changed, 20 insertions, 14 deletions
diff --git a/elm/ImageFlagging.elm b/elm/ImageFlagging.elm
index 2a34b796..0f1aa34a 100644
--- a/elm/ImageFlagging.elm
+++ b/elm/ImageFlagging.elm
@@ -167,14 +167,15 @@ view model =
]
imgView i =
- let entry = i.entry_type ++ String.fromInt i.entry_id
- in
[ div []
[ inputButton "««" Prev [ classList [("invisible", model.index == 0)] ]
- , span []
- [ b [ class "grayedout" ] [ text (entry ++ ":") ]
- , a [ href ("/" ++ entry) ] [ text i.entry_title ]
- ]
+ , span [] <|
+ case i.entry of
+ Nothing -> []
+ Just e ->
+ [ b [ class "grayedout" ] [ text (e.id ++ ":") ]
+ , a [ href ("/" ++ e.id) ] [ text e.title ]
+ ]
, inputButton "»»" Next []
]
, div [ style "width" (px boxwidth), style "height" (px boxheight) ] <|
diff --git a/lib/VNWeb/Elm.pm b/lib/VNWeb/Elm.pm
index f0712a72..4ef67779 100644
--- a/lib/VNWeb/Elm.pm
+++ b/lib/VNWeb/Elm.pm
@@ -90,11 +90,12 @@ our %apis = (
sexual_stddev => { num => 1, required => 0 },
violence_avg => { num => 1, required => 0 },
violence_stddev => { num => 1, required => 0 },
- entry_type => {},
- entry_id => { id => 1 },
- entry_title => {},
my_sexual => { uint => 1, required => 0 },
my_violence => { uint => 1, required => 0 },
+ entry => { required => 0, type => 'hash', keys => {
+ id => {},
+ title => {},
+ } },
} } ],
);
diff --git a/lib/VNWeb/Misc/ImageFlagging.pm b/lib/VNWeb/Misc/ImageFlagging.pm
index 7fb747ef..431c7f68 100644
--- a/lib/VNWeb/Misc/ImageFlagging.pm
+++ b/lib/VNWeb/Misc/ImageFlagging.pm
@@ -46,8 +46,7 @@ sub enrich_image {
, i.c_sexual_avg AS sexual_avg, i.c_sexual_stddev AS sexual_stddev
, i.c_violence_avg AS violence_avg, i.c_violence_stddev AS violence_stddev
, iv.sexual AS my_sexual, iv.violence AS my_violence
- , CASE WHEN v.title IS NOT NULL THEN 'v' WHEN c.name IS NOT NULL THEN 'c' ELSE 'v' END AS entry_type
- , COALESCE(v.id, c.id, vsv.id) AS entry_id
+ , COALESCE('v'||v.id, 'c'||c.id, 'v'||vsv.id) AS entry_id
, COALESCE(v.title, c.name, vsv.title) AS entry_title
FROM images i
LEFT JOIN image_votes iv ON iv.id = i.id AND iv.uid =}, \auth->uid, q{
@@ -57,7 +56,13 @@ sub enrich_image {
LEFT JOIN vn vsv ON (i.id).itype = 'sf' AND vsv.id = vs.id
WHERE i.id = ANY(ARRAY}, $_, '::image_id[])'
}, $l;
- $_->{url} = tuwf->imgurl($_->{id}) for @$l;
+
+ for(@$l) {
+ $_->{url} = tuwf->imgurl($_->{id});
+ $_->{entry} = $_->{entry_id} ? { id => $_->{entry_id}, title => $_->{entry_title} } : undef;
+ delete $_->{entry_id};
+ delete $_->{entry_title};
+ }
}
@@ -127,10 +132,9 @@ TUWF::get qr{/img/vote}, sub {
my $recent = tuwf->dbAlli('SELECT id FROM image_votes WHERE uid =', \auth->uid, 'ORDER BY date DESC LIMIT', \30);
enrich_image $recent;
enrich_token 1, $recent;
- $recent = [ reverse grep $_->{entry_id}, @$recent ];
framework_ title => 'Image flagging', sub {
- elm_ 'ImageFlagging', $SEND, { history => $recent };
+ elm_ 'ImageFlagging', $SEND, { history => [ reverse @$recent ] };
};
};