From aaaffdf3713736af65458ed156d384e52900f704 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Tue, 4 Jul 2017 23:35:45 +0100 Subject: [PATCH] =?UTF-8?q?Add=20=E2=80=98send=20test=20message=E2=80=99?= =?UTF-8?q?=20functionality=20to=20the=20admin=20interface?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin-plugins-chat-provider.js.es6 | 5 ++ .../modals/admin-plugins-chat-test.js.es6 | 43 +++++++++++++++ .../modal/admin-plugins-chat-test.hbs | 54 +++++++++++++++++++ .../templates/admin/plugins-chat-provider.hbs | 2 + .../stylesheets/chat-integration-admin.scss | 4 +- config/locales/client.en.yml | 10 ++++ .../provider/slack/slack_provider.rb | 7 ++- plugin.rb | 34 ++++++++++++ 8 files changed, 155 insertions(+), 4 deletions(-) create mode 100644 assets/javascripts/admin/controllers/modals/admin-plugins-chat-test.js.es6 create mode 100644 assets/javascripts/admin/templates/modal/admin-plugins-chat-test.hbs diff --git a/assets/javascripts/admin/controllers/admin-plugins-chat-provider.js.es6 b/assets/javascripts/admin/controllers/admin-plugins-chat-provider.js.es6 index e1dd35a..5fd9341 100644 --- a/assets/javascripts/admin/controllers/admin-plugins-chat-provider.js.es6 +++ b/assets/javascripts/admin/controllers/admin-plugins-chat-provider.js.es6 @@ -37,6 +37,11 @@ export default Ember.Controller.extend({ }, showError(error_key){ bootbox.alert(I18n.t(error_key)); + }, + test(){ + this.set('modalShowing', true); + var model = {provider:this.get('model.provider'), channel:''} + showModal('admin-plugins-chat-test', { model: model, admin: true }); } } diff --git a/assets/javascripts/admin/controllers/modals/admin-plugins-chat-test.js.es6 b/assets/javascripts/admin/controllers/modals/admin-plugins-chat-test.js.es6 new file mode 100644 index 0000000..0c97dfa --- /dev/null +++ b/assets/javascripts/admin/controllers/modals/admin-plugins-chat-test.js.es6 @@ -0,0 +1,43 @@ +import ModalFunctionality from 'discourse/mixins/modal-functionality'; +import { ajax } from 'discourse/lib/ajax'; + +export default Ember.Controller.extend(ModalFunctionality, { + sendDisabled: function(){ + if(this.get('model').topic_id && this.get('model').channel){ + return false + } + return true + }.property('model.topic_id', 'model.channel'), + + actions: { + + send: function(){ + self = this; + this.set('loading', true); + ajax("/admin/plugins/chat/test", { + data: { provider: this.get('model.provider.name'), + channel: this.get('model.channel'), + topic_id: this.get('model.topic_id') + }, + type: 'POST' + }).then(function (result) { + self.set('loading', false) + self.flash(I18n.t('chat_integration.test_modal.success'), 'success'); + }, function(e) { + self.set('loading', false); + + var response = e.jqXHR.responseJSON + var error_key = 'chat_integration.test_modal.error' + debugger; + if(response['error_key']){ + error_key = response['error_key'] + } + self.flash(I18n.t(error_key), 'error'); + + }); + } + + } + + +}); \ No newline at end of file diff --git a/assets/javascripts/admin/templates/modal/admin-plugins-chat-test.hbs b/assets/javascripts/admin/templates/modal/admin-plugins-chat-test.hbs new file mode 100644 index 0000000..7f2e404 --- /dev/null +++ b/assets/javascripts/admin/templates/modal/admin-plugins-chat-test.hbs @@ -0,0 +1,54 @@ +{{#d-modal-body id="chat_integration_test_modal" title="chat_integration.test_modal.title"}} +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ {{i18n (concat 'chat_integration.provider.' model.provider.id '.title')}} +
+ {{text-field + name="channel" + value=model.channel + autofocus="autofocus" + id="channel-field"}} + + {{!--  {{input-tip validation=channelValidation}} --}} +
+ {{choose-topic selectedTopicId=model.topic_id}} +
+
+
+{{/d-modal-body}} + + \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/admin/plugins-chat-provider.hbs b/assets/javascripts/discourse/templates/admin/plugins-chat-provider.hbs index 2fcd602..236c68e 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-chat-provider.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-chat-provider.hbs @@ -67,6 +67,8 @@