2017-11-21 05:53:09 -05:00
|
|
|
import SelectKitRowComponent from "select-kit/components/select-kit/select-kit-row";
|
|
|
|
import computed from "ember-addons/ember-computed-decorators";
|
|
|
|
import Category from "discourse/models/category";
|
|
|
|
import { categoryBadgeHTML } from "discourse/helpers/category-link";
|
|
|
|
|
|
|
|
export default SelectKitRowComponent.extend({
|
|
|
|
layoutName: "select-kit/templates/components/category-row",
|
|
|
|
classNames: "category-row",
|
2017-11-21 09:38:30 -05:00
|
|
|
|
2018-01-24 05:48:20 -05:00
|
|
|
hideParentCategory: Ember.computed.bool("options.hideParentCategory"),
|
|
|
|
allowUncategorized: Ember.computed.bool("options.allowUncategorized"),
|
|
|
|
categoryLink: Ember.computed.bool("options.categoryLink"),
|
|
|
|
|
2017-11-21 09:38:30 -05:00
|
|
|
@computed("options.displayCategoryDescription")
|
|
|
|
displayCategoryDescription(displayCategoryDescription) {
|
|
|
|
if (Ember.isNone(displayCategoryDescription)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return displayCategoryDescription;
|
|
|
|
},
|
2017-11-21 05:53:09 -05:00
|
|
|
|
2018-11-13 07:35:45 -05:00
|
|
|
@computed("descriptionText", "description", "category.name")
|
|
|
|
title(descriptionText, description, name) {
|
|
|
|
return descriptionText || description || name;
|
2018-03-27 06:25:05 -04:00
|
|
|
},
|
|
|
|
|
2017-11-21 05:53:09 -05:00
|
|
|
@computed("computedContent.value", "computedContent.name")
|
|
|
|
category(value, name) {
|
|
|
|
if (Ember.isEmpty(value)) {
|
|
|
|
const uncat = Category.findUncategorized();
|
|
|
|
if (uncat && uncat.get("name") === name) {
|
|
|
|
return uncat;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return Category.findById(parseInt(value, 10));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-02-14 10:42:20 -05:00
|
|
|
@computed("category", "parentCategory")
|
|
|
|
badgeForCategory(category, parentCategory) {
|
2017-11-21 05:53:09 -05:00
|
|
|
return categoryBadgeHTML(category, {
|
2019-05-27 04:15:39 -04:00
|
|
|
link: this.categoryLink,
|
|
|
|
allowUncategorized: this.allowUncategorized,
|
2018-02-14 10:42:20 -05:00
|
|
|
hideParent: parentCategory ? true : false
|
2017-11-21 05:53:09 -05:00
|
|
|
}).htmlSafe();
|
|
|
|
},
|
|
|
|
|
|
|
|
@computed("parentCategory")
|
|
|
|
badgeForParentCategory(parentCategory) {
|
2018-02-14 05:03:33 -05:00
|
|
|
return categoryBadgeHTML(parentCategory, {
|
2019-05-27 04:15:39 -04:00
|
|
|
link: this.categoryLink,
|
|
|
|
allowUncategorized: this.allowUncategorized
|
2018-02-14 05:03:33 -05:00
|
|
|
}).htmlSafe();
|
2017-11-21 05:53:09 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
@computed("parentCategoryid")
|
|
|
|
parentCategory(parentCategoryId) {
|
|
|
|
return Category.findById(parentCategoryId);
|
|
|
|
},
|
|
|
|
|
|
|
|
@computed("parentCategoryid")
|
|
|
|
hasParentCategory(parentCategoryid) {
|
|
|
|
return !Ember.isNone(parentCategoryid);
|
|
|
|
},
|
|
|
|
|
|
|
|
@computed("category")
|
|
|
|
parentCategoryid(category) {
|
|
|
|
return category.get("parent_category_id");
|
|
|
|
},
|
|
|
|
|
2018-07-16 22:06:48 -04:00
|
|
|
@computed(
|
|
|
|
"category.totalTopicCount",
|
|
|
|
"category.topic_count",
|
|
|
|
"options.countSubcategories"
|
|
|
|
)
|
|
|
|
topicCount(totalCount, topicCount, countSubcats) {
|
2019-04-02 11:38:21 -04:00
|
|
|
return countSubcats ? totalCount : topicCount;
|
2018-01-24 05:48:20 -05:00
|
|
|
},
|
2017-11-21 05:53:09 -05:00
|
|
|
|
2017-11-21 09:38:30 -05:00
|
|
|
@computed("displayCategoryDescription", "category.description")
|
|
|
|
shouldDisplayDescription(displayCategoryDescription, description) {
|
2017-11-21 05:53:09 -05:00
|
|
|
return displayCategoryDescription && description && description !== "null";
|
|
|
|
},
|
|
|
|
|
2018-11-13 07:35:45 -05:00
|
|
|
@computed("category.description_text")
|
2019-10-01 12:04:40 -04:00
|
|
|
descriptionText(descriptionText) {
|
|
|
|
if (descriptionText) {
|
|
|
|
return this._formatCategoryDescription(descriptionText);
|
2018-11-13 07:35:45 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-11-21 05:53:09 -05:00
|
|
|
@computed("category.description")
|
|
|
|
description(description) {
|
2018-03-27 08:11:05 -04:00
|
|
|
if (description) {
|
2018-11-13 07:35:45 -05:00
|
|
|
return this._formatCategoryDescription(description);
|
2018-03-27 08:11:05 -04:00
|
|
|
}
|
2018-11-13 07:35:45 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_formatCategoryDescription(description) {
|
|
|
|
return `${description.substr(0, 200)}${
|
|
|
|
description.length > 200 ? "…" : ""
|
|
|
|
}`;
|
2017-11-21 05:53:09 -05:00
|
|
|
}
|
|
|
|
});
|