Skip to content

Commit

Permalink
Feature request: What depends on this?, fixes metacpan#111
Browse files Browse the repository at this point in the history
  • Loading branch information
monken committed Aug 23, 2011
1 parent 47b6469 commit 7645f44
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 8 deletions.
3 changes: 3 additions & 0 deletions lib/MetaCPAN/Web/Controller/Activity.pm
Expand Up @@ -18,6 +18,9 @@ sub index : Path {
if ( my $distribution = $req->parameters->{distribution} ) {
push( @$q, { term => { distribution => $distribution } } );
}
if ( my $requires = $req->parameters->{requires} ) {
push( @$q, { term => { "release.dependency.module" => $requires } } );
}

my $cv = AE::cv;
my $start
Expand Down
18 changes: 18 additions & 0 deletions lib/MetaCPAN/Web/Controller/Requires.pm
@@ -0,0 +1,18 @@
package MetaCPAN::Web::Controller::Requires;

use Moose;
use namespace::autoclean;

BEGIN { extends 'MetaCPAN::Web::Controller' }

sub index : Chained('/') : PathPart('requires') : CaptureArgs(0) {
}

sub module : Chained('index') : PathPart : Args(1) {
my ( $self, $c, $module ) = @_;
my $cv = AE::cv;
my $data = $c->model('API::Module')->requires($module, $c->req->page)->recv;
$c->stash({%{$data}, module => $module, template => 'requires.html'});
}

1;
49 changes: 44 additions & 5 deletions lib/MetaCPAN/Web/Model/API/Module.pm
Expand Up @@ -135,7 +135,8 @@ sub search_distribution {
my @ids = map { $_->{fields}->{id} } @{ $data->{hits}->{hits} };
my $descriptions = $self->search_descriptions(@ids);
my $ratings = $self->model('Rating')->get(@distributions);
my $favorites = $self->model('Favorite')->get($user, @distributions);
my $favorites
= $self->model('Favorite')->get( $user, @distributions );
return $ratings & $favorites & $descriptions;
}
)->(
Expand Down Expand Up @@ -190,8 +191,9 @@ sub search_collapsed {
}

@distributions = splice( @distributions, $from, 20 );
my $ratings = $self->model('Rating')->get(@distributions);
my $favorites = $self->model('Favorite')->get($user, @distributions);
my $ratings = $self->model('Rating')->get(@distributions);
my $favorites
= $self->model('Favorite')->get( $user, @distributions );
my $results
= $self->model('Module')
->search( $query,
Expand Down Expand Up @@ -461,6 +463,43 @@ sub _search_in_distributions {
}
} };
}
__PACKAGE__->meta->make_immutable;

1;
sub requires {
my ( $self, $module, $page ) = @_;
my $cv = $self->cv;
$self->request(
'/release/_search',
{ query => {
filtered => {
query => { "match_all" => {} },
filter => {
and => [
{ term => { 'release.status' => 'latest' } },
{ term => { 'release.authorized' => \1 } },
{ term => {
"release.dependency.module" => $module
}
}
]
}
}
},
size => 50,
from => $page * 50 - 50,
sort => [{date => 'desc'}],
}
)->(
sub {
my $data = shift->recv;
$cv->send(
{ data => [map { $_->{_source} } @{$data->{hits}->{hits}}],
total => $data->{hits}->{total},
took => $data->{took}
}
);
}
);
return $cv;
}

__PACKAGE__->meta->make_immutable;
2 changes: 1 addition & 1 deletion root/author.html
Expand Up @@ -78,5 +78,5 @@
</div>

<div class="content">
<% INCLUDE inc/release-table.html releases = aggregated, header = 1 %>
<% INCLUDE inc/release-table.html releases = aggregated, header = 1, tablesorter = 1 %>
</div>
2 changes: 1 addition & 1 deletion root/inc/release-table.html
@@ -1,4 +1,4 @@
<table class="release-table author-table tablesorter">
<table class="release-table author-table<% IF tablesorter %> tablesorter<% END %>">
<%- IF header %>
<thead>
<tr>
Expand Down
1 change: 1 addition & 0 deletions root/module.html
Expand Up @@ -38,6 +38,7 @@
<input type="text" name="q">
<input type="submit" style="display: none"></form></li>
<li><a href="#" onclick="return toggleTOC()">Toggle Table of Contents</a></li>
<li><a href="/requires/module/<% module.distribution.replace('-', '::') %>">Dependants</a></li>
<li><a href="http://explorer.metacpan.org/?url=/module/<% module.author %>/<% module.release %>/<% module.path %>">MetaCPAN Explorer</a></li>
</ul>
<hr>
Expand Down
1 change: 1 addition & 0 deletions root/release.html
Expand Up @@ -28,6 +28,7 @@
<input type="hidden" name="q" value="distribution:<% release.distribution %>">
<input type="text" name="q">
<input type="submit" style="display: none"></form></li>
<li><a href="/requires/module/<% release.distribution.replace('-', '::') %>">Dependants</a></li>
<li><a href="http://explorer.metacpan.org/?url=/release/<% release.author %>/<% release.name %>">MetaCPAN Explorer</a></li>
</ul>
<hr>
Expand Down
20 changes: 20 additions & 0 deletions root/requires.html
@@ -0,0 +1,20 @@
<%- title = "Distributions depending on " _ module %>
<div class="search-bar">
<% INCLUDE inc/activity.html query = "requires=" _ module %>
<hr>
<strong>Index</strong>
<ul>
<a href=""><li>Latest</li></a>
<a href=""><li>CPAN</li></a>
<a href=""><li>BackPAN</li></a>
</ul>
</div>

<div class="content">
<% IF data.size > 0 %>
<% INCLUDE inc/release-table.html releases = data, header = 1 %>
<% INCLUDE inc/pager.html size = 50 %>
<% ELSE %>
<big><strong>No depedants for <% module %> could be found</strong></big>
<% END %>
</div>
5 changes: 5 additions & 0 deletions root/static/css/style.css
Expand Up @@ -643,6 +643,11 @@ div.qtip-github table th {
padding: 2px;
}

.release-table th {
text-align: left;
font-weight: bold;
}

.release-table .name {
width: 266px;
}
Expand Down
2 changes: 1 addition & 1 deletion root/static/js/cpan.js
Expand Up @@ -74,7 +74,7 @@ $(document).ready(function() {
$('#signin-button').mouseenter(function(){$('#signin').show()});
$('#signin').mouseleave(function(){$('#signin').hide()});

$('.author-table').tablesorter({widgets: ['zebra'],textExtraction: function(node){
$('.tablesorter').tablesorter({widgets: ['zebra'],textExtraction: function(node){
if(node.getAttribute('class') == 'date') {
var date = new Date(node.firstChild.getAttribute('sort'));
return date.getTime();
Expand Down

0 comments on commit 7645f44

Please sign in to comment.