From 724879c6c8432b17da93211745fb2f73d18aef25 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 29 Jan 2018 03:44:50 +0100 Subject: [PATCH] Implemented issue #422 - Convert Chat into Ticket. --- .../controllers/agent_ticket_create.coffee | 2 +- .../javascripts/app/controllers/chat.coffee | 30 +++++++++++++++++-- .../views/customer_chat/chat_footer.jst.eco | 6 ++-- app/controllers/chat_sessions_controller.rb | 10 +++++++ config/routes/chat.rb | 1 - config/routes/chat_session.rb | 6 ++++ 6 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 app/controllers/chat_sessions_controller.rb create mode 100644 config/routes/chat_session.rb diff --git a/app/assets/javascripts/app/controllers/agent_ticket_create.coffee b/app/assets/javascripts/app/controllers/agent_ticket_create.coffee index f4682ad80..de43df318 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_create.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_create.coffee @@ -211,7 +211,7 @@ class App.TicketCreate extends App.Controller render: (template = {}) -> # get params - params = {} + params = @prefilledParams || {} if template && !_.isEmpty(template.options) params = template.options else if App.TaskManager.get(@task_key) && !_.isEmpty(App.TaskManager.get(@task_key).state) diff --git a/app/assets/javascripts/app/controllers/chat.coffee b/app/assets/javascripts/app/controllers/chat.coffee index 091c771b2..6d2481f31 100644 --- a/app/assets/javascripts/app/controllers/chat.coffee +++ b/app/assets/javascripts/app/controllers/chat.coffee @@ -163,9 +163,10 @@ class App.CustomerChat extends App.Controller @title 'Customer Chat', true @navupdate '#customer_chat' - if params.session_id && App.ChatSession.exists(params.session_id) - session = App.ChatSession.find(params.session_id) - @addChat(session) + if params.session_id + callback = (session) => + @addChat(session) + App.ChatSession.full(params.session_id, callback) @navigate '#customer_chat' active: (state) => @@ -342,6 +343,7 @@ class ChatWindow extends App.Controller 'click .js-disconnect': 'disconnect' 'click .js-scrollHint': 'onScrollHintClick' 'click .js-info': 'toggleMeta' + 'click .js-createTicket': 'ticketCreate' 'submit .js-metaForm': 'sendMetaForm' elements: @@ -764,6 +766,28 @@ class ChatWindow extends App.Controller else if showHint @showScrollHint() + ticketCreate: (e) => + e.preventDefault() + + id = Math.floor( Math.random() * 99999 ) + @navigate "#ticket/create/id/#{id}" + + # cleanup params + fqdn = App.Config.get('fqdn') + http_type = App.Config.get('http_type') + clean_params = + id: id + prefilledParams: + body: "#{http_type}://#{fqdn}#{@session.uiUrl()}" + title: 'Chat' + + App.TaskManager.execute( + key: "TicketCreateScreen-#{id}" + controller: 'TicketCreate' + params: clean_params + show: true + ) + class Setting extends App.ControllerModal buttonClose: true buttonCancel: true diff --git a/app/assets/javascripts/app/views/customer_chat/chat_footer.jst.eco b/app/assets/javascripts/app/views/customer_chat/chat_footer.jst.eco index 9a66a4ee3..351904cca 100644 --- a/app/assets/javascripts/app/views/customer_chat/chat_footer.jst.eco +++ b/app/assets/javascripts/app/views/customer_chat/chat_footer.jst.eco @@ -1,5 +1,3 @@ - \ No newline at end of file +
<%- @T('Turn chat into ticket') %>
+ \ No newline at end of file diff --git a/app/controllers/chat_sessions_controller.rb b/app/controllers/chat_sessions_controller.rb new file mode 100644 index 000000000..e6628b304 --- /dev/null +++ b/app/controllers/chat_sessions_controller.rb @@ -0,0 +1,10 @@ +# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ + +class ChatSessionsController < ApplicationController + prepend_before_action { authentication_check(permission: 'chat.agent') } + + def show + model_show_render(Chat::Session, params) + end + +end diff --git a/config/routes/chat.rb b/config/routes/chat.rb index 6de916036..254ad0da5 100644 --- a/config/routes/chat.rb +++ b/config/routes/chat.rb @@ -1,7 +1,6 @@ Zammad::Application.routes.draw do api_path = Rails.configuration.api_path - # groups match api_path + '/chats', to: 'chats#index', via: :get match api_path + '/chats/:id', to: 'chats#show', via: :get match api_path + '/chats', to: 'chats#create', via: :post diff --git a/config/routes/chat_session.rb b/config/routes/chat_session.rb new file mode 100644 index 000000000..c297d7449 --- /dev/null +++ b/config/routes/chat_session.rb @@ -0,0 +1,6 @@ +Zammad::Application.routes.draw do + api_path = Rails.configuration.api_path + + match api_path + '/chat_sessions/:id', to: 'chat_sessions#show', via: :get + +end