2018-06-15 23:03:24 +08:00
|
|
|
import computed from "ember-addons/ember-computed-decorators";
|
|
|
|
import WatchedWord from "admin/models/watched-word";
|
2017-06-29 04:56:44 +08:00
|
|
|
|
|
|
|
export default Ember.Controller.extend({
|
|
|
|
actionNameKey: null,
|
|
|
|
adminWatchedWords: Ember.inject.controller(),
|
2018-06-15 23:03:24 +08:00
|
|
|
showWordsList: Ember.computed.or(
|
|
|
|
"adminWatchedWords.filtered",
|
|
|
|
"adminWatchedWords.showWords"
|
|
|
|
),
|
2017-06-29 04:56:44 +08:00
|
|
|
|
|
|
|
findAction(actionName) {
|
2018-06-15 23:03:24 +08:00
|
|
|
return (this.get("adminWatchedWords.model") || []).findBy(
|
|
|
|
"nameKey",
|
|
|
|
actionName
|
|
|
|
);
|
2017-06-29 04:56:44 +08:00
|
|
|
},
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
@computed("actionNameKey", "adminWatchedWords.model")
|
2018-03-28 05:26:53 +08:00
|
|
|
filteredContent(actionNameKey) {
|
2018-06-15 23:03:24 +08:00
|
|
|
if (!actionNameKey) {
|
|
|
|
return [];
|
|
|
|
}
|
2017-06-29 04:56:44 +08:00
|
|
|
|
2018-03-28 05:26:53 +08:00
|
|
|
const a = this.findAction(actionNameKey);
|
2017-06-29 04:56:44 +08:00
|
|
|
return a ? a.words : [];
|
|
|
|
},
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
@computed("actionNameKey")
|
2017-06-29 04:56:44 +08:00
|
|
|
actionDescription(actionNameKey) {
|
2018-06-15 23:03:24 +08:00
|
|
|
return I18n.t("admin.watched_words.action_descriptions." + actionNameKey);
|
2017-06-29 04:56:44 +08:00
|
|
|
},
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
@computed("actionNameKey", "adminWatchedWords.model")
|
2018-03-28 05:26:53 +08:00
|
|
|
wordCount(actionNameKey) {
|
|
|
|
const a = this.findAction(actionNameKey);
|
|
|
|
return a ? a.words.length : 0;
|
|
|
|
},
|
|
|
|
|
2017-06-29 04:56:44 +08:00
|
|
|
actions: {
|
|
|
|
recordAdded(arg) {
|
2018-06-15 23:03:24 +08:00
|
|
|
const a = this.findAction(this.get("actionNameKey"));
|
2017-06-29 04:56:44 +08:00
|
|
|
if (a) {
|
|
|
|
a.words.unshiftObject(arg);
|
2018-06-15 23:03:24 +08:00
|
|
|
a.incrementProperty("count");
|
2019-01-12 00:54:23 +08:00
|
|
|
Ember.run.schedule("afterRender", () => {
|
2017-06-29 04:56:44 +08:00
|
|
|
// remove from other actions lists
|
|
|
|
let match = null;
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("adminWatchedWords.model").forEach(action => {
|
2017-06-29 04:56:44 +08:00
|
|
|
if (match) return;
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
if (action.nameKey !== this.get("actionNameKey")) {
|
|
|
|
match = action.words.findBy("id", arg.id);
|
2017-06-29 04:56:44 +08:00
|
|
|
if (match) {
|
|
|
|
action.words.removeObject(match);
|
2018-06-15 23:03:24 +08:00
|
|
|
action.decrementProperty("count");
|
2017-06-29 04:56:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
recordRemoved(arg) {
|
2018-06-15 23:03:24 +08:00
|
|
|
const a = this.findAction(this.get("actionNameKey"));
|
2017-06-29 04:56:44 +08:00
|
|
|
if (a) {
|
|
|
|
a.words.removeObject(arg);
|
2018-06-15 23:03:24 +08:00
|
|
|
a.decrementProperty("count");
|
2017-06-29 04:56:44 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
uploadComplete() {
|
|
|
|
WatchedWord.findAll().then(data => {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("adminWatchedWords.model", data);
|
2017-06-29 04:56:44 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|