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

99 lines
2.0 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";
2023-01-23 10:30:48 -08:00
import { tracked } from "@glimmer/tracking";
2023-01-23 10:30:48 -08:00
export default class Rule extends RestModel {
@tracked type = "normal";
@tracked category_id = null;
@tracked tags = null;
@tracked channel_id = null;
@tracked filter = "watch";
@tracked error_key = null;
available_types = [
{ id: "normal", name: I18n.t("chat_integration.type.normal") },
{
id: "group_message",
name: I18n.t("chat_integration.type.group_message"),
},
{
id: "group_mention",
name: I18n.t("chat_integration.type.group_mention"),
},
];
get available_filters() {
const available = [];
2023-01-23 10:30:48 -08:00
const provider = this.channel.provider;
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: "tag_added",
name: I18n.t("chat_integration.filter.tag_added"),
icon: "tag",
},
{
id: "mute",
name: I18n.t("chat_integration.filter.mute"),
2020-09-04 13:23:28 +02:00
icon: "times-circle",
}
);
return available;
2023-01-23 10:30:48 -08:00
}
2017-06-28 18:04:21 +01:00
2023-01-23 10:30:48 -08:00
get category() {
const categoryId = this.category_id;
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;
}
2023-01-23 10:30:48 -08:00
}
2023-01-23 10:30:48 -08:00
get filterName() {
return I18n.t(`chat_integration.filter.${this.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
]);
2023-01-23 10:30:48 -08: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
]);
2023-01-23 10:30:48 -08:00
}
}