Commit f36a52e1b05da6ba88a49ec0db2198a9f01548d3
1 parent
3a8dd51e
Exists in
master
and in
29 other branches
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
app/controllers/public/category_controller.rb
... | ... | @@ -23,7 +23,18 @@ class CategoryController < ApplicationController |
23 | 23 | |
24 | 24 | # view the summary of one category |
25 | 25 | def view |
26 | + send(@category.class.name.underscore.to_sym) | |
26 | 27 | # TODO: load articles, documents, etc so the view can list them. |
27 | 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 | 40 | end | ... | ... |
app/controllers/public/product_category_viewer_controller.rb
... | ... | @@ -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 |
app/helpers/application_helper.rb
... | ... | @@ -334,4 +334,13 @@ module ApplicationHelper |
334 | 334 | concat(content_tag('div', capture(&block) + tag('br', :style => 'clear: left;'), options), block.binding) |
335 | 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 | 346 | end | ... | ... |
app/models/product.rb
app/views/catalog/show.rhtml
app/views/category/view.rhtml
1 | 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 @@ |
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 @@ |
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 @@ |
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' %> | ... | ... |
app/views/manage_products/show.rhtml
1 | 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 | 4 | <p> <%= _('Price: ') %> <%= @product.price %> </p> |
5 | 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 | 8 | <%= link_to _('edit'), :action => 'edit', :id => @product %> |
9 | 9 | <%= link_to _('destroy'), :action => 'destroy', :id => @product %> | ... | ... |
... | ... | @@ -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,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 | ... | ... |