diff options
author | Yorhel <git@yorhel.nl> | 2019-12-24 10:51:27 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2019-12-24 10:55:18 +0100 |
commit | 444990e4d924903d28b3f33c53f7df37c23b3f32 (patch) | |
tree | 824db6e0fbb0a5cc9f1a3069316916dcc7984e8c /lib | |
parent | 0916ec2e23f7c15a484781894ee0edee728ecd13 (diff) |
ulist: Add list management widget on VN pages
Minimal version. It reuses the LabelEdit and VoteEdit widgets, but
doesn't allow setting a note or start/finish date at the moment.
VN pages now have both v2rw.js and the old vndb.js; Those two scripts
aren't meant to be used together on a single page, so I'm hoping this
will be temporary. I removed the 'checkall' handling from vndb.js as
that might conflict. It's only used on the old list pages anyway.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VNDB/Handler/VNPage.pm | 53 | ||||
-rw-r--r-- | lib/VNDB/Util/LayoutHTML.pm | 2 | ||||
-rw-r--r-- | lib/VNWeb/HTML.pm | 17 | ||||
-rw-r--r-- | lib/VNWeb/User/Lists.pm | 19 |
4 files changed, 50 insertions, 41 deletions
diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm index 87c9244c..3556476c 100644 --- a/lib/VNDB/Handler/VNPage.pm +++ b/lib/VNDB/Handler/VNPage.pm @@ -531,7 +531,7 @@ sub page { _screenshots($self, $v, $r) if @{$v->{screenshots}}; } - $self->htmlFooter; + $self->htmlFooter(v2rwjs => $self->authInfo->{id}); } @@ -715,45 +715,28 @@ sub _useroptions { # Voting option is hidden if nothing has been released yet my $minreleased = min grep $_, map $_->{released}, @$r; - my $canvote = $minreleased && $minreleased < strftime '%Y%m%d', gmtime; - my $vote = $self->dbVoteGet(uid => $self->authInfo->{id}, vid => $v->{id})->[0]; - my $list = $self->dbVNListGet(uid => $self->authInfo->{id}, vid => $v->{id})->[0]; - my $wish = $self->dbWishListGet(uid => $self->authInfo->{id}, vid => $v->{id})->[0]; + my $labels = tuwf->dbAlli( + 'SELECT l.id, l.label, l.private, uvl.vid IS NOT NULL as assigned + FROM ulist_labels l + LEFT JOIN ulist_vns_labels uvl ON uvl.uid = l.uid AND uvl.lbl = l.id AND uvl.vid =', \$v->{id}, ' + WHERE l.uid =', \$self->authInfo->{id}, ' + ORDER BY CASE WHEN l.id < 10 THEN l.id ELSE 10 END, l.label' + ); + my $lst = tuwf->dbRowi('SELECT vid, vote FROM ulist_vns WHERE uid =', \$self->authInfo->{id}, 'AND vid =', \$v->{id}); Tr; td 'User options'; td; - if($vote || ($canvote && !$wish)) { - Select id => 'votesel', name => $self->authGetCode("/v$v->{id}/vote"); - option value => -3, $vote ? 'your vote: '.fmtvote($vote->{vote}) : 'not voted yet'; - optgroup label => $vote ? 'Change vote' : 'Vote'; - option value => $_, "$_ (".fmtrating($_).')' for (reverse 1..10); - option value => -2, 'Other'; - end; - option value => -1, 'revoke' if $vote; - end; - br; - } - - Select id => 'listsel', name => $self->authGetCode("/v$v->{id}/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 => $_, $VNLIST_STATUS{$_} for (keys %VNLIST_STATUS); - end; - option value => -1, 'remove from VN list' if $list; - end; - br; - - if(!$vote || $wish) { - Select id => 'wishsel', name => $self->authGetCode("/v$v->{id}/wish"); - option $wish ? "wishlist: $WISHLIST_STATUS{$wish->{wstat}}" : 'not on your wishlist'; - optgroup label => $wish ? 'Change status' : 'Add to wishlist'; - option value => $_, $WISHLIST_STATUS{$_} for (keys %WISHLIST_STATUS); - end; - option value => -1, 'remove from wishlist' if $wish; - end; - } + VNWeb::HTML::elm_('UList.VNPage', undef, { + uid => 1*$self->authInfo->{id}, + vid => 1*$v->{id}, + onlist => $lst->{vid}?\1:\0, + canvote => $minreleased && $minreleased < strftime('%Y%m%d', gmtime) ? \1 : \0, + vote => fmtvote($lst->{vote}).'', + labels => [ map +{ id => 1*$_->{id}, label => $_->{label}, private => $_->{private}?\1:\0 }, @$labels ], + selected => [ map $_->{id}, grep $_->{assigned}, @$labels ], + }); end; end 'tr'; } diff --git a/lib/VNDB/Util/LayoutHTML.pm b/lib/VNDB/Util/LayoutHTML.pm index 1b6ce1de..6bafbeda 100644 --- a/lib/VNDB/Util/LayoutHTML.pm +++ b/lib/VNDB/Util/LayoutHTML.pm @@ -11,6 +11,7 @@ our @EXPORT = qw|htmlHeader htmlFooter|; sub htmlHeader { # %options->{ title, noindex, search, feeds, metadata } my($self, %o) = @_; + %VNWeb::HTML::pagevars = (); $o{og} = $o{metadata} ? +{ map +(s/og://r, $o{metadata}{$_}), keys $o{metadata}->%* } : undef; $o{index} = !$o{noindex}; @@ -34,6 +35,7 @@ sub htmlFooter { # %options => { pref_code => 1 } noscript id => 'pref_code', title => $self->authGetCode('/xml/prefs.xml'), '' if $o{pref_code} && $self->authInfo->{id}; script type => 'text/javascript', src => $self->{url_static}.'/f/vndb.js?'.$self->{version}, ''; + VNWeb::HTML::v2rwjs_() if $o{v2rwjs}; end 'body'; end 'html'; } diff --git a/lib/VNWeb/HTML.pm b/lib/VNWeb/HTML.pm index 9dad1902..1d6731c2 100644 --- a/lib/VNWeb/HTML.pm +++ b/lib/VNWeb/HTML.pm @@ -36,7 +36,7 @@ our @EXPORT = qw/ # Encoded as JSON and appended to the end of the page, to be read by pagevars.js. -my %pagevars; +our %pagevars; # Ugly hack to move rendering down below the float object. @@ -406,6 +406,15 @@ sub _hidden_msg_ { } +sub v2rwjs_ { # Also used by VNDB::Util::LayoutHTML. + script_ type => 'application/json', id => 'pagevars', sub { + # Escaping rules for a JSON <script> context are kinda weird, but more efficient than regular xml_escape(). + lit_(JSON::XS->new->canonical->encode(\%pagevars) =~ s{</}{<\\/}rg =~ s/<!--/<\\u0021--/rg); + } if keys %pagevars; + script_ type => 'application/javascript', src => config->{url_static}.'/f/v2rw.js?'.config->{version}, ''; +} + + # Options: # title => $title # index => 1/0, default 0 @@ -435,11 +444,7 @@ sub framework_ { $cont->() unless $o{hiddenmsg} && _hidden_msg_ \%o; div_ id => 'footer', \&_footer_; }; - script_ type => 'application/json', id => 'pagevars', sub { - # Escaping rules for a JSON <script> context are kinda weird, but more efficient than regular xml_escape(). - lit_(JSON::XS->new->canonical->encode(\%pagevars) =~ s{</}{<\\/}rg =~ s/<!--/<\\u0021--/rg); - } if keys %pagevars; - script_ type => 'application/javascript', src => config->{url_static}.'/f/v2rw.js?'.config->{version}, ''; + v2rwjs_; } } } diff --git a/lib/VNWeb/User/Lists.pm b/lib/VNWeb/User/Lists.pm index 4e5ff7f9..e909fa2e 100644 --- a/lib/VNWeb/User/Lists.pm +++ b/lib/VNWeb/User/Lists.pm @@ -227,6 +227,25 @@ json_api qr{/u/ulist/del\.json}, $VNDEL, sub { + +my $VNADD = form_compile any => { + uid => { id => 1 }, + vid => { id => 1 }, +}; + +elm_form 'UListAdd', undef, $VNADD; + +json_api qr{/u/ulist/add\.json}, $VNDEL, sub { + my($data) = @_; + return elm_Unauth if !own $data->{uid}; + tuwf->dbExeci('INSERT INTO ulist_vns', $data, 'ON CONFLICT (uid, vid) DO NOTHING'); + updcache $data->{uid}; + elm_Success +}; + + + + my $RSTATUS = form_compile any => { uid => { id => 1 }, rid => { id => 1 }, |