Added helper Model.assets_of_object_list() and fixed losing references in some cases.

This commit is contained in:
Martin Edenhofer 2014-08-26 09:40:25 +02:00
parent 6ce1e7facf
commit 4c8a13d5b2
7 changed files with 47 additions and 18 deletions

View file

@ -10,6 +10,9 @@ module ExtraCollection
assets = item.assets(assets) 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 ] = [] collections[ Role.to_app_model ] = []
Role.all.each {|item| Role.all.each {|item|
assets = item.assets(assets) assets = item.assets(assets)
@ -32,6 +35,7 @@ module ExtraCollection
} }
end end
end end
[collections, assets]
end end
module_function :session module_function :session
end end

View file

@ -7,7 +7,7 @@ module ExtraCollection
collections[ Network::Category.to_app_model ] = Network::Category.all collections[ Network::Category.to_app_model ] = Network::Category.all
collections[ Network::Category::Type.to_app_model ] = Network::Category::Type.all collections[ Network::Category::Type.to_app_model ] = Network::Category::Type.all
collections[ Network::Privacy.to_app_model ] = Network::Privacy.all collections[ Network::Privacy.to_app_model ] = Network::Privacy.all
[collections, assets]
end end
module_function :session module_function :session

View file

@ -38,6 +38,7 @@ module ExtraCollection
assets = item.assets(assets) assets = item.assets(assets)
} }
end end
[collections, assets]
end end
module_function :session module_function :session
end end

View file

@ -840,6 +840,42 @@ return object and assets
} }
end 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 private
def attachments_buffer def attachments_buffer

View file

@ -45,17 +45,9 @@ class RecentView < ApplicationModel
def self.list_fulldata( user, limit = 10 ) def self.list_fulldata( user, limit = 10 )
recent_viewed = self.list( user, limit ) recent_viewed = self.list( user, limit )
# get related users # get related object
assets = {} assets = ApplicationModel.assets_of_object_list(recent_viewed)
ticket_ids = []
recent_viewed.each {|item|
# get related objects
require item['object'].to_filename
record = Kernel.const_get( item['object'] ).find( item['o_id'] )
assets = record.assets(assets)
}
return { return {
:recent_viewed => recent_viewed, :recent_viewed => recent_viewed,
:assets => assets, :assets => assets,

View file

@ -132,12 +132,8 @@ returns
return activity_stream if !fulldata return activity_stream if !fulldata
# get related objects # get related objects
assets = {} assets = ApplicationModel.assets_of_object_list(activity_stream)
activity_stream.each {|item|
require item['object'].to_filename
record = Kernel.const_get( item['object'] ).find( item['o_id'] )
assets = record.assets(assets)
}
return { return {
:activity_stream => activity_stream, :activity_stream => activity_stream,
:assets => assets, :assets => assets,

View file

@ -10,7 +10,7 @@ module SessionHelper
files = Dir.glob( "#{dir}/app/controllers/sessions/collection_*.rb" ) files = Dir.glob( "#{dir}/app/controllers/sessions/collection_*.rb" )
for file in files for file in files
load file load file
ExtraCollection.session( default_collection, assets, user ) (default_collection, assets ) = ExtraCollection.session( default_collection, assets, user )
end end
return default_collection, assets return default_collection, assets