Moved strip of meta data for small JSON stream from model to controller. History.list will return real objects now.
This commit is contained in:
parent
9e20b7d995
commit
d1c69a6170
3 changed files with 53 additions and 58 deletions
|
@ -153,13 +153,42 @@ class TicketsController < ApplicationController
|
||||||
users = {}
|
users = {}
|
||||||
users[ ticket.owner_id ] = User.user_data_full( ticket.owner_id )
|
users[ ticket.owner_id ] = User.user_data_full( ticket.owner_id )
|
||||||
users[ ticket.customer_id ] = User.user_data_full( ticket.customer_id )
|
users[ ticket.customer_id ] = User.user_data_full( ticket.customer_id )
|
||||||
|
|
||||||
|
# get only needed data to send to browser
|
||||||
|
history_list = []
|
||||||
history.each do |item|
|
history.each do |item|
|
||||||
users[ item['created_by_id'] ] = User.user_data_full( item['created_by_id'] )
|
users[ item[:created_by_id] ] = User.user_data_full( item[:created_by_id] )
|
||||||
|
item_tmp = item.attributes
|
||||||
if item['history_object'] == 'Ticket::Article'
|
if item['history_object'] == 'Ticket::Article'
|
||||||
item['type'] = 'Article ' + item['type'].to_s
|
item_temp['type'] = 'Article ' + item['type'].to_s
|
||||||
else
|
else
|
||||||
item['type'] = 'Ticket ' + item['type'].to_s
|
item_tmp['type'] = 'Ticket ' + item['type'].to_s
|
||||||
end
|
end
|
||||||
|
item_tmp['history_type'] = item.history_type.name
|
||||||
|
item_tmp['history_object'] = item.history_object.name
|
||||||
|
if item.history_attribute
|
||||||
|
item_tmp['history_attribute'] = item.history_attribute.name
|
||||||
|
end
|
||||||
|
item_tmp.delete( 'history_attribute_id' )
|
||||||
|
item_tmp.delete( 'history_object_id' )
|
||||||
|
item_tmp.delete( 'history_type_id' )
|
||||||
|
item_tmp.delete( 'o_id' )
|
||||||
|
item_tmp.delete( 'updated_at' )
|
||||||
|
if item_tmp['id_to'] == nil && item_tmp['id_from'] == nil
|
||||||
|
item_tmp.delete( 'id_to' )
|
||||||
|
item_tmp.delete( 'id_from' )
|
||||||
|
end
|
||||||
|
if item_tmp['value_to'] == nil && item_tmp['value_from'] == nil
|
||||||
|
item_tmp.delete( 'value_to' )
|
||||||
|
item_tmp.delete( 'value_from' )
|
||||||
|
end
|
||||||
|
if item_tmp['related_history_object_id'] == nil
|
||||||
|
item_tmp.delete( 'related_history_object_id' )
|
||||||
|
end
|
||||||
|
if item_tmp['related_o_id'] == nil
|
||||||
|
item_tmp.delete( 'related_o_id' )
|
||||||
|
end
|
||||||
|
history_list.push item_tmp
|
||||||
end
|
end
|
||||||
|
|
||||||
# fetch meta relations
|
# fetch meta relations
|
||||||
|
@ -171,7 +200,7 @@ class TicketsController < ApplicationController
|
||||||
render :json => {
|
render :json => {
|
||||||
:ticket => ticket,
|
:ticket => ticket,
|
||||||
:users => users,
|
:users => users,
|
||||||
:history => history,
|
:history => history_list,
|
||||||
:history_objects => history_objects,
|
:history_objects => history_objects,
|
||||||
:history_types => history_types,
|
:history_types => history_types,
|
||||||
:history_attributes => history_attributes
|
:history_attributes => history_attributes
|
||||||
|
|
|
@ -90,36 +90,7 @@ class History < ApplicationModel
|
||||||
order('created_at ASC, id ASC')
|
order('created_at ASC, id ASC')
|
||||||
end
|
end
|
||||||
|
|
||||||
list = []
|
return history
|
||||||
history.each { |item|
|
|
||||||
item_tmp = item.attributes
|
|
||||||
item_tmp['history_type'] = item.history_type.name
|
|
||||||
item_tmp['history_object'] = item.history_object.name
|
|
||||||
if item.history_attribute
|
|
||||||
item_tmp['history_attribute'] = item.history_attribute.name
|
|
||||||
end
|
|
||||||
item_tmp.delete( 'history_attribute_id' )
|
|
||||||
item_tmp.delete( 'history_object_id' )
|
|
||||||
item_tmp.delete( 'history_type_id' )
|
|
||||||
item_tmp.delete( 'o_id' )
|
|
||||||
item_tmp.delete( 'updated_at' )
|
|
||||||
if item_tmp['id_to'] == nil && item_tmp['id_from'] == nil
|
|
||||||
item_tmp.delete( 'id_to' )
|
|
||||||
item_tmp.delete( 'id_from' )
|
|
||||||
end
|
|
||||||
if item_tmp['value_to'] == nil && item_tmp['value_from'] == nil
|
|
||||||
item_tmp.delete( 'value_to' )
|
|
||||||
item_tmp.delete( 'value_from' )
|
|
||||||
end
|
|
||||||
if item_tmp['related_history_object_id'] == nil
|
|
||||||
item_tmp.delete( 'related_history_object_id' )
|
|
||||||
end
|
|
||||||
if item_tmp['related_o_id'] == nil
|
|
||||||
item_tmp.delete( 'related_o_id' )
|
|
||||||
end
|
|
||||||
list.push item_tmp
|
|
||||||
}
|
|
||||||
return list
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.activity_stream( user, limit = 10 )
|
def self.activity_stream( user, limit = 10 )
|
||||||
|
|
|
@ -163,39 +163,34 @@ class HistoryTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
# get history
|
# get history
|
||||||
history_list = History.list( 'Ticket', ticket.id, 'Ticket::Article' )
|
history_list = History.list( 'Ticket', ticket.id, 'Ticket::Article' )
|
||||||
puts history_list.inspect
|
test[:history_check].each { |check|
|
||||||
test[:history_check].each { |check_item|
|
|
||||||
# puts '+++++++++++'
|
|
||||||
# puts check_item.inspect
|
|
||||||
match = false
|
match = false
|
||||||
history_list.each { |history_item|
|
history_list.each { |history|
|
||||||
next if match
|
next if match
|
||||||
# puts '--------'
|
next if history.history_object.name != check[:history_object]
|
||||||
# puts history_item.inspect
|
next if history.history_type.name != check[:history_type]
|
||||||
next if history_item['history_object'] != check_item[:history_object]
|
next if check[:history_attribute] && history.history_attribute.name != check[:history_attribute]
|
||||||
next if history_item['history_type'] != check_item[:history_type]
|
|
||||||
next if check_item[:history_attribute] != history_item['history_attribute']
|
|
||||||
match = true
|
match = true
|
||||||
if history_item['history_type'] == check_item[:history_type]
|
if history.history_type.name == check[:history_type]
|
||||||
assert( true, "History type #{history_item['history_type']} found!")
|
assert( true, "History type #{history.history_type.name} found!")
|
||||||
end
|
end
|
||||||
if check_item[:history_attribute]
|
if check[:history_attribute]
|
||||||
assert_equal( check_item[:history_attribute], history_item['history_attribute'], "check history attribute #{check_item[:history_attribute]}")
|
assert_equal( check[:history_attribute], history.history_attribute.name, "check history attribute #{check[:history_attribute]}")
|
||||||
end
|
end
|
||||||
if check_item[:value_from]
|
if check[:value_from]
|
||||||
assert_equal( check_item[:value_from], history_item['value_from'], "check history :value_from #{history_item['value_from']} ok")
|
assert_equal( check[:value_from], history.value_from, "check history :value_from #{history.value_from} ok")
|
||||||
end
|
end
|
||||||
if check_item[:value_to]
|
if check[:value_to]
|
||||||
assert_equal( check_item[:value_to], history_item['value_to'], "check history :value_to #{history_item['value_to']} ok")
|
assert_equal( check[:value_to], history.value_to, "check history :value_to #{history.value_to} ok")
|
||||||
end
|
end
|
||||||
if check_item[:id_from]
|
if check[:id_from]
|
||||||
assert_equal( check_item[:id_from], history_item['id_from'], "check history :id_from #{history_item['id_from']} ok")
|
assert_equal( check[:id_from], history.id_from, "check history :id_from #{history.id_from} ok")
|
||||||
end
|
end
|
||||||
if check_item[:id_to]
|
if check[:id_to]
|
||||||
assert_equal( check_item[:id_to], history_item['id_to'], "check history :id_to #{history_item['id_to']} ok")
|
assert_equal( check[:id_to], history.id_to, "check history :id_to #{history.id_to} ok")
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
assert( match, "history check not matched! #{check_item.inspect}")
|
assert( match, "history check not matched! #{check.inspect}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,7 +199,7 @@ class HistoryTest < ActiveSupport::TestCase
|
||||||
ticket_id = ticket.id
|
ticket_id = ticket.id
|
||||||
ticket.destroy
|
ticket.destroy
|
||||||
found = Ticket.where( :id => ticket_id ).first
|
found = Ticket.where( :id => ticket_id ).first
|
||||||
assert( !found, "Ticket destroyed")
|
assert( !found, 'Ticket destroyed')
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue