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