Filter tags and count off of filtered list
This commit is contained in:
parent
2c9b904e15
commit
e7d93aeca6
|
@ -17,11 +17,11 @@ export default Ember.Controller.extend({
|
|||
filterTags: null,
|
||||
filterCategory: null,
|
||||
|
||||
filteredTags: null,
|
||||
filteredTopics: null,
|
||||
|
||||
@observes("filterTags")
|
||||
filterByTags() {
|
||||
debugger;
|
||||
const filterTags = this.get("filterTags");
|
||||
if (filterTags != null) {
|
||||
const filter = filterTags.split(" ");
|
||||
|
@ -32,9 +32,48 @@ export default Ember.Controller.extend({
|
|||
const filteredTopics = topics.filter(topic =>
|
||||
arrayContainsArray(topic.tags, filter)
|
||||
);
|
||||
|
||||
debugger;
|
||||
const filteredTags = [];
|
||||
|
||||
// add active tags
|
||||
filter.forEach(tag => {
|
||||
let t = {
|
||||
id: tag,
|
||||
count: 0,
|
||||
active: true
|
||||
};
|
||||
|
||||
filteredTags.push(t);
|
||||
});
|
||||
|
||||
filteredTopics.forEach(topic => {
|
||||
let topicTags = topic.tags;
|
||||
topicTags.forEach(tag => {
|
||||
if (filterTags.includes(tag)) {
|
||||
//increment count for active tags
|
||||
let index = filteredTags.findIndex(t => t.id === tag);
|
||||
filteredTags[index].count++;
|
||||
} else if (filteredTags.findIndex(t => t.id === tag) != -1) {
|
||||
//increment count for seen subtags
|
||||
let index = filteredTags.findIndex(t => t.id === tag);
|
||||
filteredTags[index].count++;
|
||||
} else {
|
||||
//add entry for unseen subtag
|
||||
let t = {
|
||||
id: tag,
|
||||
count: 1
|
||||
};
|
||||
filteredTags.push(t);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
this.set("filteredTags", filteredTags);
|
||||
this.set("filteredTopics", filteredTopics);
|
||||
this.set("filtered", true);
|
||||
} else {
|
||||
this.set("filteredTags", null);
|
||||
this.set("filteredTopics", null);
|
||||
this.set("filterTags", null);
|
||||
this.set("filtered", false);
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
<div class="knowledge-explorer">
|
||||
<div class="knowledge-explorer-browse">
|
||||
{{knowledge-explorer-tag-list
|
||||
tags=tags
|
||||
filterTags=filterTags
|
||||
searchResults=searchResults}}
|
||||
{{#if filteredTags}}
|
||||
{{knowledge-explorer-tag-list
|
||||
tags=filteredTags
|
||||
filterTags=filterTags
|
||||
}}
|
||||
{{else}}
|
||||
{{knowledge-explorer-tag-list
|
||||
tags=tags
|
||||
filterTags=filterTags
|
||||
}}
|
||||
{{/if}}
|
||||
{{#if filtered}}
|
||||
{{#if filteredTopics}}
|
||||
{{knowledge-explorer-topic-list topics=filteredTopics}}
|
||||
|
|
Loading…
Reference in New Issue