diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VNWeb/Elm.pm | 8 | ||||
-rw-r--r-- | lib/VNWeb/Releases/JS.pm | 21 | ||||
-rw-r--r-- | lib/VNWeb/User/Lists.pm | 10 |
3 files changed, 35 insertions, 4 deletions
diff --git a/lib/VNWeb/Elm.pm b/lib/VNWeb/Elm.pm index 80487839..6fa710f9 100644 --- a/lib/VNWeb/Elm.pm +++ b/lib/VNWeb/Elm.pm @@ -46,6 +46,14 @@ my %apis = ( DoubleIP => [], # Account with same IP already exists BadCurPass => [], # Current password is incorrect when changing password MailChange => [], # A confirmation mail has been sent to change a user's email address + Releases => [ { aoh => { # Response to /r/get.json + id => { id => 1 }, + title => {}, + original => { required => 0, default => '' }, + released => { uint => 1 }, + rtype => {}, + lang => { type => 'array', values => {} }, + } } ], ); diff --git a/lib/VNWeb/Releases/JS.pm b/lib/VNWeb/Releases/JS.pm new file mode 100644 index 00000000..0ecc05aa --- /dev/null +++ b/lib/VNWeb/Releases/JS.pm @@ -0,0 +1,21 @@ +package VNWeb::Releases::JS; + +use VNWeb::Prelude; + + +# Used by UList.Opt to fetch releases from a VN id. +json_api qr{/r/get.json}, { vid => { id => 1 } }, sub { + my($data) = @_; + my $l = tuwf->dbAlli( + 'SELECT r.id, r.title, r.original, r.type AS rtype, r.released + FROM releases r + JOIN releases_vn rv ON rv.id = r.id + WHERE NOT r.hidden + AND rv.vid =', \$data->{vid}, + 'ORDER BY r.released, r.title, r.id' + ); + enrich_flatten lang => id => id => sub { sql('SELECT id, lang FROM releases_lang WHERE id IN', $_, 'ORDER BY lang') }, $l; + elm_Releases $l; +}; + +1; diff --git a/lib/VNWeb/User/Lists.pm b/lib/VNWeb/User/Lists.pm index 1514e72f..80ea90f4 100644 --- a/lib/VNWeb/User/Lists.pm +++ b/lib/VNWeb/User/Lists.pm @@ -157,15 +157,15 @@ my $VNOPT = form_compile any => { uid => { id => 1 }, vid => { id => 1 }, notes => {}, - rels => { aoh => { + rels => { aoh => { # Same structure as 'elm_Releases' response id => { id => 1 }, title => {}, original => {}, released => { uint => 1 }, rtype => {}, - status => { uint => 1 }, lang => { type => 'array', values => {} }, } }, + relstatus => { type => 'array', values => { uint => 1 } }, # List of release statuses, same order as rels }; elm_form 'UListVNOpt', $VNOPT, undef; @@ -218,13 +218,14 @@ my $RSTATUS = form_compile any => { elm_form 'UListRStatus', undef, $RSTATUS; +# Adds the release when not in the list. json_api qr{/u/ulist/rstatus.json}, $RSTATUS, sub { my($data) = @_; return elm_Unauth if !auth || auth->uid != $data->{uid}; if($data->{status} == -1) { tuwf->dbExeci('DELETE FROM rlists WHERE uid =', \$data->{uid}, 'AND rid =', \$data->{rid}) } else { - tuwf->dbExeci('UPDATE rlists SET status =', \$data->{status}, 'WHERE uid =', \$data->{uid}, 'AND rid =', \$data->{rid}) + tuwf->dbExeci('INSERT INTO rlists', $data, 'ON CONFLICT (uid, rid) DO UPDATE SET status =', \$data->{status}) } elm_Success }; @@ -336,7 +337,8 @@ sub vn_ { tr_ mkclass(hidden => 1, 'collapsed_vid'.$v->{id} => 1, odd => $n % 2 == 0), sub { td_ colspan => 7, class => 'tc_opt', sub { - elm_ 'UList.Opt' => $VNOPT, { own => $own, uid => $uid, vid => $v->{id}, notes => $v->{notes}, rels => $v->{rels} }; + my $relstatus = [ map $_->{status}, $v->{rels}->@* ]; + elm_ 'UList.Opt' => $VNOPT, { own => $own, uid => $uid, vid => $v->{id}, notes => $v->{notes}, rels => $v->{rels}, relstatus => $relstatus }; }; }; } |