Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Hide unhelpful reviews from homepage and distribution pages by default

  • Loading branch information...
commit 90fca87da07c7d6a40b6c559576cf18553099df4 1 parent 73059d8
@abh abh authored
2  combust
@@ -1 +1 @@
-Subproject commit 64fd3d2c640e6c6b05fbf8668c6469478251bedc
+Subproject commit 783539402b2968569293451dc50509f0df06c367
View
2  docs/cpanratings/display/bare_list.html
@@ -0,0 +1,2 @@
+[% page.style = "none" %]
+[% PROCESS display/show_list.html, reviews = reviews %]
View
9 docs/cpanratings/display/list.html
@@ -10,4 +10,13 @@
[% END %]
</p>
+<div id="reviews">
[% PROCESS display/show_list.html, reviews = reviews %]
+
+[% IF unhelpful_count %]
+<div data-dist="[% reviews.first.distribution | html %]" id="show_unhelpful">
+ [% unhelpful_count %] hidden unhelpful review[% unhelpful_count == 1 ? '' : 's' %]
+</div>
+[% END %]
+
+</div>
View
2  docs/cpanratings/display/short_review.html
@@ -24,7 +24,7 @@ <h3 class="review_header">
[% IF review.rating_overall %]
[% star_image = "/cpanratings/images/stars-" _ review.rating_overall _ ".0.png" %]
-<img src="[% combust.static_url(star_image) %]" alt="[% star = '*'; star.repeat(review.rating_overall) %]">
+<img src="[% combust.static_url(star_image) || '/static' _ star_image %]" alt="[% star = '*'; star.repeat(review.rating_overall) %]">
[% END %]
</h3>
View
4 docs/cpanratings/display/show_list.html
@@ -1,4 +1,3 @@
-<div id="reviews">
[% WHILE (review = reviews.next) %]
[% PROCESS display/short_review.html,
@@ -6,6 +5,3 @@
no_more => (mode == 'distribution')
%]
[% END %]
-
-</div>
-
View
18 docs/static/cpanratings/cpanratings.js
@@ -30,6 +30,24 @@ $(document).ready(function() {
});
}
+ $("#show_unhelpful").click(function(ev) {
+ var unhelpful_div = $(this);
+ $.ajax({ url: "/api/review/get",
+ success: function(data) {
+ if (data.html) {
+ unhelpful_div.parents("#reviews").append( data.html );
+ unhelpful_div.hide();
+ }
+ },
+ data: { "auth_token": global_auth_token,
+ "dist": $(this).attr('data-dist'),
+ "unhelpful": 1,
+ "html": 1
+ },
+ dataType: "json",
+ type: "GET"
+ });
+ });
$("span.helpful").click(function(ev) {
var review = $(this).parents("div.review");
View
8 docs/static/css/cpanratings.css
@@ -34,4 +34,10 @@ span.vote_thanks {
color:#990000;
margin-left:5px;
display: none;
-}
+}
+
+#show_unhelpful {
+ margin-top: 30px;
+ cursor:pointer;
+ text-decoration: underline;
+}
View
1  lib/CPANRatings/API.pm
@@ -5,6 +5,7 @@ use base qw(Combust::API);
__PACKAGE__->setup_api(
'test' => 'Test',
'helpful' => 'Helpful',
+ 'review' => 'Review',
);
1;
View
34 lib/CPANRatings/API/Review.pm
@@ -0,0 +1,34 @@
+package CPANRatings::API::Review;
+use strict;
+use base qw(CPANRatings::API::Base);
+
+sub get {
+ my $self = shift;
+
+ use Data::Dump qw(pp);
+ pp($self);
+
+ my $distribution = $self->_required_param(qw(dist));
+ my $unhelpful = $self->_optional_param(qw(unhelpful));
+
+ my %query = (distribution => $distribution, 'helpful_score' => {'>', 0});
+
+ if ($unhelpful) {
+ $query{helpful_score} = { '<=', 0 };
+ }
+
+ my $reviews = $self->_schema->review->search( \%query );
+
+ if ($self->_optional_param('html')) {
+ return {
+ html => $self->evaluate_template(
+ {template => 'display/bare_list.html', params => {reviews => $reviews}}
+ )
+ };
+ }
+
+ return { reviews => [ $reviews->all ] };
+}
+
+
+1;
View
36 lib/CPANRatings/Control/Show.pm
@@ -43,6 +43,17 @@ sub render {
if ( $mode eq "user" ) {
$self->tpl_param( 'header' => "Reviews by " . $user->name );
+
+ my $reviews = $self->schema->review->search(
+ { $mode => $id,
+ status => 'active',
+ },
+ { order_by => { -desc => 'updated' } }
+ );
+
+ $self->tpl_param( 'reviews' => $reviews );
+
+
}
else {
unless ( CPANRatings::Model::SearchCPAN->valid_distribution($id) ) {
@@ -52,18 +63,33 @@ sub render {
$self->schema->review->search( { distribution => $id }, { rows => 1 } );
$self->tpl_param( 'distribution' => $first_review->distribution ) if $first_review;
$self->tpl_param( 'distribution' => $id ) unless $first_review;
- }
- my $reviews =
- $self->schema->review->search( { $mode => $id }, { order_by => { -desc => 'updated' } } );
+ my $reviews = $self->schema->review->search(
+ { $mode => $id,
+ status => 'active',
+ helpful_score => { '>', 0 }
+ },
+ { order_by => { -desc => 'updated' } }
+ );
- $self->tpl_param( 'reviews' => $reviews );
+ my $unhelpful_count = $self->schema->review->count(
+ { $mode => $id,
+ status => 'active',
+ helpful_score => { '<=', 0 }
+ },
+ );
+ $self->tpl_param( 'reviews' => $reviews );
+
+ $self->tpl_param( 'unhelpful_count' => $unhelpful_count );
+
+
+ }
if ( $format eq "html" ) {
return OK, $self->evaluate_template($template), 'text/html';
}
elsif ( $format eq "rss" ) {
- my $output = $self->as_rss( $reviews, $mode, $mode_element );
+ my $output = $self->as_rss( $self->tpl_param('reviews'), $mode, $mode_element );
return OK, $output, 'application/rss+xml';
}
View
17 lib/CPANRatings/Schema/Role/Review.pm
@@ -4,6 +4,23 @@ use String::Truncate qw(elide);
use Combust::Util qw(escape_html);
use namespace::clean;
+sub TO_JSON {
+ my $self = shift;
+
+ my $data = {
+ map +($_ => $self->$_),
+ @{$self->serializable_columns}
+ };
+
+ for my $f (qw(helpful_total helpful_yes)) {
+ $data->{$f} = $self->$f;
+ }
+
+ $data->{updated} = "" . $data->{updated};
+
+ return $data;
+}
+
has '_helpful_total' => (
is => 'rw',
isa => 'Int',
View
31 lib/CPANRatings/Schema/Scaffold.pm
@@ -2,6 +2,30 @@ package CPANRatings::Schema::Scaffold;
use Moose;
extends 'Mesoderm';
+my %no_serialize = (
+ reviews => [ qw( module ) ],
+ review_users => [ qw( id bitcard_id content_suppressed ) ],
+);
+
+override column_info => sub {
+ my ($self, $column) = @_;
+ my $info = super;
+ if ($column->{data_type} =~ m/(DATE|TIME)/) {
+ $info->{timezone} = 'UTC';
+ }
+ if (my $columns = $no_serialize{ $column->table->name } ) {
+ my $column_name = $column->name;
+ $info->{is_serializable} = 0
+ if grep { $_ eq $column_name } @$columns;
+ }
+
+ $info->{is_serializable} = 1
+ if $column->name eq 'review' and $column->table->name eq 'reviews';
+
+ return $info;
+};
+
+
sub ignore_table {
my ($self, $table) = @_;
return 1 if $table->name =~ m/_old$/;
@@ -19,4 +43,11 @@ sub __accessor {
return $a;
}
+override table_components => sub {
+ my ($self, $table) = @_;
+ my @components = super;
+ push @components, 'Helper::Row::ToJSON', 'InflateColumn::DateTime';
+ return @components;
+};
+
1;
View
49 lib/CPANRatings/Schema/_scaffold.pm
@@ -1,6 +1,6 @@
#
# *** DO NOT EDIT THIS FILE ***
-# Generated on Mon Aug 1 18:07:17 2011 UTC, by
+# Generated on Mon Aug 1 21:24:40 2011 UTC, by
# CPANRatings::Schema::Scaffold (undef)
# Mesoderm (0.111870)
# Moose::Object (2.0010)
@@ -40,7 +40,7 @@ has 'user' => (
use Moose;
extends 'DBIx::Class';
- __PACKAGE__->load_components(qw/ PK::Auto Core /);
+ __PACKAGE__->load_components(qw/ Helper::Row::ToJSON InflateColumn::DateTime PK::Auto Core /);
no Moose;
@@ -52,13 +52,15 @@ has 'user' => (
extra => { unsigned => 1 },
is_auto_increment => 1,
is_nullable => 0,
+ is_serializable => 0,
size => 8
},
bitcard_id => {
- data_type => 'CHAR',
- default_value => undef,
- is_nullable => 1,
- size => 40
+ data_type => 'CHAR',
+ default_value => undef,
+ is_nullable => 1,
+ is_serializable => 0,
+ size => 40
},
username => {
data_type => 'VARCHAR',
@@ -73,11 +75,12 @@ has 'user' => (
size => 128
},
content_suppressed => {
- data_type => 'TINYINT',
- default_value => '0',
- extra => { unsigned => 1 },
- is_nullable => 0,
- size => 3
+ data_type => 'TINYINT',
+ default_value => '0',
+ extra => { unsigned => 1 },
+ is_nullable => 0,
+ is_serializable => 0,
+ size => 3
},
);
__PACKAGE__->set_primary_key(qw/ id /);
@@ -115,7 +118,7 @@ has 'review' => (
use Moose;
extends 'DBIx::Class';
- __PACKAGE__->load_components(qw/ InflateColumn::DateTime PK::Auto Core /);
+ __PACKAGE__->load_components(qw/ Helper::Row::ToJSON InflateColumn::DateTime PK::Auto Core /);
with 'CPANRatings::Schema::Role::Review';
no Moose;
@@ -138,10 +141,11 @@ has 'review' => (
size => 8
},
module => {
- data_type => 'VARCHAR',
- default_value => undef,
- is_nullable => 0,
- size => 255
+ data_type => 'VARCHAR',
+ default_value => undef,
+ is_nullable => 0,
+ is_serializable => 0,
+ size => 255
},
distribution => {
data_type => 'VARCHAR',
@@ -170,15 +174,16 @@ has 'review' => (
},
updated => {
data_type => 'DATETIME',
- default_value => undef,
+ default_value => '0000-00-00 00:00:00',
is_nullable => 0,
size => 0
},
review => {
- data_type => 'TEXT',
- default_value => undef,
- is_nullable => 0,
- size => 65535
+ data_type => 'TEXT',
+ default_value => undef,
+ is_nullable => 0,
+ is_serializable => 1,
+ size => 65535
},
rating_overall => {
data_type => 'TINYINT',
@@ -254,7 +259,7 @@ has 'helpful' => (
use Moose;
extends 'DBIx::Class';
- __PACKAGE__->load_components(qw/ Core /);
+ __PACKAGE__->load_components(qw/ Helper::Row::ToJSON InflateColumn::DateTime Core /);
no Moose;
View
4 sql/scripts/cpanratings.2
@@ -15,7 +15,3 @@ while (my $review = $reviews->next) {
$review->review( decode_entities( utf8_safe($review->review) ) );
$review->update;
}
-
-
-
-
View
16 sql/scripts/cpanratings.6
@@ -0,0 +1,16 @@
+# -*- cperl -*-
+eval 'exec $CBROOT/bin/perl $0 ${1+"$@"}'
+ unless $running_under_some_shell;
+use strict;
+use warnings;
+use CPANRatings::Schema;
+use HTML::Entities qw(decode_entities);
+use Combust::Util qw(utf8_safe);
+
+my $schema = CPANRatings::Schema->new;
+
+my $reviews = $schema->review->search();
+
+while (my $review = $reviews->next) {
+ $review->update_helpful_score;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.