Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Stargazers: Model and display scripts
  • Loading branch information
Talina06 committed Jul 4, 2014
1 parent 7b2d99b commit 56806bc
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
63 changes: 63 additions & 0 deletions lib/MetaCPAN/Web/Model/API/Stargazer.pm
@@ -0,0 +1,63 @@
package MetaCPAN::Web::Model::API::Stargazer;
use Moose;
use namespace::autoclean;

extends 'MetaCPAN::Web::Model::API';

use List::MoreUtils qw(uniq);

sub find_starred {

This comment has been minimized.

Copy link
@Talina06

Talina06 Jul 4, 2014

Author Contributor

Here, I am retrieving all the starred modules for $user and checking if $module is in the starred list. If yes, I am returning 1 as mystargazer. Else 0

This is where the problem lies. The logic isn't right as the values aren't retrieved.

my ( $self, $user, $name ) = @_;

# search for all users, match all according to the distribution.
my $starred = $self->by_user($user);
my $starred_data = $starred->recv;

# store in an array.
my @starred_modules
= map { $_->{fields}->{user} } @{ $starred_data->{hits}->{hits} };
my $total_starred = @starred_modules;

if ( !$total_starred ) {
foreach my $module (@starred_modules) {
if ( $name eq $module ) {
return (
{
mystargazer => 1,
total_starred => $total_starred,
}
);
}
else {
return (
{
mystargazer => 0,
total_starred => $total_starred,
}
);
}
}
}
return (
{
mystargazer => 0,
total_starred => $total_starred,
}
);

}

sub by_user {
my ( $self, $user ) = @_;
return $self->request(
'/stargazer/_search',
{
query => { match_all => {} },
filter => { term => { user => $user }, },
sort => ['module'],
fields => [qw(date author module)],
size => 250,
}
);
}
__PACKAGE__->meta->make_immutable;
4 changes: 4 additions & 0 deletions root/account/stargazer.html
@@ -0,0 +1,4 @@
<% PROCESS inc/account-bar.html %>
<div class="content">
<% INCLUDE inc/stargazer-table.html stargazers = stars, author = 1, tablesorter = 1 %>
</div>
34 changes: 34 additions & 0 deletions root/inc/stargazer-table.html
@@ -0,0 +1,34 @@
<% IF stargazers.size %>
<table id="author_favorites"
<% IF tablesorter %>data-default-sort="<% default_sort || '0,0' %>"<% END %>
class="table table-condensed table-striped table-favorites<% IF tablesorter %> tablesorter<% END %>">
<thead>
<tr>
<th class="release pull-left-phone"><% author ? "Favorites" : "Module" %></th>
<th class="abstract hidden-phone"><% author ? "Author" : "Starred By" %></th>
<th class="date"><% day || "Date" %></th>
</tr>
</thead>
<tbody>
<% FOREACH stargazer IN stargazers %>
<tr>
<td>
<strong>
<a href="/pod/<% stargazer.module; %>" class="ellipsis" title="<% stargazer.author; '/'; stargazer.module %>"><% stargazer.module %></a>
</strong>
</td>
<% IF author %>
<td class="pull-left-phone">
<a href="/author/<% stargazer.author %>"><% stargazer.author %></a>
</td>
<% ELSE %>
<td class="pull-left-phone">
<a href="/author/<% stargazer.clicked_by_author %>"><% stargazer.clicked_by_author %></a>
</td>
<% END %>
<td class="date relatize" sort="<% stargazer.date.dt_http %>"><% stargazer.date.dt_http %></td>
</tr>
<% END %>
</tbody>
</table>
<% END %>
11 changes: 11 additions & 0 deletions root/inc/stargazer.html
@@ -0,0 +1,11 @@
<% IF user_exists -%>
<form action="/account/stargazer/add" style="display: inline" onsubmit="return starModule(this)">
<% IF mystarred %><input type="hidden" name="remove" value="1"><% END -%>

This comment has been minimized.

Copy link
@Talina06

Talina06 Jul 4, 2014

Author Contributor

This mystarred value is stashed in Controller/Pod.pm

<input type="hidden" name="release" value="<% module.release %>">
<input type="hidden" name="author" value="<% module.author %>">
<input type="hidden" name="module" value="<% module.documentation %>">
<button type="submit" class="stargazer<% IF mystarred %> active<% ELSE %> highlight<% END %>"><span style="visibility:hidden;"><% total_starred %></span>Bookmark</button>
</form>
<% ELSE -%>
<a href="" onclick="alert('Please sign in to bookmark the Module'); return false" class="stargazer highlight"><span style="visibility:hidden;">
<% total_starred %></span>Bookmark</a><% END -%>

0 comments on commit 56806bc

Please sign in to comment.