Skip to content

Commit

Permalink
Merge pull request #2123 from metacpan/oalders/lab-dashboard
Browse files Browse the repository at this point in the history
Fix lab dashboard
  • Loading branch information
mickeyn committed Nov 11, 2018
2 parents 81ea665 + c49ba42 commit 04c77da
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
13 changes: 9 additions & 4 deletions lib/MetaCPAN/Web/Controller/Lab.pm
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,33 @@ sub dependencies : Local : Args(0) : Does('Sortable') {
sub dashboard : Local : Args(0) {
my ( $self, $c ) = @_;

$c->stash( { template => 'lab/dashboard.html' } );

my $user = $c->model('API::User')->get_profile( $c->token )->get;
return unless $user;

my $report;
my $pauseid = $c->req->params->{'pauseid'};
if ($pauseid) {
$user = { pauseid => $pauseid };
}

# I'm not sure if the 300 limit actually corresponds to max distros.
# Setting it at 100 for OALDERS, I got less than 30 results back.

if ($user) {
$pauseid = $user->{pauseid};
if ($pauseid) {
$report = $c->model('API::Lab')
->fetch_latest_distros( 1000, $pauseid )->get;
->fetch_latest_distros( 300, $pauseid )->get;
}
}

$report->{user} = $user;

$c->stash( {
template => 'lab/dashboard.html',
pauseid => $pauseid,
report => $report,
pauseid => $pauseid,
report => $report,
} );
}

Expand Down
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Web/Model/API/Lab.pm
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ sub fetch_latest_distros {
my %distros;

foreach my $d ( @{ $data->{releases} } ) {
my $license = $d->{license}[0];
my $license = $d->{license};
my $distro = $d->{distribution};
my $repo = $d->{'resources.repository'};

Expand Down
4 changes: 1 addition & 3 deletions root/lab/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

<h2>Personal Dashboard</h2>

<%- IF user_exists %>
<% IF pauseid %>
<% END %>
<% IF report %>

<% IF report.distros.size %>
<h3>Distributions</h3>
Expand Down
13 changes: 13 additions & 0 deletions t/controller/lab/dashboard.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use strict;
use warnings;
use Test::More;
use MetaCPAN::Web::Test;

test_psgi app, sub {
my $cb = shift;

ok( my $res = $cb->( GET '/lab/dashboard' ), 'GET /lab/dashboard' );
is( $res->code, 200, 'code 200' );
};

done_testing();
17 changes: 17 additions & 0 deletions t/model/api/lab.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use strict;
use warnings;

use Test::More;
use MetaCPAN::Web;

my $model = MetaCPAN::Web->model('API::Lab');

my $report = $model->fetch_latest_distros( 2, 'OALDERS' )->get;
is( keys %{ $report->{distros} }, 2, 'gets two distros' );

my $dependencies = $model->dependencies('HTML::Restrict');
isa_ok( $dependencies, 'Future', 'dependencies' );
my @foo = $dependencies->get;
cmp_ok( @{ $dependencies->get }, '>', 10, 'finds at least 11 deps' );

done_testing;

0 comments on commit 04c77da

Please sign in to comment.