Show excerpts on Categories page

This commit is contained in:
Robin Ward 2013-05-29 11:46:01 -04:00
parent 2e26fca36b
commit f151b30044
6 changed files with 41 additions and 34 deletions

View File

@ -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();
}
});

View File

@ -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>

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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