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";
|
2020-01-17 01:56:53 +08:00
|
|
|
import { observes } from "discourse-common/utils/decorators";
|
2020-03-11 22:28:16 +08:00
|
|
|
import { INPUT_DELAY } from "discourse-common/config/environment";
|
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 => {
|
|
|
|
return wordRecord.word.indexOf(filter) > -1;
|
|
|
|
});
|
|
|
|
matchesByAction.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,
|
|
|
|
count: wordRecords.length
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.set("model", matchesByAction);
|
|
|
|
},
|
|
|
|
|
2020-01-17 01:56:53 +08:00
|
|
|
@observes("filter")
|
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));
|
2020-03-11 22:28:16 +08:00
|
|
|
}, INPUT_DELAY),
|
2017-06-29 04:56:44 +08:00
|
|
|
|
|
|
|
actions: {
|
|
|
|
clearFilter() {
|
|
|
|
this.setProperties({ filter: "" });
|
2018-05-25 23:13:34 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
toggleMenu() {
|
|
|
|
$(".admin-detail").toggleClass("mobile-closed mobile-open");
|
2017-06-29 04:56:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|