diff --git a/app/controllers/public/catalog_controller.rb b/app/controllers/public/catalog_controller.rb
new file mode 100644
index 0000000..569bd73
--- /dev/null
+++ b/app/controllers/public/catalog_controller.rb
@@ -0,0 +1,18 @@
+class CatalogController < ApplicationController
+ needs_profile
+ before_filter :check_enterprise
+
+ def index
+ @products = @profile.products
+ end
+
+ def show
+ @product = @profile.products.find(params[:id])
+ end
+
+ protected
+ def check_enterprise
+ @profile.kind_of? Enterprise
+ end
+
+end
diff --git a/app/controllers/public/product_category_viewer_controller.rb b/app/controllers/public/product_category_viewer_controller.rb
new file mode 100644
index 0000000..b228714
--- /dev/null
+++ b/app/controllers/public/product_category_viewer_controller.rb
@@ -0,0 +1,11 @@
+class ProductCategoryViewerController < ApplicationController
+ def index
+ @categories = ProductCategory.find(:all)
+ end
+
+ def view_category
+ @category = ProductCategory.find(params[:id])
+ @products = Product.find(:all, :conditions => ['product_category_id = ?', params[:id]])
+ @enterprises = Enterprise.find(:all, :conditions => ['products.id in (?)', @products.map(&:id)], :include => :products)
+ end
+end
diff --git a/app/design_blocks/list_block/controllers/list_block_controller.rb b/app/design_blocks/list_block/controllers/list_block_controller.rb
index 597d20f..75b8704 100644
--- a/app/design_blocks/list_block/controllers/list_block_controller.rb
+++ b/app/design_blocks/list_block/controllers/list_block_controller.rb
@@ -21,7 +21,7 @@ class ListBlockController < ApplicationController
#
# This hash will define the options menu on edit mode.
CONTROL_ACTION_OPTIONS = {
-# 'edit' => _('Edit')
+ 'edit' => _('Edit')
}
@@ -30,22 +30,28 @@ class ListBlockController < ApplicationController
###########################
def index
- @people = Person.find(:all)
+ @people = @design_block.people
design_render
end
###########################
# Other Sample of methods
###########################
-
-# def edit
-# design_render_on_edit
-# end
-
-# def save
-# @design_block.update_attributes(params[:design_block])
-# design_render_on_edit :nothing => true
-# end
+
+
+ def edit
+ design_render_on_edit :controller => 'list_block', :action => 'edit'
+ end
+ def save
+ if @design_block.update_attributes(params[:design_block])
+ design_render_on_edit :controller => 'list_block', :action => 'show'
+ else
+ design_render_on_edit :nothing => true
+ end
+ end
+
+ def show
+ end
end
diff --git a/app/design_blocks/list_block/models/list_block.rb b/app/design_blocks/list_block/models/list_block.rb
index d22c154..f37258c 100644
--- a/app/design_blocks/list_block/models/list_block.rb
+++ b/app/design_blocks/list_block/models/list_block.rb
@@ -11,5 +11,17 @@ class ListBlock < Design::Block
def self.description
_('List Block')
end
+
+ def limit_number= value
+ self.settings[:limit_number] = value.to_i == 0 ? nil : value.to_i
+ end
+
+ def limit_number
+ self.settings[:limit_number]
+ end
+
+ def people
+ Person.find(:all, :limit => limit_number)
+ end
end
diff --git a/app/design_blocks/list_block/views/index.rhtml b/app/design_blocks/list_block/views/index.rhtml
index a267a59..14037d0 100644
--- a/app/design_blocks/list_block/views/index.rhtml
+++ b/app/design_blocks/list_block/views/index.rhtml
@@ -1,5 +1,5 @@
<% @people.each do |p| %>
- - <%= link_to_homepage(content_tag('span', p.name), p.identifier) %>
+ - <%= link_to_homepage(content_tag('span', (p.image ? (image_tag p.image.public_filename) : p.name)), p.identifier) %>
<% end %>
diff --git a/app/helpers/catalog_helper.rb b/app/helpers/catalog_helper.rb
new file mode 100644
index 0000000..5db5cf8
--- /dev/null
+++ b/app/helpers/catalog_helper.rb
@@ -0,0 +1,2 @@
+module CatalogHelper
+end
diff --git a/app/helpers/product_category_viewer_helper.rb b/app/helpers/product_category_viewer_helper.rb
new file mode 100644
index 0000000..fb08b02
--- /dev/null
+++ b/app/helpers/product_category_viewer_helper.rb
@@ -0,0 +1,2 @@
+module ProductCategoryViewerHelper
+end
diff --git a/app/models/product.rb b/app/models/product.rb
index 2159856..b178805 100644
--- a/app/models/product.rb
+++ b/app/models/product.rb
@@ -21,4 +21,9 @@ class Product < ActiveRecord::Base
def save_image
image.save if image
end
+
+ def category_name
+ product_category ? product_category.name : _('Uncategorized product')
+ end
+
end
diff --git a/app/models/product_category.rb b/app/models/product_category.rb
index 6964f0e..1f318c2 100644
--- a/app/models/product_category.rb
+++ b/app/models/product_category.rb
@@ -1,3 +1,5 @@
class ProductCategory < Category
has_many :products
+ has_many :consumptions
+ has_many :consumers, :through => :consumptions, :source => :profile_id
end
diff --git a/app/models/profile.rb b/app/models/profile.rb
index ed8dc9b..390de94 100644
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -15,7 +15,7 @@ class Profile < ActiveRecord::Base
acts_as_design
- acts_as_ferret :fields => [ :name ]
+# acts_as_ferret :fields => [ :name ]
# Valid identifiers must match this format.
IDENTIFIER_FORMAT = /^[a-z][a-z0-9_]*[a-z0-9]$/
@@ -47,6 +47,9 @@ class Profile < ActiveRecord::Base
has_one :image, :as => :owner
+ has_many :consumptions
+ has_many :consumed_product_categories, :through => :consumptions, :source => :product_category
+
def top_level_articles(reload = false)
if reload
@top_level_articles = nil
diff --git a/app/views/catalog/index.rhtml b/app/views/catalog/index.rhtml
new file mode 100644
index 0000000..d71e7ef
--- /dev/null
+++ b/app/views/catalog/index.rhtml
@@ -0,0 +1,11 @@
+ <%= _('Catalog') %>
+
+
+<% @products.each do |p| %>
+ -
+ <%= link_to p.name, :action => 'show', :id => p %>
+ <%= image_tag p.image.public_filename if p.image %>
+ <%= p.price %>
+
+<% end %>
+
diff --git a/app/views/catalog/show.rhtml b/app/views/catalog/show.rhtml
new file mode 100644
index 0000000..e411321
--- /dev/null
+++ b/app/views/catalog/show.rhtml
@@ -0,0 +1,6 @@
+ <%= @product.name %>
+
+<%= image_tag @product.image.public_filename if @product.image %>
+<%= @product.price %>
+<%= @product.description %>
+<%= @product.category_name %>
diff --git a/app/views/product_category_viewer/index.rhtml b/app/views/product_category_viewer/index.rhtml
new file mode 100644
index 0000000..6efb0c3
--- /dev/null
+++ b/app/views/product_category_viewer/index.rhtml
@@ -0,0 +1,7 @@
+ <%= _('Categories of products') %>
+
+
+<% @categories.each do |c| %>
+ - <%= link_to c.name, :action => 'view_category', :id => c.id %>
+<% end %>
+
diff --git a/app/views/product_category_viewer/view_category.rhtml b/app/views/product_category_viewer/view_category.rhtml
new file mode 100644
index 0000000..46b1168
--- /dev/null
+++ b/app/views/product_category_viewer/view_category.rhtml
@@ -0,0 +1,13 @@
+<%= @category.name %>
+
+<%= @products.size.to_s + " products in this category" %>
+<%= @enterprises.size.to_s + " enterprises sells products in this category" %>
+
+
+ <% @products.each do |p| %>
+ -
+ <%= image_tag p.image.public_filename(:thumb) %> <%= p.name %>
+ <% _('Price:') %> <% p.price %> <%= _('Enterprise:') %> <%= link_to_homepage p.enterprise.name, p.enterprise.identifier %>
+
+ <% end %>
+
diff --git a/config/routes.rb b/config/routes.rb
index 61d88ae..09dbcbf 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -67,7 +67,10 @@ ActionController::Routing::Routes.draw do |map|
## Test controllers.
## FIXME: this should not be needed
######################################################
- map.connect 'test/:controller/:action/:id' #, :controller => /.*test.*/
+ map.connect 'test/:controller/:action/:id' , :controller => /.*test.*/
+
+ map.connect ':profile/catalog/:action/:id', :controller => 'catalog'
+
# *content viewing*
# XXX this route must come last so other routes have priority over it.
diff --git a/test/functional/catalog_controller_test.rb b/test/functional/catalog_controller_test.rb
new file mode 100644
index 0000000..27e0c4c
--- /dev/null
+++ b/test/functional/catalog_controller_test.rb
@@ -0,0 +1,18 @@
+require File.dirname(__FILE__) + '/../test_helper'
+require 'catalog_controller'
+
+# Re-raise errors caught by the controller.
+class CatalogController; def rescue_action(e) raise e end; end
+
+class CatalogControllerTest < Test::Unit::TestCase
+ def setup
+ @controller = CatalogController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ end
+
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end
diff --git a/test/functional/product_category_viewer_controller_test.rb b/test/functional/product_category_viewer_controller_test.rb
new file mode 100644
index 0000000..737031c
--- /dev/null
+++ b/test/functional/product_category_viewer_controller_test.rb
@@ -0,0 +1,18 @@
+require File.dirname(__FILE__) + '/../test_helper'
+require 'product_category_viewer_controller'
+
+# Re-raise errors caught by the controller.
+class ProductCategoryViewerController; def rescue_action(e) raise e end; end
+
+class ProductCategoryViewerControllerTest < Test::Unit::TestCase
+ def setup
+ @controller = ProductCategoryViewerController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ end
+
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end
--
libgit2 0.21.2