FEATURE: sorting by op likes shows the op likes count

This commit is contained in:
Sam 2015-01-05 17:39:49 +11:00
parent ea2f892f4b
commit 0396fd66f6
8 changed files with 34 additions and 2 deletions

View File

@ -15,6 +15,10 @@ export default Ember.Component.extend({
return this.get('order') === "likes";
}.property(),
showOpLikes: function(){
return this.get('order') === "op_likes";
}.property(),
click: function(e){
var self = this;
var on = function(sel, callback){

View File

@ -17,5 +17,8 @@
{{#if showLikes}}
{{raw "components/topic-list-header-column" sortable=sortable number='true' order='likes' name='likes'}}
{{/if}}
{{#if showOpLikes}}
{{raw "components/topic-list-header-column" sortable=sortable number='true' order='op_likes' name='likes'}}
{{/if}}
{{raw "components/topic-list-header-column" sortable=sortable number='true' order='views' name='views'}}
{{raw "components/topic-list-header-column" sortable=sortable number='true' order='activity' name='activity'}}

View File

@ -7,6 +7,7 @@
hideCategory=hideCategory
showPosters=showPosters
showLikes=showLikes
showOpLikes=showOpLikes
showParticipants=showParticipants
order=order
ascending=ascending

View File

@ -38,6 +38,15 @@
{{/if}}
{{/if}}
{{#if controller.showOpLikes}}
<td class="num likes">
{{#if hasOpLikes}}
<a href='{{topic.summaryUrl}}'>
{{number topic.op_like_count}} <i class='fa fa-heart'></i></td>
</a>
{{/if}}
{{/if}}
<td class="num views {{topic.viewsHeat}}">{{number topic.views numberKey="views_long"}}</td>
{{raw "list/activity-column" topic=topic class="num" tagName="td"}}

View File

@ -18,6 +18,10 @@ export default Discourse.View.extend(StringBuffer, {
return this.get('topic.like_count') > 0;
},
hasOpLikes: function(){
return this.get('topic.op_like_count') > 0;
},
click: function(e){
var target = $(e.target);

View File

@ -101,6 +101,8 @@ class Topic < ActiveRecord::Base
has_one :warning
has_one :first_post, -> {where post_number: 1}, class_name: Post
# When we want to temporarily attach some data to a forum topic (usually before serialization)
attr_accessor :user_data
attr_accessor :posters # TODO: can replace with posters_summary once we remove old list code

View File

@ -6,7 +6,8 @@ class TopicListItemSerializer < ListableTopicSerializer
:has_summary,
:archetype,
:last_poster_username,
:category_id
:category_id,
:op_like_count
has_many :posters, serializer: TopicPosterSerializer, embed: :objects
has_many :participants, serializer: TopicPosterSerializer, embed: :objects
@ -21,6 +22,10 @@ class TopicListItemSerializer < ListableTopicSerializer
object.posters || []
end
def op_like_count
object.first_post && object.first_post.like_count
end
def last_poster_username
posters.find { |poster| poster.user.id == object.last_post_user_id }.try(:user).try(:username)
end
@ -33,4 +38,8 @@ class TopicListItemSerializer < ListableTopicSerializer
object.private_message?
end
def include_op_like_count?
object.association(:first_post).loaded?
end
end

View File

@ -220,7 +220,7 @@ class TopicQuery
end
if sort_column == 'op_likes'
return result.order("(SELECT like_count FROM posts p3 WHERE p3.topic_id = topics.id AND p3.post_number = 1) #{sort_dir}")
return result.includes(:first_post).order("(SELECT like_count FROM posts p3 WHERE p3.topic_id = topics.id AND p3.post_number = 1) #{sort_dir}")
end
result.order("topics.#{sort_column} #{sort_dir}")