mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
Show excerpts on Categories page
This commit is contained in:
parent
2e26fca36b
commit
f151b30044
6 changed files with 41 additions and 34 deletions
|
@ -32,7 +32,12 @@ Discourse.ListCategoriesController = Discourse.ObjectController.extend({
|
|||
canEdit: function() {
|
||||
var u = Discourse.User.current();
|
||||
return u && u.admin;
|
||||
}.property()
|
||||
}.property(),
|
||||
|
||||
// clear a pinned topic
|
||||
clearPin: function(topic) {
|
||||
topic.clearPin();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -28,6 +28,19 @@
|
|||
{{#if unseen}}
|
||||
<a href="{{unbound lastReadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new}}'><i class='icon icon-asterisk'></i></a>
|
||||
{{/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>
|
||||
</td>
|
||||
<td class='num'><span class='badge-posts'>{{number posts_count}}</span></td>
|
||||
|
|
|
@ -13,7 +13,7 @@ class CategoryDetailedSerializer < ApplicationSerializer
|
|||
:is_uncategorized
|
||||
|
||||
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
|
||||
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 'pinned_check'
|
||||
|
||||
class ListableTopicSerializer < BasicTopicSerializer
|
||||
|
||||
|
@ -15,7 +16,12 @@ class ListableTopicSerializer < BasicTopicSerializer
|
|||
:last_read_post_number,
|
||||
:unread,
|
||||
:new_posts,
|
||||
:title
|
||||
:title,
|
||||
:pinned,
|
||||
:excerpt,
|
||||
:visible,
|
||||
:closed,
|
||||
:archived
|
||||
|
||||
def age
|
||||
AgeWords.age_words(Time.now - (object.created_at || Time.now))
|
||||
|
@ -58,10 +64,23 @@ class ListableTopicSerializer < BasicTopicSerializer
|
|||
end
|
||||
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
|
||||
|
||||
def unread_helper
|
||||
@unread_helper ||= Unread.new(object, object.user_data)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -1,18 +1,11 @@
|
|||
require_dependency 'pinned_check'
|
||||
|
||||
class TopicListItemSerializer < ListableTopicSerializer
|
||||
|
||||
attributes :views,
|
||||
:like_count,
|
||||
:visible,
|
||||
:pinned,
|
||||
:closed,
|
||||
:archived,
|
||||
:starred,
|
||||
:has_best_of,
|
||||
:archetype,
|
||||
:rank_details,
|
||||
:excerpt
|
||||
:rank_details
|
||||
|
||||
has_one :category, serializer: BasicCategorySerializer
|
||||
has_many :posters, serializer: TopicPosterSerializer, embed: :objects
|
||||
|
@ -51,16 +44,4 @@ class TopicListItemSerializer < ListableTopicSerializer
|
|||
object.posters || []
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue