2013-06-12 15:59:58 +00:00
|
|
|
# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2012-04-10 14:06:46 +00:00
|
|
|
class TicketOverviewsController < ApplicationController
|
|
|
|
before_filter :authentication_check
|
|
|
|
|
2012-12-27 20:17:33 +00:00
|
|
|
# GET /api/tickets
|
2012-04-10 14:06:46 +00:00
|
|
|
def show
|
|
|
|
|
2012-07-20 11:23:09 +00:00
|
|
|
# get navbar overview data
|
|
|
|
if !params[:view]
|
|
|
|
result = Ticket.overview(
|
2012-09-04 21:28:49 +00:00
|
|
|
:current_user => current_user,
|
2012-07-20 11:23:09 +00:00
|
|
|
)
|
2012-04-14 16:47:37 +00:00
|
|
|
render :json => result
|
2012-04-10 14:06:46 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-07-20 11:23:09 +00:00
|
|
|
# get real overview data
|
2012-07-20 13:47:04 +00:00
|
|
|
if params[:array]
|
|
|
|
overview = Ticket.overview(
|
2012-09-04 21:28:49 +00:00
|
|
|
:view => params[:view],
|
|
|
|
:current_user => current_user,
|
|
|
|
:array => true,
|
2013-06-12 15:59:58 +00:00
|
|
|
)
|
2012-07-20 13:47:04 +00:00
|
|
|
tickets = []
|
2012-11-26 23:22:52 +00:00
|
|
|
overview[:tickets].each {|ticket_id|
|
|
|
|
data = { :id => ticket_id }
|
2012-07-20 13:47:04 +00:00
|
|
|
tickets.push data
|
|
|
|
}
|
|
|
|
|
|
|
|
# return result
|
|
|
|
render :json => {
|
|
|
|
:overview => overview[:overview],
|
|
|
|
:tickets => tickets,
|
|
|
|
:tickets_count => overview[:tickets_count],
|
|
|
|
}
|
2012-11-26 23:22:52 +00:00
|
|
|
return
|
2012-07-20 13:47:04 +00:00
|
|
|
end
|
2012-07-20 11:23:09 +00:00
|
|
|
overview = Ticket.overview(
|
2012-11-26 23:22:52 +00:00
|
|
|
:view => params[:view],
|
2013-06-12 15:59:58 +00:00
|
|
|
# :view_mode => params[:view_mode],
|
2012-11-26 23:22:52 +00:00
|
|
|
:current_user => User.find( current_user.id ),
|
|
|
|
:array => true,
|
2012-07-20 11:23:09 +00:00
|
|
|
)
|
2012-11-26 23:22:52 +00:00
|
|
|
if !overview
|
|
|
|
render :json => { :error => "No such view #{ params[:view] }!" }, :status => :unprocessable_entity
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-04-10 14:06:46 +00:00
|
|
|
# get related users
|
|
|
|
users = {}
|
2012-07-20 11:23:09 +00:00
|
|
|
tickets = []
|
2012-11-26 23:22:52 +00:00
|
|
|
overview[:ticket_list].each {|ticket_id|
|
2013-01-01 20:29:26 +00:00
|
|
|
data = Ticket.lookup( :id => ticket_id )
|
2012-07-29 20:25:31 +00:00
|
|
|
tickets.push data
|
|
|
|
if !users[ data['owner_id'] ]
|
|
|
|
users[ data['owner_id'] ] = User.user_data_full( data['owner_id'] )
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
2012-07-29 20:25:31 +00:00
|
|
|
if !users[ data['customer_id'] ]
|
|
|
|
users[ data['customer_id'] ] = User.user_data_full( data['customer_id'] )
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
2012-07-29 20:25:31 +00:00
|
|
|
if !users[ data['created_by_id'] ]
|
|
|
|
users[ data['created_by_id'] ] = User.user_data_full( data['created_by_id'] )
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2012-09-13 00:43:45 +00:00
|
|
|
# get groups
|
|
|
|
group_ids = []
|
|
|
|
Group.where( :active => true ).each { |group|
|
|
|
|
group_ids.push group.id
|
|
|
|
}
|
|
|
|
agents = {}
|
|
|
|
Ticket.agents.each { |user|
|
|
|
|
agents[ user.id ] = 1
|
|
|
|
}
|
|
|
|
groups_users = {}
|
|
|
|
group_ids.each {|group_id|
|
2013-06-12 15:59:58 +00:00
|
|
|
groups_users[ group_id ] = []
|
|
|
|
Group.find(group_id).users.each {|user|
|
|
|
|
next if !agents[ user.id ]
|
|
|
|
groups_users[ group_id ].push user.id
|
|
|
|
if !users[user.id]
|
|
|
|
users[user.id] = User.user_data_full(user.id)
|
|
|
|
end
|
|
|
|
}
|
2012-04-10 14:06:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# return result
|
2012-04-14 16:47:37 +00:00
|
|
|
render :json => {
|
2012-07-20 11:23:09 +00:00
|
|
|
:overview => overview[:overview],
|
2012-11-26 23:22:52 +00:00
|
|
|
:ticket_list => overview[:ticket_list],
|
2012-07-20 11:23:09 +00:00
|
|
|
:tickets_count => overview[:tickets_count],
|
2012-04-14 16:47:37 +00:00
|
|
|
:bulk => {
|
2012-09-13 00:43:45 +00:00
|
|
|
:group_id__owner_id => groups_users,
|
2012-04-14 16:47:37 +00:00
|
|
|
},
|
2012-11-26 23:22:52 +00:00
|
|
|
:collections => {
|
|
|
|
:users => users,
|
|
|
|
:tickets => tickets,
|
|
|
|
},
|
2012-04-14 16:47:37 +00:00
|
|
|
}
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
|
2013-06-12 15:59:58 +00:00
|
|
|
end
|