2019-10-23 13:06:54 -04:00
|
|
|
import Controller from "@ember/controller";
|
2021-05-27 12:20:26 -04:00
|
|
|
import EmberObject, { action } from "@ember/object";
|
2020-03-11 10:28:16 -04:00
|
|
|
import { INPUT_DELAY } from "discourse-common/config/environment";
|
2020-12-18 08:18:52 -05:00
|
|
|
import discourseDebounce from "discourse-common/lib/debounce";
|
2019-10-31 13:37:24 -04:00
|
|
|
import { isEmpty } from "@ember/utils";
|
2020-01-16 12:56:53 -05:00
|
|
|
import { observes } from "discourse-common/utils/decorators";
|
2017-06-28 16:56:44 -04:00
|
|
|
|
2019-10-23 13:06:54 -04:00
|
|
|
export default Controller.extend({
|
2017-06-28 16:56:44 -04:00
|
|
|
filter: null,
|
|
|
|
showWords: false,
|
|
|
|
|
2021-05-27 12:20:26 -04:00
|
|
|
_filterContent() {
|
|
|
|
if (isEmpty(this.allWatchedWords)) {
|
2020-09-22 10:28:28 -04:00
|
|
|
return;
|
|
|
|
}
|
2017-06-28 16:56:44 -04:00
|
|
|
|
2021-05-27 12:20:26 -04:00
|
|
|
if (!this.filter) {
|
2019-05-27 04:15:39 -04:00
|
|
|
this.set("model", this.allWatchedWords);
|
2017-06-28 16:56:44 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-27 12:20:26 -04:00
|
|
|
const filter = this.filter.toLowerCase();
|
|
|
|
const model = [];
|
2017-06-28 16:56:44 -04:00
|
|
|
|
2019-05-27 04:15:39 -04:00
|
|
|
this.allWatchedWords.forEach((wordsForAction) => {
|
2017-06-28 16:56:44 -04:00
|
|
|
const wordRecords = wordsForAction.words.filter((wordRecord) => {
|
2022-07-17 14:48:36 -04:00
|
|
|
return wordRecord.word.includes(filter);
|
2017-06-28 16:56:44 -04:00
|
|
|
});
|
2021-05-27 12:20:26 -04:00
|
|
|
|
|
|
|
model.pushObject(
|
2019-10-29 15:23:50 -04:00
|
|
|
EmberObject.create({
|
2017-06-28 16:56:44 -04:00
|
|
|
nameKey: wordsForAction.nameKey,
|
|
|
|
name: wordsForAction.name,
|
|
|
|
words: wordRecords,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2021-05-27 12:20:26 -04:00
|
|
|
this.set("model", model);
|
2017-06-28 16:56:44 -04:00
|
|
|
},
|
|
|
|
|
2020-01-16 12:56:53 -05:00
|
|
|
@observes("filter")
|
2020-12-18 08:18:52 -05:00
|
|
|
filterContent() {
|
2021-05-27 12:20:26 -04:00
|
|
|
discourseDebounce(this, this._filterContent, INPUT_DELAY);
|
2020-12-18 08:18:52 -05:00
|
|
|
},
|
2017-06-28 16:56:44 -04:00
|
|
|
|
2021-05-27 12:20:26 -04:00
|
|
|
@action
|
|
|
|
clearFilter() {
|
|
|
|
this.set("filter", "");
|
|
|
|
},
|
2018-05-25 11:13:34 -04:00
|
|
|
|
2021-05-27 12:20:26 -04:00
|
|
|
@action
|
|
|
|
toggleMenu() {
|
2021-12-09 11:06:54 -05:00
|
|
|
const adminDetail = document.querySelector(".admin-detail");
|
|
|
|
["mobile-closed", "mobile-open"].forEach((state) => {
|
|
|
|
adminDetail.classList.toggle(state);
|
|
|
|
});
|
2017-06-28 16:56:44 -04:00
|
|
|
},
|
|
|
|
});
|