-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: improves select-box to support category selection on new topic
- Loading branch information
Showing
18 changed files
with
438 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
app/assets/javascripts/discourse/components/category-select-box.js.es6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import SelectBoxComponent from "discourse/components/select-box"; | ||
import { categoryBadgeHTML } from 'discourse/helpers/category-link'; | ||
import { observes, on } from 'ember-addons/ember-computed-decorators'; | ||
import PermissionType from 'discourse/models/permission-type'; | ||
import Category from 'discourse/models/category'; | ||
|
||
export default SelectBoxComponent.extend({ | ||
classNames: ["category-select-box"], | ||
|
||
textKey: "name", | ||
|
||
filterable: true, | ||
|
||
castInteger: true, | ||
|
||
width: '100%', | ||
|
||
@on("willInsertElement") | ||
@observes("selectedContent") | ||
_setHeaderText: function() { | ||
let headerText; | ||
|
||
if (Ember.isNone(this.get("selectedContent"))) { | ||
if (this.siteSettings.allow_uncategorized_topics) { | ||
headerText = Ember.get(Category.findUncategorized(), this.get("textKey")); | ||
} else { | ||
headerText = I18n.t("category.choose"); | ||
} | ||
} else { | ||
headerText = this.get("selectedContent.text"); | ||
} | ||
|
||
this.set("headerText", headerText); | ||
}, | ||
|
||
// original method is kept for compatibility | ||
selectBoxRowTemplate: function() { | ||
return (rowComponent) => this.rowContentTemplate(rowComponent.get("content")); | ||
}.property(), | ||
|
||
@observes("scopedCategoryId", "categories") | ||
_scopeCategories() { | ||
let scopedCategoryId = this.get("scopedCategoryId"); | ||
const categories = this.get("categories"); | ||
|
||
// Always scope to the parent of a category, if present | ||
if (scopedCategoryId) { | ||
const scopedCat = Category.findById(scopedCategoryId); | ||
scopedCategoryId = scopedCat.get("parent_category_id") || scopedCat.get("id"); | ||
} | ||
|
||
const excludeCategoryId = this.get("excludeCategoryId"); | ||
|
||
const filteredCategories = categories.filter(c => { | ||
const categoryId = c.get("id"); | ||
if (scopedCategoryId && categoryId !== scopedCategoryId && c.get("parent_category_id") !== scopedCategoryId) { return false; } | ||
if (excludeCategoryId === categoryId) { return false; } | ||
return c.get("permission") === PermissionType.FULL; | ||
}); | ||
|
||
this.set("content", filteredCategories); | ||
}, | ||
|
||
@on("init") | ||
@observes("site.sortedCategories") | ||
_updateCategories() { | ||
if (!this.get("categories")) { | ||
const categories = Discourse.SiteSettings.fixed_category_positions_on_create ? | ||
Category.list() : | ||
Category.listByActivity(); | ||
this.set("categories", categories); | ||
} | ||
}, | ||
|
||
rowContentTemplate(item) { | ||
let category; | ||
let result = '<div class="category-status">'; | ||
|
||
// If we have no id, but text with the uncategorized name, we can use that badge. | ||
if (Ember.isEmpty(item.id)) { | ||
const uncat = Category.findUncategorized(); | ||
if (uncat && uncat.get("name") === item.text) { | ||
category = uncat; | ||
} | ||
} else { | ||
category = Category.findById(parseInt(item.id,10)); | ||
} | ||
|
||
if (!category) return item.text; | ||
result += categoryBadgeHTML(category, {link: false, allowUncategorized: true, hideParent: true}); | ||
const parentCategoryId = category.get("parent_category_id"); | ||
|
||
if (parentCategoryId) { | ||
result += categoryBadgeHTML(Category.findById(parentCategoryId), {link: false}) + " " + result; | ||
} | ||
|
||
result += ` <span class='topic-count'>× ${category.get("topic_count")}</span></div>`; | ||
|
||
const description = category.get("description"); | ||
// TODO wtf how can this be null?; | ||
if (description && description !== 'null') { | ||
result += `<div class="category-desc">${description.substr(0, 200)}${description.length > 200 ? '…' : ''}</div>`; | ||
} | ||
|
||
return result; | ||
} | ||
}); |
7 changes: 0 additions & 7 deletions
7
app/assets/javascripts/discourse/components/d-select-box.js.es6
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 8 additions & 5 deletions
13
app/assets/javascripts/discourse/components/topic-footer-mobile-dropdown.js.es6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
7b4e302
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit has been mentioned on Discourse Meta. There might be relevant details there:
https://meta.discourse.org/t/category-from-new-topic-route-not-displayed-in-composer/68790/1