Commit ac34368862633aefe92f31c34e6e2679d17d8b05
1 parent
3ca93524
Exists in
master
and in
22 other branches
[media-panel-improvements] Load recent media on published media box
Showing
5 changed files
with
32 additions
and
11 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
@@ -17,6 +17,9 @@ class CmsController < MyProfileController | @@ -17,6 +17,9 @@ class CmsController < MyProfileController | ||
17 | end | 17 | end |
18 | 18 | ||
19 | before_filter :login_required, :except => [:suggest_an_article] | 19 | before_filter :login_required, :except => [:suggest_an_article] |
20 | + before_filter :load_recent_files, :only => [:new, :edit] | ||
21 | + | ||
22 | + helper_method :file_types | ||
20 | 23 | ||
21 | protect_if :only => :upload_files do |c, user, profile| | 24 | protect_if :only => :upload_files do |c, user, profile| |
22 | article_id = c.params[:parent_id] | 25 | article_id = c.params[:parent_id] |
@@ -418,4 +421,20 @@ class CmsController < MyProfileController | @@ -418,4 +421,20 @@ class CmsController < MyProfileController | ||
418 | end | 421 | end |
419 | end | 422 | end |
420 | 423 | ||
424 | + def file_types | ||
425 | + {:images => _('Images'), :generics => _('Files')} | ||
426 | + end | ||
427 | + | ||
428 | + def load_recent_files | ||
429 | + #TODO Since we only have special support for images, I'm limiting myself to | ||
430 | + # consider generic files as non-images. In the future, with more supported | ||
431 | + # file types we'll need to have a smart way to fetch from the database | ||
432 | + # scopes of each supported type as well as the non-supported types as a | ||
433 | + # whole. | ||
434 | + @recent_files = {} | ||
435 | + files = profile.files.more_recent | ||
436 | + @recent_files[:images] = files.images.limit(6) | ||
437 | + @recent_files[:generics] = files.no_images.limit(6) | ||
438 | + end | ||
439 | + | ||
421 | end | 440 | end |
app/models/article.rb
@@ -461,6 +461,7 @@ class Article < ActiveRecord::Base | @@ -461,6 +461,7 @@ class Article < ActiveRecord::Base | ||
461 | scope :no_folders, lambda {|profile|{:conditions => ['type NOT IN (?)', profile.folder_types]}} | 461 | scope :no_folders, lambda {|profile|{:conditions => ['type NOT IN (?)', profile.folder_types]}} |
462 | scope :galleries, :conditions => { :type => 'Gallery' } | 462 | scope :galleries, :conditions => { :type => 'Gallery' } |
463 | scope :images, :conditions => { :is_image => true } | 463 | scope :images, :conditions => { :is_image => true } |
464 | + scope :no_images, :conditions => { :is_image => false } | ||
464 | scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ] | 465 | scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ] |
465 | scope :with_types, lambda { |types| { :conditions => [ 'articles.type IN (?)', types ] } } | 466 | scope :with_types, lambda { |types| { :conditions => [ 'articles.type IN (?)', types ] } } |
466 | 467 |
app/models/profile.rb
@@ -200,6 +200,7 @@ class Profile < ActiveRecord::Base | @@ -200,6 +200,7 @@ class Profile < ActiveRecord::Base | ||
200 | has_many :tasks, :dependent => :destroy, :as => 'target' | 200 | has_many :tasks, :dependent => :destroy, :as => 'target' |
201 | 201 | ||
202 | has_many :events, :source => 'articles', :class_name => 'Event', :order => 'start_date' | 202 | has_many :events, :source => 'articles', :class_name => 'Event', :order => 'start_date' |
203 | + has_many :files, :source => 'articles', :class_name => 'UploadedFile', :order => 'start_date' | ||
203 | 204 | ||
204 | def find_in_all_tasks(task_id) | 205 | def find_in_all_tasks(task_id) |
205 | begin | 206 | begin |
app/views/cms/_text_editor_sidebar.html.erb
@@ -25,12 +25,17 @@ | @@ -25,12 +25,17 @@ | ||
25 | <div class='header'><strong><%= _('Published media') %></strong></div> | 25 | <div class='header'><strong><%= _('Published media') %></strong></div> |
26 | <%= render :partial => 'drag_and_drop_note' %> | 26 | <%= render :partial => 'drag_and_drop_note' %> |
27 | <div class='items'> | 27 | <div class='items'> |
28 | - <div class='images'> | ||
29 | - <h3><%= _('Images') %></h3> | ||
30 | - </div> | ||
31 | - <div class='generics'> | ||
32 | - <h3><%= _('Files') %></h3> | ||
33 | - </div> | 28 | + <% file_types.each do |key, label| %> |
29 | + <% if @recent_files[key].present? %> | ||
30 | + <div class='<%= key.to_s%>'> | ||
31 | + <h3><%= label %></h3> | ||
32 | + <% @recent_files[key].each do |file| %> | ||
33 | + <% @file = file %> | ||
34 | + <%= render :partial => "cms/media_panel/#{key.to_s.singularize}" %> | ||
35 | + <% end %> | ||
36 | + </div> | ||
37 | + <% end %> | ||
38 | + <% end %> | ||
34 | </div> | 39 | </div> |
35 | </div> | 40 | </div> |
36 | 41 |
public/stylesheets/application.css
@@ -3441,11 +3441,6 @@ div.with_media_panel .formfield input[type="checkbox"] { | @@ -3441,11 +3441,6 @@ div.with_media_panel .formfield input[type="checkbox"] { | ||
3441 | margin-bottom: 10px; | 3441 | margin-bottom: 10px; |
3442 | } | 3442 | } |
3443 | 3443 | ||
3444 | -#published-media .items .images, | ||
3445 | -#published-media .items .generics { | ||
3446 | - display: none; | ||
3447 | -} | ||
3448 | - | ||
3449 | .text-editor-sidebar .items .file { | 3444 | .text-editor-sidebar .items .file { |
3450 | background-repeat: no-repeat; | 3445 | background-repeat: no-repeat; |
3451 | background-position: 0px 0px; | 3446 | background-position: 0px 0px; |