Commit dd61d0cf17d2498e596b7c62ec7214fa0bf5cffc

Authored by AurelioAHeckert
1 parent db2488c5

ActionItem518: product icons on profile and product category selector

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2211 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/helpers/application_helper.rb
... ... @@ -346,6 +346,30 @@ module ApplicationHelper
346 346 sex
347 347 end
348 348  
  349 + def profile_cat_icons( profile )
  350 + if profile.class == Enterprise
  351 + icons =
  352 + profile.product_categories.map{ |c| c.size > 1 ? [c[0],c[1]] : nil }.
  353 + compact.uniq.map{ |c|
  354 + cat_name = (c[0]+'_'+c[1]).gsub( /\s/, '_' )
  355 + cat_icon = "/images/icons-cat/#{cat_name}.png"
  356 + if ! File.exists? RAILS_ROOT.to_s() + '/public/' + cat_icon
  357 + cat_icon = '/images/icons-cat/undefined.png'
  358 + end
  359 + content_tag 'span',
  360 + content_tag( 'span', c.join(' → ') ),
  361 + :title => c.join(' → '),
  362 + :class => 'product-cat-icon cat_icon_' + cat_name,
  363 + :style => "background-image:url(#{cat_icon})"
  364 + }.join "\n"
  365 + content_tag 'div',
  366 + content_tag( 'span', _('Principal Product Categories'), :class => 'header' ) +"\n"+ icons,
  367 + :class => 'product-category-icons'
  368 + else
  369 + ''
  370 + end
  371 + end
  372 +
349 373 # displays a link to the profile homepage with its image (as generated by
350 374 # #profile_image) and its name below it.
351 375 def profile_image_link( profile, size=:portrait, tag='li' )
... ... @@ -360,7 +384,7 @@ module ApplicationHelper
360 384 link_to(
361 385 content_tag( 'span', profile_image( profile, size ), :class => 'profile-image' ) +
362 386 content_tag( 'span', name, :class => ( profile.class == Person ? 'fn' : 'org' ) ) +
363   - city + profile_sex_icon( profile ),
  387 + city + profile_sex_icon( profile ) + profile_cat_icons( profile ),
364 388 profile.url,
365 389 :class => 'profile_link url',
366 390 :help => _('Click on this icon to go to the <b>%s</b>\'s home page') % profile.name ),
... ...
app/views/blocks/profile_info.rhtml
... ... @@ -7,12 +7,14 @@
7 7 <span class="profile-info-picture-inner2">
8 8 <%=
9 9 profile_image(block.owner, :thumb) +"\n"+
10   - profile_sex_icon( profile )
  10 + profile_sex_icon( profile ) +
  11 + profile_cat_icons( profile )
11 12 %>
12 13 </span>
13 14 </div>
14 15 </div>
15 16  
  17 +
16 18 <ul class="profile-info-data">
17 19 <li><%= _('Since %{year}/%{month}') % { :year => block.owner.created_at.year, :month => block.owner.created_at.month } %></li>
18 20 <li><%= link_to _('Homepage'), block.owner.url, :class => 'url' %></li>
... ...
app/views/manage_products/_subcategories.rhtml
  1 +<div id="category-ajax-selector">
1 2 <% if !@current_category.nil? and !@current_category.top_level? %>
2 3  
3   - <p><%= _('Current category:') %></p>
4   - <%= hidden_field_tag 'product[product_category_id]', @current_category.id %>
5   - <%
6   - categories = [@current_category]
7   - categories.push(@current_category) while @current_category = @current_category.parent
8   - categories.last.name = _('Back')
9   - %>
10   - <% if categories.size > 1 %>
11   - <%= categories.compact.reverse.map{|i|
12   - link_to_remote(i.name,
13   - :update => "subcategories",
14   - :url => { :action => 'update_subcategories', :id => i, :loaded => visual_effect(:highlight, "subcategories") },
15   - :class => 'select-current-category-link')}.join(' &rarr; ')
  4 + <h3 class="box-title"><%= _('Current category:') %></h3>
  5 + <%= hidden_field_tag 'product[product_category_id]', @current_category.id %>
  6 + <%
  7 + categories = [@current_category]
  8 + categories.push(@current_category) while @current_category = @current_category.parent
16 9 %>
17   - <% end %>
  10 + <% if categories.size > 1 %>
  11 + <%= categories.compact.reverse.map{|i|
  12 + link_to_remote(i.name,
  13 + :update => "subcategories",
  14 + :url => { :action => 'update_subcategories', :id => i, :loaded => visual_effect(:highlight, "subcategories") },
  15 + :class => 'select-current-category-link')}.join(' &rarr; ')
  16 + %>
  17 + <% end %>
18 18  
19 19 <% end %>
20 20  
21 21 <% if @current_category %>
22   - <p><%= _('Select a category:') %></p>
  22 + <h3 class="box-title"><%= _('Select a category:') %></h3>
23 23 <% elsif !@categories.empty? %>
24   - <p><%= _('Select a subcategory:') %></p>
  24 + <h3><%= _('Select a subcategory:') %></h3>
25 25 <% end %>
26 26  
27 27 <% for category in @categories do %>
... ... @@ -32,3 +32,4 @@
32 32 :class => 'select-subcategory-link'
33 33 %>
34 34 <% end %>
  35 +</div>
... ...
db/schema.rb
... ... @@ -71,8 +71,8 @@ ActiveRecord::Schema.define(:version =&gt; 45) do
71 71 t.boolean "virtual", :default => false
72 72 end
73 73  
74   - add_index "articles_categories", ["article_id"], :name => "index_articles_categories_on_article_id"
75 74 add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id"
  75 + add_index "articles_categories", ["article_id"], :name => "index_articles_categories_on_article_id"
76 76  
77 77 create_table "blocks", :force => true do |t|
78 78 t.string "title"
... ... @@ -230,8 +230,8 @@ ActiveRecord::Schema.define(:version =&gt; 45) do
230 230 t.datetime "created_at"
231 231 end
232 232  
233   - add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
234 233 add_index "taggings", ["taggable_id", "taggable_type"], :name => "index_taggings_on_taggable_id_and_taggable_type"
  234 + add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
235 235  
236 236 create_table "tags", :force => true do |t|
237 237 t.string "name"
... ...
public/images/icons-cat/Produtos_Alimentação.png 0 → 100644

382 Bytes

public/images/icons-cat/Produtos_Software.png 0 → 100644

408 Bytes

public/images/icons-cat/Produtos_Software_Livre.png 0 → 100644

408 Bytes

public/images/icons-cat/undefined.png 0 → 100644

338 Bytes

public/stylesheets/blocks/profile-info-block.css
... ... @@ -71,10 +71,6 @@
71 71 display: none;
72 72 }
73 73  
74   -.product-categories {
75   - clear: both;
76   -}
77   -
78 74 .profile-info-data {
79 75 width: 110px;
80 76 font-size: 10px;
... ...
public/stylesheets/common.css
... ... @@ -224,12 +224,8 @@ table {
224 224 }
225 225 th, td {
226 226 font-size: 14px;
227   - border: 1px solid #999999;
228   - padding: 2px;
229 227 }
230 228 th {
231   - background: #f0f0f0;
232   - color: black;
233 229 font-weight: bold;
234 230 }
235 231  
... ... @@ -293,3 +289,57 @@ div.sitemap-item a:hover {
293 289 color: red;
294 290 }
295 291  
  292 +
  293 +/* * * icons for product category on profile * * */
  294 +
  295 +#content .product-category-icons {
  296 + position: absolute;
  297 + top: 1px;
  298 + right: 1px;
  299 +}
  300 +#content .profile-list-block .product-category-icons,
  301 +#content .search-results-innerbox .product-category-icons {
  302 + top: 3px;
  303 + right: 3px;
  304 +}
  305 +
  306 +#content .product-category-icons .header,
  307 +#content .product-cat-icon span {
  308 + display: none;
  309 +}
  310 +
  311 +#content .product-cat-icon {
  312 + display: block;
  313 + width: 13px;
  314 + height: 13px;
  315 + margin-bottom: 1px;
  316 +}
  317 +
  318 +
  319 +/* * * category ajax selector * * */
  320 +
  321 +#category-ajax-selector {
  322 + border: 1px solid #AAA;
  323 + background: #EEE;
  324 + padding: 15px 0px 15px 20px;
  325 + margin: 30px 0px 0px 0px;
  326 + position: relative;
  327 +}
  328 +
  329 +#category-ajax-selector h3 {
  330 + margin: 10px 0px;
  331 + font-size: 100%;
  332 +}
  333 +
  334 +#category-ajax-selector .box-title {
  335 + position: absolute;
  336 + top: -30px;
  337 + left: 30px;
  338 + line-height: 19px;
  339 + padding: 0px 10px;
  340 + border: 1px solid #AAA;
  341 + border-bottom: none;
  342 + background: #EEE;
  343 + float: left;
  344 +}
  345 +
... ...
test/functional/manage_products_controller_test.rb
... ... @@ -118,7 +118,7 @@ class ManageProductsControllerTest &lt; Test::Unit::TestCase
118 118 category2 = ProductCategory.create!(:name => 'Category 2', :environment => environment, :parent => category1)
119 119 category3 = ProductCategory.create!(:name => 'Category 3', :environment => environment, :parent => category2)
120 120 get :new, :profile => @enterprise.identifier
121   - assert_tag :tag => 'p', :content => /Select a category:/, :sibling => { :tag => 'a', :content => /#{category2.name}/ }
  121 + assert_tag :tag => 'h3', :content => /Select a category:/, :sibling => { :tag => 'a', :content => /#{category2.name}/ }
122 122 end
123 123  
124 124 should 'show current category' do
... ... @@ -127,7 +127,7 @@ class ManageProductsControllerTest &lt; Test::Unit::TestCase
127 127 category2 = ProductCategory.create!(:name => 'Category 2', :environment => environment, :parent => category1)
128 128 category3 = ProductCategory.create!(:name => 'Category 3', :environment => environment, :parent => category2)
129 129 get 'update_subcategories', :profile => @enterprise.identifier, :id => category2.id
130   - assert_tag :tag => 'p', :content => /Current category:/, :sibling => { :tag => 'a', :content => /#{category3.name}/ }
  130 + assert_tag :tag => 'h3', :content => /Current category:/, :sibling => { :tag => 'a', :content => /#{category3.name}/ }
131 131 end
132 132  
133 133 should 'show subcategories list' do
... ... @@ -137,7 +137,7 @@ class ManageProductsControllerTest &lt; Test::Unit::TestCase
137 137 category3 = ProductCategory.create!(:name => 'Category 3', :environment => environment, :parent => category2)
138 138 get 'update_subcategories', :profile => @enterprise.identifier, :id => category2.id
139 139 assert !assigns(:categories).empty?
140   - assert_tag :tag => 'p', :content => /Select a subcategory:/, :sibling => { :tag => 'a', :attributes => { :href => '#' }, :content => /#{category2.name}/ }
  140 + assert_tag :tag => 'h3', :content => /Select a subcategory:/, :sibling => { :tag => 'a', :attributes => { :href => '#' }, :content => /#{category2.name}/ }
141 141 end
142 142  
143 143 should 'update subcategories' do
... ...