diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 8f3cb60..403dc52 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -330,9 +330,7 @@ class CmsController < MyProfileController end def published_media_items - parent = profile.articles.find(params[:parent_id]) - load_recent_files(parent) - @published_media_items_id = params[:parent_id] + load_recent_files(params[:parent_id], params[:q]) render :partial => 'published_media_items' end @@ -432,23 +430,32 @@ class CmsController < MyProfileController {:images => _('Images'), :generics => _('Files')} end - def load_recent_files(parent = nil) + def load_recent_files(parent_id = nil, q = nil) #TODO Since we only have special support for images, I'm limiting myself to # consider generic files as non-images. In the future, with more supported # file types we'll need to have a smart way to fetch from the database # scopes of each supported type as well as the non-supported types as a # whole. @recent_files = {} + + parent = parent_id.present? ? profile.articles.find(parent_id) : nil if parent.present? files = parent.children.files - @published_media_items_id = parent.id else files = profile.files - @published_media_items_id = 'recent-media' end + files = files.more_recent - @recent_files[:images] = files.images.limit(6) - @recent_files[:generics] = files.no_images.limit(6) + images = files.images.limit(6) + generics = files.no_images.limit(6) + + if q.present? + @recent_files[:images] = find_by_contents(:images, images, q)[:results] + @recent_files[:generics] = find_by_contents(:generics, generics, q)[:results] + else + @recent_files[:images] = images + @recent_files[:generics] = generics + end end end diff --git a/app/views/cms/_published_media_items.html.erb b/app/views/cms/_published_media_items.html.erb index abddc44..7a32ac3 100644 --- a/app/views/cms/_published_media_items.html.erb +++ b/app/views/cms/_published_media_items.html.erb @@ -1,4 +1,4 @@ -