Commit 81ca0e3a779187100adb58d6e96d5ee030707bee

Authored by Rodrigo Souto
2 parents 5a911ba4 278f8b85

Merge commit 'refs/merge-requests/264' of git://gitorious.org/noosfero/noosfero …

…into merge-requests/264

Conflicts:
	app/controllers/public/catalog_controller.rb
	app/views/catalog/index.rhtml
app/controllers/public/catalog_controller.rb
@@ -5,15 +5,14 @@ class CatalogController < PublicController @@ -5,15 +5,14 @@ class CatalogController < PublicController
5 before_filter :check_enterprise_and_environment 5 before_filter :check_enterprise_and_environment
6 6
7 def index 7 def index
8 - @category = params[:level] ? ProductCategory.find(params[:level]) : nil  
9 - @products = @profile.products.from_category(@category).paginate(:order => 'available desc, highlighted desc, name asc', :per_page => 9, :page => params[:page])  
10 - @categories = ProductCategory.on_level(params[:level]).order(:name) 8 + extend CatalogHelper
  9 + catalog_load_index
11 end 10 end
12 11
13 protected 12 protected
14 13
15 def check_enterprise_and_environment 14 def check_enterprise_and_environment
16 - unless @profile.kind_of?(Enterprise) && !@profile.environment.enabled?('disable_products_for_enterprises') 15 + unless profile.kind_of?(Enterprise) && !profile.environment.enabled?('disable_products_for_enterprises')
17 redirect_to :controller => 'profile', :profile => profile.identifier, :action => 'index' 16 redirect_to :controller => 'profile', :profile => profile.identifier, :action => 'index'
18 end 17 end
19 end 18 end
app/helpers/catalog_helper.rb
@@ -3,9 +3,18 @@ module CatalogHelper @@ -3,9 +3,18 @@ module CatalogHelper
3 include DisplayHelper 3 include DisplayHelper
4 include ManageProductsHelper 4 include ManageProductsHelper
5 5
  6 + def catalog_load_index options = {:page => params[:page], :show_categories => true}
  7 + if options[:show_categories]
  8 + @category = params[:level] ? ProductCategory.find(params[:level]) : nil
  9 + @categories = ProductCategory.on_level(params[:level]).order(:name)
  10 + end
  11 +
  12 + @products = profile.products.from_category(@category).paginate(:order => 'available desc, highlighted desc, name asc', :per_page => 9, :page => options[:page])
  13 + end
  14 +
6 def breadcrumb(category) 15 def breadcrumb(category)
7 - start = link_to(_('Start'), {:action => 'index'})  
8 - ancestors = category.ancestors.map { |c| link_to(c.name, {:action => 'index', :level => c.id}) }.reverse 16 + start = link_to(_('Start'), {:controller => :catalog, :action => 'index'})
  17 + ancestors = category.ancestors.map { |c| link_to(c.name, {:controller => :catalog, :action => 'index', :level => c.id}) }.reverse
9 current_level = content_tag('strong', category.name) 18 current_level = content_tag('strong', category.name)
10 all_items = [start] + ancestors + [current_level] 19 all_items = [start] + ancestors + [current_level]
11 content_tag('div', all_items.join(' → '), :id => 'breadcrumb') 20 content_tag('div', all_items.join(' → '), :id => 'breadcrumb')
@@ -15,7 +24,7 @@ module CatalogHelper @@ -15,7 +24,7 @@ module CatalogHelper
15 count = profile.products.from_category(category).count 24 count = profile.products.from_category(category).count
16 name = truncate(category.name, :length => 22 - count.to_s.size) 25 name = truncate(category.name, :length => 22 - count.to_s.size)
17 link_name = sub ? name : content_tag('strong', name) 26 link_name = sub ? name : content_tag('strong', name)
18 - link = link_to(link_name, {:action => 'index', :level => category.id}, :title => category.name) 27 + link = link_to(link_name, {:controller => :catalog, :action => 'index', :level => category.id}, :title => category.name)
19 content_tag('li', "#{link} (#{count})") if count > 0 28 content_tag('li', "#{link} (#{count})") if count > 0
20 end 29 end
21 30
app/models/enterprise_homepage.rb
@@ -20,7 +20,8 @@ class EnterpriseHomepage < Article @@ -20,7 +20,8 @@ class EnterpriseHomepage < Article
20 enterprise_homepage = self 20 enterprise_homepage = self
21 lambda do 21 lambda do
22 extend EnterpriseHomepageHelper 22 extend EnterpriseHomepageHelper
23 - @products = profile.products.paginate(:order => 'id asc', :per_page => 9, :page => 1) 23 + extend CatalogHelper
  24 + catalog_load_index :page => 1, :show_categories => false
24 render :partial => 'content_viewer/enterprise_homepage', :object => enterprise_homepage 25 render :partial => 'content_viewer/enterprise_homepage', :object => enterprise_homepage
25 end 26 end
26 end 27 end
app/views/catalog/index.rhtml
@@ -3,26 +3,28 @@ @@ -3,26 +3,28 @@
3 3
4 <h1><%= _('Products/Services') %></h1> 4 <h1><%= _('Products/Services') %></h1>
5 5
6 -<%= breadcrumb(@category) if params[:level] %>  
7 -  
8 -<div class='l-sidebar-left-bar'>  
9 - <ul>  
10 - <%= content_tag('li', link_to(_('Homepage'), profile.url), :class => 'catalog-categories-link') %>  
11 - <%= content_tag('li', link_to(_('Catalog start'), profile.catalog_url), :class => 'catalog-categories-link') %>  
12 - <% if @categories.present? %>  
13 - <% @categories.each do |category| %>  
14 - <%= category_link(category) %>  
15 - <%= category_sub_links(category) %> 6 +<% if @categories %>
  7 + <%= breadcrumb(@category) if params[:level] %>
  8 +
  9 + <div class='l-sidebar-left-bar'>
  10 + <ul>
  11 + <%= content_tag('li', link_to(_('Homepage'), profile.url), :class => 'catalog-categories-link') %>
  12 + <%= content_tag('li', link_to(_('Catalog start'), profile.catalog_url), :class => 'catalog-categories-link') %>
  13 + <% if @categories.present? %>
  14 + <% @categories.each do |category| %>
  15 + <%= category_link(category) %>
  16 + <%= category_sub_links(category) %>
  17 + <% end %>
  18 + <% elsif @category.present? %>
  19 + <%= content_tag('li', _('There are no sub-categories for %s') % @category.name, :id => 'catalog-categories-notice') %>
  20 + <% else %>
  21 + <%= content_tag('li', _('There are no categories available.'), :id => 'catalog-categories-notice') %>
16 <% end %> 22 <% end %>
17 - <% elsif @category.present? %>  
18 - <%= content_tag('li', _('There are no sub-categories for %s') % @category.name, :id => 'catalog-categories-notice') %>  
19 - <% else %>  
20 - <%= content_tag('li', _('There are no categories available.'), :id => 'catalog-categories-notice') %>  
21 - <% end %>  
22 - </ul>  
23 -</div>  
24 -  
25 -<ul id="product-list" class="l-sidebar-left-content"> 23 + </ul>
  24 + </div>
  25 +<% end %>
  26 +
  27 +<ul id="product-list" class="<%="l-sidebar-left-content" if @categories %>">
26 <% @products.each do |product| %> 28 <% @products.each do |product| %>
27 <% extra_content = @plugins.dispatch(:catalog_item_extras, product).collect { |content| instance_eval(&content) } %> 29 <% extra_content = @plugins.dispatch(:catalog_item_extras, product).collect { |content| instance_eval(&content) } %>
28 <% extra_content_list = @plugins.dispatch(:catalog_list_item_extras, product).collect { |content| instance_eval(&content) } %> 30 <% extra_content_list = @plugins.dispatch(:catalog_list_item_extras, product).collect { |content| instance_eval(&content) } %>