Added helper Model.assets_of_object_list() and fixed losing references in some cases.
This commit is contained in:
parent
6ce1e7facf
commit
4c8a13d5b2
7 changed files with 47 additions and 18 deletions
|
@ -10,6 +10,9 @@ module ExtraCollection
|
|||
assets = item.assets(assets)
|
||||
}
|
||||
|
||||
collections[ OnlineNotification.to_app_model ] = OnlineNotification.list(user, 20)
|
||||
assets = ApplicationModel.assets_of_object_list(collections[ OnlineNotification.to_app_model ], assets)
|
||||
|
||||
collections[ Role.to_app_model ] = []
|
||||
Role.all.each {|item|
|
||||
assets = item.assets(assets)
|
||||
|
@ -32,6 +35,7 @@ module ExtraCollection
|
|||
}
|
||||
end
|
||||
end
|
||||
[collections, assets]
|
||||
end
|
||||
module_function :session
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ module ExtraCollection
|
|||
collections[ Network::Category.to_app_model ] = Network::Category.all
|
||||
collections[ Network::Category::Type.to_app_model ] = Network::Category::Type.all
|
||||
collections[ Network::Privacy.to_app_model ] = Network::Privacy.all
|
||||
|
||||
[collections, assets]
|
||||
end
|
||||
|
||||
module_function :session
|
||||
|
|
|
@ -38,6 +38,7 @@ module ExtraCollection
|
|||
assets = item.assets(assets)
|
||||
}
|
||||
end
|
||||
[collections, assets]
|
||||
end
|
||||
module_function :session
|
||||
end
|
|
@ -840,6 +840,42 @@ return object and assets
|
|||
}
|
||||
end
|
||||
|
||||
=begin
|
||||
|
||||
get assets of object list
|
||||
|
||||
list = [
|
||||
{
|
||||
object => 'Ticket',
|
||||
o_id => 1,
|
||||
},
|
||||
{
|
||||
object => 'User',
|
||||
o_id => 121,
|
||||
},
|
||||
]
|
||||
|
||||
assets = Model.assets_of_object_list(list, assets)
|
||||
|
||||
=end
|
||||
|
||||
def self.assets_of_object_list(list, assets = {})
|
||||
list.each {|item|
|
||||
require item['object'].to_filename
|
||||
record = Kernel.const_get( item['object'] ).find( item['o_id'] )
|
||||
assets = record.assets(assets)
|
||||
if item['created_by_id']
|
||||
user = User.find( item['created_by_id'] )
|
||||
assets = user.assets(assets)
|
||||
end
|
||||
if item['updated_by_id']
|
||||
user = User.find( item['updated_by_id'] )
|
||||
assets = user.assets(assets)
|
||||
end
|
||||
}
|
||||
assets
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def attachments_buffer
|
||||
|
|
|
@ -45,17 +45,9 @@ class RecentView < ApplicationModel
|
|||
def self.list_fulldata( user, limit = 10 )
|
||||
recent_viewed = self.list( user, limit )
|
||||
|
||||
# get related users
|
||||
assets = {}
|
||||
ticket_ids = []
|
||||
recent_viewed.each {|item|
|
||||
# get related object
|
||||
assets = ApplicationModel.assets_of_object_list(recent_viewed)
|
||||
|
||||
# get related objects
|
||||
require item['object'].to_filename
|
||||
record = Kernel.const_get( item['object'] ).find( item['o_id'] )
|
||||
assets = record.assets(assets)
|
||||
|
||||
}
|
||||
return {
|
||||
:recent_viewed => recent_viewed,
|
||||
:assets => assets,
|
||||
|
|
|
@ -132,12 +132,8 @@ returns
|
|||
return activity_stream if !fulldata
|
||||
|
||||
# get related objects
|
||||
assets = {}
|
||||
activity_stream.each {|item|
|
||||
require item['object'].to_filename
|
||||
record = Kernel.const_get( item['object'] ).find( item['o_id'] )
|
||||
assets = record.assets(assets)
|
||||
}
|
||||
assets = ApplicationModel.assets_of_object_list(activity_stream)
|
||||
|
||||
return {
|
||||
:activity_stream => activity_stream,
|
||||
:assets => assets,
|
||||
|
|
|
@ -10,7 +10,7 @@ module SessionHelper
|
|||
files = Dir.glob( "#{dir}/app/controllers/sessions/collection_*.rb" )
|
||||
for file in files
|
||||
load file
|
||||
ExtraCollection.session( default_collection, assets, user )
|
||||
(default_collection, assets ) = ExtraCollection.session( default_collection, assets, user )
|
||||
end
|
||||
|
||||
return default_collection, assets
|
||||
|
|
Loading…
Reference in a new issue