mirror of
https://github.com/discourse/discourse.git
synced 2025-06-02 04:08:41 +08:00
FEATURE: sorting by op likes shows the op likes count
This commit is contained in:
@ -15,6 +15,10 @@ export default Ember.Component.extend({
|
|||||||
return this.get('order') === "likes";
|
return this.get('order') === "likes";
|
||||||
}.property(),
|
}.property(),
|
||||||
|
|
||||||
|
showOpLikes: function(){
|
||||||
|
return this.get('order') === "op_likes";
|
||||||
|
}.property(),
|
||||||
|
|
||||||
click: function(e){
|
click: function(e){
|
||||||
var self = this;
|
var self = this;
|
||||||
var on = function(sel, callback){
|
var on = function(sel, callback){
|
||||||
|
@ -17,5 +17,8 @@
|
|||||||
{{#if showLikes}}
|
{{#if showLikes}}
|
||||||
{{raw "components/topic-list-header-column" sortable=sortable number='true' order='likes' name='likes'}}
|
{{raw "components/topic-list-header-column" sortable=sortable number='true' order='likes' name='likes'}}
|
||||||
{{/if}}
|
{{/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='views' name='views'}}
|
||||||
{{raw "components/topic-list-header-column" sortable=sortable number='true' order='activity' name='activity'}}
|
{{raw "components/topic-list-header-column" sortable=sortable number='true' order='activity' name='activity'}}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
hideCategory=hideCategory
|
hideCategory=hideCategory
|
||||||
showPosters=showPosters
|
showPosters=showPosters
|
||||||
showLikes=showLikes
|
showLikes=showLikes
|
||||||
|
showOpLikes=showOpLikes
|
||||||
showParticipants=showParticipants
|
showParticipants=showParticipants
|
||||||
order=order
|
order=order
|
||||||
ascending=ascending
|
ascending=ascending
|
||||||
|
@ -38,6 +38,15 @@
|
|||||||
{{/if}}
|
{{/if}}
|
||||||
{{/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>
|
<td class="num views {{topic.viewsHeat}}">{{number topic.views numberKey="views_long"}}</td>
|
||||||
|
|
||||||
{{raw "list/activity-column" topic=topic class="num" tagName="td"}}
|
{{raw "list/activity-column" topic=topic class="num" tagName="td"}}
|
||||||
|
@ -18,6 +18,10 @@ export default Discourse.View.extend(StringBuffer, {
|
|||||||
return this.get('topic.like_count') > 0;
|
return this.get('topic.like_count') > 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
hasOpLikes: function(){
|
||||||
|
return this.get('topic.op_like_count') > 0;
|
||||||
|
},
|
||||||
|
|
||||||
click: function(e){
|
click: function(e){
|
||||||
var target = $(e.target);
|
var target = $(e.target);
|
||||||
|
|
||||||
|
@ -101,6 +101,8 @@ class Topic < ActiveRecord::Base
|
|||||||
|
|
||||||
has_one :warning
|
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)
|
# When we want to temporarily attach some data to a forum topic (usually before serialization)
|
||||||
attr_accessor :user_data
|
attr_accessor :user_data
|
||||||
attr_accessor :posters # TODO: can replace with posters_summary once we remove old list code
|
attr_accessor :posters # TODO: can replace with posters_summary once we remove old list code
|
||||||
|
@ -6,7 +6,8 @@ class TopicListItemSerializer < ListableTopicSerializer
|
|||||||
:has_summary,
|
:has_summary,
|
||||||
:archetype,
|
:archetype,
|
||||||
:last_poster_username,
|
:last_poster_username,
|
||||||
:category_id
|
:category_id,
|
||||||
|
:op_like_count
|
||||||
|
|
||||||
has_many :posters, serializer: TopicPosterSerializer, embed: :objects
|
has_many :posters, serializer: TopicPosterSerializer, embed: :objects
|
||||||
has_many :participants, serializer: TopicPosterSerializer, embed: :objects
|
has_many :participants, serializer: TopicPosterSerializer, embed: :objects
|
||||||
@ -21,6 +22,10 @@ class TopicListItemSerializer < ListableTopicSerializer
|
|||||||
object.posters || []
|
object.posters || []
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def op_like_count
|
||||||
|
object.first_post && object.first_post.like_count
|
||||||
|
end
|
||||||
|
|
||||||
def last_poster_username
|
def last_poster_username
|
||||||
posters.find { |poster| poster.user.id == object.last_post_user_id }.try(:user).try(:username)
|
posters.find { |poster| poster.user.id == object.last_post_user_id }.try(:user).try(:username)
|
||||||
end
|
end
|
||||||
@ -33,4 +38,8 @@ class TopicListItemSerializer < ListableTopicSerializer
|
|||||||
object.private_message?
|
object.private_message?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def include_op_like_count?
|
||||||
|
object.association(:first_post).loaded?
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -220,7 +220,7 @@ class TopicQuery
|
|||||||
end
|
end
|
||||||
|
|
||||||
if sort_column == 'op_likes'
|
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
|
end
|
||||||
|
|
||||||
result.order("topics.#{sort_column} #{sort_dir}")
|
result.order("topics.#{sort_column} #{sort_dir}")
|
||||||
|
Reference in New Issue
Block a user