Commit f9a7c1f77d40bf4562ce46a1a30550aba4f2b3d9
1 parent
ac370ca2
Exists in
master
and in
29 other branches
Makes folder listing context-able
Also enables to correctly display icons Closes ActionItem3158
Showing
6 changed files
with
62 additions
and
28 deletions
Show diff stats
app/helpers/folder_helper.rb
| ... | ... | @@ -3,15 +3,17 @@ module FolderHelper |
| 3 | 3 | include ShortFilename |
| 4 | 4 | include ArticleHelper |
| 5 | 5 | |
| 6 | - def list_articles(articles, recursive = false) | |
| 7 | - if !articles.blank? | |
| 8 | - articles = articles.paginate( | |
| 6 | + def list_contents(configure={}) | |
| 7 | + configure[:recursive] ||= false | |
| 8 | + configure[:list_type] ||= :folder | |
| 9 | + if !configure[:contents].blank? | |
| 10 | + configure[:contents] = configure[:contents].paginate( | |
| 9 | 11 | :order => "updated_at DESC", |
| 10 | 12 | :per_page => 10, |
| 11 | 13 | :page => params[:npage] |
| 12 | 14 | ) |
| 13 | 15 | |
| 14 | - render :file => 'shared/articles_list', :locals => {:articles => articles, :recursive => recursive} | |
| 16 | + render :file => 'shared/articles_list', :locals => configure | |
| 15 | 17 | else |
| 16 | 18 | content_tag('em', _('(empty folder)')) |
| 17 | 19 | end |
| ... | ... | @@ -21,21 +23,33 @@ module FolderHelper |
| 21 | 23 | articles.select {|article| article.display_to?(user)} |
| 22 | 24 | end |
| 23 | 25 | |
| 24 | - def display_article_in_listing(article, recursive = false, level = 0) | |
| 25 | - article = FilePresenter.for article | |
| 26 | - article_link = if article.image? | |
| 27 | - link_to(' ' * (level * 4) + image_tag(icon_for_article(article)) + short_filename(article.name), article.url.merge(:view => true)) | |
| 26 | + def display_content_in_listing(configure={}) | |
| 27 | + recursive = configure[:recursive] || false | |
| 28 | + list_type = configure[:list_type] || :folder | |
| 29 | + level = configure[:level] || 0 | |
| 30 | + content = FilePresenter.for configure[:content] | |
| 31 | + content_link = if content.image? | |
| 32 | + link_to(' ' * (level * 4) + | |
| 33 | + image_tag(icon_for_article(content)) + short_filename(content.name), | |
| 34 | + content.url.merge(:view => true) | |
| 35 | + ) | |
| 28 | 36 | else |
| 29 | - link_to(' ' * (level * 4) + short_filename(article.name), article.url.merge(:view => true), :class => icon_for_article(article)) | |
| 37 | + link_to(' ' * (level * 4) + | |
| 38 | + short_filename(content.name), | |
| 39 | + content.url.merge(:view => true), :class => icon_for_article(content) | |
| 40 | + ) | |
| 30 | 41 | end |
| 31 | 42 | result = content_tag( |
| 32 | 43 | 'tr', |
| 33 | - content_tag('td', article_link )+ | |
| 34 | - content_tag('td', show_date(article.updated_at), :class => 'last-update'), | |
| 35 | - :class => 'sitemap-item' | |
| 44 | + content_tag('td', content_link ) + | |
| 45 | + content_tag('td', show_date(content.updated_at), :class => 'last-update'), | |
| 46 | + :class => "#{list_type}-item" | |
| 36 | 47 | ) |
| 37 | 48 | if recursive |
| 38 | - result + article.children.map {|item| display_article_in_listing(item, recursive, level + 1) }.join('') | |
| 49 | + result + content.children.map {|item| | |
| 50 | + display_content_in_listing :content=>item, :recursive=>recursive, | |
| 51 | + :list_type=>list_type, :level=>level+1 | |
| 52 | + }.join("\n") | |
| 39 | 53 | else |
| 40 | 54 | result |
| 41 | 55 | end | ... | ... |
app/views/content_viewer/folder.rhtml
app/views/profile/sitemap.rhtml
app/views/shared/articles_list.rhtml
| 1 | -<table> | |
| 2 | - | |
| 1 | +<table class="<%= list_type %>-content"> | |
| 3 | 2 | <tr> |
| 4 | 3 | <th><%= _('Title') %></th> |
| 5 | 4 | <th><%= _('Last update') %></th> |
| 6 | 5 | </tr> |
| 7 | - <% articles.each do |article| %> | |
| 8 | - <% if article.display_to?(user) %> | |
| 9 | - <%= display_article_in_listing(article, recursive, 0) %> | |
| 6 | + <% contents.each do |content| %> | |
| 7 | + <% if content.display_to?(user) %> | |
| 8 | + <%= display_content_in_listing :content=>content, :list_type=>list_type, :recursive=>recursive %> | |
| 10 | 9 | <% end %> |
| 11 | 10 | <% end %> |
| 12 | 11 | </table> |
| 13 | 12 | |
| 14 | -<p><%= pagination_links(articles, {:param_name => 'npage', :page_links => true}) %></p> | |
| 13 | +<p><%= pagination_links contents, :param_name => 'npage', :page_links => true %></p> | ... | ... |
public/stylesheets/application.css
| ... | ... | @@ -305,17 +305,19 @@ div.pending-tasks { |
| 305 | 305 | -khtml-border-radius: 2px; |
| 306 | 306 | border-radius: 2px; |
| 307 | 307 | } |
| 308 | -/* sitemap and agenda */ | |
| 309 | 308 | |
| 309 | +/* sitemap and agenda */ | |
| 310 | 310 | |
| 311 | -.agenda-item a.icon, .sitemap-item a.icon { | |
| 311 | +.agenda-item a.icon { | |
| 312 | 312 | background-image: none; |
| 313 | 313 | line-height: 150%; |
| 314 | 314 | } |
| 315 | -.agenda-item .icon:hover, .sitemap-item .icon:hover { | |
| 315 | + | |
| 316 | +.agenda-item:hover, .sitemap-item:hover, .sitemap-item:hover a { | |
| 316 | 317 | background-color: transparent; |
| 317 | 318 | text-decoration: underline; |
| 318 | 319 | } |
| 320 | + | |
| 319 | 321 | .agenda-item a, a:visited{ |
| 320 | 322 | font-weight: bold; |
| 321 | 323 | color: black; |
| ... | ... | @@ -326,6 +328,14 @@ div.pending-tasks { |
| 326 | 328 | text-decoration: none; |
| 327 | 329 | } |
| 328 | 330 | |
| 331 | +.sitemap-item a.icon { | |
| 332 | + background-repeat: no-repeat; | |
| 333 | + background-position: 0% 50%; | |
| 334 | + padding-left: 20px; | |
| 335 | + display: inline-block; | |
| 336 | + line-height: 16px; | |
| 337 | +} | |
| 338 | + | |
| 329 | 339 | .sitemap-item img, .agenda-item img { |
| 330 | 340 | border: none; |
| 331 | 341 | } |
| ... | ... | @@ -3453,7 +3463,15 @@ div.with_media_panel .formfield input[type="checkbox"] { |
| 3453 | 3463 | .pagination a:hover { |
| 3454 | 3464 | color: #2e3436; |
| 3455 | 3465 | } |
| 3456 | -/* ==> @import url('folder.css'); <== */ | |
| 3466 | + | |
| 3467 | +/* Folders */ | |
| 3468 | + | |
| 3469 | +.folder-content .folder-item img { | |
| 3470 | + vertical-align: middle; | |
| 3471 | + position: relative; | |
| 3472 | + left: -3px; | |
| 3473 | +} | |
| 3474 | + | |
| 3457 | 3475 | .image-gallery { |
| 3458 | 3476 | text-align: center; |
| 3459 | 3477 | } | ... | ... |
test/unit/folder_helper_test.rb
| ... | ... | @@ -97,14 +97,17 @@ class FolderHelperTest < ActiveSupport::TestCase |
| 97 | 97 | article2 = fast_create(Article, {:name => 'Article2', :parent_id => folder.id, :profile_id => profile.id, :updated_at => DateTime.now }) |
| 98 | 98 | self.stubs(:params).returns({:npage => nil}) |
| 99 | 99 | |
| 100 | - articles = folder.children.find(:all, :order => 'updated_at DESC').paginate(:per_page => 10, :page => params[:npage]) | |
| 100 | + contents = folder.children.find(:all, :order => 'updated_at DESC').paginate(:per_page => 10, :page => params[:npage]) | |
| 101 | 101 | expects(:user).returns(profile).at_least_once |
| 102 | + expects(:list_type).returns(:folder).at_least_once | |
| 102 | 103 | expects(:recursive).returns(false).at_least_once |
| 103 | 104 | expects(:pagination_links).with(anything, anything).returns('') |
| 104 | 105 | list = render 'shared/articles_list', binding |
| 105 | - expects(:render).with(:file => 'shared/articles_list', :locals => { :articles => articles, :recursive => false}).returns(list) | |
| 106 | + expects(:render).with(:file => 'shared/articles_list', | |
| 107 | + :locals => { :contents => contents, :recursive => false, :list_type => :folder } | |
| 108 | + ).returns(list) | |
| 106 | 109 | |
| 107 | - result = list_articles(folder.children) | |
| 110 | + result = list_contents(:contents=>contents) | |
| 108 | 111 | |
| 109 | 112 | assert_tag_in_string result, :tag => 'td', :descendant => { :tag => 'a', :attributes => { :href => /.*\/folder-owner\/my-article-[0-9]*(\?|$)/ } }, :content => /Article1/ |
| 110 | 113 | assert_tag_in_string result, :tag => 'td', :descendant => { :tag => 'a', :attributes => { :href => /.*\/folder-owner\/my-article-[0-9]*(\?|$)/ } }, :content => /Article2/ | ... | ... |