Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Stargazers: Model and display scripts
- Loading branch information
Showing
4 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
Sorry, something went wrong. |
||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<% PROCESS inc/account-bar.html %> | ||
<div class="content"> | ||
<% INCLUDE inc/stargazer-table.html stargazers = stars, author = 1, tablesorter = 1 %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.
Sorry, something went wrong. |
||
<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 -%> |
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.