From 4115f1691d6a94330d66095f2bd37131a852f99a Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 19 Aug 2013 10:21:52 +0200 Subject: [PATCH] Moved ticket merge to new assets feature. --- .../controllers/agent_ticket_merge.js.coffee | 26 +++++++++--------- app/controllers/tickets_controller.rb | 27 ++++++++++++++----- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee index 6daae0830..8c5c4fee7 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_merge.js.coffee @@ -16,25 +16,23 @@ class App.TicketMerge extends App.ControllerModal processData: true, success: (data, status, xhr) => - if data.customer - App.Collection.load( type: 'Ticket', data: data.customer.tickets ) - App.Collection.load( type: 'User', data: data.customer.users ) + # load collections + App.Event.trigger 'loadAssets', data.assets - if data.recent - App.Collection.load( type: 'Ticket', data: data.recent.tickets ) - App.Collection.load( type: 'User', data: data.recent.users ) + @ticket_ids_by_customer = data.ticket_ids_by_customer + @ticket_ids_recent_viewed = data.ticket_ids_recent_viewed - @render( data ) + @render() ) - render: (data) -> + render: -> @html App.view('agent_ticket_merge')() list = [] - for t in data.customer.tickets - if t.id isnt @ticket_id - ticketItem = App.Ticket.retrieve( t.id ) + for ticket_id in @ticket_ids_by_customer + if ticket_id isnt @ticket_id + ticketItem = App.Ticket.retrieve( ticket_id ) list.push ticketItem new App.ControllerTable( el: @el.find('#ticket-merge-customer-tickets'), @@ -59,9 +57,9 @@ class App.TicketMerge extends App.ControllerModal ) list = [] - for t in data.recent.tickets - if t.id isnt @ticket_id - ticketItem = App.Ticket.retrieve( t.id ) + for ticket_id in @ticket_ids_recent_viewed + if ticket_id isnt @ticket_id + ticketItem = App.Ticket.retrieve( ticket_id ) list.push ticketItem new App.ControllerTable( el: @el.find('#ticket-merge-recent-tickets'), diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index d8f991ee4..ecd5a144f 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -182,7 +182,10 @@ class TicketsController < ApplicationController # GET /api/v1/ticket_merge_list/1 def ticket_merge_list - ticket = Ticket.find( params[:ticket_id] ) + ticket = Ticket.find( params[:ticket_id] ) + assets = ticket.assets({}) + + # open tickets by customer ticket_list = Ticket.where( :customer_id => ticket.customer_id, :ticket_state_id => Ticket::State.by_category( 'open' ) @@ -191,19 +194,29 @@ class TicketsController < ApplicationController .order('created_at DESC') .limit(6) - # get related users - assets = {} + # get related assets + ticket_ids_by_customer = [] ticket_list.each {|ticket| - ticket = Ticket.lookup( :id => ticket.id ) + ticket_ids_by_customer.push ticket.id assets = ticket.assets(assets) } - recent_viewed = RecentView.list_fulldata( current_user, 8 ) + + ticket_ids_recent_viewed = [] + ticket_recent_view = RecentView.list( current_user, 8 ) + ticket_recent_view.each {|item| + if item['recent_view_object'] == 'Ticket' + ticket_ids_recent_viewed.push item['o_id'] + ticket = Ticket.find( item['o_id'] ) + assets = ticket.assets(assets) + end + } # return result render :json => { - :customer => assets, - :recent => recent_viewed + :assets => assets, + :ticket_ids_by_customer => ticket_ids_by_customer, + :ticket_ids_recent_viewed => ticket_ids_recent_viewed, } end