mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 18:30:26 -06:00
Show excerpts on Categories page
This commit is contained in:
parent
2e26fca36b
commit
f151b30044
@ -32,7 +32,12 @@ Discourse.ListCategoriesController = Discourse.ObjectController.extend({
|
|||||||
canEdit: function() {
|
canEdit: function() {
|
||||||
var u = Discourse.User.current();
|
var u = Discourse.User.current();
|
||||||
return u && u.admin;
|
return u && u.admin;
|
||||||
}.property()
|
}.property(),
|
||||||
|
|
||||||
|
// clear a pinned topic
|
||||||
|
clearPin: function(topic) {
|
||||||
|
topic.clearPin();
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -28,6 +28,19 @@
|
|||||||
{{#if unseen}}
|
{{#if unseen}}
|
||||||
<a href="{{unbound lastReadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new}}'><i class='icon icon-asterisk'></i></a>
|
<a href="{{unbound lastReadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new}}'><i class='icon icon-asterisk'></i></a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if hasExcerpt}}
|
||||||
|
<div class="topic-excerpt">
|
||||||
|
{{excerpt}}
|
||||||
|
{{#if excerptTruncated}}
|
||||||
|
{{#unless canClearPin}}<a href="{{lastReadUrl}}">{{i18n read_more}}</a>{{/unless}}
|
||||||
|
{{/if}}
|
||||||
|
{{#if canClearPin}}
|
||||||
|
<a href="#" {{action clearPin this}} title="{{unbound i18n topic.clear_pin.help}}">{{i18n topic.clear_pin.title}}</a>
|
||||||
|
{{/if}}
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td class='num'><span class='badge-posts'>{{number posts_count}}</span></td>
|
<td class='num'><span class='badge-posts'>{{number posts_count}}</span></td>
|
||||||
|
@ -13,7 +13,7 @@ class CategoryDetailedSerializer < ApplicationSerializer
|
|||||||
:is_uncategorized
|
:is_uncategorized
|
||||||
|
|
||||||
has_many :featured_users, serializer: BasicUserSerializer
|
has_many :featured_users, serializer: BasicUserSerializer
|
||||||
has_many :displayable_topics, serializer: CategoryTopicSerializer, embed: :objects, key: :topics
|
has_many :displayable_topics, serializer: ListableTopicSerializer, embed: :objects, key: :topics
|
||||||
|
|
||||||
def topics_week
|
def topics_week
|
||||||
object.topics_week || 0
|
object.topics_week || 0
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
require_dependency 'pinned_check'
|
|
||||||
|
|
||||||
class CategoryTopicSerializer < ListableTopicSerializer
|
|
||||||
|
|
||||||
attributes :visible, :closed, :archived, :pinned
|
|
||||||
|
|
||||||
def pinned
|
|
||||||
PinnedCheck.new(object, object.user_data).pinned?
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
@ -1,4 +1,5 @@
|
|||||||
require_dependency 'age_words'
|
require_dependency 'age_words'
|
||||||
|
require_dependency 'pinned_check'
|
||||||
|
|
||||||
class ListableTopicSerializer < BasicTopicSerializer
|
class ListableTopicSerializer < BasicTopicSerializer
|
||||||
|
|
||||||
@ -15,7 +16,12 @@ class ListableTopicSerializer < BasicTopicSerializer
|
|||||||
:last_read_post_number,
|
:last_read_post_number,
|
||||||
:unread,
|
:unread,
|
||||||
:new_posts,
|
:new_posts,
|
||||||
:title
|
:title,
|
||||||
|
:pinned,
|
||||||
|
:excerpt,
|
||||||
|
:visible,
|
||||||
|
:closed,
|
||||||
|
:archived
|
||||||
|
|
||||||
def age
|
def age
|
||||||
AgeWords.age_words(Time.now - (object.created_at || Time.now))
|
AgeWords.age_words(Time.now - (object.created_at || Time.now))
|
||||||
@ -58,10 +64,23 @@ class ListableTopicSerializer < BasicTopicSerializer
|
|||||||
end
|
end
|
||||||
alias :include_new_posts? :seen
|
alias :include_new_posts? :seen
|
||||||
|
|
||||||
|
def include_excerpt?
|
||||||
|
pinned
|
||||||
|
end
|
||||||
|
|
||||||
|
def excerpt
|
||||||
|
object.posts.by_post_number.first.try(:excerpt, 220, strip_links: true) || nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def pinned
|
||||||
|
PinnedCheck.new(object, object.user_data).pinned?
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def unread_helper
|
def unread_helper
|
||||||
@unread_helper ||= Unread.new(object, object.user_data)
|
@unread_helper ||= Unread.new(object, object.user_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,18 +1,11 @@
|
|||||||
require_dependency 'pinned_check'
|
|
||||||
|
|
||||||
class TopicListItemSerializer < ListableTopicSerializer
|
class TopicListItemSerializer < ListableTopicSerializer
|
||||||
|
|
||||||
attributes :views,
|
attributes :views,
|
||||||
:like_count,
|
:like_count,
|
||||||
:visible,
|
|
||||||
:pinned,
|
|
||||||
:closed,
|
|
||||||
:archived,
|
|
||||||
:starred,
|
:starred,
|
||||||
:has_best_of,
|
:has_best_of,
|
||||||
:archetype,
|
:archetype,
|
||||||
:rank_details,
|
:rank_details
|
||||||
:excerpt
|
|
||||||
|
|
||||||
has_one :category, serializer: BasicCategorySerializer
|
has_one :category, serializer: BasicCategorySerializer
|
||||||
has_many :posters, serializer: TopicPosterSerializer, embed: :objects
|
has_many :posters, serializer: TopicPosterSerializer, embed: :objects
|
||||||
@ -51,16 +44,4 @@ class TopicListItemSerializer < ListableTopicSerializer
|
|||||||
object.posters || []
|
object.posters || []
|
||||||
end
|
end
|
||||||
|
|
||||||
def pinned
|
|
||||||
PinnedCheck.new(object, object.user_data).pinned?
|
|
||||||
end
|
|
||||||
|
|
||||||
def include_excerpt?
|
|
||||||
pinned
|
|
||||||
end
|
|
||||||
|
|
||||||
def excerpt
|
|
||||||
object.posts.by_post_number.first.try(:excerpt, 220, strip_links: true) || nil
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user