Files
discourse-chat-integration/assets/javascripts/admin/models/rule.js.es6
T

108 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-09-04 13:23:28 +02:00
import I18n from "I18n";
2018-09-12 16:16:18 +01:00
import RestModel from "discourse/models/rest";
import Category from "discourse/models/category";
import {
default as computed,
2020-09-04 13:23:28 +02:00
observes,
2020-02-19 11:56:45 -05:00
} from "discourse-common/utils/decorators";
export default RestModel.extend({
@computed("channel.provider")
available_filters(provider) {
const available = [];
if (provider === "slack") {
available.push({
id: "thread",
name: I18n.t("chat_integration.filter.thread"),
2020-09-04 13:23:28 +02:00
icon: "chevron-right",
});
2018-09-12 16:16:18 +01:00
}
available.push(
{
id: "watch",
name: I18n.t("chat_integration.filter.watch"),
2020-09-04 13:23:28 +02:00
icon: "exclamation-circle",
},
{
id: "follow",
name: I18n.t("chat_integration.filter.follow"),
2020-09-04 13:23:28 +02:00
icon: "circle",
},
{
id: "mute",
name: I18n.t("chat_integration.filter.mute"),
2020-09-04 13:23:28 +02:00
icon: "times-circle",
}
);
return available;
},
2017-06-28 18:04:21 +01:00
available_types: [
2018-09-12 16:16:18 +01:00
{ id: "normal", name: I18n.t("chat_integration.type.normal") },
{
id: "group_message",
2020-09-04 13:23:28 +02:00
name: I18n.t("chat_integration.type.group_message"),
},
{
id: "group_mention",
name: I18n.t("chat_integration.type.group_mention"),
2018-09-12 16:16:18 +01:00
},
],
category_id: null,
tags: null,
channel_id: null,
2018-09-12 16:16:18 +01:00
filter: "watch",
type: "normal",
2017-07-04 19:37:56 +01:00
error_key: null,
2018-09-12 16:16:18 +01:00
@observes("type")
2017-10-03 17:42:07 +08:00
removeUnneededInfo() {
2018-09-12 16:16:18 +01:00
const type = this.get("type");
2017-08-21 16:46:43 +01:00
2018-09-12 16:16:18 +01:00
if (type === "normal") {
this.set("group_id", null);
2017-10-03 17:42:07 +08:00
} else {
2018-09-12 16:16:18 +01:00
this.set("category_id", null);
}
2017-10-03 17:42:07 +08:00
},
2018-09-12 16:16:18 +01:00
@computed("category_id")
category(categoryId) {
2018-09-12 16:16:18 +01:00
if (categoryId) {
return Category.findById(categoryId);
2017-10-03 17:42:07 +08:00
} else {
return false;
}
},
2018-09-12 16:16:18 +01:00
@computed("filter")
filterName(filter) {
return I18n.t(`chat_integration.filter.${filter}`);
},
updateProperties() {
2018-09-12 16:16:18 +01:00
return this.getProperties([
"type",
"category_id",
"group_id",
"tags",
2020-09-04 13:23:28 +02:00
"filter",
2018-09-12 16:16:18 +01:00
]);
2017-06-29 20:19:40 +01:00
},
createProperties() {
2018-09-12 16:16:18 +01:00
return this.getProperties([
"type",
"channel_id",
"category_id",
"group_id",
"tags",
2020-09-04 13:23:28 +02:00
"filter",
2018-09-12 16:16:18 +01:00
]);
2020-09-04 13:23:28 +02:00
},
});