discourse-chat-integration/assets/javascripts/admin/controllers/admin-plugins-chat-integration-provider.js

107 lines
2.1 KiB
JavaScript
Raw Normal View History

2022-03-06 21:18:46 +01:00
import Controller from "@ember/controller";
import showModal from "discourse/lib/show-modal";
2023-01-23 10:30:48 -08:00
import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
2023-01-23 10:30:48 -08:00
const MODALS = {
editChannel: "admin-plugins-chat-integration-edit-channel",
testChannel: "admin-plugins-chat-integration-test",
editRule: "admin-plugins-chat-integration-edit-rule",
channelError: "admin-plugins-chat-integration-channel-error",
};
2023-01-23 10:30:48 -08:00
export default class AdminPluginsChatIntegrationEditRule extends Controller {
@tracked modalShowing = false;
get anyErrors() {
const channels = this.model.channels;
2017-10-03 17:42:07 +08:00
let anyErrors = false;
2020-09-04 13:23:28 +02:00
channels.forEach((channel) => {
2017-10-03 17:42:07 +08:00
if (channel.error_key) {
anyErrors = true;
}
});
2017-10-03 17:42:07 +08:00
return anyErrors;
2023-01-23 10:30:48 -08:00
}
triggerModal(model, modal) {
this.modalShowing = true;
2023-01-23 10:30:48 -08:00
showModal(modal, {
model,
admin: true,
});
}
2017-10-03 17:42:07 +08:00
2023-01-23 10:30:48 -08:00
@action
createChannel() {
return this.triggerModal(
{
channel: this.store.createRecord("channel", {
2023-01-23 10:30:48 -08:00
provider: this.model.provider.id,
2020-09-04 13:23:28 +02:00
data: {},
}),
2023-01-23 10:30:48 -08:00
provider: this.model.provider,
},
MODALS.editChannel
);
}
@action
editChannel(channel) {
return this.triggerModal(
{
channel,
2023-01-23 10:30:48 -08:00
provider: this.model.provider,
},
MODALS.editChannel
);
}
@action
testChannel(channel) {
return this.triggerModal({ channel }, MODALS.testChannel);
}
@action
createRule(channel) {
return this.triggerModal(
{
2020-07-16 12:41:05 +01:00
rule: this.store.createRecord("rule", {
channel_id: channel.id,
2020-09-04 13:23:28 +02:00
channel,
2020-07-16 12:41:05 +01:00
}),
channel,
2023-01-23 10:30:48 -08:00
provider: this.model.provider,
groups: this.model.groups,
},
MODALS.editRule
);
}
@action
editRuleWithChannel(rule, channel) {
return this.triggerModal(
{
rule,
channel,
2023-01-23 10:30:48 -08:00
provider: this.model.provider,
groups: this.model.groups,
},
MODALS.editRule
);
}
@action
showError(channel) {
return this.triggerModal({ channel }, MODALS.channelError);
}
@action
refresh() {
this.send("refreshProvider");
}
}