Commit 118042b5d1e8de4bd9fe935a0ed7587930a50095
1 parent
4fc900d2
Exists in
master
and in
22 other branches
ActionItem28: added consume management
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@992 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
17 changed files
with
151 additions
and
14 deletions
Show diff stats
@@ -0,0 +1,18 @@ | @@ -0,0 +1,18 @@ | ||
1 | +class CatalogController < ApplicationController | ||
2 | + needs_profile | ||
3 | + before_filter :check_enterprise | ||
4 | + | ||
5 | + def index | ||
6 | + @products = @profile.products | ||
7 | + end | ||
8 | + | ||
9 | + def show | ||
10 | + @product = @profile.products.find(params[:id]) | ||
11 | + end | ||
12 | + | ||
13 | + protected | ||
14 | + def check_enterprise | ||
15 | + @profile.kind_of? Enterprise | ||
16 | + end | ||
17 | + | ||
18 | +end |
app/controllers/public/product_category_viewer_controller.rb
0 → 100644
@@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
1 | +class ProductCategoryViewerController < ApplicationController | ||
2 | + def index | ||
3 | + @categories = ProductCategory.find(:all) | ||
4 | + end | ||
5 | + | ||
6 | + def view_category | ||
7 | + @category = ProductCategory.find(params[:id]) | ||
8 | + @products = Product.find(:all, :conditions => ['product_category_id = ?', params[:id]]) | ||
9 | + @enterprises = Enterprise.find(:all, :conditions => ['products.id in (?)', @products.map(&:id)], :include => :products) | ||
10 | + end | ||
11 | +end |
app/design_blocks/list_block/controllers/list_block_controller.rb
@@ -21,7 +21,7 @@ class ListBlockController < ApplicationController | @@ -21,7 +21,7 @@ class ListBlockController < ApplicationController | ||
21 | # | 21 | # |
22 | # This hash will define the options menu on edit mode. | 22 | # This hash will define the options menu on edit mode. |
23 | CONTROL_ACTION_OPTIONS = { | 23 | CONTROL_ACTION_OPTIONS = { |
24 | -# 'edit' => _('Edit') | 24 | + 'edit' => _('Edit') |
25 | } | 25 | } |
26 | 26 | ||
27 | 27 | ||
@@ -30,22 +30,28 @@ class ListBlockController < ApplicationController | @@ -30,22 +30,28 @@ class ListBlockController < ApplicationController | ||
30 | ########################### | 30 | ########################### |
31 | 31 | ||
32 | def index | 32 | def index |
33 | - @people = Person.find(:all) | 33 | + @people = @design_block.people |
34 | design_render | 34 | design_render |
35 | end | 35 | end |
36 | 36 | ||
37 | ########################### | 37 | ########################### |
38 | # Other Sample of methods | 38 | # Other Sample of methods |
39 | ########################### | 39 | ########################### |
40 | - | ||
41 | -# def edit | ||
42 | -# design_render_on_edit | ||
43 | -# end | ||
44 | - | ||
45 | -# def save | ||
46 | -# @design_block.update_attributes(params[:design_block]) | ||
47 | -# design_render_on_edit :nothing => true | ||
48 | -# end | 40 | + |
41 | + | ||
42 | + def edit | ||
43 | + design_render_on_edit :controller => 'list_block', :action => 'edit' | ||
44 | + end | ||
49 | 45 | ||
46 | + def save | ||
47 | + if @design_block.update_attributes(params[:design_block]) | ||
48 | + design_render_on_edit :controller => 'list_block', :action => 'show' | ||
49 | + else | ||
50 | + design_render_on_edit :nothing => true | ||
51 | + end | ||
52 | + end | ||
53 | + | ||
54 | + def show | ||
55 | + end | ||
50 | 56 | ||
51 | end | 57 | end |
app/design_blocks/list_block/models/list_block.rb
@@ -11,5 +11,17 @@ class ListBlock < Design::Block | @@ -11,5 +11,17 @@ class ListBlock < Design::Block | ||
11 | def self.description | 11 | def self.description |
12 | _('List Block') | 12 | _('List Block') |
13 | end | 13 | end |
14 | + | ||
15 | + def limit_number= value | ||
16 | + self.settings[:limit_number] = value.to_i == 0 ? nil : value.to_i | ||
17 | + end | ||
18 | + | ||
19 | + def limit_number | ||
20 | + self.settings[:limit_number] | ||
21 | + end | ||
22 | + | ||
23 | + def people | ||
24 | + Person.find(:all, :limit => limit_number) | ||
25 | + end | ||
14 | 26 | ||
15 | end | 27 | end |
app/design_blocks/list_block/views/index.rhtml
1 | <ul class='people_list_block'> | 1 | <ul class='people_list_block'> |
2 | <% @people.each do |p| %> | 2 | <% @people.each do |p| %> |
3 | - <li> <%= link_to_homepage(content_tag('span', p.name), p.identifier) %> </li> | 3 | + <li> <%= link_to_homepage(content_tag('span', (p.image ? (image_tag p.image.public_filename) : p.name)), p.identifier) %> </li> |
4 | <% end %> | 4 | <% end %> |
5 | </ul> | 5 | </ul> |
app/models/product.rb
@@ -21,4 +21,9 @@ class Product < ActiveRecord::Base | @@ -21,4 +21,9 @@ class Product < ActiveRecord::Base | ||
21 | def save_image | 21 | def save_image |
22 | image.save if image | 22 | image.save if image |
23 | end | 23 | end |
24 | + | ||
25 | + def category_name | ||
26 | + product_category ? product_category.name : _('Uncategorized product') | ||
27 | + end | ||
28 | + | ||
24 | end | 29 | end |
app/models/product_category.rb
app/models/profile.rb
@@ -15,7 +15,7 @@ class Profile < ActiveRecord::Base | @@ -15,7 +15,7 @@ class Profile < ActiveRecord::Base | ||
15 | 15 | ||
16 | acts_as_design | 16 | acts_as_design |
17 | 17 | ||
18 | - acts_as_ferret :fields => [ :name ] | 18 | +# acts_as_ferret :fields => [ :name ] |
19 | 19 | ||
20 | # Valid identifiers must match this format. | 20 | # Valid identifiers must match this format. |
21 | IDENTIFIER_FORMAT = /^[a-z][a-z0-9_]*[a-z0-9]$/ | 21 | IDENTIFIER_FORMAT = /^[a-z][a-z0-9_]*[a-z0-9]$/ |
@@ -47,6 +47,9 @@ class Profile < ActiveRecord::Base | @@ -47,6 +47,9 @@ class Profile < ActiveRecord::Base | ||
47 | 47 | ||
48 | has_one :image, :as => :owner | 48 | has_one :image, :as => :owner |
49 | 49 | ||
50 | + has_many :consumptions | ||
51 | + has_many :consumed_product_categories, :through => :consumptions, :source => :product_category | ||
52 | + | ||
50 | def top_level_articles(reload = false) | 53 | def top_level_articles(reload = false) |
51 | if reload | 54 | if reload |
52 | @top_level_articles = nil | 55 | @top_level_articles = nil |
@@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
1 | +<h2> <%= _('Catalog') %> </h2> | ||
2 | + | ||
3 | +<ul> | ||
4 | +<% @products.each do |p| %> | ||
5 | + <li> | ||
6 | + <%= link_to p.name, :action => 'show', :id => p %> <br/> | ||
7 | + <%= image_tag p.image.public_filename if p.image %> <br/> | ||
8 | + <%= p.price %> <br/><br/> | ||
9 | + </li> | ||
10 | +<% end %> | ||
11 | +</ul> |
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +<h3><%= @category.name %> </h3> | ||
2 | + | ||
3 | +<%= @products.size.to_s + " products in this category" %> | ||
4 | +<%= @enterprises.size.to_s + " enterprises sells products in this category" %> | ||
5 | + | ||
6 | +<ul> | ||
7 | + <% @products.each do |p| %> | ||
8 | + <li> | ||
9 | + <%= image_tag p.image.public_filename(:thumb) %> <%= p.name %> <br/> | ||
10 | + <% _('Price:') %> <% p.price %> <%= _('Enterprise:') %> <%= link_to_homepage p.enterprise.name, p.enterprise.identifier %> <br/><br/> | ||
11 | + </li> | ||
12 | + <% end %> | ||
13 | +</ul> |
config/routes.rb
@@ -67,7 +67,10 @@ ActionController::Routing::Routes.draw do |map| | @@ -67,7 +67,10 @@ ActionController::Routing::Routes.draw do |map| | ||
67 | ## Test controllers. | 67 | ## Test controllers. |
68 | ## FIXME: this should not be needed | 68 | ## FIXME: this should not be needed |
69 | ###################################################### | 69 | ###################################################### |
70 | - map.connect 'test/:controller/:action/:id' #, :controller => /.*test.*/ | 70 | + map.connect 'test/:controller/:action/:id' , :controller => /.*test.*/ |
71 | + | ||
72 | + map.connect ':profile/catalog/:action/:id', :controller => 'catalog' | ||
73 | + | ||
71 | 74 | ||
72 | # *content viewing* | 75 | # *content viewing* |
73 | # XXX this route must come last so other routes have priority over it. | 76 | # XXX this route must come last so other routes have priority over it. |
@@ -0,0 +1,18 @@ | @@ -0,0 +1,18 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | +require 'catalog_controller' | ||
3 | + | ||
4 | +# Re-raise errors caught by the controller. | ||
5 | +class CatalogController; def rescue_action(e) raise e end; end | ||
6 | + | ||
7 | +class CatalogControllerTest < Test::Unit::TestCase | ||
8 | + def setup | ||
9 | + @controller = CatalogController.new | ||
10 | + @request = ActionController::TestRequest.new | ||
11 | + @response = ActionController::TestResponse.new | ||
12 | + end | ||
13 | + | ||
14 | + # Replace this with your real tests. | ||
15 | + def test_truth | ||
16 | + assert true | ||
17 | + end | ||
18 | +end |
test/functional/product_category_viewer_controller_test.rb
0 → 100644
@@ -0,0 +1,18 @@ | @@ -0,0 +1,18 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | +require 'product_category_viewer_controller' | ||
3 | + | ||
4 | +# Re-raise errors caught by the controller. | ||
5 | +class ProductCategoryViewerController; def rescue_action(e) raise e end; end | ||
6 | + | ||
7 | +class ProductCategoryViewerControllerTest < Test::Unit::TestCase | ||
8 | + def setup | ||
9 | + @controller = ProductCategoryViewerController.new | ||
10 | + @request = ActionController::TestRequest.new | ||
11 | + @response = ActionController::TestResponse.new | ||
12 | + end | ||
13 | + | ||
14 | + # Replace this with your real tests. | ||
15 | + def test_truth | ||
16 | + assert true | ||
17 | + end | ||
18 | +end |