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
|
2015-05-07 11:23:55 +00:00
|
|
|
before_action :authentication_check
|
2012-04-10 14:06:46 +00:00
|
|
|
|
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(
|
2015-04-27 13:42:53 +00:00
|
|
|
current_user: current_user,
|
2012-07-20 11:23:09 +00:00
|
|
|
)
|
2015-04-27 13:42:53 +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(
|
2015-04-27 13:42:53 +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|
|
2015-04-27 13:42:53 +00:00
|
|
|
data = { id: ticket_id }
|
2012-07-20 13:47:04 +00:00
|
|
|
tickets.push data
|
|
|
|
}
|
|
|
|
|
|
|
|
# return result
|
2015-04-27 13:42:53 +00:00
|
|
|
render json: {
|
|
|
|
overview: overview[:overview],
|
|
|
|
tickets: tickets,
|
|
|
|
tickets_count: overview[:tickets_count],
|
2012-07-20 13:47:04 +00:00
|
|
|
}
|
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(
|
2015-04-27 13:42:53 +00:00
|
|
|
view: params[:view],
|
|
|
|
current_user: current_user,
|
|
|
|
array: true,
|
2012-07-20 11:23:09 +00:00
|
|
|
)
|
2012-11-26 23:22:52 +00:00
|
|
|
if !overview
|
2015-07-03 15:18:01 +00:00
|
|
|
render json: { error: "No such view #{params[:view]}!" }, status: :unprocessable_entity
|
2012-11-26 23:22:52 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-04-10 14:06:46 +00:00
|
|
|
# get related users
|
2014-08-02 22:06:51 +00:00
|
|
|
assets = {}
|
2013-08-19 06:29:49 +00:00
|
|
|
overview[:ticket_ids].each {|ticket_id|
|
2015-04-27 13:42:53 +00:00
|
|
|
ticket = Ticket.lookup( id: ticket_id )
|
2013-08-19 06:29:49 +00:00
|
|
|
assets = ticket.assets(assets)
|
2012-04-10 14:06:46 +00:00
|
|
|
}
|
|
|
|
|
2012-09-13 00:43:45 +00:00
|
|
|
# get groups
|
|
|
|
group_ids = []
|
2015-04-27 13:42:53 +00:00
|
|
|
Group.where( active: true ).each { |group|
|
2012-09-13 00:43:45 +00:00
|
|
|
group_ids.push group.id
|
|
|
|
}
|
|
|
|
agents = {}
|
2015-07-25 14:36:16 +00:00
|
|
|
User.of_role('Agent').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
|
2014-08-02 22:06:51 +00:00
|
|
|
assets = user.assets( assets )
|
2013-06-12 15:59:58 +00:00
|
|
|
}
|
2012-04-10 14:06:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# return result
|
2015-04-27 13:42:53 +00:00
|
|
|
render json: {
|
|
|
|
view: params[:view],
|
|
|
|
overview: overview[:overview],
|
|
|
|
ticket_ids: overview[:ticket_ids],
|
|
|
|
tickets_count: overview[:tickets_count],
|
|
|
|
bulk: {
|
|
|
|
group_id__owner_id: groups_users,
|
2012-04-14 16:47:37 +00:00
|
|
|
},
|
2015-04-27 13:42:53 +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
|