Browse Source

Added browser tests for customer chat.

Martin Edenhofer 9 years ago
parent
commit
7831f1c1f8

+ 3 - 1
app/assets/javascripts/app/controllers/_channel/chat.coffee

@@ -24,7 +24,7 @@ class App.ChannelChat extends App.Controller
     '.js-code': 'code'
     '.js-palette': 'palette'
     '.js-color': 'colorField'
-    '.js-chatSetting': 'chatSetting'
+    '.js-chatSetting input': 'chatSetting'
 
   apiOptions: [
     {
@@ -279,6 +279,8 @@ class App.ChannelChat extends App.Controller
     setting.state_current = { value: value }
     setting.save()
     @Config.set('chat', value)
+    delay = -> App.Event.trigger('ui:rerender')
+    @delay(delay, 200)
 
   updateParams: =>
     quote = (value) ->

+ 1 - 1
app/assets/javascripts/app/controllers/_channel/form.coffee

@@ -7,7 +7,7 @@ class App.ChannelForm extends App.Controller
 
   elements:
     '.js-paramsBlock': 'paramsBlock'
-    '.js-formSetting': 'formSetting'
+    '.js-formSetting input': 'formSetting'
 
   constructor: ->
     super

+ 7 - 9
app/assets/javascripts/app/controllers/chat.coffee

@@ -11,14 +11,6 @@ class App.CustomerChat extends App.Controller
   constructor: ->
     super
 
-    # access check
-    if !@isRole('Chat')
-      @renderScreenUnauthorized(objectName: 'Chat')
-      return
-    if !@Config.get('chat')
-      @renderScreenError(detail: 'Feature disabled!')
-      return
-
     @chatWindows = {}
     @maxChatWindows = 4
     preferences = @Session.get('preferences')
@@ -49,7 +41,6 @@ class App.CustomerChat extends App.Controller
 
     # add new chat window
     @bind('chat_session_start', (data) =>
-      console.log('chat_session_start', data)
       if data.session
         @addChat(data.session)
     )
@@ -78,6 +69,13 @@ class App.CustomerChat extends App.Controller
     )
 
   render: ->
+    if !@isRole('Chat')
+      @renderScreenUnauthorized(objectName: 'Chat')
+      return
+    if !@Config.get('chat')
+      @renderScreenError(detail: 'Feature disabled!')
+      return
+
     @html App.view('customer_chat/index')()
 
   show: (params) =>

+ 1 - 1
app/assets/javascripts/app/controllers/navigation.coffee

@@ -82,7 +82,7 @@ class App.Navigation extends App.ControllerWidgetPermanent
     )
 
     # bind on switch changes and execute it on controller
-    @$('.js-menu .js-switch').bind('change', (e) ->
+    @$('.js-menu .js-switch input').bind('change', (e) ->
       val = $(e.target).prop('checked')
       key = $(e.target).closest('.menu-item').data('key')
       return if !key

+ 2 - 2
app/assets/javascripts/app/views/channel/chat.jst.eco

@@ -8,8 +8,8 @@
 
   <h2><%- @T('Enable') %>/<%- @T('Disable') %></h2>
   <form>
-    <div class="zammad-switch">
-       <input name="chat" type="checkbox" id="setting-chat" class="js-chatSetting" <% if @chatSetting: %>checked<% end %>>
+    <div class="zammad-switch js-chatSetting">
+       <input name="chat" type="checkbox" id="setting-chat" <% if @chatSetting: %>checked<% end %>>
        <label for="setting-chat"></label>
     </div>
   </form>

+ 2 - 2
app/assets/javascripts/app/views/channel/form.jst.eco

@@ -8,8 +8,8 @@
 
   <h2><%- @T('Enable') %>/<%- @T('Disable') %></h2>
   <form>
-    <div class="zammad-switch">
-       <input name="form_ticket_create" type="checkbox" id="setting-form" class="js-formSetting" <% if @formSetting: %>checked<% end %>>
+    <div class="zammad-switch js-formSetting">
+       <input name="form_ticket_create" type="checkbox" id="setting-form" <% if @formSetting: %>checked<% end %>>
        <label for="setting-form"></label>
     </div>
   </form>

+ 2 - 2
app/assets/javascripts/app/views/navigation/menu.jst.eco

@@ -30,8 +30,8 @@
       <span class="counter badge badge--big"><%= item.counter %></span>
     <% end %>
     <% if item.switch isnt undefined: %>
-      <span class="zammad-switch zammad-switch--dark zammad-switch--small zammad-switch--green">
-         <input type="checkbox" id="<%- item.class %>-switch" class="js-switch" <% if item.switch: %>checked<% end %>>
+      <span class="zammad-switch zammad-switch--dark zammad-switch--small zammad-switch--green js-switch">
+         <input type="checkbox" id="<%- item.class %>-switch" <% if item.switch: %>checked<% end %>>
          <label for="<%- item.class %>-switch"></label>
       </span>
     <% end %>

+ 12 - 0
app/models/chat/session.rb

@@ -18,6 +18,18 @@ class Chat::Session < ApplicationModel
     preferences[:participants]
   end
 
+  def recipients_active?
+    return true if !preferences
+    return true if !preferences[:participants]
+    count = 0
+    preferences[:participants].each {|client_id|
+      next if !Sessions.session_exists?(client_id)
+      count += 1
+    }
+    return true if count >= 2
+    false
+  end
+
   def send_to_recipients(message, ignore_client_id = nil)
     preferences[:participants].each {|local_client_id|
       next if local_client_id == ignore_client_id

+ 36 - 0
app/models/observer/chat/leave/background_job.rb

@@ -0,0 +1,36 @@
+# encoding: utf-8
+
+class Observer::Chat::Leave::BackgroundJob
+  def initialize(chat_session_id, client_id, session)
+    @chat_session_id = chat_session_id
+    @client_id = client_id
+    @session = session
+  end
+
+  def perform
+
+    # check if customer has permanently left the conversation
+    chat_session = Chat::Session.find_by(id: @chat_session_id)
+    return if !chat_session
+    return if chat_session.recipients_active?
+    chat_session.state = 'closed'
+    chat_session.save
+
+    realname = 'Anonymous'
+    if @session && @session['id']
+      realname = User.lookup(id: @session['id']).fullname
+    end
+
+    # notifiy participients
+    message = {
+      event: 'chat_session_left',
+      data: {
+        realname: realname,
+        session_id: chat_session.session_id,
+      },
+    }
+    chat_session.send_to_recipients(message, @client_id)
+
+  end
+
+end

+ 5 - 1
app/models/setting.rb

@@ -16,7 +16,11 @@ class Setting < ApplicationModel
   @@current        = {} # rubocop:disable Style/ClassVars
   @@change_id      = nil # rubocop:disable Style/ClassVars
   @@lookup_at      = nil # rubocop:disable Style/ClassVars
-  @@lookup_timeout = 2.minutes # rubocop:disable Style/ClassVars
+  if ENV['ZAMMAD_SETTING_TTL']
+    @@lookup_timeout = ENV['ZAMMAD_SETTING_TTL'].to_i # rubocop:disable Style/ClassVars
+  else
+    @@lookup_timeout = 2.minutes # rubocop:disable Style/ClassVars
+  end
 
 =begin
 

Some files were not shown because too many files changed in this diff