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',
|
||||
map() {
|
||||
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 computed from "ember-addons/ember-computed-decorators";
|
||||
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';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
|
||||
model: FilterRule.create({}),
|
||||
model: Rule.create({}),
|
||||
|
||||
actions: {
|
||||
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'
|
||||
|
||||
export default AdminPluginsChatProvider.extend({
|
||||
afterModel(model, transition) {
|
||||
this.transitionTo('adminPlugins.chat.provider', model);
|
||||
export default Discourse.Route.extend({
|
||||
afterModel(model, transition) {
|
||||
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';
|
||||
|
||||
export default Discourse.Route.extend({
|
||||
|
||||
model(params, transition) {
|
||||
|
||||
var url = '/admin/plugins/chat'
|
||||
if(params.provider !== undefined){
|
||||
url += `/${params.provider}`
|
||||
}
|
||||
url += '.json'
|
||||
console.log("Loading rules for "+params.provider)
|
||||
return this.store.find('rule', {provider: params.provider});
|
||||
|
||||
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};
|
||||
});
|
||||
// var url = '/admin/plugins/chat'
|
||||
// if(params.provider !== undefined){
|
||||
// url += `/${params.provider}`
|
||||
// }
|
||||
// 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) {
|
||||
|
|
|
@ -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>
|
||||
<tr>
|
||||
|
@ -26,7 +17,7 @@
|
|||
<th></th>
|
||||
</tr>
|
||||
|
||||
{{#each model.rules as |rule|}}
|
||||
{{#each model as |rule|}}
|
||||
<tr class="">
|
||||
<td>{{rule.channel}}</td>
|
||||
<td>{{rule.filterName}}</td>
|
||||
|
@ -60,4 +51,3 @@
|
|||
title="chat.reset_settings"
|
||||
label="chat.reset_settings"}}
|
||||
{{/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)
|
||||
.where("key ~* :pattern", pattern: "^#{DiscourseChat::Manager::KEY_PREFIX}.*")
|
||||
.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 =
|
||||
if row.key == DiscourseChat::Manager.get_store_key
|
||||
nil
|
||||
|
@ -25,6 +25,7 @@ module DiscourseChat
|
|||
end
|
||||
|
||||
rules << {
|
||||
id: "#{(category_id || 'all')}_#{thisIndex}",
|
||||
provider: rule[:provider],
|
||||
channel: rule[:channel],
|
||||
filter: rule[:filter],
|
||||
|
|
36
plugin.rb
36
plugin.rb
|
@ -28,36 +28,46 @@ after_initialize do
|
|||
class ::DiscourseChat::ChatController < ::ApplicationController
|
||||
requires_plugin DiscourseChat::PLUGIN_NAME
|
||||
|
||||
def list
|
||||
requested_provider = params[:provider]
|
||||
def respond
|
||||
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}
|
||||
|
||||
if requested_provider.nil?
|
||||
requested_provider = providers[0]
|
||||
end
|
||||
requested_provider = params[:provider]
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
rules = DiscourseChat::Manager.get_rules_for_provider(requested_provider)
|
||||
|
||||
out = {provider: requested_provider, providers: providers, rules: rules}
|
||||
|
||||
render json: out
|
||||
render json: rules, root: 'rules'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
require_dependency 'admin_constraint'
|
||||
|
||||
|
||||
add_admin_route 'chat.menu_title', 'chat'
|
||||
|
||||
DiscourseChat::Engine.routes.draw do
|
||||
get "(.:format)" => "chat#list" # TODO: Fix this hack
|
||||
get "/:provider" => "chat#list"
|
||||
get "" => "chat#respond"
|
||||
get '/providers' => "chat#list_providers"
|
||||
get '/rules' => "chat#list_rules"
|
||||
|
||||
get "/:provider" => "chat#respond"
|
||||
end
|
||||
|
||||
Discourse::Application.routes.append do
|
||||
|
|
Loading…
Reference in New Issue