From 3967e2cd915eaefa1f36abea0b772753a337a2cf Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 26 Jun 2017 19:19:50 +0100 Subject: [PATCH] Created basic system to allow multiple integrations to register themselves, creating a separate tab in the admin interface for each one. --- .../discourse/chat-route-map.js.es6 | 7 +++++ .../controllers/admin-plugins-chat.js.es6 | 3 ++ .../routes/admin-plugins-chat.js.es6 | 9 ++++++ .../templates/admin/plugins-chat.hbs | 12 ++++++++ config/locales/client.en.yml | 10 +++++-- lib/integration.rb | 12 ++++++++ lib/integration/slack/slack_integration.rb | 7 +++++ .../telegram/telegram_integration.rb | 7 +++++ plugin.rb | 29 +++++++++++++++++++ 9 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 assets/javascripts/discourse/chat-route-map.js.es6 create mode 100644 assets/javascripts/discourse/controllers/admin-plugins-chat.js.es6 create mode 100644 assets/javascripts/discourse/routes/admin-plugins-chat.js.es6 create mode 100644 assets/javascripts/discourse/templates/admin/plugins-chat.hbs create mode 100644 lib/integration.rb create mode 100644 lib/integration/slack/slack_integration.rb create mode 100644 lib/integration/telegram/telegram_integration.rb diff --git a/assets/javascripts/discourse/chat-route-map.js.es6 b/assets/javascripts/discourse/chat-route-map.js.es6 new file mode 100644 index 0000000..9458f36 --- /dev/null +++ b/assets/javascripts/discourse/chat-route-map.js.es6 @@ -0,0 +1,7 @@ +export default { + resource: 'admin.adminPlugins', + path: '/plugins', + map() { + this.route('chat'); + } +}; \ No newline at end of file diff --git a/assets/javascripts/discourse/controllers/admin-plugins-chat.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-chat.js.es6 new file mode 100644 index 0000000..4ee344f --- /dev/null +++ b/assets/javascripts/discourse/controllers/admin-plugins-chat.js.es6 @@ -0,0 +1,3 @@ +export default Ember.Controller.extend({ + +}); \ No newline at end of file diff --git a/assets/javascripts/discourse/routes/admin-plugins-chat.js.es6 b/assets/javascripts/discourse/routes/admin-plugins-chat.js.es6 new file mode 100644 index 0000000..7212c76 --- /dev/null +++ b/assets/javascripts/discourse/routes/admin-plugins-chat.js.es6 @@ -0,0 +1,9 @@ +import { ajax } from 'discourse/lib/ajax'; + +export default Discourse.Route.extend({ + model() { + return ajax("/chat/list-integrations.json").then(result => { + return result.chat; + }); + } +}); diff --git a/assets/javascripts/discourse/templates/admin/plugins-chat.hbs b/assets/javascripts/discourse/templates/admin/plugins-chat.hbs new file mode 100644 index 0000000..8669772 --- /dev/null +++ b/assets/javascripts/discourse/templates/admin/plugins-chat.hbs @@ -0,0 +1,12 @@ +
+
+
+ + +
+
+
\ No newline at end of file diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 6072116..6cafab4 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1,4 +1,10 @@ en: js: - discourse_chat: - \ No newline at end of file + chat: + menu_title: "Chat Integrations" + + integration: + telegram: + title: "Telegram" + slack: + title: "Slack" \ No newline at end of file diff --git a/lib/integration.rb b/lib/integration.rb new file mode 100644 index 0000000..58cce36 --- /dev/null +++ b/lib/integration.rb @@ -0,0 +1,12 @@ +module DiscourseChat + module Integration + def self.integrations + constants.select do |constant| + constant.to_s =~ /Integration$/ + end.map(&method(:const_get)) + end + end +end + +require_relative "integration/slack/slack_integration.rb" +require_relative "integration/telegram/telegram_integration.rb" \ No newline at end of file diff --git a/lib/integration/slack/slack_integration.rb b/lib/integration/slack/slack_integration.rb new file mode 100644 index 0000000..98a501d --- /dev/null +++ b/lib/integration/slack/slack_integration.rb @@ -0,0 +1,7 @@ +module DiscourseChat + module Integration + module SlackIntegration + INTEGRATION_NAME = "slack".freeze + end + end +end \ No newline at end of file diff --git a/lib/integration/telegram/telegram_integration.rb b/lib/integration/telegram/telegram_integration.rb new file mode 100644 index 0000000..380579a --- /dev/null +++ b/lib/integration/telegram/telegram_integration.rb @@ -0,0 +1,7 @@ +module DiscourseChat + module Integration + module TelegramIntegration + INTEGRATION_NAME = "telegram".freeze + end + end +end \ No newline at end of file diff --git a/plugin.rb b/plugin.rb index 6943aad..3bd2042 100644 --- a/plugin.rb +++ b/plugin.rb @@ -15,4 +15,33 @@ after_initialize do isolate_namespace DiscourseChat end end + + require_relative "lib/integration" + + class ::DiscourseChat::ChatController < ::ApplicationController + requires_plugin DiscourseChat::PLUGIN_NAME + + def list_integrations + render json: ::DiscourseChat::Integration.integrations.map {|x| x::INTEGRATION_NAME} + end + + end + + require_dependency 'admin_constraint' + + + add_admin_route 'chat.menu_title', 'chat' + + DiscourseChat::Engine.routes.draw do + get "/list-integrations" => "chat#list_integrations", constraints: AdminConstraint.new + end + + Discourse::Application.routes.prepend do + mount ::DiscourseChat::Engine, at: "/chat" + end + + Discourse::Application.routes.append do + get '/admin/plugins/chat' => 'admin/plugins#index', constraints: StaffConstraint.new + end + end