FEATURE: displays category badge in {{category-chooser}} header

This commit is contained in:
Joffrey JAFFEUX 2018-02-14 11:49:23 +01:00 committed by GitHub
parent 25dd8ff62a
commit e3774c7bed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@ import { on } from "ember-addons/ember-computed-decorators";
import computed from "ember-addons/ember-computed-decorators";
import PermissionType from "discourse/models/permission-type";
import Category from "discourse/models/category";
import { categoryBadgeHTML } from "discourse/helpers/category-link";
const { get, isNone, isEmpty } = Ember;
export default ComboBoxComponent.extend({
@ -57,6 +58,34 @@ export default ComboBoxComponent.extend({
}
},
computeHeaderContent() {
let content = this.baseHeaderComputedContent();
if (this.get("hasSelection")) {
const category = Category.findById(content.value);
const parentCategoryId = category.get("parent_category_id");
let badge = "";
if (!Ember.isNone(parentCategoryId)) {
const parentCategory = Category.findById(parentCategoryId);
badge += categoryBadgeHTML(parentCategory, {
link: false,
allowUncategorized: true
}).htmlSafe();
}
badge += categoryBadgeHTML(category, {
link: false,
allowUncategorized: true
}).htmlSafe();
content.label = badge;
}
return content;
},
@on("didRender")
_bindComposerResizing() {
this.appEvents.on("composer:resized", this, this.applyDirection);