2014-02-03 19:24:49 +00:00
|
|
|
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
2013-06-12 15:59:58 +00:00
|
|
|
|
2013-08-21 18:35:22 +00:00
|
|
|
require 'ticket/overviews'
|
|
|
|
|
2012-04-10 14:06:46 +00:00
|
|
|
class TicketOverviewsController < ApplicationController
|
|
|
|
before_filter :authentication_check
|
|
|
|
|
2013-08-19 06:29:49 +00:00
|
|
|
# GET /api/v1/ticket_overviews
|
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]
|
2013-08-19 10:21:31 +00:00
|
|
|
result = Ticket::Overviews.list(
|
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]
|
2013-08-19 10:21:31 +00:00
|
|
|
overview = Ticket::Overviews.list(
|
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
|
2013-08-19 10:21:31 +00:00
|
|
|
overview = Ticket::Overviews.list(
|
2012-11-26 23:22:52 +00:00
|
|
|
:view => params[:view],
|
2013-08-19 06:29:49 +00:00
|
|
|
:current_user => current_user,
|
2012-11-26 23:22:52 +00:00
|
|
|
: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
|
2013-09-21 22:50:23 +00:00
|
|
|
assets = { User.to_app_model => {} }
|
2013-08-19 06:29:49 +00:00
|
|
|
overview[:ticket_ids].each {|ticket_id|
|
|
|
|
ticket = Ticket.lookup( :id => ticket_id )
|
|
|
|
assets = ticket.assets(assets)
|
2012-04-10 14:06:46 +00:00
|
|
|
}
|
|
|
|
|
2012-09-13 00:43:45 +00:00
|
|
|
# get groups
|
|
|
|
group_ids = []
|
|
|
|
Group.where( :active => true ).each { |group|
|
|
|
|
group_ids.push group.id
|
|
|
|
}
|
|
|
|
agents = {}
|
2013-08-17 21:10:11 +00:00
|
|
|
Ticket::ScreenOptions.agents.each { |user|
|
2012-09-13 00:43:45 +00:00
|
|
|
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
|
2013-09-21 22:50:23 +00:00
|
|
|
if !assets[ User.to_app_model ][user.id]
|
|
|
|
assets[ User.to_app_model ][user.id] = User.user_data_full(user.id)
|
2013-06-12 15:59:58 +00:00
|
|
|
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],
|
2013-08-19 06:29:49 +00:00
|
|
|
:ticket_ids => overview[:ticket_ids],
|
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
|
|
|
},
|
2013-08-19 06:29:49 +00:00
|
|
|
:assets => assets,
|
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
|