Commit
f36a52e1b05da6ba88a49ec0db2198a9f01548d3
Exists in
master
and in
22 other branches
angular_poc, api-article-archived, article-readonly, backup-7-jan-2016, captcha_serpro_plugin, content-manager-hostspot, export-comment-paragraph, fix_event_date_issue, login-captcha, master_rails3, new_video_plugin, pg_search_rank, production, refactor_with_role, refactor_with_role_scope, remove_profile_cat_icons, resend_confirmation_email, staging, staging_rails3, tasks_keep_filter_params, theme-brasil-digital-from-staging, travis
ActionItem28: added consumed products management
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1019 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
14 changed files
with
89 additions
and
24 deletions
Show diff stats
| @@ -23,7 +23,18 @@ class CategoryController < ApplicationController |
| @@ -23,7 +23,18 @@ class CategoryController < ApplicationController |
23
| |
23
| |
24
| # view the summary of one category |
24
| # view the summary of one category |
25
| def view |
25
| def view |
| |
26
| + send(@category.class.name.underscore.to_sym) |
26
| # TODO: load articles, documents, etc so the view can list them. |
27
| # TODO: load articles, documents, etc so the view can list them. |
27
| end |
28
| end |
| |
29
| + |
| |
30
| + protected |
| |
31
| + def product_category |
| |
32
| + @products = Product.find(:all, :conditions => ['product_category_id = ?', @category.id]) |
| |
33
| + @enterprises = Enterprise.find(:all, :conditions => ['products.id in (?)', @products.map(&:id)], :include => :products) |
| |
34
| + end |
| |
35
| + |
| |
36
| + def category |
| |
37
| + end |
| |
38
| + |
28
| |
39
| |
29
| end |
40
| end |
| @@ -1,11 +0,0 @@ |
| @@ -1,11 +0,0 @@ |
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 |
| |
| @@ -334,4 +334,13 @@ module ApplicationHelper |
| @@ -334,4 +334,13 @@ module ApplicationHelper |
334
| concat(content_tag('div', capture(&block) + tag('br', :style => 'clear: left;'), options), block.binding) |
334
| concat(content_tag('div', capture(&block) + tag('br', :style => 'clear: left;'), options), block.binding) |
335
| end |
335
| end |
336
| |
336
| |
| |
337
| + def link_to_category(category) |
| |
338
| + return _('Uncategorized product') unless category |
| |
339
| + link_to category.name, :controller => 'category', :action => 'view', :path => category.path.split('/') |
| |
340
| + end |
| |
341
| + |
| |
342
| + def link_to_product(product) |
| |
343
| + return _('No product') unless product |
| |
344
| + link_to product.name, :controller => 'catalog', :action => 'show', :id => product, :profile => product.enterprise.identifier |
| |
345
| + end |
337
| end |
346
| end |
| @@ -0,0 +1,4 @@ |
| @@ -0,0 +1,4 @@ |
| |
1
| +class Consumption < ActiveRecord::Base |
| |
2
| + belongs_to :profile |
| |
3
| + belongs_to :product_category |
| |
4
| +end |
| @@ -10,6 +10,8 @@ class Product < ActiveRecord::Base |
| @@ -10,6 +10,8 @@ class Product < ActiveRecord::Base |
10
| |
10
| |
11
| after_update :save_image |
11
| after_update :save_image |
12
| |
12
| |
| |
13
| + acts_as_searchable :fields => [:name, :description] |
| |
14
| + |
13
| def image_builder=(img) |
15
| def image_builder=(img) |
14
| if image && image.id == img[:id] |
16
| if image && image.id == img[:id] |
15
| image.attributes = img |
17
| image.attributes = img |
| @@ -3,4 +3,4 @@ |
| @@ -3,4 +3,4 @@ |
3
| <%= image_tag @product.image.public_filename if @product.image %> <br/> |
3
| <%= image_tag @product.image.public_filename if @product.image %> <br/> |
4
| <%= @product.price %> <br/> |
4
| <%= @product.price %> <br/> |
5
| <%= @product.description %> <br/> |
5
| <%= @product.description %> <br/> |
6
| -<%= @product.category_name %> <br/> |
6
| +<%= link_to_category(@product.product_category) %> <br/> |
1
| <h2><%= _('Category: %s') % @category.full_name %></h2> |
1
| <h2><%= _('Category: %s') % @category.full_name %></h2> |
2
| |
2
| |
3
| -<%# FIXME %> |
| |
4
| -<p> |
| |
5
| -This page will list everything (articles, documents, photos, etc) that is |
| |
6
| -related to <%= @category.full_name %>. Actually generating this content is not |
| |
7
| -implement yet, though. |
| |
8
| -</p> |
| |
9
| - |
| |
10
| -<p> |
| |
11
| -And yes, this placeholder text is not translated. |
| |
12
| -</p> |
3
| +<%= render :partial => @category.class.name.underscore %> |
| @@ -0,0 +1,8 @@ |
| @@ -0,0 +1,8 @@ |
| |
1
| +<h2> <%=_('Listing products') %> </h2> |
| |
2
| + |
| |
3
| +<p> <%= link_to _('Add product'), :action => 'new' %> </p> |
| |
4
| + |
| |
5
| +<% @consumptions.each do |consumption| %> |
| |
6
| + <p> <b> <%= link_to consumption.product_category.name %> </b> |
| |
7
| + <%= link_to _('destroy'), :action => 'destroy', :id => consumption %> <br/> |
| |
8
| +<% end %> |
| @@ -0,0 +1,6 @@ |
| @@ -0,0 +1,6 @@ |
| |
1
| +<h2> <%= _('Add product') %> </h2> |
| |
2
| + |
| |
3
| +<% form_for :consumption, @consuption do |f| %> |
| |
4
| + <%= _('Product: ') %> <%= f.select "product_category_id", ProductCategory.find(:all).map{|pc| [pc.name, pc.id]} %> |
| |
5
| + <%= display_submit_tag _('Add product') %> |
| |
6
| +<% end %> |
| @@ -0,0 +1,10 @@ |
| @@ -0,0 +1,10 @@ |
| |
1
| +<h3> <%= @product.name %> </h3> |
| |
2
| + |
| |
3
| +<p> <%= image_tag @product.image.public_filename if @product.image %> </p> |
| |
4
| +<p> <%= _('Price: ') %> <%= @product.price %> </p> |
| |
5
| +<p> <%= _('Description: ') %> <%= @product.description %> </p> |
| |
6
| +<p> <%= _('Category: ') %> <%= @product.product_category ? @product.product_category.name : _('Uncategorized product') %> </p> |
| |
7
| + |
| |
8
| +<%= link_to _('destroy'), :action => 'destroy', :id => @product %> |
| |
9
| +<br/> |
| |
10
| +<%= link_to _('back'), :action => 'index' %> |
1
| <h3> <%= @product.name %> </h3> |
1
| <h3> <%= @product.name %> </h3> |
2
| |
2
| |
3
| -<p> <%= image_tag @product.image.public_filename %> </p> |
3
| +<p> <%= image_tag @product.image.public_filename if @product.image %> </p> |
4
| <p> <%= _('Price: ') %> <%= @product.price %> </p> |
4
| <p> <%= _('Price: ') %> <%= @product.price %> </p> |
5
| <p> <%= _('Description: ') %> <%= @product.description %> </p> |
5
| <p> <%= _('Description: ') %> <%= @product.description %> </p> |
6
| -<p> <%= _('Category: ') %> <%= @product.product_category ? @product.product_category.name : _('Uncategorized product') %> </p> |
6
| +<p> <%= _('Category: ') %> <%= link_to_category(@product.product_category) %> </p> |
7
| |
7
| |
8
| <%= link_to _('edit'), :action => 'edit', :id => @product %> |
8
| <%= link_to _('edit'), :action => 'edit', :id => @product %> |
9
| <%= link_to _('destroy'), :action => 'destroy', :id => @product %> |
9
| <%= link_to _('destroy'), :action => 'destroy', :id => @product %> |
| @@ -0,0 +1,12 @@ |
| @@ -0,0 +1,12 @@ |
| |
1
| +class CreateConsumptions < ActiveRecord::Migration |
| |
2
| + def self.up |
| |
3
| + create_table :consumptions do |t| |
| |
4
| + t.column :product_category_id, :integer |
| |
5
| + t.column :profile_id, :integer |
| |
6
| + end |
| |
7
| + end |
| |
8
| + |
| |
9
| + def self.down |
| |
10
| + drop_table :consumptions |
| |
11
| + end |
| |
12
| +end |
| @@ -0,0 +1,5 @@ |
| @@ -0,0 +1,5 @@ |
| |
1
| +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html |
| |
2
| +one: |
| |
3
| + id: 1 |
| |
4
| +two: |
| |
5
| + id: 2 |
| @@ -0,0 +1,18 @@ |
| @@ -0,0 +1,18 @@ |
| |
1
| +require File.dirname(__FILE__) + '/../test_helper' |
| |
2
| +require 'consumed_products_controller' |
| |
3
| + |
| |
4
| +# Re-raise errors caught by the controller. |
| |
5
| +class ConsumedProductsController; def rescue_action(e) raise e end; end |
| |
6
| + |
| |
7
| +class ConsumedProductsControllerTest < Test::Unit::TestCase |
| |
8
| + def setup |
| |
9
| + @controller = ConsumedProductsController.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 |