2019-10-24 01:06:54 +08:00
|
|
|
import Controller from "@ember/controller";
|
2021-05-28 00:20:26 +08:00
|
|
|
import EmberObject, { action } from "@ember/object";
|
2020-03-11 22:28:16 +08:00
|
|
|
import { INPUT_DELAY } from "discourse-common/config/environment";
|
2020-12-18 21:18:52 +08:00
|
|
|
import discourseDebounce from "discourse-common/lib/debounce";
|
2019-11-01 01:37:24 +08:00
|
|
|
import { isEmpty } from "@ember/utils";
|
2020-01-17 01:56:53 +08:00
|
|
|
import { observes } from "discourse-common/utils/decorators";
|
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,
|
|
|
|
showWords: false,
|
|
|
|
|
2021-05-28 00:20:26 +08:00
|
|
|
_filterContent() {
|
|
|
|
if (isEmpty(this.allWatchedWords)) {
|
2020-09-22 22:28:28 +08:00
|
|
|
return;
|
|
|
|
}
|
2017-06-29 04:56:44 +08:00
|
|
|
|
2021-05-28 00:20:26 +08:00
|
|
|
if (!this.filter) {
|
2019-05-27 16:15:39 +08:00
|
|
|
this.set("model", this.allWatchedWords);
|
2017-06-29 04:56:44 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-28 00:20:26 +08:00
|
|
|
const filter = this.filter.toLowerCase();
|
|
|
|
const model = [];
|
2017-06-29 04:56:44 +08:00
|
|
|
|
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) => {
|
|
|
|
return wordRecord.word.indexOf(filter) > -1;
|
|
|
|
});
|
2021-05-28 00:20:26 +08:00
|
|
|
|
|
|
|
model.pushObject(
|
2019-10-30 03:23:50 +08:00
|
|
|
EmberObject.create({
|
2017-06-29 04:56:44 +08:00
|
|
|
nameKey: wordsForAction.nameKey,
|
|
|
|
name: wordsForAction.name,
|
|
|
|
words: wordRecords,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2021-05-28 00:20:26 +08:00
|
|
|
this.set("model", model);
|
2017-06-29 04:56:44 +08:00
|
|
|
},
|
|
|
|
|
2020-01-17 01:56:53 +08:00
|
|
|
@observes("filter")
|
2020-12-18 21:18:52 +08:00
|
|
|
filterContent() {
|
2021-05-28 00:20:26 +08:00
|
|
|
discourseDebounce(this, this._filterContent, INPUT_DELAY);
|
2020-12-18 21:18:52 +08:00
|
|
|
},
|
2017-06-29 04:56:44 +08:00
|
|
|
|
2021-05-28 00:20:26 +08:00
|
|
|
@action
|
|
|
|
clearFilter() {
|
|
|
|
this.set("filter", "");
|
|
|
|
},
|
2018-05-25 23:13:34 +08:00
|
|
|
|
2021-05-28 00:20:26 +08:00
|
|
|
@action
|
|
|
|
toggleMenu() {
|
|
|
|
$(".admin-detail").toggleClass("mobile-closed mobile-open");
|
2017-06-29 04:56:44 +08:00
|
|
|
},
|
|
|
|
});
|