2019-11-01 01:37:24 +08:00
|
|
|
import { isEmpty } from "@ember/utils";
|
2019-10-31 04:28:29 +08:00
|
|
|
import { alias } from "@ember/object/computed";
|
2019-10-30 03:23:50 +08:00
|
|
|
import EmberObject from "@ember/object";
|
2019-10-24 01:06:54 +08:00
|
|
|
import Controller from "@ember/controller";
|
2019-11-12 02:34:01 +08:00
|
|
|
import discourseDebounce from "discourse/lib/debounce";
|
2017-06-29 04:56:44 +08:00
|
|
|
|
2019-10-24 01:06:54 +08:00
|
|
|
export default Controller.extend({
|
2017-06-29 04:56:44 +08:00
|
|
|
filter: null,
|
|
|
|
filtered: false,
|
|
|
|
showWords: false,
|
2019-10-31 04:28:29 +08:00
|
|
|
disableShowWords: alias("filtered"),
|
2017-09-28 03:48:57 +08:00
|
|
|
regularExpressions: null,
|
2017-06-29 04:56:44 +08:00
|
|
|
|
|
|
|
filterContentNow() {
|
2019-11-01 01:37:24 +08:00
|
|
|
if (!!isEmpty(this.allWatchedWords)) return;
|
2017-06-29 04:56:44 +08:00
|
|
|
|
|
|
|
let filter;
|
2019-05-27 16:15:39 +08:00
|
|
|
if (this.filter) {
|
|
|
|
filter = this.filter.toLowerCase();
|
2017-06-29 04:56:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (filter === undefined || filter.length < 1) {
|
2019-05-27 16:15:39 +08:00
|
|
|
this.set("model", this.allWatchedWords);
|
2017-06-29 04:56:44 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const matchesByAction = [];
|
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
this.allWatchedWords.forEach(wordsForAction => {
|
2017-06-29 04:56:44 +08:00
|
|
|
const wordRecords = wordsForAction.words.filter(wordRecord => {
|
2018-06-15 23:03:24 +08:00
|
|
|
return wordRecord.word.indexOf(filter) > -1;
|
2017-06-29 04:56:44 +08:00
|
|
|
});
|
2018-06-15 23:03:24 +08:00
|
|
|
matchesByAction.pushObject(
|
2019-10-30 03:23:50 +08:00
|
|
|
EmberObject.create({
|
2018-06-15 23:03:24 +08:00
|
|
|
nameKey: wordsForAction.nameKey,
|
|
|
|
name: wordsForAction.name,
|
|
|
|
words: wordRecords,
|
|
|
|
count: wordRecords.length
|
|
|
|
})
|
|
|
|
);
|
2017-06-29 04:56:44 +08:00
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("model", matchesByAction);
|
2017-06-29 04:56:44 +08:00
|
|
|
},
|
|
|
|
|
2019-11-12 02:34:01 +08:00
|
|
|
filterContent: discourseDebounce(function() {
|
2017-06-29 04:56:44 +08:00
|
|
|
this.filterContentNow();
|
2019-11-01 01:37:24 +08:00
|
|
|
this.set("filtered", !isEmpty(this.filter));
|
2018-06-15 23:03:24 +08:00
|
|
|
}, 250).observes("filter"),
|
2017-06-29 04:56:44 +08:00
|
|
|
|
|
|
|
actions: {
|
|
|
|
clearFilter() {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.setProperties({ filter: "" });
|
2018-05-25 23:13:34 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
toggleMenu() {
|
2018-06-15 23:03:24 +08:00
|
|
|
$(".admin-detail").toggleClass("mobile-closed mobile-open");
|
2017-06-29 04:56:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|