2012-08-21 10:28:41 +00:00
|
|
|
class LinksController < ApplicationController
|
|
|
|
before_filter :authentication_check
|
|
|
|
|
2012-11-18 10:51:54 +00:00
|
|
|
# GET /api/links
|
2012-08-21 10:28:41 +00:00
|
|
|
def index
|
|
|
|
links = Link.list(
|
|
|
|
:link_object => params[:link_object],
|
|
|
|
:link_object_value => params[:link_object_value],
|
|
|
|
)
|
|
|
|
|
|
|
|
#
|
|
|
|
tickets = []
|
|
|
|
users = {}
|
|
|
|
link_list = []
|
|
|
|
links.each { |item|
|
|
|
|
link_list.push item
|
|
|
|
if item['link_object'] == 'Ticket'
|
|
|
|
data = Ticket.full_data( item['link_object_value'] )
|
|
|
|
tickets.push data
|
|
|
|
if !users[ data['owner_id'] ]
|
|
|
|
users[ data['owner_id'] ] = User.user_data_full( data['owner_id'] )
|
|
|
|
end
|
|
|
|
if !users[ data['customer_id'] ]
|
|
|
|
users[ data['customer_id'] ] = User.user_data_full( data['customer_id'] )
|
|
|
|
end
|
|
|
|
if !users[ data['created_by_id'] ]
|
|
|
|
users[ data['created_by_id'] ] = User.user_data_full( data['created_by_id'] )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
# return result
|
|
|
|
render :json => {
|
|
|
|
:links => link_list,
|
|
|
|
:tickets => tickets,
|
|
|
|
:users => users,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2012-11-18 10:51:54 +00:00
|
|
|
# POST /api/links/add
|
2012-08-21 10:28:41 +00:00
|
|
|
def add
|
2012-08-24 18:54:57 +00:00
|
|
|
|
2012-08-23 22:08:27 +00:00
|
|
|
# lookup object id
|
2012-08-24 19:40:22 +00:00
|
|
|
object_id = Ticket.where( :number => params[:link_object_source_number] ).first.id
|
2012-08-21 10:28:41 +00:00
|
|
|
link = Link.add(
|
|
|
|
:link_type => params[:link_type],
|
|
|
|
:link_object_target => params[:link_object_target],
|
2012-08-24 19:40:22 +00:00
|
|
|
:link_object_target_value => params[:link_object_target_value],
|
|
|
|
:link_object_source => params[:link_object_source],
|
|
|
|
:link_object_source_value => object_id
|
2012-08-21 10:28:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if link
|
|
|
|
render :json => link, :status => :created
|
|
|
|
else
|
|
|
|
render :json => link.errors, :status => :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-18 10:51:54 +00:00
|
|
|
# DELETE /api/links/remove
|
2012-08-23 22:08:27 +00:00
|
|
|
def remove
|
|
|
|
link = Link.remove(params)
|
2012-08-21 10:28:41 +00:00
|
|
|
|
2012-08-23 22:08:27 +00:00
|
|
|
if link
|
|
|
|
render :json => link, :status => :created
|
2012-08-21 10:28:41 +00:00
|
|
|
else
|
2012-08-23 22:08:27 +00:00
|
|
|
render :json => link.errors, :status => :unprocessable_entity
|
2012-08-21 10:28:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|