diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index f997730..61454e4 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -285,20 +285,20 @@ class CmsController < MyProfileController def media_listing if params[:image_folder_id] folder = profile.articles.find(params[:image_folder_id]) if !params[:image_folder_id].blank? - @images = (folder ? folder.children : UploadedFile.find(:all, :order => 'created_at desc', :conditions => ["profile_id = ? AND parent_id is NULL", profile ])).select { |c| c.image? } + @images = (folder ? folder.children : profile.top_level_articles).images elsif params[:document_folder_id] folder = profile.articles.find(params[:document_folder_id]) if !params[:document_folder_id].blank? - @documents = (folder ? folder.children : UploadedFile.find(:all, :order => 'created_at desc', :conditions => ["profile_id = ? AND parent_id is NULL", profile ])).select { |c| c.kind_of?(UploadedFile) && !c.image? } + @documents = (folder ? folder.children : profile.top_level_articles) else - @documents = UploadedFile.find(:all, :order => 'created_at desc', :conditions => ["profile_id = ? AND parent_id is NULL", profile ]) - @images = @documents.select(&:image?) + @documents = profile.articles + @images = @documents.images @documents -= @images end - @images = @images.paginate(:per_page => per_page, :page => params[:ipage]) if @images - @documents = @documents.paginate(:per_page => per_page, :page => params[:dpage]) if @documents + @images = @images.paginate(:per_page => per_page, :page => params[:ipage], :order => "updated_at desc") if @images + @documents = @documents.paginate(:per_page => per_page, :page => params[:dpage], :order => "updated_at desc", :conditions => {:is_image => false}) if @documents - @folders = Folder.find(:all, :conditions => { :profile_id => profile }) + @folders = profile.folders @image_folders = @folders.select {|f| f.children.any? {|c| c.image?} } @document_folders = @folders.select {|f| f.children.any? {|c| !c.image? && c.kind_of?(UploadedFile) } } diff --git a/app/models/article.rb b/app/models/article.rb index d573961..3849fff 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -238,6 +238,7 @@ class Article < ActiveRecord::Base named_scope :published, :conditions => { :published => true } named_scope :folders, :conditions => { :type => ['Folder', 'Blog'] } + named_scope :images, :conditions => { :is_image => true } def display_unpublished_article_to?(user) self.author == user || allow_view_private_content?(user) || user == self.profile || diff --git a/app/models/uploaded_file.rb b/app/models/uploaded_file.rb index 2863ac2..c85a56c 100644 --- a/app/models/uploaded_file.rb +++ b/app/models/uploaded_file.rb @@ -16,6 +16,10 @@ class UploadedFile < Article validates_size_of :title, :maximum => 60, :if => (lambda { |file| !file.title.blank? }) + before_create do |uploaded_file| + uploaded_file.is_image = true if uploaded_file.image? + end + def thumbnail_path self.image? ? self.full_filename(:thumb).gsub(File.join(RAILS_ROOT, 'public'), '') : nil end diff --git a/db/migrate/20100921121528_add_is_image_to_articles.rb b/db/migrate/20100921121528_add_is_image_to_articles.rb new file mode 100644 index 0000000..d571435 --- /dev/null +++ b/db/migrate/20100921121528_add_is_image_to_articles.rb @@ -0,0 +1,13 @@ +class AddIsImageToArticles < ActiveRecord::Migration + def self.up + add_column :articles, :is_image, :boolean, :default => false + add_column :article_versions, :is_image, :boolean, :default => false + + execute ActiveRecord::Base.sanitize_sql(["update articles set is_image = ? where articles.content_type like 'image/%'", true]) + end + + def self.down + remove_column :articles, :is_image + remove_column :article_versions, :is_image + end +end diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index a3f4968..73e9883 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -1164,6 +1164,7 @@ class CmsControllerTest < Test::Unit::TestCase should 'display pagination links of documents' do @controller.stubs(:per_page).returns(1) + profile.articles.destroy_all file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/feed.xml', 'text/xml')) file2 = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')) file2.created_at = 1.day.ago diff --git a/test/unit/uploaded_file_test.rb b/test/unit/uploaded_file_test.rb index c5e2fac..91cd2d0 100644 --- a/test/unit/uploaded_file_test.rb +++ b/test/unit/uploaded_file_test.rb @@ -56,6 +56,7 @@ class UploadedFileTest < Test::Unit::TestCase file = UploadedFile.new(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) file.profile = profile assert file.save + assert file.is_image end should 'has attachment_fu validation options' do -- libgit2 0.21.2