Use RestModel and buildPluginAdapter to deal with communication of data models between client and server
This commit is contained in:
parent
e067f8611d
commit
8e0bec6e6f
|
@ -0,0 +1,5 @@
|
||||||
|
import buildPluginAdapter from 'admin/adapters/build-plugin';
|
||||||
|
|
||||||
|
export default buildPluginAdapter('chat').extend({
|
||||||
|
|
||||||
|
});
|
|
@ -0,0 +1,5 @@
|
||||||
|
import buildPluginAdapter from 'admin/adapters/build-plugin';
|
||||||
|
|
||||||
|
export default buildPluginAdapter('chat').extend({
|
||||||
|
|
||||||
|
});
|
|
@ -3,8 +3,9 @@ export default {
|
||||||
path: '/plugins',
|
path: '/plugins',
|
||||||
map() {
|
map() {
|
||||||
this.route('chat', function(){
|
this.route('chat', function(){
|
||||||
this.route('index', { 'path': '/' });
|
this.route('provider', {path: '/:provider'});
|
||||||
this.route('provider', {path: '/:provider'});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -1,4 +1,4 @@
|
||||||
import FilterRule from 'discourse/plugins/discourse-chat/admin/models/filter-rule'
|
import Rule from 'discourse/plugins/discourse-chat/admin/models/rule'
|
||||||
import { ajax } from 'discourse/lib/ajax';
|
import { ajax } from 'discourse/lib/ajax';
|
||||||
import computed from "ember-addons/ember-computed-decorators";
|
import computed from "ember-addons/ember-computed-decorators";
|
||||||
import showModal from 'discourse/lib/show-modal';
|
import showModal from 'discourse/lib/show-modal';
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
export default Ember.Controller.extend({
|
||||||
|
|
||||||
|
});
|
|
@ -1,9 +1,9 @@
|
||||||
import FilterRule from 'discourse/plugins/discourse-chat/admin/models/filter-rule'
|
import Rule from 'discourse/plugins/discourse-chat/admin/models/rule'
|
||||||
import { ajax } from 'discourse/lib/ajax';
|
import { ajax } from 'discourse/lib/ajax';
|
||||||
|
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
|
|
||||||
model: FilterRule.create({}),
|
model: Rule.create({}),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
cancel: function(){
|
cancel: function(){
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
import RestModel from 'discourse/models/rest';
|
||||||
|
import Category from 'discourse/models/category';
|
||||||
|
import computed from "ember-addons/ember-computed-decorators";
|
||||||
|
|
||||||
|
export default RestModel.extend({
|
||||||
|
|
||||||
|
});
|
|
@ -1,7 +1,7 @@
|
||||||
import AdminPluginsChatProvider from 'discourse/plugins/discourse-chat/admin/routes/admin-plugins-chat-provider'
|
import AdminPluginsChatProvider from 'discourse/plugins/discourse-chat/admin/routes/admin-plugins-chat-provider'
|
||||||
|
|
||||||
export default AdminPluginsChatProvider.extend({
|
export default Discourse.Route.extend({
|
||||||
afterModel(model, transition) {
|
afterModel(model, transition) {
|
||||||
this.transitionTo('adminPlugins.chat.provider', model);
|
this.transitionTo('adminPlugins.chat.provider', model.get('firstObject').name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,21 +1,23 @@
|
||||||
import FilterRule from 'discourse/plugins/discourse-chat/admin/models/filter-rule'
|
import Rule from 'discourse/plugins/discourse-chat/admin/models/rule'
|
||||||
import { ajax } from 'discourse/lib/ajax';
|
import { ajax } from 'discourse/lib/ajax';
|
||||||
|
|
||||||
export default Discourse.Route.extend({
|
export default Discourse.Route.extend({
|
||||||
|
|
||||||
model(params, transition) {
|
model(params, transition) {
|
||||||
|
console.log("Loading rules for "+params.provider)
|
||||||
var url = '/admin/plugins/chat'
|
return this.store.find('rule', {provider: params.provider});
|
||||||
if(params.provider !== undefined){
|
|
||||||
url += `/${params.provider}`
|
|
||||||
}
|
|
||||||
url += '.json'
|
|
||||||
|
|
||||||
return ajax(url).then(result => {
|
// var url = '/admin/plugins/chat'
|
||||||
var rules = result.rules.map(v => FilterRule.create(v))
|
// if(params.provider !== undefined){
|
||||||
var providers = result.providers
|
// url += `/${params.provider}`
|
||||||
return {provider: result.provider, rules: rules, providers: providers};
|
// }
|
||||||
});
|
// url += '.json'
|
||||||
|
|
||||||
|
// return ajax(url).then(result => {
|
||||||
|
// var rules = result.rules.map(v => FilterRule.create(v))
|
||||||
|
// var providers = result.providers
|
||||||
|
// return {provider: result.provider, rules: rules, providers: providers};
|
||||||
|
// });
|
||||||
},
|
},
|
||||||
|
|
||||||
serialize: function(model, params) {
|
serialize: function(model, params) {
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
import AdminPluginsChatProvider from 'discourse/plugins/discourse-chat/admin/routes/admin-plugins-chat-provider'
|
||||||
|
|
||||||
|
export default Discourse.Route.extend({
|
||||||
|
model(params, transition) {
|
||||||
|
return this.store.findAll('provider');
|
||||||
|
}
|
||||||
|
});
|
|
@ -1,14 +1,5 @@
|
||||||
|
|
||||||
<div id="admin-plugin-slack">
|
|
||||||
<div class="admin-controls">
|
|
||||||
<div class="span15">
|
|
||||||
<ul class="nav nav-pills">
|
|
||||||
{{#each model.providers as |provider|}}
|
|
||||||
{{nav-item route='adminPlugins.chat.provider' routeParam=provider label=(concat 'chat.integration.' provider '.title')}}
|
|
||||||
{{/each}}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -26,7 +17,7 @@
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
{{#each model.rules as |rule|}}
|
{{#each model as |rule|}}
|
||||||
<tr class="">
|
<tr class="">
|
||||||
<td>{{rule.channel}}</td>
|
<td>{{rule.channel}}</td>
|
||||||
<td>{{rule.filterName}}</td>
|
<td>{{rule.filterName}}</td>
|
||||||
|
@ -60,4 +51,3 @@
|
||||||
title="chat.reset_settings"
|
title="chat.reset_settings"
|
||||||
label="chat.reset_settings"}}
|
label="chat.reset_settings"}}
|
||||||
{{/d-button}}
|
{{/d-button}}
|
||||||
</div>
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
<div id="admin-plugin-slack">
|
||||||
|
<div class="admin-controls">
|
||||||
|
<div class="span15">
|
||||||
|
<ul class="nav nav-pills">
|
||||||
|
{{#each model as |provider|}}
|
||||||
|
{{nav-item route='adminPlugins.chat.provider' routeParam=provider.name label=(concat 'chat.integration.' provider.name '.title')}}
|
||||||
|
{{/each}}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{outlet}}
|
||||||
|
</div>
|
||||||
|
|
|
@ -15,7 +15,7 @@ module DiscourseChat
|
||||||
PluginStoreRow.where(plugin_name: DiscourseChat::PLUGIN_NAME)
|
PluginStoreRow.where(plugin_name: DiscourseChat::PLUGIN_NAME)
|
||||||
.where("key ~* :pattern", pattern: "^#{DiscourseChat::Manager::KEY_PREFIX}.*")
|
.where("key ~* :pattern", pattern: "^#{DiscourseChat::Manager::KEY_PREFIX}.*")
|
||||||
.each do |row|
|
.each do |row|
|
||||||
PluginStore.cast_value(row.type_name, row.value).each do |rule|
|
PluginStore.cast_value(row.type_name, row.value).each_with_index do |rule, thisIndex|
|
||||||
category_id =
|
category_id =
|
||||||
if row.key == DiscourseChat::Manager.get_store_key
|
if row.key == DiscourseChat::Manager.get_store_key
|
||||||
nil
|
nil
|
||||||
|
@ -25,6 +25,7 @@ module DiscourseChat
|
||||||
end
|
end
|
||||||
|
|
||||||
rules << {
|
rules << {
|
||||||
|
id: "#{(category_id || 'all')}_#{thisIndex}",
|
||||||
provider: rule[:provider],
|
provider: rule[:provider],
|
||||||
channel: rule[:channel],
|
channel: rule[:channel],
|
||||||
filter: rule[:filter],
|
filter: rule[:filter],
|
||||||
|
|
36
plugin.rb
36
plugin.rb
|
@ -28,36 +28,46 @@ after_initialize do
|
||||||
class ::DiscourseChat::ChatController < ::ApplicationController
|
class ::DiscourseChat::ChatController < ::ApplicationController
|
||||||
requires_plugin DiscourseChat::PLUGIN_NAME
|
requires_plugin DiscourseChat::PLUGIN_NAME
|
||||||
|
|
||||||
def list
|
def respond
|
||||||
requested_provider = params[:provider]
|
render
|
||||||
|
end
|
||||||
|
|
||||||
|
def list_providers
|
||||||
|
providers = ::DiscourseChat::Provider.providers.map {|x| {name: x::PROVIDER_NAME, id: x::PROVIDER_NAME}}
|
||||||
|
render json:providers, root: 'providers'
|
||||||
|
end
|
||||||
|
|
||||||
|
def list_rules
|
||||||
providers = ::DiscourseChat::Provider.providers.map {|x| x::PROVIDER_NAME}
|
providers = ::DiscourseChat::Provider.providers.map {|x| x::PROVIDER_NAME}
|
||||||
|
|
||||||
if requested_provider.nil?
|
requested_provider = params[:provider]
|
||||||
requested_provider = providers[0]
|
|
||||||
end
|
|
||||||
|
|
||||||
if not providers.include? requested_provider
|
if requested_provider.nil?
|
||||||
|
rules = DiscourseChat::Manager.get_all_rules()
|
||||||
|
elsif providers.include? requested_provider
|
||||||
|
rules = DiscourseChat::Manager.get_rules_for_provider(requested_provider)
|
||||||
|
else
|
||||||
raise Discourse::NotFound
|
raise Discourse::NotFound
|
||||||
end
|
end
|
||||||
|
|
||||||
rules = DiscourseChat::Manager.get_rules_for_provider(requested_provider)
|
render json: rules, root: 'rules'
|
||||||
|
|
||||||
out = {provider: requested_provider, providers: providers, rules: rules}
|
|
||||||
|
|
||||||
render json: out
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
require_dependency 'admin_constraint'
|
require_dependency 'admin_constraint'
|
||||||
|
|
||||||
|
|
||||||
add_admin_route 'chat.menu_title', 'chat'
|
add_admin_route 'chat.menu_title', 'chat'
|
||||||
|
|
||||||
DiscourseChat::Engine.routes.draw do
|
DiscourseChat::Engine.routes.draw do
|
||||||
get "(.:format)" => "chat#list" # TODO: Fix this hack
|
get "" => "chat#respond"
|
||||||
get "/:provider" => "chat#list"
|
get '/providers' => "chat#list_providers"
|
||||||
|
get '/rules' => "chat#list_rules"
|
||||||
|
|
||||||
|
get "/:provider" => "chat#respond"
|
||||||
end
|
end
|
||||||
|
|
||||||
Discourse::Application.routes.append do
|
Discourse::Application.routes.append do
|
||||||
|
|
Loading…
Reference in New Issue