Browse files

Adds /favorite/leaderboard

  • Loading branch information...
1 parent 4154250 commit 96ede3da241dfc5486d10afe2b9fdc6022df4d36 @oalders oalders committed Oct 22, 2011
View
24 lib/MetaCPAN/Web/Controller/Favorite.pm
@@ -3,7 +3,8 @@ use strict;
use warnings;
use base 'MetaCPAN::Web::Controller';
-sub index : Path('/recent/favorites') {
+
+sub recent : Path('/favorite/recent') {
my ( $self, $c ) = @_;
my $cv = AE::cv();
$c->model('API::Favorite')->recent( $c->req->page )->(
@@ -17,7 +18,24 @@ sub index : Path('/recent/favorites') {
);
}
);
- $c->stash({%{$cv->recv}, template => 'recent/favorite.html'});
+ $c->stash({%{$cv->recv}, template => 'favorite/recent.html'});
+}
+
+sub index : Path('/favorite/leaderboard') {
+ my ( $self, $c ) = @_;
+ my $cv = AE::cv();
+ $c->model( 'API::Favorite' )->leaderboard( $c->req->page )->(
+ sub {
+ my ( $data ) = shift->recv;
+ $cv->send(
+ { leaders => $data->{facets}->{leaderboard}->{terms},
+ took => $data->{took},
+ total => $data->{hits}->{total}
+ }
+ );
+ }
+ );
+ $c->stash( { %{ $cv->recv }, template => 'favorite/leaderboard.html' } );
}
-1
+1;
View
6 lib/MetaCPAN/Web/Controller/Recent.pm
@@ -20,4 +20,10 @@ sub index : Path {
$c->stash({%{$cv->recv}, template => 'recent.html'});
}
+sub faves : Path('/recent/favorites') {
+ my ( $self, $c ) = @_;
+ $c->res->redirect('/favorite/recent', 301);
+ $c->detach;
+}
+
1;
View
14 lib/MetaCPAN/Web/Model/API/Favorite.pm
@@ -75,6 +75,18 @@ sub recent {
);
}
-
+sub leaderboard {
+ my ( $self, $page ) = @_;
+ $self->request(
+ '/favorite/_search',
+ { size => 0,
+ query => { match_all => {} },
+ facets => {
+ leaderboard =>
+ { terms => { field => 'distribution', size => 100 }, },
+ },
+ }
+ );
+}
__PACKAGE__->meta->make_immutable;
View
22 root/favorite/leaderboard.html
@@ -0,0 +1,22 @@
+<div class="content">
+
+<table class="release-table author-table<% IF tablesorter %> tablesorter remote<% END %>">
+ <thead>
+ <tr>
+ <th class="name">Release</th>
+ <th class="abstract">++ Count</th>
+ </tr>
+</thead>
+<tbody>
+<% i = 0; FOREACH leader IN leaders %>
+<% header = 1 %>
+<tr<% i = i + 1; IF i % 2 %> class="odd"<% END %>>
+ <td class="name"><strong><a href="/release/<% leader.term %>" class="ellipsis" style="width: 260px" title="<% leader.term %>"><% leader.term %></a></strong></td>
+ <td class="abstract"><% leader.count %></td>
+</tr>
+<% END %>
+</tbody>
+</table>
+
+<% INCLUDE inc/pager.html size = 100 %>
+</div>
View
0 root/recent/favorite.html → root/favorite/recent.html
File renamed without changes.
View
2 root/wrapper.html
@@ -8,7 +8,7 @@
},
{
title = "Recent ++'s",
- path = ["/recent/favorites"]
+ path = ["/favorite/recent"]
},
{
title = "Mirrors",

0 comments on commit 96ede3d

Please sign in to comment.