diff --git a/app/assets/javascripts/admin/addon/components/admin-flag-item.gjs b/app/assets/javascripts/admin/addon/components/admin-flag-item.gjs index 1b52162f4a5..8f0cbdae58b 100644 --- a/app/assets/javascripts/admin/addon/components/admin-flag-item.gjs +++ b/app/assets/javascripts/admin/addon/components/admin-flag-item.gjs @@ -127,15 +127,17 @@ export default class AdminFlagItem extends Component { }}

-
- + + + +
-
-
- - - {{yield to="breadcrumbs"}} -
+export default class AdminPageHeader extends Component { + get title() { + if (this.args.titleLabelTranslated) { + return this.args.titleLabelTranslated; + } else if (this.args.titleLabel) { + return i18n(this.args.titleLabel); + } + } -
- {{#if @titleLabel}} -

{{i18n @titleLabel}}

- {{/if}} -
- {{yield - (hash Primary=PrimaryButton Default=DefaultButton Danger=DangerButton) - to="actions" - }} + get description() { + if (this.args.descriptionLabelTranslated) { + return this.args.descriptionLabelTranslated; + } else if (this.args.descriptionLabel) { + return i18n(this.args.descriptionLabel); + } + } + + ; -export default AdminPageHeader; + {{#if this.description}} +

+ {{htmlSafe this.description}} + {{#if @learnMoreUrl}} + {{htmlSafe (i18n "learn_more_with_link" url=@learnMoreUrl)}} + {{/if}} +

+ {{/if}} + + {{#unless @hideTabs}} +
+ + {{yield to="tabs"}} + +
+ {{/unless}} +
+ +} diff --git a/app/assets/javascripts/admin/addon/components/admin-page-subheader.gjs b/app/assets/javascripts/admin/addon/components/admin-page-subheader.gjs index 4706a8a4133..3e4533607df 100644 --- a/app/assets/javascripts/admin/addon/components/admin-page-subheader.gjs +++ b/app/assets/javascripts/admin/addon/components/admin-page-subheader.gjs @@ -1,3 +1,4 @@ +import Component from "@glimmer/component"; import { hash } from "@ember/helper"; import { htmlSafe } from "@ember/template"; import i18n from "discourse-common/helpers/i18n"; @@ -7,27 +8,45 @@ import { PrimaryButton, } from "admin/components/admin-page-action-button"; -const AdminPageSubheader = +} diff --git a/app/assets/javascripts/admin/addon/components/admin-plugin-config-metadata.gjs b/app/assets/javascripts/admin/addon/components/admin-plugin-config-metadata.gjs deleted file mode 100644 index 427ecc180bb..00000000000 --- a/app/assets/javascripts/admin/addon/components/admin-plugin-config-metadata.gjs +++ /dev/null @@ -1,22 +0,0 @@ -import i18n from "discourse-common/helpers/i18n"; - -const AdminPluginConfigMetadata = ; - -export default AdminPluginConfigMetadata; diff --git a/app/assets/javascripts/admin/addon/components/admin-plugin-config-page.gjs b/app/assets/javascripts/admin/addon/components/admin-plugin-config-page.gjs index 11314fa458a..262101958d5 100644 --- a/app/assets/javascripts/admin/addon/components/admin-plugin-config-page.gjs +++ b/app/assets/javascripts/admin/addon/components/admin-plugin-config-page.gjs @@ -1,11 +1,12 @@ import Component from "@glimmer/component"; +import { hash } from "@ember/helper"; import { service } from "@ember/service"; -import DBreadcrumbsContainer from "discourse/components/d-breadcrumbs-container"; import DBreadcrumbsItem from "discourse/components/d-breadcrumbs-item"; +import NavItem from "discourse/components/nav-item"; +import PluginOutlet from "discourse/components/plugin-outlet"; import i18n from "discourse-common/helpers/i18n"; +import AdminPageHeader from "./admin-page-header"; import AdminPluginConfigArea from "./admin-plugin-config-area"; -import AdminPluginConfigMetadata from "./admin-plugin-config-metadata"; -import AdminPluginConfigTopNav from "./admin-plugin-config-top-nav"; export default class AdminPluginConfigPage extends Component { @service currentUser; @@ -23,25 +24,56 @@ export default class AdminPluginConfigPage extends Component { return classes.join(" "); } + linkText(navLink) { + if (navLink.label) { + return i18n(navLink.label); + } else { + return navLink.text; + } + } + diff --git a/app/assets/javascripts/discourse/tests/integration/components/form-kit/layout/submit-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/form-kit/layout/submit-test.gjs index d25066ec1ef..364a29033dd 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/form-kit/layout/submit-test.gjs +++ b/app/assets/javascripts/discourse/tests/integration/components/form-kit/layout/submit-test.gjs @@ -38,4 +38,14 @@ module("Integration | Component | FormKit | Layout | Submit", function (hooks) { .dom(".form-kit__button") .hasText(I18n.t("cancel"), "it allows to override the label"); }); + + test("@isLoading", async function (assert) { + await render(); + + assert.dom(".form-kit__button .d-icon-spinner").exists(); + }); }); diff --git a/app/assets/stylesheets/common/admin/admin_base.scss b/app/assets/stylesheets/common/admin/admin_base.scss index e10fb9fbd84..7a9de7ecb3a 100644 --- a/app/assets/stylesheets/common/admin/admin_base.scss +++ b/app/assets/stylesheets/common/admin/admin_base.scss @@ -142,6 +142,18 @@ $mobile-breakpoint: 700px; max-width: 100px; } } + + .admin-table-row-controls { + text-align: right; + display: flex; + flex-direction: row; + gap: 0.5em; + justify-content: flex-end; + + .fk-d-menu__trigger { + font-size: var(--font-down-1); + } + } } .admin-contents table.grid { diff --git a/app/assets/stylesheets/common/admin/flags.scss b/app/assets/stylesheets/common/admin/flags.scss index 125232c7e64..b35a962971d 100644 --- a/app/assets/stylesheets/common/admin/flags.scss +++ b/app/assets/stylesheets/common/admin/flags.scss @@ -7,24 +7,12 @@ &__description { margin-top: 0.5em; } - &__options { - display: flex; - align-items: center; - justify-content: space-between; - } .d-toggle-switch__label { margin-bottom: 0; } .d-toggle-switch { margin-right: 2em; } - .btn-secondary { - padding: 0.25em 0.325em; - margin-right: 0.75em; - } - .flag-menu-trigger { - padding: 0.25em 0.325em; - } &__delete.btn, &__delete.btn:hover { diff --git a/plugins/chat/admin/assets/javascripts/admin/components/admin-chat-incoming-webhooks-list.gjs b/plugins/chat/admin/assets/javascripts/admin/components/admin-chat-incoming-webhooks-list.gjs new file mode 100644 index 00000000000..2e6c8c79a30 --- /dev/null +++ b/plugins/chat/admin/assets/javascripts/admin/components/admin-chat-incoming-webhooks-list.gjs @@ -0,0 +1,85 @@ +import Component from "@glimmer/component"; +import { tracked } from "@glimmer/tracking"; +import { fn } from "@ember/helper"; +import { action } from "@ember/object"; +import { LinkTo } from "@ember/routing"; +import { service } from "@ember/service"; +import DButton from "discourse/components/d-button"; +import replaceEmoji from "discourse/helpers/replace-emoji"; +import { ajax } from "discourse/lib/ajax"; +import { popupAjaxError } from "discourse/lib/ajax-error"; +import i18n from "discourse-common/helpers/i18n"; +import I18n from "discourse-i18n"; +import ChannelTitle from "discourse/plugins/chat/discourse/components/channel-title"; + +export default class AdminChatIncomingWebhooksList extends Component { + @service dialog; + + @tracked loading = false; + + get sortedWebhooks() { + return this.args.webhooks?.sortBy("updated_at").reverse() || []; + } + + @action + destroyWebhook(webhook) { + this.dialog.deleteConfirm({ + message: I18n.t("chat.incoming_webhooks.confirm_destroy"), + didConfirm: async () => { + this.loading = true; + + try { + await ajax(`/admin/plugins/chat/hooks/${webhook.id}`, { + type: "DELETE", + }); + this.args.webhooks.removeObject(webhook); + } catch (err) { + popupAjaxError(err); + } finally { + this.loading = false; + } + }, + }); + } + + +} diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/admin/export-messages.gjs b/plugins/chat/admin/assets/javascripts/admin/components/chat-admin-plugin-actions.gjs similarity index 50% rename from plugins/chat/assets/javascripts/discourse/components/chat/admin/export-messages.gjs rename to plugins/chat/admin/assets/javascripts/admin/components/chat-admin-plugin-actions.gjs index 8ba238db472..66b02e3dcb9 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat/admin/export-messages.gjs +++ b/plugins/chat/admin/assets/javascripts/admin/components/chat-admin-plugin-actions.gjs @@ -1,14 +1,20 @@ import Component from "@glimmer/component"; import { action } from "@ember/object"; import { service } from "@ember/service"; -import DButton from "discourse/components/d-button"; import { popupAjaxError } from "discourse/lib/ajax-error"; -import i18n from "discourse-common/helpers/i18n"; import I18n from "discourse-i18n"; -export default class ChatAdminExportMessages extends Component { - @service chatAdminApi; +export default class ChatAdminPluginActions extends Component { @service dialog; + @service chatAdminApi; + + @action + confirmExportMessages() { + return this.dialog.confirm({ + message: I18n.t("chat.admin.export_messages.confirm_export"), + didConfirm: () => this.exportMessages(), + }); + } @action async exportMessages() { @@ -23,15 +29,11 @@ export default class ChatAdminExportMessages extends Component { } } diff --git a/plugins/chat/admin/assets/javascripts/admin/components/chat-incoming-webhook-edit-form.gjs b/plugins/chat/admin/assets/javascripts/admin/components/chat-incoming-webhook-edit-form.gjs new file mode 100644 index 00000000000..d608bc29ed1 --- /dev/null +++ b/plugins/chat/admin/assets/javascripts/admin/components/chat-incoming-webhook-edit-form.gjs @@ -0,0 +1,187 @@ +import Component from "@glimmer/component"; +import { tracked } from "@glimmer/tracking"; +import { fn } from "@ember/helper"; +import { action } from "@ember/object"; +import { service } from "@ember/service"; +import { not } from "truth-helpers"; +import DButton from "discourse/components/d-button"; +import EmojiPicker from "discourse/components/emoji-picker"; +import Form from "discourse/components/form"; +import replaceEmoji from "discourse/helpers/replace-emoji"; +import { ajax } from "discourse/lib/ajax"; +import { popupAjaxError } from "discourse/lib/ajax-error"; +import i18n from "discourse-common/helpers/i18n"; +import I18n from "discourse-i18n"; +import ChatChannelChooser from "discourse/plugins/chat/discourse/components/chat-channel-chooser"; + +export default class ChatIncomingWebhookEditForm extends Component { + @service toasts; + @service router; + + @tracked emojiPickerIsActive = false; + + get formData() { + return { + name: this.args.webhook?.name, + description: this.args.webhook?.description, + username: this.args.webhook?.username, + chat_channel_id: this.args.webhook?.chat_channel.id, + emoji: this.args.webhook?.emoji, + }; + } + + @action + emojiSelected(setData, emoji) { + setData("emoji", `:${emoji}:`); + this.emojiPickerIsActive = false; + } + + @action + resetEmoji(setData) { + setData("emoji", null); + } + + @action + async save(data) { + try { + if (this.args.webhook?.id) { + await ajax(`/admin/plugins/chat/hooks/${this.args.webhook.id}`, { + data, + type: "PUT", + }); + + this.toasts.success({ + duration: 3000, + data: { + message: I18n.t("chat.incoming_webhooks.saved"), + }, + }); + } else { + const webhook = await ajax(`/admin/plugins/chat/hooks`, { + data, + type: "POST", + }); + + this.toasts.success({ + duration: 3000, + data: { + message: I18n.t("chat.incoming_webhooks.created"), + }, + }); + + this.router + .transitionTo( + "adminPlugins.show.discourse-chat-incoming-webhooks.show", + webhook + ) + .then(() => { + this.router.refresh(); + }); + } + } catch (err) { + popupAjaxError(err); + } + } + + +} diff --git a/plugins/chat/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-chat-incoming-webhooks-index.js b/plugins/chat/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-chat-incoming-webhooks-index.js new file mode 100644 index 00000000000..e44d27a867c --- /dev/null +++ b/plugins/chat/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-chat-incoming-webhooks-index.js @@ -0,0 +1,40 @@ +import EmberObject from "@ember/object"; +import { service } from "@ember/service"; +import { ajax } from "discourse/lib/ajax"; +import { popupAjaxError } from "discourse/lib/ajax-error"; +import DiscourseRoute from "discourse/routes/discourse"; +import I18n from "discourse-i18n"; +import ChatChannel from "discourse/plugins/chat/discourse/models/chat-channel"; + +export default class DiscourseChatIncomingWebhooksIndex extends DiscourseRoute { + @service currentUser; + + async model() { + if (!this.currentUser?.admin) { + return { model: null }; + } + + try { + const model = await ajax("/admin/plugins/chat/hooks.json"); + + model.chat_channels = model.chat_channels.map((channel) => + ChatChannel.create(channel) + ); + + model.incoming_chat_webhooks = model.incoming_chat_webhooks.map( + (webhook) => { + webhook.chat_channel = ChatChannel.create(webhook.chat_channel); + return EmberObject.create(webhook); + } + ); + + return model; + } catch (err) { + popupAjaxError(err); + } + } + + titleToken() { + return I18n.t("chat.incoming_webhooks.title"); + } +} diff --git a/plugins/chat/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-chat-incoming-webhooks-new.js b/plugins/chat/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-chat-incoming-webhooks-new.js new file mode 100644 index 00000000000..87db78dee7b --- /dev/null +++ b/plugins/chat/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-chat-incoming-webhooks-new.js @@ -0,0 +1,33 @@ +import EmberObject from "@ember/object"; +import { service } from "@ember/service"; +import { ajax } from "discourse/lib/ajax"; +import { popupAjaxError } from "discourse/lib/ajax-error"; +import DiscourseRoute from "discourse/routes/discourse"; +import ChatChannel from "discourse/plugins/chat/discourse/models/chat-channel"; + +export default class DiscourseChatIncomingWebhooksNew extends DiscourseRoute { + @service adminPluginNavManager; + @service currentUser; + + async model() { + if (!this.currentUser?.admin) { + return { model: null }; + } + + try { + const model = await ajax("/admin/plugins/chat/hooks/new.json"); + + model.webhook = EmberObject.create(model.webhook); + model.webhook.chat_channel = ChatChannel.create( + model.webhook.chat_channel + ); + model.chat_channels = model.chat_channels.map((channel) => + ChatChannel.create(channel) + ); + + return model; + } catch (err) { + popupAjaxError(err); + } + } +} diff --git a/plugins/chat/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-chat-incoming-webhooks-show.js b/plugins/chat/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-chat-incoming-webhooks-show.js new file mode 100644 index 00000000000..07cf5edc522 --- /dev/null +++ b/plugins/chat/admin/assets/javascripts/discourse/routes/admin-plugins-show-discourse-chat-incoming-webhooks-show.js @@ -0,0 +1,32 @@ +import EmberObject from "@ember/object"; +import { service } from "@ember/service"; +import { ajax } from "discourse/lib/ajax"; +import { popupAjaxError } from "discourse/lib/ajax-error"; +import DiscourseRoute from "discourse/routes/discourse"; +import ChatChannel from "discourse/plugins/chat/discourse/models/chat-channel"; + +export default class DiscourseChatIncomingWebhooksShow extends DiscourseRoute { + @service currentUser; + + async model(params) { + if (!this.currentUser?.admin) { + return { model: null }; + } + + try { + const model = await ajax(`/admin/plugins/chat/hooks/${params.id}.json`); + + model.webhook = EmberObject.create(model.webhook); + model.webhook.chat_channel = ChatChannel.create( + model.webhook.chat_channel + ); + model.chat_channels = model.chat_channels.map((channel) => + ChatChannel.create(channel) + ); + + return model; + } catch (err) { + popupAjaxError(err); + } + } +} diff --git a/plugins/chat/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-chat-incoming-webhooks/index.hbs b/plugins/chat/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-chat-incoming-webhooks/index.hbs new file mode 100644 index 00000000000..f050a5ff06b --- /dev/null +++ b/plugins/chat/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-chat-incoming-webhooks/index.hbs @@ -0,0 +1,31 @@ + + +
+ + <:actions as |actions|> + + + + +
+ {{#if this.model.incoming_chat_webhooks}} + + {{else}} + {{i18n "chat.incoming_webhooks.none"}} + {{/if}} +
+
\ No newline at end of file diff --git a/plugins/chat/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-chat-incoming-webhooks/new.hbs b/plugins/chat/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-chat-incoming-webhooks/new.hbs new file mode 100644 index 00000000000..2ed27eeb6c6 --- /dev/null +++ b/plugins/chat/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-chat-incoming-webhooks/new.hbs @@ -0,0 +1,9 @@ +
+ + + +
\ No newline at end of file diff --git a/plugins/chat/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-chat-incoming-webhooks/show.hbs b/plugins/chat/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-chat-incoming-webhooks/show.hbs new file mode 100644 index 00000000000..b4b1220ba1e --- /dev/null +++ b/plugins/chat/admin/assets/javascripts/discourse/templates/admin-plugins/show/discourse-chat-incoming-webhooks/show.hbs @@ -0,0 +1,14 @@ +
+ + + + + +
\ No newline at end of file diff --git a/plugins/chat/app/controllers/chat/admin/incoming_webhooks_controller.rb b/plugins/chat/app/controllers/chat/admin/incoming_webhooks_controller.rb index 14932e9212f..95beaa6fc46 100644 --- a/plugins/chat/app/controllers/chat/admin/incoming_webhooks_controller.rb +++ b/plugins/chat/app/controllers/chat/admin/incoming_webhooks_controller.rb @@ -16,6 +16,25 @@ module Chat ) end + def show + webhook = + Chat::IncomingWebhook.includes(:chat_channel).find(params[:incoming_chat_webhook_id]) + render_serialized( + { chat_channels: Chat::Channel.public_channels, webhook: webhook }, + Chat::AdminChatWebhookShowSerializer, + root: false, + ) + end + + def new + serialized_channels = + Chat::Channel.public_channels.map do |channel| + Chat::ChannelSerializer.new(channel, scope: Guardian.new(current_user)) + end + + render json: serialized_channels, root: "chat_channels" + end + def create params.require(%i[name chat_channel_id]) diff --git a/plugins/chat/app/serializers/chat/admin_chat_webhook_show_serializer.rb b/plugins/chat/app/serializers/chat/admin_chat_webhook_show_serializer.rb new file mode 100644 index 00000000000..abcf0a41580 --- /dev/null +++ b/plugins/chat/app/serializers/chat/admin_chat_webhook_show_serializer.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Chat + class AdminChatWebhookShowSerializer < ApplicationSerializer + has_many :chat_channels, serializer: Chat::ChannelSerializer, embed: :objects + has_one :webhook, serializer: Chat::IncomingWebhookSerializer, embed: :objects + + def chat_channels + object[:chat_channels] + end + + def webhook + object[:webhook] + end + end +end diff --git a/plugins/chat/assets/javascripts/discourse/admin-chat-route-map.js b/plugins/chat/assets/javascripts/discourse/admin-chat-route-map.js index a1e74d0708c..0fdf407be59 100644 --- a/plugins/chat/assets/javascripts/discourse/admin-chat-route-map.js +++ b/plugins/chat/assets/javascripts/discourse/admin-chat-route-map.js @@ -1,7 +1,14 @@ export default { - resource: "admin.adminPlugins", + resource: "admin.adminPlugins.show", path: "/plugins", map() { - this.route("chat"); + this.route( + "discourse-chat-incoming-webhooks", + { path: "hooks" }, + function () { + this.route("new"); + this.route("show", { path: "/:id" }); + } + ); }, }; diff --git a/plugins/chat/assets/javascripts/discourse/controllers/admin-plugins-chat.js b/plugins/chat/assets/javascripts/discourse/controllers/admin-plugins-chat.js deleted file mode 100644 index 93058983b10..00000000000 --- a/plugins/chat/assets/javascripts/discourse/controllers/admin-plugins-chat.js +++ /dev/null @@ -1,139 +0,0 @@ -import Controller from "@ember/controller"; -import EmberObject, { action, computed } from "@ember/object"; -import { and } from "@ember/object/computed"; -import { service } from "@ember/service"; -import { ajax } from "discourse/lib/ajax"; -import { popupAjaxError } from "discourse/lib/ajax-error"; -import I18n from "discourse-i18n"; - -export default class AdminPluginsChatController extends Controller { - @service dialog; - queryParams = [ - { - selectedWebhookId: "id", - }, - ]; - - loading = false; - creatingNew = false; - newWebhookName = ""; - newWebhookChannelId = null; - emojiPickerIsActive = false; - - @and("newWebhookName", "newWebhookChannelId") nameAndChannelValid; - - @computed("model.incoming_chat_webhooks.@each.updated_at") - get sortedWebhooks() { - return ( - this.model.incoming_chat_webhooks?.sortBy("updated_at").reverse() || [] - ); - } - - @computed("selectedWebhookId") - get selectedWebhook() { - if (!this.selectedWebhookId) { - return; - } - - const id = parseInt(this.selectedWebhookId, 10); - return this.model.incoming_chat_webhooks.findBy("id", id); - } - - @computed("selectedWebhook.name", "selectedWebhook.chat_channel.id") - get saveEditDisabled() { - return !this.selectedWebhook.name || !this.selectedWebhook.chat_channel.id; - } - - @action - createNewWebhook() { - if (this.loading) { - return; - } - - this.set("loading", true); - const data = { - name: this.newWebhookName, - chat_channel_id: this.newWebhookChannelId, - }; - - return ajax("/admin/plugins/chat/hooks", { data, type: "POST" }) - .then((webhook) => { - const newWebhook = EmberObject.create(webhook); - this.set( - "model.incoming_chat_webhooks", - [newWebhook].concat(this.model.incoming_chat_webhooks) - ); - this.resetNewWebhook(); - this.setProperties({ - loading: false, - selectedWebhookId: newWebhook.id, - }); - }) - .catch(popupAjaxError); - } - - @action - resetNewWebhook() { - this.setProperties({ - creatingNew: false, - newWebhookName: "", - newWebhookChannelId: null, - }); - } - - @action - destroyWebhook(webhook) { - this.dialog.deleteConfirm({ - message: I18n.t("chat.incoming_webhooks.confirm_destroy"), - didConfirm: () => { - this.set("loading", true); - return ajax(`/admin/plugins/chat/hooks/${webhook.id}`, { - type: "DELETE", - }) - .then(() => { - this.model.incoming_chat_webhooks.removeObject(webhook); - this.set("loading", false); - }) - .catch(popupAjaxError); - }, - }); - } - - @action - emojiSelected(emoji) { - this.selectedWebhook.set("emoji", `:${emoji}:`); - return this.set("emojiPickerIsActive", false); - } - - @action - saveEdit() { - this.set("loading", true); - const data = { - name: this.selectedWebhook.name, - chat_channel_id: this.selectedWebhook.chat_channel.id, - description: this.selectedWebhook.description, - emoji: this.selectedWebhook.emoji, - username: this.selectedWebhook.username, - }; - return ajax(`/admin/plugins/chat/hooks/${this.selectedWebhook.id}`, { - data, - type: "PUT", - }) - .then(() => { - this.selectedWebhook.set("updated_at", new Date()); - this.setProperties({ - loading: false, - selectedWebhookId: null, - }); - }) - .catch(popupAjaxError); - } - - @action - changeChatChannel(chatChannelId) { - this.selectedWebhook.set( - "chat_channel", - this.model.chat_channels.findBy("id", chatChannelId) - ); - } -} diff --git a/plugins/chat/assets/javascripts/discourse/initializers/chat-admin-plugin-configuration-nav.js b/plugins/chat/assets/javascripts/discourse/initializers/chat-admin-plugin-configuration-nav.js new file mode 100644 index 00000000000..68df5e41c61 --- /dev/null +++ b/plugins/chat/assets/javascripts/discourse/initializers/chat-admin-plugin-configuration-nav.js @@ -0,0 +1,28 @@ +import { PLUGIN_NAV_MODE_TOP } from "discourse/lib/admin-plugin-config-nav"; +import { withPluginApi } from "discourse/lib/plugin-api"; +import ChatAdminPluginActions from "discourse/plugins/chat/admin/components/chat-admin-plugin-actions"; + +export default { + name: "discourse-chat-admin-plugin-configuration-nav", + + initialize(container) { + const currentUser = container.lookup("service:current-user"); + if (!currentUser?.admin) { + return; + } + + withPluginApi("1.1.0", (api) => { + api.addAdminPluginConfigurationNav("chat", PLUGIN_NAV_MODE_TOP, [ + { + label: "chat.incoming_webhooks.title", + route: "adminPlugins.show.discourse-chat-incoming-webhooks", + }, + ]); + + api.renderInOutlet( + "admin-plugin-config-page-actions", + ChatAdminPluginActions + ); + }); + }, +}; diff --git a/plugins/chat/assets/javascripts/discourse/routes/admin-plugins-chat.js b/plugins/chat/assets/javascripts/discourse/routes/admin-plugins-chat.js deleted file mode 100644 index 5109d9db4fe..00000000000 --- a/plugins/chat/assets/javascripts/discourse/routes/admin-plugins-chat.js +++ /dev/null @@ -1,24 +0,0 @@ -import EmberObject from "@ember/object"; -import { ajax } from "discourse/lib/ajax"; -import DiscourseRoute from "discourse/routes/discourse"; -import ChatChannel from "discourse/plugins/chat/discourse/models/chat-channel"; - -export default class AdminPluginsChatRoute extends DiscourseRoute { - model() { - if (!this.currentUser?.admin) { - return { model: null }; - } - - return ajax("/admin/plugins/chat/hooks.json").then((model) => { - model.incoming_chat_webhooks = model.incoming_chat_webhooks.map( - (webhook) => EmberObject.create(webhook) - ); - - model.chat_channels = model.chat_channels.map((channel) => { - return ChatChannel.create(channel); - }); - - return model; - }); - } -} diff --git a/plugins/chat/assets/javascripts/discourse/templates/admin-plugins-chat.hbs b/plugins/chat/assets/javascripts/discourse/templates/admin-plugins-chat.hbs deleted file mode 100644 index e20a13b0b61..00000000000 --- a/plugins/chat/assets/javascripts/discourse/templates/admin-plugins-chat.hbs +++ /dev/null @@ -1,196 +0,0 @@ - - -{{#if this.selectedWebhook}} - - -
-
- - -
- -
- -