diff --git a/app/assets/javascripts/discourse/templates/featured_topics.js.handlebars b/app/assets/javascripts/discourse/templates/featured_topics.js.handlebars index afc1a07b6..818978286 100644 --- a/app/assets/javascripts/discourse/templates/featured_topics.js.handlebars +++ b/app/assets/javascripts/discourse/templates/featured_topics.js.handlebars @@ -13,34 +13,42 @@ <th class='num'>{{i18n age}}</th> </tr> + {{#if description_excerpt}} + <tr class="category-description"> + <td colspan="3"> + {{{description_excerpt}}} + </td> + </tr> + {{/if}} + {{#each topics}} <tr {{bindAttr class="archived"}}> <td class='main-link'> <div class='topic-inset'> {{topicStatus topic=this}} {{{topicLink this}}} - {{#if unread}} - <a href="{{unbound lastReadUrl}}" class='badge unread badge-notification' title='{{i18n topic.unread_posts unread="unread"}}'>{{unbound unread}}</a> - {{/if}} - {{#if new_posts}} - <a href="{{unbound lastReadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new_posts new_posts="new_posts"}}'>{{unbound new_posts}}</a> - {{/if}} - {{#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}} + {{#if unread}} + <a href="{{unbound lastReadUrl}}" class='badge unread badge-notification' title='{{i18n topic.unread_posts unread="unread"}}'>{{unbound unread}}</a> + {{/if}} + {{#if new_posts}} + <a href="{{unbound lastReadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new_posts new_posts="new_posts"}}'>{{unbound new_posts}}</a> + {{/if}} + {{#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> diff --git a/app/assets/stylesheets/application/topic-list.css.scss b/app/assets/stylesheets/application/topic-list.css.scss index c06854f5d..a562f9700 100644 --- a/app/assets/stylesheets/application/topic-list.css.scss +++ b/app/assets/stylesheets/application/topic-list.css.scss @@ -54,6 +54,11 @@ vertical-align: top; margin-top: 2px; } + &.category-description { + td { + color: lighten($topic-list-td-color, 5%); + } + } } th, td { diff --git a/app/models/category_featured_topic.rb b/app/models/category_featured_topic.rb index 32165840d..4e7b55078 100644 --- a/app/models/category_featured_topic.rb +++ b/app/models/category_featured_topic.rb @@ -23,7 +23,7 @@ class CategoryFeaturedTopic < ActiveRecord::Base admin.admin = true admin.id = -1 - query = TopicQuery.new(admin, per_page: SiteSetting.category_featured_topics) + query = TopicQuery.new(admin, per_page: SiteSetting.category_featured_topics, except_topic_id: c.topic_id) results = query.list_category(c) if results.present? results.topic_ids.each_with_index do |topic_id, idx| diff --git a/app/serializers/category_detailed_serializer.rb b/app/serializers/category_detailed_serializer.rb index a11ae6b97..2d8841f47 100644 --- a/app/serializers/category_detailed_serializer.rb +++ b/app/serializers/category_detailed_serializer.rb @@ -10,6 +10,7 @@ class CategoryDetailedSerializer < ApplicationSerializer :topics_month, :topics_year, :description, + :description_excerpt, :is_uncategorized has_many :featured_users, serializer: BasicUserSerializer @@ -39,4 +40,8 @@ class CategoryDetailedSerializer < ApplicationSerializer return displayable_topics.present? end + def description_excerpt + PrettyText.excerpt(description,300) if description + end + end diff --git a/spec/models/category_featured_topic_spec.rb b/spec/models/category_featured_topic_spec.rb index f40577bbf..6baa36e97 100644 --- a/spec/models/category_featured_topic_spec.rb +++ b/spec/models/category_featured_topic_spec.rb @@ -16,7 +16,8 @@ describe CategoryFeaturedTopic do category.allow(Group[:trust_level_1]) category.save - post = PostCreator.create(user, raw: "this is my new post 123 post", title: "hello world") + uncategorized_post = PostCreator.create(user, raw: "this is my new post 123 post", title: "hello world") + category_post = PostCreator.create(user, raw: "I put this post in the category", title: "categorize THIS", category: category.name) CategoryFeaturedTopic.feature_topics_for(category) CategoryFeaturedTopic.count.should == 1