diff options
author | Yorhel <git@yorhel.nl> | 2021-11-15 11:37:56 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2021-11-15 11:37:58 +0100 |
commit | e822056651fd5d72b57fd06980c3def12ebbe349 (patch) | |
tree | 5bda9b83ef2400ebcca77385905ba9d68bec77a8 /lib/VNWeb/Releases | |
parent | 5f87c138de277519732176475cd618c9d7ee61f7 (diff) |
Make release type a property of the release<->vn relation
That is, allow a release to have different types per VN, such as a
complete release for one VN that includes a trial for another.
Diffstat (limited to 'lib/VNWeb/Releases')
-rw-r--r-- | lib/VNWeb/Releases/Edit.pm | 5 | ||||
-rw-r--r-- | lib/VNWeb/Releases/Lib.pm | 10 | ||||
-rw-r--r-- | lib/VNWeb/Releases/List.pm | 2 | ||||
-rw-r--r-- | lib/VNWeb/Releases/Page.pm | 19 | ||||
-rw-r--r-- | lib/VNWeb/Releases/VNTab.pm | 6 |
5 files changed, 21 insertions, 21 deletions
diff --git a/lib/VNWeb/Releases/Edit.pm b/lib/VNWeb/Releases/Edit.pm index 975cd3b2..0689857a 100644 --- a/lib/VNWeb/Releases/Edit.pm +++ b/lib/VNWeb/Releases/Edit.pm @@ -7,7 +7,6 @@ my $FORM = { id => { required => 0, vndbid => 'r' }, title => { maxlength => 300 }, original => { required => 0, default => '', maxlength => 250 }, - rtype => { default => 'complete', enum => \%RELEASE_TYPE }, official => { anybool => 1 }, patch => { anybool => 1 }, freeware => { anybool => 1 }, @@ -38,6 +37,7 @@ my $FORM = { vn => { sort_keys => 'vid', aoh => { vid => { vndbid => 'v' }, title => { _when => 'out' }, + rtype => { default => 'complete', enum => \%RELEASE_TYPE }, } }, producers => { sort_keys => 'pid', aoh => { pid => { vndbid => 'p' }, @@ -64,7 +64,6 @@ TUWF::get qr{/$RE{rrev}/(?<action>edit|copy)} => sub { my $copy = tuwf->capture('action') eq 'copy'; return tuwf->resDenied if !can_edit r => $copy ? {} : $e; - $e->{rtype} = delete $e->{type}; $e->{editsum} = $copy ? "Copied from $e->{id}.$e->{chrev}" : $e->{chrev} == $e->{maxrev} ? '' : "Reverted to revision $e->{id}.$e->{chrev}"; $e->{authmod} = auth->permDbmod; @@ -146,13 +145,11 @@ elm_api ReleaseEdit => $FORM_OUT, $FORM_IN, sub { die "Invalid resolution: ($data->{reso_x},$data->{reso_y})" if (!$data->{reso_x} && $data->{reso_y} > 1) || ($data->{reso_x} && !$data->{reso_y}); to_extlinks $e; - $e->{rtype} = delete $e->{type}; return elm_Unchanged if !$new && !form_changed $FORM_CMP, $data, $e; $data->{$_} = $data->{extlinks}{$_} for $data->{extlinks}->%*; delete $data->{extlinks}; - $data->{type} = delete $data->{rtype}; my $ch = db_edit r => $e->{id}, $data; elm_Redirect "/$ch->{nitemid}.$ch->{nrev}"; diff --git a/lib/VNWeb/Releases/Lib.pm b/lib/VNWeb/Releases/Lib.pm index a008c8d1..0da2f2a9 100644 --- a/lib/VNWeb/Releases/Lib.pm +++ b/lib/VNWeb/Releases/Lib.pm @@ -7,8 +7,9 @@ our @EXPORT = qw/enrich_release_elm releases_by_vn enrich_release release_row_/; # Enrich a list of releases so that it's suitable as 'Releases' Elm response. +# Given objects must have 'id' and 'rtype' fields (appropriate for the VN in context). sub enrich_release_elm { - enrich_merge id => 'SELECT id, title, original, released, type as rtype, reso_x, reso_y FROM releases WHERE id IN', @_; + enrich_merge id => 'SELECT id, title, original, released, reso_x, reso_y FROM releases WHERE id IN', @_; enrich_flatten lang => id => id => sub { sql('SELECT id, lang FROM releases_lang WHERE id IN', $_, 'ORDER BY lang') }, @_; enrich_flatten platforms => id => id => sub { sql('SELECT id, platform FROM releases_platforms WHERE id IN', $_, 'ORDER BY platform') }, @_; } @@ -16,17 +17,18 @@ sub enrich_release_elm { # Return the list of releases associated with a VN in the format suitable as 'Releases' Elm response. sub releases_by_vn { my($id) = @_; - my $l = tuwf->dbAlli('SELECT r.id FROM releases r JOIN releases_vn rv ON rv.id = r.id WHERE NOT r.hidden AND rv.vid =', \$id, 'ORDER BY r.released, r.title, r.id'); + my $l = tuwf->dbAlli('SELECT r.id, rv.rtype FROM releases r JOIN releases_vn rv ON rv.id = r.id WHERE NOT r.hidden AND rv.vid =', \$id, 'ORDER BY r.released, r.title, r.id'); enrich_release_elm $l; $l } # Enrich a list of releases so that it's suitable for release_row_(). -# Assumption: Each release already has id, type, patch, released, gtin and enrich_extlinks(). +# Assumption: Each release already has id, patch, released, gtin and enrich_extlinks(). sub enrich_release { my($r) = @_; enrich_merge id => 'SELECT id, title, original, notes, minage, official, freeware, doujin, reso_x, reso_y, voiced, ani_story, ani_ero, uncensored FROM releases WHERE id IN', $r; + enrich_merge id => sub { sql 'SELECT id, MAX(rtype) AS rtype FROM releases_vn WHERE id IN', $_, 'GROUP BY id' }, grep !$_->{rtype}, ref $r ? @$r : $r; enrich_merge id => sql('SELECT rid as id, status as rlist_status FROM rlists WHERE uid =', \auth->uid, 'AND rid IN'), $r if auth; enrich_flatten platforms => id => id => sub { sql 'SELECT id, platform FROM releases_platforms WHERE id IN', $_, 'ORDER BY id, platform' }, $r; enrich lang => id => id => sub { 'SELECT id, lang, mtl FROM releases_lang WHERE id IN', $_, 'ORDER BY id, mtl, lang' }, $r; @@ -112,7 +114,7 @@ sub release_row_ { if(!$opt->{lang}) { abbr_ class => "icons lang $_->{lang}".($_->{mtl}?' mtl':''), title => $LANGUAGE{$_->{lang}}, '' for $r->{lang}->@*; } - abbr_ class => "icons rt$r->{type}", title => $r->{type}, ''; + abbr_ class => "icons rt$r->{rtype}", title => $r->{rtype}, ''; }; td_ class => 'tc4', sub { a_ href => "/$r->{id}", title => $r->{original}||$r->{title}, $r->{title}; diff --git a/lib/VNWeb/Releases/List.pm b/lib/VNWeb/Releases/List.pm index 70deb40a..3f5717a2 100644 --- a/lib/VNWeb/Releases/List.pm +++ b/lib/VNWeb/Releases/List.pm @@ -62,7 +62,7 @@ TUWF::get qr{/r}, sub { db_maytimeout { $count = tuwf->dbVali('SELECT count(*) FROM releases r WHERE', $where); $list = $count ? tuwf->dbPagei({results => 50, page => $opt->{p}}, ' - SELECT r.id, r.type, r.patch, r.released, r.gtin, ', sql_extlinks(r => 'r.'), ' + SELECT r.id, r.patch, r.released, r.gtin, ', sql_extlinks(r => 'r.'), ' FROM releases r WHERE', $where, ' ORDER BY', sprintf { diff --git a/lib/VNWeb/Releases/Page.pm b/lib/VNWeb/Releases/Page.pm index 7a83b149..dbc799f7 100644 --- a/lib/VNWeb/Releases/Page.pm +++ b/lib/VNWeb/Releases/Page.pm @@ -22,8 +22,11 @@ sub enrich_item { sub _rev_ { my($r) = @_; revision_ $r, \&enrich_item, - [ vn => 'Relations', fmt => sub { a_ href => "/$_->{vid}", title => $_->{original}||$_->{title}, $_->{title} } ], - [ type => 'Type' ], + [ vn => 'Relations', fmt => sub { + abbr_ class => "icons rt$_->{rtype}", title => $_->{rtype}, ' '; + a_ href => "/$_->{vid}", title => $_->{original}||$_->{title}, $_->{title}; + txt_ " ($_->{rtype})" if $_->{rtype} ne 'complete'; + } ], [ official => 'Official', fmt => 'bool' ], [ patch => 'Patch', fmt => 'bool' ], [ freeware => 'Freeware', fmt => 'bool' ], @@ -62,7 +65,9 @@ sub _infotable_ { td_ class => 'key', 'Relation'; td_ sub { join_ \&br_, sub { + abbr_ class => "icons rt$_->{rtype}", title => $_->{rtype}, ' '; a_ href => "/$_->{vid}", title => $_->{original}||$_->{title}, $_->{title}; + txt_ " ($_->{rtype})" if $_->{rtype} ne 'complete'; }, $r->{vn}->@* } }; @@ -79,13 +84,9 @@ sub _infotable_ { tr_ sub { td_ 'Type'; - td_ sub { - abbr_ class => "icons rt$r->{type}", title => $r->{type}, ' '; - txt_ ' '.$RELEASE_TYPE{$r->{type}}; - txt_ ', patch' if $r->{patch}; - txt_ ', unofficial' if !$r->{official}; - } - }; + td_ !$r->{official} && $r->{patch} ? 'Unofficial patch' : + !$r->{official} ? 'Unofficial' : 'Patch'; + } if !$r->{official} || $r->{patch}; tr_ sub { td_ 'Language'; diff --git a/lib/VNWeb/Releases/VNTab.pm b/lib/VNWeb/Releases/VNTab.pm index a606827e..dabad6dd 100644 --- a/lib/VNWeb/Releases/VNTab.pm +++ b/lib/VNWeb/Releases/VNTab.pm @@ -34,10 +34,10 @@ my @rel_cols = ( }, { # Type id => 'typ', sort_field => 'type', - sort_sql => 'r.patch %s, r.type %1$s, r.released %1$s, r.title %1$s', + sort_sql => 'r.patch %s, rv.rtype %1$s, r.released %1$s, r.title %1$s', button_string => 'Type', default => 1, - draw => sub { abbr_ class => "icons rt$_[0]{type}", title => $_[0]{type}, ''; txt_ '(patch)' if $_[0]{patch} }, + draw => sub { abbr_ class => "icons rt$_[0]{rtype}", title => $_[0]{rtype}, ''; txt_ '(patch)' if $_[0]{patch} }, }, { # Languages id => 'lan', button_string => 'Language', @@ -237,7 +237,7 @@ TUWF::get qr{/$RE{vid}/releases} => sub { $opt->{o} = 'd' if $opt->{o} eq 1; my $r = tuwf->dbAlli(' - SELECT r.id, r.type, r.patch, r.released, r.gtin + SELECT r.id, rv.rtype, r.patch, r.released, r.gtin FROM releases r JOIN releases_vn rv ON rv.id = r.id WHERE NOT hidden AND rv.vid =', \$v->{id}, ' |