Skip to content

Commit

Permalink
Display the Web of Trust Leaderboard. [Part 1]
Browse files Browse the repository at this point in the history
  • Loading branch information
Talina06 committed Aug 20, 2014
1 parent 7f0fd85 commit c61a802
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/MetaCPAN/Web/Controller/Trust.pm
@@ -0,0 +1,21 @@
package MetaCPAN::Web::Controller::Trust;
use strict;
use warnings;
use base 'MetaCPAN::Web::Controller';

sub index : Path('/trust/leaderboard') {
my ( $self, $c ) = @_;

my $data = $c->model('API::Trust')->leaderboard( $c->req->page )->recv;
my @leaders = @{ $data->{facets}->{leaderboard}->{terms} }[ 0 .. 99 ];
$c->stash(
{
leaders => \@leaders,
took => $data->{took},
total => $data->{hits}->{total},
template => 'trust/leaderboard.html',
}
);
}

1;
32 changes: 32 additions & 0 deletions lib/MetaCPAN/Web/Model/API/Trust.pm
Expand Up @@ -46,4 +46,36 @@ sub by_user {
}
);
}

=pod
sub gravatar_for_pauseid {
my ( $self, $authors ) = @_;
return $self->request(
'/author/_search',
{
query => { match_all => {} },
filter =>
{ or => [ map { { term => { pauseid => $_ } } } @{$authors} ] },
fields => [qw(gravatar_url pauseid)],
size => 1000,
sort => ['pauseid']
}
);
}
=cut

sub leaderboard {
my ( $self, $page ) = @_;
return $self->request(
'/trust/_search',
{
size => 0,
query => { match_all => {} },
facets => {
leaderboard =>
{ terms => { field => 'author', size => 600 }, },
},
}
);
}
__PACKAGE__->meta->make_immutable;
1 change: 1 addition & 0 deletions root/inc/recent-bar.html
Expand Up @@ -15,6 +15,7 @@
<input type="submit" class="hidden">
</form>
<li class="nav-header">Other</li>
<li><a href="/trust/leaderboard">Web of Trust Leaderboard</a></li>
<li><a href="/favorite/recent">Recent Favorites</a></li>
<li><a href="/favorite/leaderboard">Popular Distributions</a></li>
<li><a href="/recent/log">Indexer Log</a></li>
Expand Down
23 changes: 23 additions & 0 deletions root/trust/leaderboard.html
@@ -0,0 +1,23 @@
<% title = 'Most Trusted Authors' %>
<%- INCLUDE inc/recent-bar.html %>

<div class="content">
<table class="table table-condensed table-striped table-releases">
<thead>
<tr>
<th class="position"></th>
<th class="name pull-left-phone">Author</th>
<th class="date"></th>
</tr>
</thead>
<tbody>
<% FOREACH leader IN leaders %>
<tr>
<td class="number<% IF loop.index() < 5; " strong"; END %>"><% loop.index() + 1 %></td>
<td class="name"><strong><a href="/author/<% leader.term %>"><% leader.term %></a></strong></td>
<td class="number"><% leader.count %> <% IF leader.count == 1 %>trust <% ELSE %>trusts <% END %></td>
</tr>
<% END %>
</tbody>
</table>
</div>

0 comments on commit c61a802

Please sign in to comment.