Skip to content

Commit

Permalink
Profile page likes are now rendered on the same page (publiclab#2293)
Browse files Browse the repository at this point in the history
  • Loading branch information
SidharthBansal authored and jywarren committed Mar 7, 2018
1 parent 892dc6b commit a5587a7
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def profile
@questions = @user.user.questions
.order('node.nid DESC')
.paginate(:page => params[:page], :per_page => 24)
@likes = (@user.liked_notes.includes([:tag, :comments])+@user.liked_pages)
.paginate(page: params[:page], per_page: 24)
questions = Node.questions
.where(status: 1)
.order('node.nid DESC')
Expand Down
69 changes: 69 additions & 0 deletions app/views/users/_likes.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<div id="notes">
<div class="row">
<% @likes.each_with_index do |like,i| %>
<div class="<% if @widget %>col-xs-3 col-sm-3 <% end %><%= like.tagnames_as_classes %> col-md-3 clearfix like note like-nid-<%= like.id %> note-nid-<%= like.id %><% if like.status == 4 %> moderated<% end %>" style="overflow:hidden; text-align:center">

<% if like.main_image %>
<a class="img" <% if @widget %>target="_blank"<% end %> href="<%= like.path %>"><img src="<%= like.main_image.path(:default) %>" style="width:100%;" /></a>
<% end %>

<% if like.status == 4 %>
<p class="alert alert-warning moderated">
<% if logged_in_as(['admin','moderator']) %>
<%= t('notes._notes.moderate_first_time_post') %> <br class="hidden-xs hidden-sm"/>
<a class="btn btn-default btn-xs" href="/moderate/publish/<%= like.id %>"><%= t('notes._notes.approve') %></a>
<a class="btn btn-default btn-xs" href="/moderate/spam/<%= like.id %>"><%= t('notes._notes.spam') %></a>
<% else %>
<%= raw t('notes._notes.pending_approval', :url1 => '/wiki/moderation') %>
<% end %>
</p>
<% end %>

<h3><a <% if @widget %>target="_blank"<% end %> href="<%= like.path %>"><%= (like.type == 'note') ? like.title : like.latest.title %></a></h3>

<p class="meta"><small>
<% if like.type == 'note' %>
by <a <% if @widget %>target="_blank"<% end %> href="/profile/<%= like.author.name %>"><%= like.author.name %></a>
<%= distance_of_time_in_words(like.created_at, Time.current, { include_seconds: false, scope:'datetime.time_ago_in_words' }) %>
| <a <% if @widget %>target="_blank"<% end %> href="<%= like.path %>#comments"><i style="color:#888;" class="fa fa-comment-o"></i> <%= like.comment_count %></a>
<% else %>
<%= t('notes._notes.last_edit_by') %> <a <% if @widget %>target="_blank"<% end %> href="/profile/<%= like.latest.author.name %>"><%= like.latest.author.name %></a>
<%= distance_of_time_in_words(Time.at(like.latest.timestamp), Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' }) %>
<% end %>
| <i class="fa fa-eye"></i> <%= number_with_delimiter(like.totalviews) %> <span class="hidden-xs hidden-sm"><%= t('notes._notes.views') %></span>
| <i style="<% if like.likes > 0 %>color:#db4;<% else %>color:#888;<% end %>" class="fa fa-star-o"></i> <%= like.likes %>
</small></p>

<div class="content">
<% if @compact.nil? %>
<% if params[:action].to_s.include?("methods") %>
<p><small>
<a <% if @widget %>target="_blank"<% end %> href="<%= like.path %>#Activities"><i class="fa fa-flask" style="color:#3da56a;"></i> <%= like.activities.count %> activities</a> &nbsp;
<!-- <p><i class="fa fa-users" style="color:blue"></i> contributors</p> -->
<a <% if @widget %>target="_blank"<% end %> href="<%= like.path %>#Questions"><i class="fa fa-question-circle" style="color:#db3a1e;"></i> <%= like.questions.count %> questions</a>
</small></p>
<% else %>
<p><%= raw strip_tags(sanitize(RDiscount.new(like.body_preview).to_html)) if like.body %></p>
<% end %>
<p>
<% if logged_in_as(['admin','moderator']) %><a class="btn btn-default" href="/moderate/spam/<%= like.id %>"><i class="fa fa-ban"></i> <%= t('notes._notes.spam') %></a><% end %>
<a class="btn btn-default" style="float: right;" href="<%= like.path %>"><%= t('notes._notes.read_more') %></a>
</p>
<% end %>
<% if params[:mod] %>
<a class="btn btn-default" href="#"><i class="fa fa-ban-circle"></i> <%= t('notes._notes.spam') %></a>
<% end %>
<hr style="display:none;" class="bottom" />
</div>

</div>
<% unless @widget %><hr class="visible-xs visible-sm" /><% end %>
<% if ((i+1)/4.0).to_i == ((i+1)/4.0) %>
</div>
<% unless @widget %><hr class="visible-xs visible-sm grid" /><% end %>
<div class="row">
<% end %>
<% end %>
</div>
</div>
<%= will_paginate @likes, :renderer => BootstrapPagination::Rails unless @unpaginated %>
5 changes: 4 additions & 1 deletion app/views/users/profile.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
<li><a href="#coauthored" data-toggle="tab"><i class="fa fa-file-o"></i><span class="hidden-sm hidden-xs"> <%= t('users.profile.Coauthored') %></span> (<%= @coauthored.size %>)</a></li>
<li><a href="#questions" data-toggle="tab"><i class="fa fa-question-circle"></i><span class="hidden-sm hidden-xs"> <%= t('users.profile.questions') %></span> (<%= Node.questions.where(status: 1, uid: @user.id).length %>)</a></li>
<li><a href="#comments" id="comments-tab" data-toggle="tab"><i class="fa fa-comment"></i><span class="hidden-sm hidden-xs"> Comments</span> (<%= @comment_count %>)</a></li>
<li><a href="/profile/<%= @user.username %>/likes"><i class="fa fa-star"></i><span class="hidden-sm hidden-xs"> <%= t('users.profile.liked') %></span> (<%= @user.like_count %>)</a></li>
<li><a href="#likes" data-toggle="tab"><i class="fa fa-certificate"></i><span class="hidden-sm hidden-xs"> <%= t('users.profile.liked') %></span> (<%= @user.like_count %>)</a></li>
<li><a href="#barnstars" data-toggle="tab"><i class="fa fa-certificate"></i><span class="hidden-sm hidden-xs"> Barnstars</span> (<%= @user.user.try(:barnstars).try(:length) %>)</a></li>
</ul>

Expand Down Expand Up @@ -224,6 +224,9 @@
<h2 style="text-align:center;"><i class="fa fa-spinner fa fa-spin"></i></h2>
</div>

<div class="tab-pane" id="likes">
<%= render :partial => "users/likes" %>
</div>
<div class="tab-pane" id="barnstars">
<% if @user.user %>
<% @user.user.barnstars.each do |tag| %>
Expand Down

0 comments on commit a5587a7

Please sign in to comment.