discourse/app/assets/javascripts/admin/controllers/admin-watched-words.js.es6
Jarek Radosz fe588cc7f8
DEV: Fix function prototype deprecations (#8681)
* DEV: Fix the function prototype observers deprecation

DEPRECATION: Function prototype extensions have been deprecated, please migrate from function(){}.observes('foo') to observer('foo', function() {}). [deprecation id: function-prototype-extensions.observes] See https://deprecations.emberjs.com/v3.x/#toc_function-prototype-extensions-observes for more details.

* DEV: Fix the function prototype event listeners deprecation

DEPRECATION: Function prototype extensions have been deprecated, please migrate from function(){}.on('foo') to on('foo', function() {}). [deprecation id: function-prototype-extensions.on] See https://deprecations.emberjs.com/v3.x/#toc_function-prototype-extensions-on for more details.

* DEV: Simplify `default as` imports

Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2020-01-16 18:56:53 +01:00

63 lines
1.5 KiB
JavaScript

import { isEmpty } from "@ember/utils";
import { alias } from "@ember/object/computed";
import EmberObject from "@ember/object";
import Controller from "@ember/controller";
import discourseDebounce from "discourse/lib/debounce";
import { observes } from "discourse-common/utils/decorators";
export default Controller.extend({
filter: null,
filtered: false,
showWords: false,
disableShowWords: alias("filtered"),
regularExpressions: null,
filterContentNow() {
if (!!isEmpty(this.allWatchedWords)) return;
let filter;
if (this.filter) {
filter = this.filter.toLowerCase();
}
if (filter === undefined || filter.length < 1) {
this.set("model", this.allWatchedWords);
return;
}
const matchesByAction = [];
this.allWatchedWords.forEach(wordsForAction => {
const wordRecords = wordsForAction.words.filter(wordRecord => {
return wordRecord.word.indexOf(filter) > -1;
});
matchesByAction.pushObject(
EmberObject.create({
nameKey: wordsForAction.nameKey,
name: wordsForAction.name,
words: wordRecords,
count: wordRecords.length
})
);
});
this.set("model", matchesByAction);
},
@observes("filter")
filterContent: discourseDebounce(function() {
this.filterContentNow();
this.set("filtered", !isEmpty(this.filter));
}, 250),
actions: {
clearFilter() {
this.setProperties({ filter: "" });
},
toggleMenu() {
$(".admin-detail").toggleClass("mobile-closed mobile-open");
}
}
});