From ac34368862633aefe92f31c34e6e2679d17d8b05 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Wed, 16 Jul 2014 17:04:32 -0300 Subject: [PATCH] [media-panel-improvements] Load recent media on published media box --- app/controllers/my_profile/cms_controller.rb | 19 +++++++++++++++++++ app/models/article.rb | 1 + app/models/profile.rb | 1 + app/views/cms/_text_editor_sidebar.html.erb | 17 +++++++++++------ public/stylesheets/application.css | 5 ----- 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index a1dbeae..d439479 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -17,6 +17,9 @@ class CmsController < MyProfileController end before_filter :login_required, :except => [:suggest_an_article] + before_filter :load_recent_files, :only => [:new, :edit] + + helper_method :file_types protect_if :only => :upload_files do |c, user, profile| article_id = c.params[:parent_id] @@ -418,4 +421,20 @@ class CmsController < MyProfileController end end + def file_types + {:images => _('Images'), :generics => _('Files')} + end + + def load_recent_files + #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 = {} + files = profile.files.more_recent + @recent_files[:images] = files.images.limit(6) + @recent_files[:generics] = files.no_images.limit(6) + end + end diff --git a/app/models/article.rb b/app/models/article.rb index c44af59..4df59b2 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -461,6 +461,7 @@ class Article < ActiveRecord::Base scope :no_folders, lambda {|profile|{:conditions => ['type NOT IN (?)', profile.folder_types]}} scope :galleries, :conditions => { :type => 'Gallery' } scope :images, :conditions => { :is_image => true } + scope :no_images, :conditions => { :is_image => false } scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ] scope :with_types, lambda { |types| { :conditions => [ 'articles.type IN (?)', types ] } } diff --git a/app/models/profile.rb b/app/models/profile.rb index 1506d8d..26e7a1e 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -200,6 +200,7 @@ class Profile < ActiveRecord::Base has_many :tasks, :dependent => :destroy, :as => 'target' has_many :events, :source => 'articles', :class_name => 'Event', :order => 'start_date' + has_many :files, :source => 'articles', :class_name => 'UploadedFile', :order => 'start_date' def find_in_all_tasks(task_id) begin diff --git a/app/views/cms/_text_editor_sidebar.html.erb b/app/views/cms/_text_editor_sidebar.html.erb index edb3499..8f81070 100644 --- a/app/views/cms/_text_editor_sidebar.html.erb +++ b/app/views/cms/_text_editor_sidebar.html.erb @@ -25,12 +25,17 @@
<%= _('Published media') %>
<%= render :partial => 'drag_and_drop_note' %>
-
-

<%= _('Images') %>

-
-
-

<%= _('Files') %>

-
+ <% file_types.each do |key, label| %> + <% if @recent_files[key].present? %> +
+

<%= label %>

+ <% @recent_files[key].each do |file| %> + <% @file = file %> + <%= render :partial => "cms/media_panel/#{key.to_s.singularize}" %> + <% end %> +
+ <% end %> + <% end %>
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index a9aebd3..c09fedb 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -3441,11 +3441,6 @@ div.with_media_panel .formfield input[type="checkbox"] { margin-bottom: 10px; } -#published-media .items .images, -#published-media .items .generics { - display: none; -} - .text-editor-sidebar .items .file { background-repeat: no-repeat; background-position: 0px 0px; -- libgit2 0.21.2