REFACTOR: Clean up code in plugin.
This commit is contained in:
@@ -26,7 +26,7 @@ class DiscourseChat::ChatController < ApplicationController
|
||||
|
||||
provider = ::DiscourseChat::Provider.get_by_name(channel.provider)
|
||||
|
||||
if not ::DiscourseChat::Provider.is_enabled(provider)
|
||||
if !DiscourseChat::Provider.is_enabled(provider)
|
||||
raise Discourse::NotFound
|
||||
end
|
||||
|
||||
@@ -48,16 +48,12 @@ class DiscourseChat::ChatController < ApplicationController
|
||||
end
|
||||
|
||||
def list_channels
|
||||
providers = ::DiscourseChat::Provider.enabled_providers.map { |x| x::PROVIDER_NAME }
|
||||
|
||||
providers = ::DiscourseChat::Provider.enabled_provider_names
|
||||
requested_provider = params[:provider]
|
||||
|
||||
if not providers.include? requested_provider
|
||||
raise Discourse::NotFound
|
||||
end
|
||||
raise Discourse::InvalidParameters if !providers.include?(requested_provider)
|
||||
|
||||
channels = DiscourseChat::Channel.with_provider(requested_provider)
|
||||
|
||||
render_serialized channels, DiscourseChat::ChannelSerializer, root: 'channels'
|
||||
end
|
||||
|
||||
@@ -65,13 +61,13 @@ class DiscourseChat::ChatController < ApplicationController
|
||||
begin
|
||||
providers = ::DiscourseChat::Provider.enabled_providers.map { |x| x::PROVIDER_NAME }
|
||||
|
||||
if (not defined? params[:channel]) && defined? params[:channel][:provider]
|
||||
if !defined?(params[:channel]) && defined?(params[:channel][:provider])
|
||||
raise Discourse::InvalidParameters, 'Provider is not valid'
|
||||
end
|
||||
|
||||
requested_provider = params[:channel][:provider]
|
||||
|
||||
if not providers.include? requested_provider
|
||||
if !providers.include?(requested_provider)
|
||||
raise Discourse::InvalidParameters, 'Provider is not valid'
|
||||
end
|
||||
|
||||
@@ -81,7 +77,7 @@ class DiscourseChat::ChatController < ApplicationController
|
||||
|
||||
channel = DiscourseChat::Channel.new(hash)
|
||||
|
||||
if not channel.save(hash)
|
||||
if !channel.save(hash)
|
||||
raise Discourse::InvalidParameters, 'Channel is not valid'
|
||||
end
|
||||
|
||||
@@ -100,7 +96,7 @@ class DiscourseChat::ChatController < ApplicationController
|
||||
|
||||
hash = params.require(:channel).permit(data: allowed_keys)
|
||||
|
||||
if not channel.update(hash)
|
||||
if !channel.update(hash)
|
||||
raise Discourse::InvalidParameters, 'Channel is not valid'
|
||||
end
|
||||
|
||||
@@ -111,9 +107,9 @@ class DiscourseChat::ChatController < ApplicationController
|
||||
end
|
||||
|
||||
def destroy_channel
|
||||
rule = DiscourseChat::Channel.find(params[:id].to_i)
|
||||
|
||||
rule.destroy
|
||||
rule = DiscourseChat::Channel.find_by(id: params[:id])
|
||||
raise Discourse::InvalidParameters unless rule
|
||||
rule.destroy!
|
||||
|
||||
render json: success_json
|
||||
end
|
||||
@@ -121,10 +117,9 @@ class DiscourseChat::ChatController < ApplicationController
|
||||
def create_rule
|
||||
begin
|
||||
hash = params.require(:rule).permit(:channel_id, :type, :filter, :group_id, :category_id, tags: [])
|
||||
|
||||
rule = DiscourseChat::Rule.new(hash)
|
||||
|
||||
if not rule.save(hash)
|
||||
if !rule.save(hash)
|
||||
raise Discourse::InvalidParameters, 'Rule is not valid'
|
||||
end
|
||||
|
||||
@@ -139,7 +134,7 @@ class DiscourseChat::ChatController < ApplicationController
|
||||
rule = DiscourseChat::Rule.find(params[:id].to_i)
|
||||
hash = params.require(:rule).permit(:type, :filter, :group_id, :category_id, tags: [])
|
||||
|
||||
if not rule.update(hash)
|
||||
if !rule.update(hash)
|
||||
raise Discourse::InvalidParameters, 'Rule is not valid'
|
||||
end
|
||||
|
||||
@@ -150,9 +145,9 @@ class DiscourseChat::ChatController < ApplicationController
|
||||
end
|
||||
|
||||
def destroy_rule
|
||||
rule = DiscourseChat::Rule.find(params[:id].to_i)
|
||||
|
||||
rule.destroy
|
||||
rule = DiscourseChat::Rule.find_by(id: params[:id])
|
||||
raise Discourse::InvalidParameters.new unless rule
|
||||
rule.destroy!
|
||||
|
||||
render json: success_json
|
||||
end
|
||||
|
||||
@@ -4,15 +4,13 @@ class DiscourseChat::PublicController < ApplicationController
|
||||
def post_transcript
|
||||
params.require(:secret)
|
||||
|
||||
redis_key = "chat_integration:transcript:" + params[:secret]
|
||||
redis_key = "chat_integration:transcript:#{params[:secret]}"
|
||||
content = $redis.get(redis_key)
|
||||
|
||||
if content
|
||||
render json: { content: content }
|
||||
return
|
||||
else
|
||||
raise Discourse::NotFound
|
||||
end
|
||||
|
||||
raise Discourse::NotFound
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
+21
-24
@@ -33,11 +33,12 @@ module DiscourseChat
|
||||
if token.start_with?('tag:')
|
||||
tag_name = token.sub(/^tag:/, '')
|
||||
else
|
||||
return error_text # Abort and send help text
|
||||
return error_text
|
||||
end
|
||||
|
||||
tag = Tag.find_by(name: tag_name)
|
||||
unless tag # If tag doesn't exist, abort
|
||||
|
||||
unless tag
|
||||
return I18n.t("chat_integration.provider.#{provider}.not_found.tag", name: tag_name)
|
||||
end
|
||||
tags.push(tag.name)
|
||||
@@ -46,11 +47,11 @@ module DiscourseChat
|
||||
category_id = category.nil? ? nil : category.id
|
||||
case DiscourseChat::Helper.smart_create_rule(channel: channel, filter: cmd, category_id: category_id, tags: tags)
|
||||
when :created
|
||||
return I18n.t("chat_integration.provider.#{provider}.create.created")
|
||||
I18n.t("chat_integration.provider.#{provider}.create.created")
|
||||
when :updated
|
||||
return I18n.t("chat_integration.provider.#{provider}.create.updated")
|
||||
I18n.t("chat_integration.provider.#{provider}.create.updated")
|
||||
else
|
||||
return I18n.t("chat_integration.provider.#{provider}.create.error")
|
||||
I18n.t("chat_integration.provider.#{provider}.create.error")
|
||||
end
|
||||
when "remove"
|
||||
return error_text unless tokens.size == 1
|
||||
@@ -59,16 +60,16 @@ module DiscourseChat
|
||||
return error_text unless rule_number.to_s == tokens[0] # Check we were given a number
|
||||
|
||||
if DiscourseChat::Helper.delete_by_index(channel, rule_number)
|
||||
return I18n.t("chat_integration.provider.#{provider}.delete.success")
|
||||
I18n.t("chat_integration.provider.#{provider}.delete.success")
|
||||
else
|
||||
return I18n.t("chat_integration.provider.#{provider}.delete.error")
|
||||
I18n.t("chat_integration.provider.#{provider}.delete.error")
|
||||
end
|
||||
when "status"
|
||||
return DiscourseChat::Helper.status_for_channel(channel)
|
||||
when "help"
|
||||
return I18n.t("chat_integration.provider.#{provider}.help")
|
||||
I18n.t("chat_integration.provider.#{provider}.help")
|
||||
else
|
||||
return error_text
|
||||
error_text
|
||||
end
|
||||
end
|
||||
|
||||
@@ -105,12 +106,12 @@ module DiscourseChat
|
||||
end
|
||||
|
||||
text << I18n.t("chat_integration.provider.#{provider}.status.rule_string",
|
||||
index: i,
|
||||
filter: rule.filter,
|
||||
category: category_name
|
||||
)
|
||||
index: i,
|
||||
filter: rule.filter,
|
||||
category: category_name
|
||||
)
|
||||
|
||||
if SiteSetting.tagging_enabled && (not rule.tags.nil?)
|
||||
if SiteSetting.tagging_enabled && (!rule.tags.nil?)
|
||||
text << I18n.t("chat_integration.provider.#{provider}.status.rule_string_tags_suffix", tags: rule.tags.join(', '))
|
||||
end
|
||||
|
||||
@@ -121,16 +122,15 @@ module DiscourseChat
|
||||
if rules.size == 0
|
||||
text << I18n.t("chat_integration.provider.#{provider}.status.no_rules")
|
||||
end
|
||||
return text
|
||||
|
||||
text
|
||||
end
|
||||
|
||||
# Delete a rule based on its (1 based) index as seen in the
|
||||
# status_for_channel function
|
||||
def self.delete_by_index(channel, index)
|
||||
rules = channel.rules.order_by_precedence
|
||||
|
||||
return false if index < (1) || index > (rules.size)
|
||||
|
||||
return :deleted if rules[index - 1].destroy
|
||||
end
|
||||
|
||||
@@ -184,17 +184,14 @@ module DiscourseChat
|
||||
|
||||
# This rule is unique! Create a new one:
|
||||
return :created if Rule.new(channel: channel, filter: filter, category_id: category_id, tags: tags).save
|
||||
|
||||
return false # Error
|
||||
|
||||
false
|
||||
end
|
||||
|
||||
def self.save_transcript(transcript)
|
||||
secret = SecureRandom.hex
|
||||
redis_key = "chat_integration:transcript:" + secret
|
||||
$redis.set(redis_key, transcript, ex: 3600) # Expire in 1 hour
|
||||
|
||||
return secret
|
||||
redis_key = "chat_integration:transcript:#{secret}"
|
||||
$redis.setex(redis_key, 3600, transcript)
|
||||
secret
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -2,12 +2,12 @@ module ::DiscourseChat
|
||||
PLUGIN_NAME = "discourse-chat-integration".freeze
|
||||
|
||||
class AdminEngine < ::Rails::Engine
|
||||
engine_name DiscourseChat::PLUGIN_NAME + "-admin"
|
||||
engine_name "#{DiscourseChat::PLUGIN_NAME}-admin"
|
||||
isolate_namespace DiscourseChat
|
||||
end
|
||||
|
||||
class PublicEngine < ::Rails::Engine
|
||||
engine_name DiscourseChat::PLUGIN_NAME + "-public"
|
||||
engine_name "#{DiscourseChat::PLUGIN_NAME}-public"
|
||||
isolate_namespace DiscourseChat
|
||||
end
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
module Jobs
|
||||
class NotifyChats < Jobs::Base
|
||||
sidekiq_options retry: false # Don't retry, could result in duplicate notifications for some providers
|
||||
def execute(args)
|
||||
return if not SiteSetting.chat_integration_enabled? # Plugin may have been disabled since job triggered
|
||||
sidekiq_options retry: false
|
||||
|
||||
def execute(args)
|
||||
return if !SiteSetting.chat_integration_enabled?
|
||||
::DiscourseChat::Manager.trigger_notifications(args[:post_id])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -29,10 +29,8 @@ class DiscourseChat::Channel < DiscourseChat::PluginModel
|
||||
end
|
||||
|
||||
def provider_valid?
|
||||
# Validate provider
|
||||
if not ::DiscourseChat::Provider.provider_names.include? provider
|
||||
if !DiscourseChat::Provider.provider_names.include?(provider)
|
||||
errors.add(:provider, "#{provider} is not a valid provider")
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
@@ -66,6 +64,5 @@ class DiscourseChat::Channel < DiscourseChat::PluginModel
|
||||
if check_unique && matching_channels.exists?
|
||||
errors.add(:data, "matches an existing channel")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,8 +17,6 @@ module DiscourseChat
|
||||
return if post.blank? || post.post_type != Post.types[:regular]
|
||||
|
||||
topic = post.topic
|
||||
|
||||
# Abort if topic is blank... this should never be the case
|
||||
return if topic.blank?
|
||||
|
||||
# If it's a private message, filter rules by groups, otherwise filter rules by category
|
||||
@@ -66,7 +64,7 @@ module DiscourseChat
|
||||
matching_rules = matching_rules.select { |rule| rule.filter != "mute" }
|
||||
|
||||
# If this is not the first post, discard all "follow" rules
|
||||
if not post.is_first_post?
|
||||
if !post.is_first_post?
|
||||
matching_rules = matching_rules.select { |rule| rule.filter != "follow" }
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
import buildPluginAdapter from 'admin/adapters/build-plugin';
|
||||
|
||||
export default buildPluginAdapter('chat').extend({
|
||||
|
||||
|
||||
});
|
||||
export default buildPluginAdapter('chat');
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import buildPluginAdapter from 'admin/adapters/build-plugin';
|
||||
|
||||
export default buildPluginAdapter('chat').extend({
|
||||
|
||||
});
|
||||
export default buildPluginAdapter('chat');
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import buildPluginAdapter from 'admin/adapters/build-plugin';
|
||||
|
||||
export default buildPluginAdapter('chat').extend({
|
||||
|
||||
});
|
||||
export default buildPluginAdapter('chat');
|
||||
|
||||
@@ -33,9 +33,9 @@ export default Ember.Component.extend({
|
||||
this.sendAction('editRule', rule, this.get('channel'));
|
||||
},
|
||||
|
||||
showError(error_key){
|
||||
bootbox.alert(I18n.t(error_key));
|
||||
showError(errorKey){
|
||||
bootbox.alert(I18n.t(errorKey));
|
||||
},
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,32 +1,37 @@
|
||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
import computed from 'ember-addons/ember-computed-decorators';
|
||||
|
||||
export default Ember.Component.extend({
|
||||
tagName: 'tr',
|
||||
|
||||
isCategory: function(){
|
||||
return this.get('rule.type') === 'normal';
|
||||
}.property('rule.type'),
|
||||
@computed('rule.type')
|
||||
isCategory(type) {
|
||||
return type === 'normal';
|
||||
},
|
||||
|
||||
isMessage: function(){
|
||||
return this.get('rule.type') === 'group_message';
|
||||
}.property('rule.type'),
|
||||
@computed('rule.type')
|
||||
isMessage(type) {
|
||||
return type === 'group_message';
|
||||
},
|
||||
|
||||
isMention: function(){
|
||||
return this.get('rule.type') === 'group_mention';
|
||||
}.property('rule.type'),
|
||||
@computed('rule.type')
|
||||
isMention(type) {
|
||||
return type === 'group_mention';
|
||||
},
|
||||
|
||||
actions: {
|
||||
edit: function(){
|
||||
edit() {
|
||||
this.sendAction('edit', this.get('rule'));
|
||||
},
|
||||
delete(rule){
|
||||
|
||||
delete(rule) {
|
||||
rule.destroyRecord().then(() => {
|
||||
this.send('refresh');
|
||||
}).catch(popupAjaxError);
|
||||
},
|
||||
refresh: function(){
|
||||
|
||||
refresh() {
|
||||
this.sendAction('refresh');
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,46 +1,73 @@
|
||||
import showModal from 'discourse/lib/show-modal';
|
||||
import computed from "ember-addons/ember-computed-decorators";
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
modalShowing: false,
|
||||
|
||||
anyErrors: function(){
|
||||
var anyErrors = false;
|
||||
this.get('model.channels').forEach(function(channel){
|
||||
if(channel.error_key){
|
||||
@computed('model.channels')
|
||||
anyErrors(channels) {
|
||||
let anyErrors = false;
|
||||
|
||||
channels.forEach((channel) => {
|
||||
if (channel.error_key) {
|
||||
anyErrors = true;
|
||||
}
|
||||
});
|
||||
|
||||
return anyErrors;
|
||||
}.property('model.channels'),
|
||||
},
|
||||
|
||||
actions:{
|
||||
createChannel(){
|
||||
createChannel() {
|
||||
this.set('modalShowing', true);
|
||||
var model = {channel: this.store.createRecord('channel',{provider: this.get('model.provider').id, data:{}},), provider:this.get('model.provider')};
|
||||
|
||||
const model = {
|
||||
channel: this.store.createRecord('channel', { provider: this.get('model.provider.id'), data:{} }),
|
||||
provider: this.get('model.provider')
|
||||
};
|
||||
|
||||
showModal('admin-plugins-chat-edit-channel', { model: model, admin: true });
|
||||
},
|
||||
editChannel(channel){
|
||||
|
||||
editChannel(channel) {
|
||||
this.set('modalShowing', true);
|
||||
var model = {channel: channel, provider: this.get('model.provider')};
|
||||
|
||||
const model = {
|
||||
channel: channel,
|
||||
provider: this.get('model.provider')
|
||||
};
|
||||
|
||||
showModal('admin-plugins-chat-edit-channel', { model: model, admin: true });
|
||||
},
|
||||
testChannel(channel){
|
||||
|
||||
testChannel(channel) {
|
||||
this.set('modalShowing', true);
|
||||
var model = {channel:channel};
|
||||
showModal('admin-plugins-chat-test', { model: model, admin: true });
|
||||
showModal('admin-plugins-chat-test', { model: { channel: channel }, admin: true });
|
||||
},
|
||||
|
||||
createRule(channel){
|
||||
this.set('modalShowing', true);
|
||||
var model = {rule: this.store.createRecord('rule',{channel_id: channel.id}), channel:channel, provider:this.get('model.provider'), groups:this.get('model.groups')};
|
||||
|
||||
const model = {
|
||||
rule: this.store.createRecord('rule', { channel_id: channel.id }),
|
||||
channel: channel,
|
||||
provider: this.get('model.provider'),
|
||||
groups: this.get('model.groups')
|
||||
};
|
||||
|
||||
showModal('admin-plugins-chat-edit-rule', { model: model, admin: true });
|
||||
},
|
||||
editRule(rule, channel){
|
||||
this.set('modalShowing', true);
|
||||
var model = {rule: rule, channel:channel, provider:this.get('model.provider'), groups:this.get('model.groups')};
|
||||
|
||||
const model = {
|
||||
rule: rule,
|
||||
channel: channel,
|
||||
provider: this.get('model.provider'),
|
||||
groups: this.get('model.groups')
|
||||
};
|
||||
|
||||
showModal('admin-plugins-chat-edit-rule', { model: model, admin: true });
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
+38
-39
@@ -1,10 +1,11 @@
|
||||
import ModalFunctionality from 'discourse/mixins/modal-functionality';
|
||||
import { extractError } from 'discourse/lib/ajax-error';
|
||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
import InputValidation from 'discourse/models/input-validation';
|
||||
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
|
||||
|
||||
export default Ember.Controller.extend(ModalFunctionality, {
|
||||
|
||||
setupKeydown: function() {
|
||||
setupKeydown() {
|
||||
Ember.run.schedule('afterRender', () => {
|
||||
$('#chat_integration_edit_channel_modal').keydown(e => {
|
||||
if (e.keyCode === 13) {
|
||||
@@ -15,36 +16,37 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
||||
}.on('init'),
|
||||
|
||||
// The validation property must be defined at runtime since the possible parameters vary by provider
|
||||
setupValidations: function(){
|
||||
@observes('model')
|
||||
setupValidations() {
|
||||
if(this.get('model.provider')){
|
||||
var theKeys = this.get('model.provider.channel_parameters').map( ( param ) => param['key'] );
|
||||
Ember.defineProperty(this,'paramValidation',Ember.computed('model.channel.data.{' + theKeys.join(',') + '}',this._paramValidation));
|
||||
const theKeys = this.get('model.provider.channel_parameters').map( ( param ) => param['key'] );
|
||||
Ember.defineProperty(this,'paramValidation', Ember.computed(`model.channel.data.{${theKeys.join(',')}},this._paramValidation`));
|
||||
}
|
||||
}.observes('model'),
|
||||
},
|
||||
|
||||
validate(parameter){
|
||||
var regString = parameter.regex;
|
||||
var regex = new RegExp(regString);
|
||||
var val = this.get('model.channel.data.'+parameter.key);
|
||||
validate(parameter) {
|
||||
const regString = parameter.regex;
|
||||
const regex = new RegExp(regString);
|
||||
let val = this.get(`model.channel.data.${parameter.key}`);
|
||||
|
||||
if(val===undefined){
|
||||
if (val === undefined) {
|
||||
val = "";
|
||||
}
|
||||
|
||||
if(val === ""){ // Fail silently if field blank
|
||||
if (val === "") { // Fail silently if field blank
|
||||
return InputValidation.create({
|
||||
failed: true,
|
||||
});
|
||||
}else if(!regString){ // Pass silently if no regex available for provider
|
||||
} else if (!regString) { // Pass silently if no regex available for provider
|
||||
return InputValidation.create({
|
||||
ok: true,
|
||||
});
|
||||
}else if(regex.test(val)){ // Test against regex
|
||||
} else if (regex.test(val)) { // Test against regex
|
||||
return InputValidation.create({
|
||||
ok: true,
|
||||
reason: I18n.t('chat_integration.edit_channel_modal.channel_validation.ok')
|
||||
});
|
||||
}else{ // Failed regex
|
||||
} else { // Failed regex
|
||||
return InputValidation.create({
|
||||
failed: true,
|
||||
reason: I18n.t('chat_integration.edit_channel_modal.channel_validation.fail')
|
||||
@@ -53,50 +55,47 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
||||
|
||||
},
|
||||
|
||||
_paramValidation: function(){
|
||||
var response = {};
|
||||
var parameters = this.get('model.provider.channel_parameters');
|
||||
_paramValidation() {
|
||||
const response = {};
|
||||
const parameters = this.get('model.provider.channel_parameters');
|
||||
|
||||
parameters.forEach(parameter => {
|
||||
response[parameter.key] = this.validate(parameter);
|
||||
});
|
||||
|
||||
return response;
|
||||
},
|
||||
|
||||
saveDisabled: function(){
|
||||
var validations = this.get('paramValidation');
|
||||
@computed('paramValidation')
|
||||
saveDisabled(paramValidation) {
|
||||
if (!paramValidation) return true;
|
||||
|
||||
if(!validations){ return true; }
|
||||
let invalid = false;
|
||||
|
||||
var invalid = false;
|
||||
|
||||
Object.keys(validations).forEach(key =>{
|
||||
if(!validations[key]){
|
||||
Object.keys(paramValidation).forEach(key =>{
|
||||
if (!validations[key]) {
|
||||
invalid = true;
|
||||
}
|
||||
if(!validations[key]['ok']){
|
||||
|
||||
if (!validations[key]['ok']) {
|
||||
invalid = true;
|
||||
}
|
||||
});
|
||||
|
||||
return invalid;
|
||||
}.property('paramValidation'),
|
||||
},
|
||||
|
||||
actions: {
|
||||
cancel: function(){
|
||||
cancel() {
|
||||
this.send('closeModal');
|
||||
},
|
||||
|
||||
save: function(){
|
||||
if(this.get('saveDisabled')){return;};
|
||||
|
||||
const self = this;
|
||||
|
||||
this.get('model.channel').save().then(function() {
|
||||
self.send('closeModal');
|
||||
}).catch(function(error) {
|
||||
self.flash(extractError(error), 'error');
|
||||
});
|
||||
save() {
|
||||
if (this.get('saveDisabled')) return;
|
||||
|
||||
this.get('model.channel').save().then(() => {
|
||||
this.send('closeModal');
|
||||
}).catch(popupAjaxError);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import ModalFunctionality from 'discourse/mixins/modal-functionality';
|
||||
import { extractError } from 'discourse/lib/ajax-error';
|
||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
import computed from "ember-addons/ember-computed-decorators";
|
||||
|
||||
export default Ember.Controller.extend(ModalFunctionality, {
|
||||
setupKeydown: function() {
|
||||
saveDisabled: false,
|
||||
|
||||
setupKeydown() {
|
||||
Ember.run.schedule('afterRender', () => {
|
||||
$('#chat_integration_edit_channel_modal').keydown(e => {
|
||||
if (e.keyCode === 13) {
|
||||
@@ -13,31 +15,22 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
||||
});
|
||||
}.on('init'),
|
||||
|
||||
saveDisabled: function(){
|
||||
return false;
|
||||
}.property(),
|
||||
|
||||
@computed('model.rule.type')
|
||||
showCategory: function(type){
|
||||
return (type === "normal");
|
||||
showCategory(type) {
|
||||
return type === "normal";
|
||||
},
|
||||
|
||||
actions: {
|
||||
cancel: function(){
|
||||
cancel() {
|
||||
this.send('closeModal');
|
||||
},
|
||||
|
||||
save: function(){
|
||||
if(this.get('saveDisabled')){return;};
|
||||
|
||||
const self = this;
|
||||
|
||||
this.get('model.rule').save().then(function() {
|
||||
self.send('closeModal');
|
||||
}).catch(function(error) {
|
||||
self.flash(extractError(error), 'error');
|
||||
});
|
||||
save() {
|
||||
if (this.get('saveDisabled')) return;
|
||||
|
||||
this.get('model.rule').save().then(() => {
|
||||
this.send('closeModal');
|
||||
}).catch(popupAjaxError);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import ModalFunctionality from 'discourse/mixins/modal-functionality';
|
||||
import { ajax } from 'discourse/lib/ajax';
|
||||
import computed from "ember-addons/ember-computed-decorators";
|
||||
|
||||
export default Ember.Controller.extend(ModalFunctionality, {
|
||||
setupKeydown: function() {
|
||||
setupKeydown() {
|
||||
Ember.run.schedule('afterRender', () => {
|
||||
$('#chat_integration_test_modal').keydown(e => {
|
||||
if (e.keyCode === 13) {
|
||||
@@ -12,42 +13,26 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
||||
});
|
||||
}.on('init'),
|
||||
|
||||
sendDisabled: function(){
|
||||
if(this.get('model').topic_id){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}.property('model.topic_id'),
|
||||
@computed('model.topic_id')
|
||||
sendDisabled(topicId) {
|
||||
return !topicId;
|
||||
},
|
||||
|
||||
actions: {
|
||||
send() {
|
||||
if (this.get('sendDisabled')) return;
|
||||
|
||||
send: function(){
|
||||
if(this.get('sendDisabled')){return;};
|
||||
self = this;
|
||||
this.set('loading', true);
|
||||
ajax("/admin/plugins/chat/test", {
|
||||
data: { channel_id: this.get('model.channel.id'),
|
||||
topic_id: this.get('model.topic_id')
|
||||
},
|
||||
data: {
|
||||
channel_id: this.get('model.channel.id'),
|
||||
topic_id: this.get('model.topic_id')
|
||||
},
|
||||
type: 'POST'
|
||||
}).then(function () {
|
||||
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';
|
||||
|
||||
if(response['error_key']){
|
||||
error_key = response['error_key'];
|
||||
}
|
||||
self.flash(I18n.t(error_key), 'error');
|
||||
|
||||
});
|
||||
}).then(() => {
|
||||
this.set('loading', false);
|
||||
this.flash(I18n.t('chat_integration.test_modal.success'), 'success');
|
||||
}.catch(popupAjaxError);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
import RestModel from 'discourse/models/rest';
|
||||
|
||||
export default RestModel.extend({
|
||||
|
||||
updateProperties() {
|
||||
var prop_names = ['data'];
|
||||
return this.getProperties(prop_names);
|
||||
return this.getProperties(['data']);
|
||||
},
|
||||
|
||||
createProperties() {
|
||||
var prop_names = ['provider','data'];
|
||||
return this.getProperties(prop_names);
|
||||
return this.getProperties(['provider','data']);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import RestModel from 'discourse/models/rest';
|
||||
import Category from 'discourse/models/category';
|
||||
import computed from "ember-addons/ember-computed-decorators";
|
||||
import { default as computed, observes } from "ember-addons/ember-computed-decorators";
|
||||
|
||||
export default RestModel.extend({
|
||||
available_filters: [
|
||||
@@ -22,21 +22,22 @@ export default RestModel.extend({
|
||||
type: 'normal',
|
||||
error_key: null,
|
||||
|
||||
@observes('type')
|
||||
removeUnneededInfo() {
|
||||
const type = this.get('type');
|
||||
|
||||
removeUnneededInfo: function(){
|
||||
const type=this.get('type');
|
||||
if(type==='normal'){
|
||||
if (type === 'normal') {
|
||||
this.set('group_id', null);
|
||||
}else{
|
||||
} else {
|
||||
this.set('category_id', null);
|
||||
}
|
||||
}.observes('type'),
|
||||
},
|
||||
|
||||
@computed('category_id')
|
||||
category(categoryId) {
|
||||
if (categoryId){
|
||||
return Category.findById(categoryId);
|
||||
}else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
@@ -47,13 +48,10 @@ export default RestModel.extend({
|
||||
},
|
||||
|
||||
updateProperties() {
|
||||
var prop_names = ['type','category_id','group_id','tags','filter'];
|
||||
return this.getProperties(prop_names);
|
||||
return this.getProperties(['type','category_id','group_id','tags','filter']);
|
||||
},
|
||||
|
||||
createProperties() {
|
||||
var prop_names = ['type','channel_id', 'category_id','group_id','tags','filter'];
|
||||
return this.getProperties(prop_names);
|
||||
return this.getProperties(['type','channel_id', 'category_id','group_id','tags','filter']);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
export default Discourse.Route.extend({
|
||||
afterModel(model) {
|
||||
|
||||
if(model.totalRows > 0){
|
||||
this.transitionTo('adminPlugins.chat.provider', model.get('firstObject').name);
|
||||
}
|
||||
afterModel(model) {
|
||||
if (model.totalRows > 0) {
|
||||
this.transitionTo('adminPlugins.chat.provider', model.get('firstObject').name);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -17,17 +17,18 @@ export default Discourse.Route.extend({
|
||||
return rule;
|
||||
}));
|
||||
});
|
||||
|
||||
return value;
|
||||
});
|
||||
},
|
||||
|
||||
serialize: function(model) {
|
||||
return { provider: model['provider'].get('id')};
|
||||
serialize(model) {
|
||||
return { provider: model['provider'].get('id') };
|
||||
},
|
||||
|
||||
actions: {
|
||||
closeModal: function(){
|
||||
if(this.get('controller.modalShowing')){
|
||||
closeModal() {
|
||||
if (this.get('controller.modalShowing')) {
|
||||
this.refresh();
|
||||
this.set('controller.modalShowing', false);
|
||||
}
|
||||
@@ -35,9 +36,8 @@ export default Discourse.Route.extend({
|
||||
return true; // Continue bubbling up, so the modal actually closes
|
||||
},
|
||||
|
||||
refresh: function(){
|
||||
refresh() {
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
export default Discourse.Route.extend({
|
||||
model() {
|
||||
model() {
|
||||
return this.store.findAll('provider');
|
||||
},
|
||||
|
||||
actions: {
|
||||
showSettings: function(){
|
||||
this.transitionTo('adminSiteSettingsCategory', 'plugins', {
|
||||
queryParams: { filter: 'chat_integration'}
|
||||
});
|
||||
}
|
||||
}
|
||||
showSettings() {
|
||||
this.transitionTo('adminSiteSettingsCategory', 'plugins', {
|
||||
queryParams: { filter: 'chat_integration'}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
<form {{action "save" on="submit"}}>
|
||||
<table>
|
||||
|
||||
<tr class="input">
|
||||
<tr class="input">
|
||||
<td class="label"><label for='provider'>{{i18n "chat_integration.edit_channel_modal.provider"}}</label></td>
|
||||
<td>
|
||||
{{i18n (concat 'chat_integration.provider.' model.channel.provider '.title')}}
|
||||
{{i18n (concat 'chat_integration.provider.' model.channel.provider '.title')}}
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="instructions">
|
||||
@@ -14,13 +14,13 @@
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
{{# each model.provider.channel_parameters as |param|}}
|
||||
{{#each model.provider.channel_parameters as |param|}}
|
||||
<tr class="input">
|
||||
<td class="label"><label for='param-{{param.key}}'>{{i18n (concat 'chat_integration.provider.' model.channel.provider '.param.' param.key '.title')}}</label></td>
|
||||
<td>
|
||||
{{text-field
|
||||
name=(concat 'param-' param.key)
|
||||
value=(mut (get model.channel.data param.key))
|
||||
{{text-field
|
||||
name=(concat 'param-' param.key)
|
||||
value=(mut (get model.channel.data param.key))
|
||||
}}
|
||||
|
||||
|
||||
@@ -37,13 +37,19 @@
|
||||
</table>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{{/d-modal-body}}
|
||||
|
||||
<div class="modal-footer">
|
||||
{{d-button id="save-channel"
|
||||
class='btn-primary btn-large'
|
||||
action="save"
|
||||
title="chat_integration.edit_channel_modal.save"
|
||||
label="chat_integration.edit_channel_modal.save"
|
||||
disabled=saveDisabled}}
|
||||
|
||||
{{d-button id="save_channel" class='btn-primary btn-large' action="save" title="chat_integration.edit_channel_modal.save" label="chat_integration.edit_channel_modal.save" disabled=saveDisabled}}
|
||||
|
||||
{{d-button class="btn-large" action="cancel" title="chat_integration.edit_channel_modal.cancel" label="chat_integration.edit_channel_modal.cancel"}}
|
||||
|
||||
</div>
|
||||
{{d-button class="btn-large"
|
||||
action="cancel"
|
||||
title="chat_integration.edit_channel_modal.cancel"
|
||||
label="chat_integration.edit_channel_modal.cancel"}}
|
||||
</div>
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
<form {{action "save" on="submit"}}>
|
||||
<table>
|
||||
|
||||
<tr class="input">
|
||||
<tr class="input">
|
||||
<td class="label"><label for='provider'>{{i18n "chat_integration.edit_rule_modal.provider"}}</label></td>
|
||||
<td>
|
||||
{{i18n (concat 'chat_integration.provider.' model.channel.provider '.title')}}
|
||||
{{i18n (concat 'chat_integration.provider.' model.channel.provider '.title')}}
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="instructions">
|
||||
@@ -57,7 +57,7 @@
|
||||
rootNoneLabel="chat_integration.all_categories"
|
||||
rootNone=true
|
||||
overrideWidths=false
|
||||
}}
|
||||
}}
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="instructions">
|
||||
@@ -95,13 +95,19 @@
|
||||
</table>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{{/d-modal-body}}
|
||||
|
||||
<div class="modal-footer">
|
||||
{{d-button id="save-rule"
|
||||
class='btn-primary btn-large'
|
||||
action="save"
|
||||
title="chat_integration.edit_rule_modal.save"
|
||||
label="chat_integration.edit_rule_modal.save"
|
||||
disabled=saveDisabled}}
|
||||
|
||||
{{d-button id="save_rule" class='btn-primary btn-large' action="save" title="chat_integration.edit_rule_modal.save" label="chat_integration.edit_rule_modal.save" disabled=saveDisabled}}
|
||||
|
||||
{{d-button class="btn-large" action="cancel" title="chat_integration.edit_rule_modal.cancel" label="chat_integration.edit_rule_modal.cancel"}}
|
||||
|
||||
</div>
|
||||
{{d-button class="btn-large"
|
||||
action="cancel"
|
||||
title="chat_integration.edit_rule_modal.cancel"
|
||||
label="chat_integration.edit_rule_modal.cancel"}}
|
||||
</div>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export default function() {
|
||||
this.route('transcript', {path: '/chat-transcript/:secret'});
|
||||
};
|
||||
this.route('transcript', { path: '/chat-transcript/:secret' });
|
||||
};
|
||||
|
||||
@@ -2,25 +2,22 @@ import { ajax } from 'discourse/lib/ajax';
|
||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
|
||||
export default Discourse.Route.extend({
|
||||
beforeModel: function(transition) {
|
||||
beforeModel(transition) {
|
||||
if (this.currentUser) {
|
||||
const secret = transition.params.transcript.secret;
|
||||
|
||||
if (Discourse.User.current()) {
|
||||
var secret = transition.params.transcript.secret;
|
||||
// User is logged in
|
||||
this.replaceWith('discovery.latest').then(e => {
|
||||
if (this.controllerFor('navigation/default').get('canCreateTopic')) {
|
||||
// User can create topic
|
||||
Ember.run.next(() => {
|
||||
ajax("/chat-transcript/"+secret).then(result => {
|
||||
ajax(`chat-transcript/${secret}`).then(result => {
|
||||
e.send('createNewTopicViaParams', null, result['content'], null, null, null);
|
||||
}, popupAjaxError);
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// User is not logged in
|
||||
this.session.set("shouldRedirectToUrl", window.location.href);
|
||||
this.replaceWith('login');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,27 +1,29 @@
|
||||
{{#if anyErrors}}
|
||||
<div class="error">
|
||||
<i class="fa fa-exclamation-triangle"></i>
|
||||
<span class="error-message">{{i18n "chat_integration.channels_with_errors"}}</span>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{#if anyErrors}}
|
||||
<div class="error">
|
||||
<i class="fa fa-exclamation-triangle"></i>
|
||||
<span class="error-message">{{i18n "chat_integration.channels_with_errors"}}</span>
|
||||
</div>
|
||||
{{/if}}
|
||||
{{#each model.channels as |channel|}}
|
||||
{{channel-details
|
||||
channel=channel
|
||||
provider=model.provider
|
||||
store=store
|
||||
refresh='refresh'
|
||||
edit='editChannel'
|
||||
test='testChannel'
|
||||
createRule='createRule'
|
||||
editRule='editRule'}}
|
||||
{{/each}}
|
||||
|
||||
{{# each model.channels as |channel|}}
|
||||
{{channel-details
|
||||
channel=channel
|
||||
provider=model.provider
|
||||
store=store
|
||||
refresh='refresh'
|
||||
edit='editChannel'
|
||||
test='testChannel'
|
||||
createRule='createRule'
|
||||
editRule='editRule'
|
||||
}}
|
||||
|
||||
{{/each}}
|
||||
|
||||
<div class="table-footer">
|
||||
<div class="pull-right">
|
||||
{{d-button id="create_channel" action="createChannel" actionParam=model.provider icon="plus" title="chat_integration.create_channel" label="chat_integration.create_channel"}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="table-footer">
|
||||
<div class="pull-right">
|
||||
{{d-button id="create-channel"
|
||||
action="createChannel"
|
||||
actionParam=model.provider
|
||||
icon="plus"
|
||||
title="chat_integration.create_channel"
|
||||
label="chat_integration.create_channel"}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,27 +1,25 @@
|
||||
<div id="admin-plugin-chat">
|
||||
|
||||
<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.' provider.name '.title')}}
|
||||
{{/each}}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="pull-right">
|
||||
{{#d-button
|
||||
action="showSettings"
|
||||
icon="gear"
|
||||
title="chat_integration.settings"
|
||||
label="chat_integration.settings"}}
|
||||
{{/d-button}}
|
||||
</div>
|
||||
</div>
|
||||
{{#if model.totalRows}}
|
||||
{{else}}
|
||||
{{i18n "chat_integration.no_providers"}}
|
||||
{{/if}}
|
||||
|
||||
{{outlet}}
|
||||
<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.' provider.name '.title')}}
|
||||
{{/each}}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="pull-right">
|
||||
{{#d-button
|
||||
action="showSettings"
|
||||
icon="gear"
|
||||
title="chat_integration.settings"
|
||||
label="chat_integration.settings"}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{#unless model.totalRows}}
|
||||
{{i18n "chat_integration.no_providers"}}
|
||||
{{/unless}}
|
||||
|
||||
{{outlet}}
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{{# each provider.channel_parameters as |param|}}
|
||||
{{#if param.hidden}}{{else}}
|
||||
{{#each provider.channel_parameters as |param|}}
|
||||
{{#unless param.hidden}}
|
||||
<span class='field-name'>{{i18n (concat 'chat_integration.provider.' channel.provider '.param.' param.key '.title')}}:</span>
|
||||
<span class='field-value'>{{get channel.data param.key}}</span>
|
||||
<span class='field-value'>{{get channel.data param.key}}</span>
|
||||
<br/>
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
{{/unless}}
|
||||
{{/each}}
|
||||
|
||||
@@ -6,44 +6,41 @@
|
||||
|
||||
{{d-button class='cancel' action="delete" actionParam=channel icon="trash" title="chat_integration.delete_channel" label="chat_integration.delete_channel"}}
|
||||
</div>
|
||||
|
||||
<span class='channel-title'>
|
||||
{{#if channel.error_key}}
|
||||
{{d-button action="showError" actionParam=channel.error_key class="delete btn-danger" icon="exclamation-triangle"}}
|
||||
{{/if}}
|
||||
|
||||
|
||||
{{channel-data provider=provider channel=channel}}
|
||||
|
||||
</span>
|
||||
|
||||
</div>
|
||||
|
||||
<div class='channel-body'>
|
||||
<table>
|
||||
<tr>
|
||||
{{!-- <th></th> --}}
|
||||
<th>{{i18n "chat_integration.rule_table.filter"}}</th>
|
||||
<table>
|
||||
<tr>
|
||||
<th>{{i18n "chat_integration.rule_table.filter"}}</th>
|
||||
<th>{{i18n "chat_integration.rule_table.category"}}</th>
|
||||
|
||||
<th>{{i18n "chat_integration.rule_table.category"}}</th>
|
||||
{{#if siteSettings.tagging_enabled}}
|
||||
<th>{{i18n "chat_integration.rule_table.tags"}}</th>
|
||||
{{/if}}
|
||||
|
||||
{{#if siteSettings.tagging_enabled}}
|
||||
<th>{{i18n "chat_integration.rule_table.tags"}}</th>
|
||||
{{/if}}
|
||||
<th></th>
|
||||
</tr>
|
||||
|
||||
|
||||
|
||||
<th></th>
|
||||
</tr>
|
||||
|
||||
|
||||
{{#each channel.rules as |rule|}}
|
||||
{{rule-row rule=rule edit='editRule' refresh='refresh'}}
|
||||
|
||||
{{/each}}
|
||||
|
||||
</table>
|
||||
{{#each channel.rules as |rule|}}
|
||||
{{rule-row rule=rule edit='editRule' refresh='refresh'}}
|
||||
{{/each}}
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class='channel-footer'>
|
||||
<div class='pull-right'>
|
||||
{{d-button action="createRule" actionParam=channel icon="plus" title="chat_integration.create_rule" label="chat_integration.create_rule"}}
|
||||
{{d-button action="createRule"
|
||||
actionParam=channel
|
||||
icon="plus"
|
||||
title="chat_integration.create_rule"
|
||||
label="chat_integration.create_rule"}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
|
||||
<td>
|
||||
{{rule.filterName}}
|
||||
</td>
|
||||
|
||||
|
||||
<td>
|
||||
{{#if isCategory}}
|
||||
{{#if rule.category}}
|
||||
@@ -31,5 +30,4 @@
|
||||
<td>
|
||||
{{d-button action="edit" actionParam=rule icon="pencil" class="edit" title="chat_integration.rule_table.edit_rule"}}
|
||||
{{d-button action="delete" actionParam=rule icon="trash-o" class="delete" title="chat_integration.rule_table.delete_rule"}}
|
||||
|
||||
</td>
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user