FIX: hide category column in topic list only when the current category has no children
This commit is contained in:
parent
0cd393f310
commit
d34f42d2f7
|
@ -163,10 +163,9 @@ TopicList.reopenClass({
|
||||||
return this.find(filter);
|
return this.find(filter);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Sets `hideCategory` if all topics in the last have a particular category
|
// hide the category when it has no children
|
||||||
hideUniformCategory(list, category) {
|
hideUniformCategory(list, category) {
|
||||||
const hideCategory = !list.get('topics').any(function (t) { return t.get('category') !== category; });
|
list.set('hideCategory', !category.get("has_children"));
|
||||||
list.set('hideCategory', hideCategory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -79,7 +79,7 @@ class Category < ActiveRecord::Base
|
||||||
|
|
||||||
# permission is just used by serialization
|
# permission is just used by serialization
|
||||||
# we may consider wrapping this in another spot
|
# we may consider wrapping this in another spot
|
||||||
attr_accessor :displayable_topics, :permission, :subcategory_ids, :notification_level
|
attr_accessor :displayable_topics, :permission, :subcategory_ids, :notification_level, :has_children
|
||||||
|
|
||||||
def self.last_updated_at
|
def self.last_updated_at
|
||||||
order('updated_at desc').limit(1).pluck(:updated_at).first.to_i
|
order('updated_at desc').limit(1).pluck(:updated_at).first.to_i
|
||||||
|
|
|
@ -30,7 +30,7 @@ class Site
|
||||||
end
|
end
|
||||||
|
|
||||||
def groups
|
def groups
|
||||||
@groups ||= Group.order(:name).map { |g| {:id => g.id, :name => g.name}}
|
@groups ||= Group.order(:name).map { |g| { id: g.id, name: g.name } }
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_fields
|
def user_fields
|
||||||
|
@ -41,7 +41,7 @@ class Site
|
||||||
@categories ||= begin
|
@categories ||= begin
|
||||||
categories = Category
|
categories = Category
|
||||||
.secured(@guardian)
|
.secured(@guardian)
|
||||||
.includes(:topic_only_relative_url)
|
.includes(:topic_only_relative_url, :subcategories)
|
||||||
.order(:position)
|
.order(:position)
|
||||||
|
|
||||||
unless SiteSetting.allow_uncategorized_topics
|
unless SiteSetting.allow_uncategorized_topics
|
||||||
|
@ -62,10 +62,11 @@ class Site
|
||||||
categories.each do |category|
|
categories.each do |category|
|
||||||
category.notification_level = category_user[category.id]
|
category.notification_level = category_user[category.id]
|
||||||
category.permission = CategoryGroup.permission_types[:full] if allowed_topic_create.include?(category.id)
|
category.permission = CategoryGroup.permission_types[:full] if allowed_topic_create.include?(category.id)
|
||||||
|
category.has_children = category.subcategories.present?
|
||||||
by_id[category.id] = category
|
by_id[category.id] = category
|
||||||
end
|
end
|
||||||
|
|
||||||
categories.reject! {|c| c.parent_category_id && !by_id[c.parent_category_id]}
|
categories.reject! { |c| c.parent_category_id && !by_id[c.parent_category_id] }
|
||||||
categories
|
categories
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,7 +17,8 @@ class BasicCategorySerializer < ApplicationSerializer
|
||||||
:logo_url,
|
:logo_url,
|
||||||
:background_url,
|
:background_url,
|
||||||
:can_edit,
|
:can_edit,
|
||||||
:topic_template
|
:topic_template,
|
||||||
|
:has_children
|
||||||
|
|
||||||
def include_parent_category_id?
|
def include_parent_category_id?
|
||||||
parent_category_id
|
parent_category_id
|
||||||
|
|
Loading…
Reference in New Issue