Show more than one topic per category on the wide categories page. Disable support for the 2-column categories page. The category_featured_topics site setting controls how many topics to show.
This commit is contained in:
parent
50c4e3707b
commit
6fa2e68742
|
@ -41,7 +41,11 @@ Discourse.ListCategoriesController = Discourse.ObjectController.extend({
|
|||
|
||||
moveCategory: function(categoryId, position){
|
||||
this.get('model.categories').moveCategory(categoryId, position);
|
||||
}
|
||||
},
|
||||
|
||||
latestTopicOnly: function() {
|
||||
return this.get('categories').find(function(c) { return c.get('featuredTopics.length') > 1; }) === undefined;
|
||||
}.property('categories.featuredTopics.length')
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -117,6 +117,13 @@ Discourse.Category = Discourse.Model.extend({
|
|||
}
|
||||
}.property("topics"),
|
||||
|
||||
featuredTopics: function() {
|
||||
var topics = this.get('topics');
|
||||
if (topics && topics.length) {
|
||||
return topics.slice(0, Discourse.SiteSettings.category_featured_topics || 2);
|
||||
}
|
||||
}.property('topics'),
|
||||
|
||||
topicTrackingState: function(){
|
||||
return Discourse.TopicTrackingState.current();
|
||||
}.property(),
|
||||
|
|
|
@ -9,7 +9,10 @@
|
|||
Discourse.ListCategoriesRoute = Discourse.Route.extend({
|
||||
|
||||
template: function() {
|
||||
return Discourse.SiteSettings.enable_wide_category_list ? 'listWideCategories' : 'listCategories';
|
||||
// Remove the option to have 2-column layout on categories page.
|
||||
// TODO: remove this old code when we're sure about it.
|
||||
// return Discourse.SiteSettings.enable_wide_category_list ? 'listWideCategories' : 'listCategories';
|
||||
return 'listWideCategories';
|
||||
}.property(),
|
||||
|
||||
redirect: function() { Discourse.redirectIfLoginRequired(this); },
|
||||
|
|
|
@ -49,25 +49,33 @@
|
|||
</td>
|
||||
<td class='num'>{{number topic_count}}</td>
|
||||
<td class='num'>{{number post_count}}</td>
|
||||
{{#with latestTopic}}
|
||||
<td {{bindAttr class="archived :latest"}}>
|
||||
{{topicStatus topic=this}}
|
||||
<a class='title' href="{{unbound lastUnreadUrl}}">{{{unbound fancy_title}}}</a>
|
||||
{{#if unread}}
|
||||
<a href="{{unbound lastUnreadUrl}}" class='badge unread badge-notification' title='{{i18n topic.unread_posts count="unread"}}'>{{unread}}</a>
|
||||
{{/if}}
|
||||
{{#if new_posts}}
|
||||
<a href="{{unbound lastUnreadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new_posts count="new_posts"}}'>{{new_posts}}</a>
|
||||
{{/if}}
|
||||
{{#if unseen}}
|
||||
<a href="{{unbound lastUnreadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new}}'><i class='fa fa-asterisk'></i></a>
|
||||
{{/if}}
|
||||
<div class='last-user-info'>
|
||||
{{i18n categories.latest_by}} <a href="{{{unbound lastPosterUrl}}}">{{unbound last_poster.username}}</a>
|
||||
<a href="{{unbound lastPostUrl}}">{{unboundAge last_posted_at}}</a>
|
||||
<td {{bindAttr class="archived :latest"}}>
|
||||
{{#each featuredTopics}}
|
||||
<div class="featured-topic">
|
||||
{{topicStatus topic=this}}
|
||||
<a class='title' href="{{unbound lastUnreadUrl}}">{{{unbound fancy_title}}}</a>
|
||||
{{#if unread}}
|
||||
<a href="{{unbound lastUnreadUrl}}" class='badge unread badge-notification' title='{{i18n topic.unread_posts count="unread"}}'>{{unread}}</a>
|
||||
{{/if}}
|
||||
{{#if new_posts}}
|
||||
<a href="{{unbound lastUnreadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new_posts count="new_posts"}}'>{{new_posts}}</a>
|
||||
{{/if}}
|
||||
{{#if unseen}}
|
||||
<a href="{{unbound lastUnreadUrl}}" class='badge new-posts badge-notification' title='{{i18n topic.new}}'><i class='fa fa-asterisk'></i></a>
|
||||
{{/if}}
|
||||
|
||||
{{#if controller.latestTopicOnly}}
|
||||
<div class='last-user-info'>
|
||||
{{i18n categories.latest_by}} <a href="{{{unbound lastPosterUrl}}}">{{unbound last_poster.username}}</a>
|
||||
<a href="{{unbound lastPostUrl}}">{{unboundAge last_posted_at}}</a>
|
||||
</div>
|
||||
{{else}}
|
||||
|
||||
<a href="{{unbound lastPostUrl}}" class="last-posted-at">{{unboundAge last_posted_at}}</a>
|
||||
{{/if}}
|
||||
</div>
|
||||
</td>
|
||||
{{/with}}
|
||||
{{/each}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</tbody>
|
||||
|
|
|
@ -252,7 +252,6 @@
|
|||
}
|
||||
.last-user-info {
|
||||
font-size: 12px;
|
||||
margin-top: 3px;
|
||||
}
|
||||
tbody td {
|
||||
padding-bottom: 20px;
|
||||
|
@ -287,6 +286,13 @@
|
|||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
|
||||
.featured-topic {
|
||||
margin: 6px 0;
|
||||
a.last-posted-at, a.last-posted-at:visited {
|
||||
color: #888;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -9,10 +9,11 @@ class CategoriesController < ApplicationController
|
|||
def index
|
||||
@description = SiteSetting.site_description
|
||||
|
||||
wide_mode = SiteSetting.enable_wide_category_list
|
||||
# TODO: remove this when we're sure about removing 2-column layout on categories page
|
||||
# wide_mode = SiteSetting.enable_wide_category_list
|
||||
|
||||
options = {}
|
||||
options[:latest_post_only] = params[:latest_post_only] || wide_mode
|
||||
options[:latest_posts] = params[:latest_posts] || SiteSetting.category_featured_topics
|
||||
|
||||
@list = CategoryList.new(guardian,options)
|
||||
@list.draft_key = Draft::NEW_TOPIC
|
||||
|
|
|
@ -22,7 +22,15 @@ class CategoryList
|
|||
private
|
||||
|
||||
def latest_post_only?
|
||||
@options[:latest_post_only]
|
||||
@options[:latest_posts] and latest_posts_count == 1
|
||||
end
|
||||
|
||||
def include_latest_posts?
|
||||
@options[:latest_posts] and latest_posts_count > 1
|
||||
end
|
||||
|
||||
def latest_posts_count
|
||||
@options[:latest_posts].to_i > 0 ? @options[:latest_posts].to_i : SiteSetting.category_featured_topics
|
||||
end
|
||||
|
||||
# Retrieve a list of all the topics we'll need
|
||||
|
@ -33,6 +41,7 @@ class CategoryList
|
|||
|
||||
@all_topics = Topic.where(id: category_featured_topics.map(&:topic_id))
|
||||
@all_topics.each do |t|
|
||||
t.include_last_poster = true if include_latest_posts? # hint for serialization
|
||||
@topics_by_id[t.id] = t
|
||||
end
|
||||
|
||||
|
|
|
@ -514,7 +514,7 @@ en:
|
|||
delete_removed_posts_after: "Number of hours after which posts removed by the author will be deleted."
|
||||
max_image_width: "Maximum allowed width of images in a post"
|
||||
max_image_height: "Maximum allowed height of images in a post"
|
||||
category_featured_topics: "Number of topics displayed per category in the /categories page"
|
||||
category_featured_topics: "Number of topics displayed per category on the /categories page. After changing this value, it takes up to 15 minutes for the categories page to update."
|
||||
add_rel_nofollow_to_user_content: "Add rel nofollow to all submitted user content, except for internal links (including parent domains) changing this requires you update all your baked markdown with: \"rake posts:rebake\""
|
||||
exclude_rel_nofollow_domains: "A comma delimited list of domains where nofollow is not added (tld.com will automatically allow sub.tld.com as well)"
|
||||
|
||||
|
@ -681,7 +681,7 @@ en:
|
|||
min_body_similar_length: "The minimum length of a post's body before it will be checked for similar topics"
|
||||
|
||||
category_colors: "A pipe (|) separated list of hexadecimal color values allowed for categories"
|
||||
enable_wide_category_list: "Enable traditional full width, non-tiling, category list"
|
||||
enable_wide_category_list: "Enable traditional full width, non-tiling, category list. NOTE: this setting currently does nothing and will be removed. Wide list is the only option now."
|
||||
|
||||
max_image_size_kb: "The maximum size of images we allow users to upload in kB - configure the limit in nginx (client_max_body_size) / apache or proxy as well."
|
||||
max_attachment_size_kb: "The maximum size of files we allow users to upload in kB - configure the limit in nginx (client_max_body_size) / apache or proxy as well."
|
||||
|
|
|
@ -32,10 +32,10 @@ basic:
|
|||
default: ''
|
||||
enable_wide_category_list:
|
||||
client: true
|
||||
default: false
|
||||
default: true
|
||||
category_featured_topics:
|
||||
client: true
|
||||
default: 6
|
||||
default: 3
|
||||
topics_per_page: 30
|
||||
posts_per_page:
|
||||
client: true
|
||||
|
|
|
@ -22,7 +22,7 @@ test("Categories List", function() {
|
|||
expect(1);
|
||||
|
||||
visit("/categories").then(function() {
|
||||
ok(exists('.category-list-item'), "has a list of categories");
|
||||
ok(exists('.category'), "has a list of categories");
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue