List subcategories on categories page
This commit is contained in:
parent
5a78c1cb34
commit
b93ca1089e
|
@ -34,6 +34,10 @@ Discourse.CategoryList.reopenClass({
|
|||
c.parentCategory = list.findBy('id', c.parent_category_id);
|
||||
}
|
||||
|
||||
if (c.subcategory_ids) {
|
||||
c.subcategories = c.subcategory_ids.map(function(scid) { return list.findBy('id', parseInt(scid, 10)); });
|
||||
}
|
||||
|
||||
if (c.featured_user_ids) {
|
||||
c.featured_users = c.featured_user_ids.map(function(u) {
|
||||
return users[u];
|
||||
|
|
|
@ -26,7 +26,7 @@ Discourse.ListCategoriesRoute = Discourse.Route.extend({
|
|||
|
||||
model: function() {
|
||||
var listTopicsController = this.controllerFor('listTopics');
|
||||
if (listTopicsController) listTopicsController.set('content', null);
|
||||
if (listTopicsController) { listTopicsController.set('content', null); }
|
||||
return this.controllerFor('list').load('categories');
|
||||
},
|
||||
|
||||
|
|
|
@ -56,6 +56,19 @@
|
|||
</tr>
|
||||
{{/each}}
|
||||
|
||||
{{#if subcategories}}
|
||||
<tr>
|
||||
<td>
|
||||
<div class='subcategories'>
|
||||
{{i18n categories.subcategories}}
|
||||
{{#each subcategory in subcategories}}
|
||||
{{categoryLink subcategory}}
|
||||
{{/each}}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{{/if}}
|
||||
|
||||
</table>
|
||||
<footer class="clearfix">
|
||||
<figure title="{{i18n year_desc}}">{{number topics_year}} <figcaption>{{i18n category.this_year}}</figcaption></figure>
|
||||
|
|
|
@ -37,6 +37,15 @@
|
|||
{{{description_excerpt}}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{#if subcategories}}
|
||||
<div class='subcategories'>
|
||||
{{i18n categories.subcategories}}
|
||||
{{#each subcategory in subcategories}}
|
||||
{{categoryLink subcategory}}
|
||||
{{/each}}
|
||||
</div>
|
||||
{{/if}}
|
||||
</td>
|
||||
<td class='num'>{{number topic_count}}</td>
|
||||
<td class='num'>{{number post_count}}</td>
|
||||
|
|
|
@ -235,9 +235,23 @@
|
|||
tbody td {
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
td.category {
|
||||
padding-top: 15px;
|
||||
}
|
||||
|
||||
.category{
|
||||
position: relative;
|
||||
width: 55%;
|
||||
|
||||
.subcategories {
|
||||
margin-top: 10px;
|
||||
.badge-category {
|
||||
font-size: 12px;
|
||||
padding: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.featured-users {
|
||||
position: absolute;
|
||||
right: 18px;
|
||||
|
@ -287,7 +301,7 @@
|
|||
#topic-list tbody tr:nth-child(even) {
|
||||
background-color: $white;
|
||||
}
|
||||
.badge-category {
|
||||
th .badge-category {
|
||||
float: left;
|
||||
margin: 1px 4px 0 0;
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ class Category < ActiveRecord::Base
|
|||
|
||||
# permission is just used by serialization
|
||||
# we may consider wrapping this in another spot
|
||||
attr_accessor :displayable_topics, :permission
|
||||
attr_accessor :displayable_topics, :permission, :subcategory_ids
|
||||
|
||||
|
||||
def self.scoped_to_permissions(guardian, permission_types)
|
||||
|
|
|
@ -61,6 +61,23 @@ class CategoryList
|
|||
|
||||
@categories = @categories.to_a
|
||||
|
||||
subcategories = {}
|
||||
to_delete = Set.new
|
||||
@categories.each do |c|
|
||||
if c.parent_category_id.present?
|
||||
subcategories[c.parent_category_id] ||= []
|
||||
subcategories[c.parent_category_id] << c.id
|
||||
to_delete << c
|
||||
end
|
||||
end
|
||||
|
||||
if subcategories.present?
|
||||
@categories.each do |c|
|
||||
c.subcategory_ids = subcategories[c.id]
|
||||
end
|
||||
@categories.delete_if {|c| to_delete.include?(c) }
|
||||
end
|
||||
|
||||
if latest_post_only?
|
||||
@all_topics = []
|
||||
@categories.each do |c|
|
||||
|
|
|
@ -5,7 +5,8 @@ class CategoryDetailedSerializer < BasicCategorySerializer
|
|||
:topics_month,
|
||||
:topics_year,
|
||||
:description_excerpt,
|
||||
:is_uncategorized
|
||||
:is_uncategorized,
|
||||
:subcategory_ids
|
||||
|
||||
has_many :featured_users, serializer: BasicUserSerializer
|
||||
has_many :displayable_topics, serializer: ListableTopicSerializer, embed: :objects, key: :topics
|
||||
|
@ -38,4 +39,8 @@ class CategoryDetailedSerializer < BasicCategorySerializer
|
|||
PrettyText.excerpt(description,300) if description
|
||||
end
|
||||
|
||||
def include_subcategory_ids?
|
||||
subcategory_ids.present?
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -192,6 +192,7 @@ en:
|
|||
latest: "Latest"
|
||||
latest_by: "latest by"
|
||||
toggle_ordering: "toggle ordering control"
|
||||
subcategories: "Subcategories:"
|
||||
|
||||
user:
|
||||
said: "{{username}} said:"
|
||||
|
|
Loading…
Reference in New Issue