Commit ac13979729e58776f0be86edba763b7ecfe5b687

Authored by Rodrigo Souto
2 parents b2ff3fa1 526c04a9

Merge branch 'AI3158-icons-in-folder' into 'stable'

Display missed icons on folder view

A small rewrite with more coherent names and context-able listing to make that thing to work.

http://noosfero.org/Development/ActionItem3158
app/helpers/folder_helper.rb
@@ -3,15 +3,17 @@ module FolderHelper @@ -3,15 +3,17 @@ module FolderHelper
3 include ShortFilename 3 include ShortFilename
4 include ArticleHelper 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 :order => "updated_at DESC", 11 :order => "updated_at DESC",
10 :per_page => 10, 12 :per_page => 10,
11 :page => params[:npage] 13 :page => params[:npage]
12 ) 14 )
13 15
14 - render :file => 'shared/articles_list', :locals => {:articles => articles, :recursive => recursive} 16 + render :file => 'shared/content_list', :locals => configure
15 else 17 else
16 content_tag('em', _('(empty folder)')) 18 content_tag('em', _('(empty folder)'))
17 end 19 end
@@ -21,21 +23,33 @@ module FolderHelper @@ -21,21 +23,33 @@ module FolderHelper
21 articles.select {|article| article.display_to?(user)} 23 articles.select {|article| article.display_to?(user)}
22 end 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 else 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 end 41 end
31 result = content_tag( 42 result = content_tag(
32 'tr', 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 if recursive 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 else 53 else
40 result 54 result
41 end 55 end
app/views/content_viewer/folder.rhtml
@@ -8,5 +8,5 @@ @@ -8,5 +8,5 @@
8 <% if folder.children.empty? %> 8 <% if folder.children.empty? %>
9 <em><%= _('(empty folder)') %></em> 9 <em><%= _('(empty folder)') %></em>
10 <% else %> 10 <% else %>
11 - <%= list_articles(folder.children) %> 11 + <%= list_contents(:contents=>folder.children) %>
12 <% end %> 12 <% end %>
app/views/profile/sitemap.rhtml
1 <h1><%= _("%s: site map") % profile.name %></h1> 1 <h1><%= _("%s: site map") % profile.name %></h1>
2 2
3 -<%= list_articles(available_articles(@articles, user), false) %> 3 +<%= list_contents :contents=>available_articles(@articles, user), :list_type=>:sitemap %>
app/views/shared/articles_list.rhtml
@@ -1,14 +0,0 @@ @@ -1,14 +0,0 @@
1 -<table>  
2 -  
3 - <tr>  
4 - <th><%= _('Title') %></th>  
5 - <th><%= _('Last update') %></th>  
6 - </tr>  
7 - <% articles.each do |article| %>  
8 - <% if article.display_to?(user) %>  
9 - <%= display_article_in_listing(article, recursive, 0) %>  
10 - <% end %>  
11 - <% end %>  
12 -</table>  
13 -  
14 -<p><%= pagination_links(articles, {:param_name => 'npage', :page_links => true}) %></p>  
app/views/shared/content_list.rhtml 0 → 100644
@@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
  1 +<table class="<%= list_type %>-content">
  2 + <tr>
  3 + <th><%= _('Title') %></th>
  4 + <th><%= _('Last update') %></th>
  5 + </tr>
  6 + <% contents.each do |content| %>
  7 + <% if content.display_to?(user) %>
  8 + <%= display_content_in_listing :content=>content, :list_type=>list_type, :recursive=>recursive %>
  9 + <% end %>
  10 + <% end %>
  11 +</table>
  12 +
  13 +<p><%= pagination_links contents, :param_name => 'npage', :page_links => true %></p>
public/stylesheets/application.css
@@ -305,17 +305,19 @@ div.pending-tasks { @@ -305,17 +305,19 @@ div.pending-tasks {
305 -khtml-border-radius: 2px; 305 -khtml-border-radius: 2px;
306 border-radius: 2px; 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 background-image: none; 312 background-image: none;
313 line-height: 150%; 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 background-color: transparent; 317 background-color: transparent;
317 text-decoration: underline; 318 text-decoration: underline;
318 } 319 }
  320 +
319 .agenda-item a, a:visited{ 321 .agenda-item a, a:visited{
320 font-weight: bold; 322 font-weight: bold;
321 color: black; 323 color: black;
@@ -326,6 +328,14 @@ div.pending-tasks { @@ -326,6 +328,14 @@ div.pending-tasks {
326 text-decoration: none; 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 .sitemap-item img, .agenda-item img { 339 .sitemap-item img, .agenda-item img {
330 border: none; 340 border: none;
331 } 341 }
@@ -3459,7 +3469,15 @@ div.with_media_panel .formfield input[type=&quot;checkbox&quot;] { @@ -3459,7 +3469,15 @@ div.with_media_panel .formfield input[type=&quot;checkbox&quot;] {
3459 .pagination a:hover { 3469 .pagination a:hover {
3460 color: #2e3436; 3470 color: #2e3436;
3461 } 3471 }
3462 -/* ==> @import url('folder.css'); <== */ 3472 +
  3473 +/* Folders */
  3474 +
  3475 +.folder-content .folder-item img {
  3476 + vertical-align: middle;
  3477 + position: relative;
  3478 + left: -3px;
  3479 +}
  3480 +
3463 .image-gallery { 3481 .image-gallery {
3464 text-align: center; 3482 text-align: center;
3465 } 3483 }
test/unit/folder_helper_test.rb
@@ -97,14 +97,17 @@ class FolderHelperTest &lt; ActiveSupport::TestCase @@ -97,14 +97,17 @@ class FolderHelperTest &lt; ActiveSupport::TestCase
97 article2 = fast_create(Article, {:name => 'Article2', :parent_id => folder.id, :profile_id => profile.id, :updated_at => DateTime.now }) 97 article2 = fast_create(Article, {:name => 'Article2', :parent_id => folder.id, :profile_id => profile.id, :updated_at => DateTime.now })
98 self.stubs(:params).returns({:npage => nil}) 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 expects(:user).returns(profile).at_least_once 101 expects(:user).returns(profile).at_least_once
  102 + expects(:list_type).returns(:folder).at_least_once
102 expects(:recursive).returns(false).at_least_once 103 expects(:recursive).returns(false).at_least_once
103 expects(:pagination_links).with(anything, anything).returns('') 104 expects(:pagination_links).with(anything, anything).returns('')
104 - list = render 'shared/articles_list', binding  
105 - expects(:render).with(:file => 'shared/articles_list', :locals => { :articles => articles, :recursive => false}).returns(list) 105 + list = render 'shared/content_list', binding
  106 + expects(:render).with(:file => 'shared/content_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 assert_tag_in_string result, :tag => 'td', :descendant => { :tag => 'a', :attributes => { :href => /.*\/folder-owner\/my-article-[0-9]*(\?|$)/ } }, :content => /Article1/ 112 assert_tag_in_string result, :tag => 'td', :descendant => { :tag => 'a', :attributes => { :href => /.*\/folder-owner\/my-article-[0-9]*(\?|$)/ } }, :content => /Article1/
110 assert_tag_in_string result, :tag => 'td', :descendant => { :tag => 'a', :attributes => { :href => /.*\/folder-owner\/my-article-[0-9]*(\?|$)/ } }, :content => /Article2/ 113 assert_tag_in_string result, :tag => 'td', :descendant => { :tag => 'a', :attributes => { :href => /.*\/folder-owner\/my-article-[0-9]*(\?|$)/ } }, :content => /Article2/