mirror of
https://github.com/discourse/discourse.git
synced 2025-05-05 00:44:37 +08:00
DEV: Allow the creation of sub-sub-categories
This commits adds a new site setting (max_category_nesting), that determines whether sub-sub-categories are allowable.
This commit is contained in:
parent
6e5fedb312
commit
2f5adbe1f4
@ -61,7 +61,7 @@ export default buildCategoryPanel("general", {
|
|||||||
parentCategories() {
|
parentCategories() {
|
||||||
return this.site
|
return this.site
|
||||||
.get("categoriesList")
|
.get("categoriesList")
|
||||||
.filter(c => !c.get("parentCategory"));
|
.filter(c => c.level + 1 < Discourse.SiteSettings.max_category_nesting);
|
||||||
},
|
},
|
||||||
|
|
||||||
@discourseComputed(
|
@discourseComputed(
|
||||||
|
@ -60,6 +60,11 @@ const Category = RestModel.extend({
|
|||||||
return [...(parentAncestors || []), this];
|
return [...(parentAncestors || []), this];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@discourseComputed("parentCategory.level")
|
||||||
|
level(parentLevel) {
|
||||||
|
return (parentLevel || -1) + 1;
|
||||||
|
},
|
||||||
|
|
||||||
@discourseComputed("notification_level")
|
@discourseComputed("notification_level")
|
||||||
isMuted(notificationLevel) {
|
isMuted(notificationLevel) {
|
||||||
return notificationLevel === NotificationLevels.MUTED;
|
return notificationLevel === NotificationLevels.MUTED;
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
value=category.parent_category_id
|
value=category.parent_category_id
|
||||||
excludeCategoryId=category.id
|
excludeCategoryId=category.id
|
||||||
categories=parentCategories
|
categories=parentCategories
|
||||||
allowSubCategories=false
|
allowSubCategories=true
|
||||||
allowUncategorized=false}}
|
allowUncategorized=false}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</section>
|
</section>
|
||||||
|
@ -13,7 +13,6 @@ class Category < ActiveRecord::Base
|
|||||||
include AnonCacheInvalidator
|
include AnonCacheInvalidator
|
||||||
include HasDestroyedWebHook
|
include HasDestroyedWebHook
|
||||||
|
|
||||||
MAX_NESTING = 2 # category + subcategory
|
|
||||||
REQUIRE_TOPIC_APPROVAL = 'require_topic_approval'
|
REQUIRE_TOPIC_APPROVAL = 'require_topic_approval'
|
||||||
REQUIRE_REPLY_APPROVAL = 'require_reply_approval'
|
REQUIRE_REPLY_APPROVAL = 'require_reply_approval'
|
||||||
NUM_AUTO_BUMP_DAILY = 'num_auto_bump_daily'
|
NUM_AUTO_BUMP_DAILY = 'num_auto_bump_daily'
|
||||||
@ -329,7 +328,7 @@ class Category < ActiveRecord::Base
|
|||||||
|
|
||||||
# This is used in a validation so has to produce accurate results before the
|
# This is used in a validation so has to produce accurate results before the
|
||||||
# record has been saved
|
# record has been saved
|
||||||
def height_of_ancestors(max_height = MAX_NESTING)
|
def height_of_ancestors(max_height = SiteSetting.max_category_nesting)
|
||||||
parent_id = self.parent_category_id
|
parent_id = self.parent_category_id
|
||||||
|
|
||||||
return max_height if parent_id == id
|
return max_height if parent_id == id
|
||||||
@ -357,7 +356,7 @@ class Category < ActiveRecord::Base
|
|||||||
|
|
||||||
# This is used in a validation so has to produce accurate results before the
|
# This is used in a validation so has to produce accurate results before the
|
||||||
# record has been saved
|
# record has been saved
|
||||||
def depth_of_descendants(max_depth = MAX_NESTING)
|
def depth_of_descendants(max_depth = SiteSetting.max_category_nesting)
|
||||||
parent_id = self.parent_category_id
|
parent_id = self.parent_category_id
|
||||||
|
|
||||||
return max_depth if parent_id == id
|
return max_depth if parent_id == id
|
||||||
@ -390,7 +389,7 @@ class Category < ActiveRecord::Base
|
|||||||
errors.add(:base, I18n.t("category.errors.self_parent")) if parent_category_id == id
|
errors.add(:base, I18n.t("category.errors.self_parent")) if parent_category_id == id
|
||||||
|
|
||||||
total_depth = height_of_ancestors + 1 + depth_of_descendants
|
total_depth = height_of_ancestors + 1 + depth_of_descendants
|
||||||
errors.add(:base, I18n.t("category.errors.depth")) if total_depth > MAX_NESTING
|
errors.add(:base, I18n.t("category.errors.depth")) if total_depth > SiteSetting.max_category_nesting
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -240,6 +240,12 @@ basic:
|
|||||||
- box
|
- box
|
||||||
- bullet
|
- bullet
|
||||||
- none
|
- none
|
||||||
|
max_category_nesting:
|
||||||
|
client: true
|
||||||
|
default: 2
|
||||||
|
min: 2
|
||||||
|
max: 3
|
||||||
|
hidden: true
|
||||||
enable_mobile_theme:
|
enable_mobile_theme:
|
||||||
client: true
|
client: true
|
||||||
default: true
|
default: true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user