FEATURE: Add category to knowledge explorer topic list

This commit is contained in:
Justin DiRose 2019-11-04 15:05:32 -06:00
parent 1c845cd517
commit 42ac7bb984
3 changed files with 31 additions and 3 deletions

View File

@ -1,8 +1,18 @@
import {
default as computed
} from "ember-addons/ember-computed-decorators";
import { default as computed } from "ember-addons/ember-computed-decorators";
import KnowledgeExplorer from "discourse/plugins/discourse-knowledge-explorer/discourse/models/knowledge-explorer";
function mergeCategories(results) {
const categories = Discourse.Category.list();
const topics = results.topics.topic_list.topics.map(t => {
t.category = categories.findBy("id", t.category_id);
return t;
});
results.topics.topic_list.topics = topics;
return results;
}
export default Ember.Controller.extend({
application: Ember.inject.controller(),
queryParams: {
@ -108,6 +118,7 @@ export default Ember.Controller.extend({
this.set("isLoadingMore", true);
KnowledgeExplorer.loadMore(this.loadMoreUrl).then(result => {
result = mergeCategories(result);
const topics = this.topics.concat(result.topics.topic_list.topics);
this.setProperties({
@ -129,6 +140,7 @@ export default Ember.Controller.extend({
);
KnowledgeExplorer.list(params).then(result => {
result = mergeCategories(result);
this.setProperties({
model: result,
isLoading: false

View File

@ -9,5 +9,20 @@ export default Ember.Route.extend({
model(params) {
return KnowledgeExplorer.list(params);
},
setupController(controller, model) {
const categories = Discourse.Category.list();
let topics = model.topics.topic_list.topics;
topics = topics.map(t => {
t.category = categories.findBy("id", t.category_id);
return t;
});
model.topics.topic_list.topics = topics;
controller.set("model", model);
}
});

View File

@ -15,6 +15,7 @@
}}
</span>
<span class="link-bottom-line">
{{category-link topic.category}}
{{#each topic.tags as |tag|}}
<span class="discourse-tag">{{tag}}</span>
{{/each}}