trabajo-afectivo/app/controllers/ticket_overviews_controller.rb

104 lines
2.7 KiB
Ruby
Raw Normal View History

# 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
# get navbar overview data
if !params[:view]
result = Ticket.overview(
2012-09-04 21:28:49 +00:00
:current_user => current_user,
)
2012-04-14 16:47:37 +00:00
render :json => result
2012-04-10 14:06:46 +00:00
return
end
# get real overview data
if params[:array]
overview = Ticket.overview(
2012-09-04 21:28:49 +00:00
:view => params[:view],
:current_user => current_user,
:array => true,
)
tickets = []
2012-11-26 23:22:52 +00:00
overview[:tickets].each {|ticket_id|
data = { :id => ticket_id }
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
end
overview = Ticket.overview(
2012-11-26 23:22:52 +00:00
:view => params[:view],
# :view_mode => params[:view_mode],
2012-11-26 23:22:52 +00:00
:current_user => User.find( current_user.id ),
:array => true,
)
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 = {}
tickets = []
2012-11-26 23:22:52 +00:00
overview[:ticket_list].each {|ticket_id|
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|
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 => {
:overview => overview[:overview],
2012-11-26 23:22:52 +00:00
:ticket_list => overview[:ticket_list],
: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
end