2012-04-10 14:06:46 +00:00
|
|
|
class TicketOverviewsController < ApplicationController
|
|
|
|
before_filter :authentication_check
|
|
|
|
|
|
|
|
# GET /tickets
|
|
|
|
def show
|
2012-05-11 09:21:41 +00:00
|
|
|
#sleep 2
|
2012-04-10 14:06:46 +00:00
|
|
|
|
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,
|
2012-07-20 13:47:04 +00:00
|
|
|
)
|
|
|
|
tickets = []
|
|
|
|
overview[:tickets].each {|ticket|
|
|
|
|
data = { :id => ticket.id }
|
|
|
|
tickets.push data
|
|
|
|
}
|
|
|
|
|
|
|
|
# return result
|
|
|
|
render :json => {
|
|
|
|
:overview => overview[:overview],
|
|
|
|
:tickets => tickets,
|
|
|
|
:tickets_count => overview[:tickets_count],
|
|
|
|
}
|
|
|
|
return
|
|
|
|
end
|
2012-07-20 11:23:09 +00:00
|
|
|
overview = Ticket.overview(
|
|
|
|
:view => params[:view],
|
|
|
|
:view_mode => params[:view_mode],
|
|
|
|
:current_user_id => current_user.id,
|
|
|
|
:start_page => params[:start_page],
|
2012-07-29 20:25:31 +00:00
|
|
|
:array => true,
|
2012-07-20 11:23:09 +00:00
|
|
|
)
|
|
|
|
|
2012-04-10 14:06:46 +00:00
|
|
|
# get related users
|
|
|
|
users = {}
|
2012-07-20 11:23:09 +00:00
|
|
|
tickets = []
|
|
|
|
overview[:tickets].each {|ticket|
|
2012-07-29 20:25:31 +00:00
|
|
|
data = Ticket.full_data(ticket.id)
|
|
|
|
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|
|
|
|
|
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-04-14 16:47:37 +00:00
|
|
|
:tickets => tickets,
|
2012-07-20 11:23:09 +00:00
|
|
|
:tickets_count => overview[:tickets_count],
|
2012-04-14 16:47:37 +00:00
|
|
|
:users => users,
|
|
|
|
:bulk => {
|
2012-09-13 00:43:45 +00:00
|
|
|
:group_id__owner_id => groups_users,
|
2012-04-14 16:47:37 +00:00
|
|
|
},
|
|
|
|
}
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|