discourse/app/assets/javascripts/admin/controllers/admin-watched-words.js.es6

57 lines
1.4 KiB
Plaintext
Raw Normal View History

2018-06-15 11:03:24 -04:00
import debounce from "discourse/lib/debounce";
export default Ember.Controller.extend({
filter: null,
filtered: false,
showWords: false,
2018-06-15 11:03:24 -04:00
disableShowWords: Ember.computed.alias("filtered"),
regularExpressions: null,
filterContentNow() {
2018-06-15 11:03:24 -04:00
if (!!Ember.isEmpty(this.get("allWatchedWords"))) return;
let filter;
2018-06-15 11:03:24 -04:00
if (this.get("filter")) {
filter = this.get("filter").toLowerCase();
}
if (filter === undefined || filter.length < 1) {
2018-06-15 11:03:24 -04:00
this.set("model", this.get("allWatchedWords"));
return;
}
const matchesByAction = [];
2018-06-15 11:03:24 -04:00
this.get("allWatchedWords").forEach(wordsForAction => {
const wordRecords = wordsForAction.words.filter(wordRecord => {
2018-06-15 11:03:24 -04:00
return wordRecord.word.indexOf(filter) > -1;
});
2018-06-15 11:03:24 -04:00
matchesByAction.pushObject(
Ember.Object.create({
nameKey: wordsForAction.nameKey,
name: wordsForAction.name,
words: wordRecords,
count: wordRecords.length
})
);
});
2018-06-15 11:03:24 -04:00
this.set("model", matchesByAction);
},
filterContent: debounce(function() {
this.filterContentNow();
2018-06-15 11:03:24 -04:00
this.set("filtered", !Ember.isEmpty(this.get("filter")));
}, 250).observes("filter"),
actions: {
clearFilter() {
2018-06-15 11:03:24 -04:00
this.setProperties({ filter: "" });
},
toggleMenu() {
2018-06-15 11:03:24 -04:00
$(".admin-detail").toggleClass("mobile-closed mobile-open");
}
}
});