Commit c90b8e63ac3b9700b9c23242f391244ed4181181
1 parent
7af9fa59
Exists in
master
and in
22 other branches
Highlight the products in listing
(ActionItem2439)
Showing
9 changed files
with
62 additions
and
2 deletions
Show diff stats
app/helpers/display_helper.rb
| ... | ... | @@ -8,6 +8,14 @@ module DisplayHelper |
| 8 | 8 | opts |
| 9 | 9 | end |
| 10 | 10 | |
| 11 | + def themed_path(file) | |
| 12 | + if File.exists?(File.join(Rails.root, 'public', theme_path, file)) | |
| 13 | + File.join(theme_path, file) | |
| 14 | + else | |
| 15 | + file | |
| 16 | + end | |
| 17 | + end | |
| 18 | + | |
| 11 | 19 | def image_link_to_product(product, opts={}) |
| 12 | 20 | return _('No product') unless product |
| 13 | 21 | target = product_path(product) | ... | ... |
app/views/catalog/index.rhtml
| ... | ... | @@ -8,9 +8,12 @@ |
| 8 | 8 | <% extra_content = @plugins.dispatch(:catalog_item_extras, product).collect { |content| instance_eval(&content) } %> |
| 9 | 9 | <% extra_content_list = @plugins.dispatch(:catalog_list_item_extras, product).collect { |content| instance_eval(&content) } %> |
| 10 | 10 | |
| 11 | - <li class="product <%= "not-available" unless product.available %>"> | |
| 11 | + <li class="product<%= " not-available" unless product.available %><%= ' highlighted-product' if product.highlighted? %>"> | |
| 12 | 12 | <ul> |
| 13 | 13 | <li class="product-image-link"> |
| 14 | + <% if product.highlighted? %> | |
| 15 | + <%= link_to image_tag(themed_path('/images/star.png'), :class => 'star', :alt => _('Highlighted product')), product_path(product) %> | |
| 16 | + <% end %> | |
| 14 | 17 | <% if product.image %> |
| 15 | 18 | <div class="zoomable-image"> |
| 16 | 19 | <%= link_to_product product, :class => 'product-big', :style => "background-image: url(#{product.default_image(:big)})" %> | ... | ... |
app/views/search/_product.rhtml
| 1 | 1 | <% extra_content = @plugins.dispatch(:asset_product_extras, product, product.enterprise).collect { |content| instance_eval(&content) } %> |
| 2 | 2 | <% extra_properties = @plugins.dispatch(:asset_product_properties, product)%> |
| 3 | 3 | |
| 4 | -<li class="search-product-item"> | |
| 4 | +<li class="search-product-item <%= 'highlighted-product' if product.highlighted? %>"> | |
| 5 | 5 | |
| 6 | 6 | <div class="search-product-item-first-column"> |
| 7 | 7 | <%= render :partial => 'search/image', :object => product %> | ... | ... |
1.75 KB
3.58 KB
public/stylesheets/application.css
| ... | ... | @@ -6146,3 +6146,10 @@ li.profile-activity-item.upload_image .activity-gallery-images-count-1 img { |
| 6146 | 6146 | width: 100px; |
| 6147 | 6147 | text-align: center; |
| 6148 | 6148 | } |
| 6149 | + | |
| 6150 | +#product-list .highlighted-product img.star { | |
| 6151 | + position: absolute; | |
| 6152 | + top: 2px; | |
| 6153 | + right: 2px; | |
| 6154 | + z-index: 10; | |
| 6155 | +} | ... | ... |
test/functional/catalog_controller_test.rb
| ... | ... | @@ -109,4 +109,22 @@ class CatalogControllerTest < ActionController::TestCase |
| 109 | 109 | assert_tag :tag => 'span', :content => 'This is Plugin2 speaking!', :attributes => {:id => 'plugin2'} |
| 110 | 110 | end |
| 111 | 111 | |
| 112 | + should 'add highlighted-product CSS class around a highlighted product' do | |
| 113 | + prod = @enterprise.products.create!(:name => 'Highlighted Product', :product_category => @product_category, :highlighted => true) | |
| 114 | + get :index, :profile => @enterprise.identifier | |
| 115 | + assert_tag :tag => 'li', :attributes => { :class => 'product highlighted-product' }, :content => /Highlighted Product/ | |
| 116 | + end | |
| 117 | + | |
| 118 | + should 'do not add highlighted-product CSS class around an ordinary product' do | |
| 119 | + prod = @enterprise.products.create!(:name => 'Ordinary Product', :product_category => @product_category, :highlighted => false) | |
| 120 | + get :index, :profile => @enterprise.identifier | |
| 121 | + assert_no_tag :tag => 'li', :attributes => { :class => 'product highlighted-product' }, :content => /Ordinary Product/ | |
| 122 | + end | |
| 123 | + | |
| 124 | + should 'display star image in highlighted product' do | |
| 125 | + prod = @enterprise.products.create!(:name => 'The Eyes Are The Light', :product_category => @product_category, :highlighted => true) | |
| 126 | + get :index, :profile => @enterprise.identifier | |
| 127 | + assert_tag :tag => 'img', :attributes => { :class => 'star', :src => /star.png/ } | |
| 128 | + end | |
| 129 | + | |
| 112 | 130 | end | ... | ... |
test/functional/search_controller_test.rb
| ... | ... | @@ -926,6 +926,20 @@ class SearchControllerTest < ActionController::TestCase |
| 926 | 926 | end |
| 927 | 927 | end |
| 928 | 928 | |
| 929 | + should 'add highlighted-product CSS class around a highlighted product' do | |
| 930 | + enterprise = fast_create(Enterprise) | |
| 931 | + product = Product.create!(:name => 'Enter Sandman', :enterprise_id => enterprise.id, :product_category_id => @product_category.id, :highlighted => true) | |
| 932 | + get :products | |
| 933 | + assert_tag :tag => 'li', :attributes => { :class => 'search-product-item highlighted-product' }, :content => /Enter Sandman/ | |
| 934 | + end | |
| 935 | + | |
| 936 | + should 'do not add highlighted-product CSS class around an ordinary product' do | |
| 937 | + enterprise = fast_create(Enterprise) | |
| 938 | + product = Product.create!(:name => 'Holier Than Thou', :enterprise_id => enterprise.id, :product_category_id => @product_category.id, :highlighted => false) | |
| 939 | + get :products | |
| 940 | + assert_no_tag :tag => 'li', :attributes => { :class => 'search-product-item highlighted-product' }, :content => /Holier Than Thou/ | |
| 941 | + end | |
| 942 | + | |
| 929 | 943 | ################################################################## |
| 930 | 944 | ################################################################## |
| 931 | 945 | ... | ... |
test/unit/display_helper_test.rb
| ... | ... | @@ -44,4 +44,14 @@ class DisplayHelperTest < ActiveSupport::TestCase |
| 44 | 44 | assert_equal 'go to <a href="http://www.noosfero.org" onclick="return confirm(\'Are you sure you want to visit this web site?\')" rel="nofolow" target="_blank">www.​noos​fero​.org</a> yeah!', html |
| 45 | 45 | end |
| 46 | 46 | |
| 47 | + should 'return path to file under theme dir if theme has that file' do | |
| 48 | + stubs(:theme_path).returns('/designs/themes/noosfero') | |
| 49 | + assert_equal '/designs/themes/noosfero/images/rails.png', themed_path('/images/rails.png') | |
| 50 | + end | |
| 51 | + | |
| 52 | + should 'return path to file under public dir if theme hasnt that file' do | |
| 53 | + stubs(:theme_path).returns('/designs/themes/noosfero') | |
| 54 | + assert_equal '/images/invalid-file.png', themed_path('/images/invalid-file.png') | |
| 55 | + end | |
| 56 | + | |
| 47 | 57 | end | ... | ... |