Created basic system to allow multiple integrations to register themselves, creating a separate tab in the admin interface for each one.

This commit is contained in:
David Taylor 2017-06-26 19:19:50 +01:00
parent 3e3a309c44
commit 3967e2cd91
9 changed files with 94 additions and 2 deletions

View File

@ -0,0 +1,7 @@
export default {
resource: 'admin.adminPlugins',
path: '/plugins',
map() {
this.route('chat');
}
};

View File

@ -0,0 +1,3 @@
export default Ember.Controller.extend({
});

View File

@ -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;
});
}
});

View File

@ -0,0 +1,12 @@
<div class='admin-chat'>
<div class="admin-controls">
<div class="span15">
<ul class="nav nav-pills">
{{#each model as |provider|}}
{{nav-item label=(concat 'chat.integration.' provider '.title')}}
{{/each}}
</ul>
</div>
</div>
</div>

View File

@ -1,4 +1,10 @@
en:
js:
discourse_chat:
chat:
menu_title: "Chat Integrations"
integration:
telegram:
title: "Telegram"
slack:
title: "Slack"

12
lib/integration.rb Normal file
View File

@ -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"

View File

@ -0,0 +1,7 @@
module DiscourseChat
module Integration
module SlackIntegration
INTEGRATION_NAME = "slack".freeze
end
end
end

View File

@ -0,0 +1,7 @@
module DiscourseChat
module Integration
module TelegramIntegration
INTEGRATION_NAME = "telegram".freeze
end
end
end

View File

@ -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