diff options
author | Yorhel <git@yorhel.nl> | 2019-10-28 10:54:15 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2019-11-10 12:44:55 +0100 |
commit | dc243fb2d89c69611e3c2a154749c14643a69db0 (patch) | |
tree | ea63ed1fcb0fa1403781ca60f5344e17d965a671 /lib/VNWeb | |
parent | 279c4c9f82b45863f91a16867e4830695de7e0ce (diff) |
ulist: Inline editable votes
Diffstat (limited to 'lib/VNWeb')
-rw-r--r-- | lib/VNWeb/HTML.pm | 2 | ||||
-rw-r--r-- | lib/VNWeb/User/Lists.pm | 35 | ||||
-rw-r--r-- | lib/VNWeb/Validation.pm | 2 |
3 files changed, 34 insertions, 5 deletions
diff --git a/lib/VNWeb/HTML.pm b/lib/VNWeb/HTML.pm index f8c32abe..20c78565 100644 --- a/lib/VNWeb/HTML.pm +++ b/lib/VNWeb/HTML.pm @@ -95,7 +95,7 @@ sub elm_ { my($mod, $schema, $data) = @_; div_ 'data-elm-module' => $mod, $data ? ( - 'data-elm-flags' => JSON::XS->new->allow_nonref->encode($schema->analyze->coerce_for_json($data, unknown => 'remove')) + 'data-elm-flags' => JSON::XS->new->allow_nonref->encode($schema ? $schema->analyze->coerce_for_json($data, unknown => 'remove') : $data) ) : (), ''; } diff --git a/lib/VNWeb/User/Lists.pm b/lib/VNWeb/User/Lists.pm index e29985fc..db55e74b 100644 --- a/lib/VNWeb/User/Lists.pm +++ b/lib/VNWeb/User/Lists.pm @@ -17,6 +17,15 @@ my $LABELS = form_compile any => { elm_form 'ManageLabels', undef, $LABELS; +my $VNVOTE = form_compile any => { + uid => { id => 1 }, + vid => { id => 1 }, + vote => { vnvote => 1 }, +}; + +elm_form 'VoteEdit', undef, $VNVOTE; + + # TODO: Filters to find unlabeled VNs or VNs with notes? sub filters_ { my($own, $labels) = @_; @@ -68,7 +77,7 @@ sub filters_ { sub vn_ { - my($n, $v, $labels) = @_; + my($uid, $own, $n, $v, $labels) = @_; tr_ mkclass(odd => $n % 2 == 0), sub { td_ class => 'tc1', sub { input_ type => 'checkbox', class => 'checkhidden', name => 'collapse_vid', id => 'collapse_vid'.$v->{id}, value => 'collapsed_vid'.$v->{id}; @@ -91,7 +100,10 @@ sub vn_ { join_ ', ', sub { txt_ $_->{label} }, @l if @l; txt_ '-' if !@l; }; - td_ class => 'tc4', fmtvote $v->{vote}; + td_ mkclass(tc4 => 1, compact => $own, stealth => $own), sub { + txt_ fmtvote $v->{vote} if !$own; + elm_ 'ULists.VoteEdit' => $VNVOTE, { uid => $uid*1, vid => $v->{id}*1, vote => fmtvote($v->{vote}) } if $own; + }; td_ class => 'tc5', fmtdate $v->{added}, 'compact'; td_ class => 'tc6', $v->{started}||''; td_ class => 'tc7', $v->{finished}||''; @@ -146,7 +158,7 @@ sub listing_ { my sub url { '?'.query_encode %$opt, @_ } - # TODO: In-line editable + # TODO: In-line editable labels, start/end dates, notes, remove-from-list # TODO: Releases # TODO: Thumbnail view paginate_ \&url, $opt->{p}, [ $count, 50 ], 't'; @@ -164,7 +176,7 @@ sub listing_ { td_ class => 'tc6', sub { txt_ 'Start date'; sortable_ 'started', $opt, \&url }; td_ class => 'tc7', sub { txt_ 'End date'; sortable_ 'finished', $opt, \&url }; }}; - vn_ $_, $lst->[$_], $labels for (0..$#$lst); + vn_ $uid, $own, $_, $lst->[$_], $labels for (0..$#$lst); }; }; paginate_ \&url, $opt->{p}, [ $count, 50 ], 'b'; @@ -173,6 +185,7 @@ sub listing_ { # TODO: Keep this URL? Steal /u+/list when that one's gone? # TODO: Display something useful when all labels are private? +# TODO: Ability to add VNs from this page TUWF::get qr{/$RE{uid}/ulist}, sub { my $u = tuwf->dbRowi('SELECT id,', sql_user(), 'FROM users u WHERE id =', \tuwf->capture('id')); return tuwf->resNotFound if !$u->{id}; @@ -252,4 +265,18 @@ json_api qr{/u/ulist/labels.json}, $LABELS, sub { elm_Success }; + +# XXX: Doesn't add the VN to the list if it isn't in there, yet. +json_api qr{/u/ulist/setvote.json}, $VNVOTE, sub { + my($data) = @_; + return elm_Unauth if !auth || auth->uid != $data->{uid}; + tuwf->dbExeci( + 'UPDATE ulists + SET vote =', \$data->{vote}, + ', vote_date = CASE WHEN', \$data->{vote}, '::smallint IS NULL THEN NULL WHEN vote IS NULL THEN NOW() ELSE vote_date END + WHERE uid =', \$data->{uid}, 'AND vid =', \$data->{vid} + ); + elm_Success +}; + 1; diff --git a/lib/VNWeb/Validation.pm b/lib/VNWeb/Validation.pm index ee3bc386..7f60d1ac 100644 --- a/lib/VNWeb/Validation.pm +++ b/lib/VNWeb/Validation.pm @@ -27,6 +27,8 @@ TUWF::set custom_validations => { username => { regex => qr/^(?!-*[a-z][0-9]+-*$)[a-z0-9-]*$/, minlength => 2, maxlength => 15 }, password => { length => [ 4, 500 ] }, language => { enum => \%LANGUAGE }, + # Accepts a user-entered vote string (or '-' or empty) and converts that into a DB vote number (or undef) - opposite of fmtvote() + vnvote => { required => 0, default => undef, regex => qr/^(?:|-|[1-9]|10|[1-9]\.[0-9]|10\.0)$/, func => sub { $_[0] = $_[0] eq '-' ? undef : 10*$_[0]; 1 } }, # Sort an array by the listed hash keys, using string comparison on each key sort_keys => sub { my @keys = ref $_[0] eq 'ARRAY' ? @{$_[0]} : $_[0]; |