Commit 2d8b231ff56dea22387b97d297ebd79c76fed38d
1 parent
c79fa28f
Exists in
master
and in
29 other branches
ActionItem93: added links to the views
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1036 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
19 changed files
with
101 additions
and
42 deletions
Show diff stats
app/controllers/my_profile/profile_members_controller.rb
app/models/consumption.rb
app/models/image.rb
| ... | ... | @@ -5,7 +5,7 @@ class Image < ActiveRecord::Base |
| 5 | 5 | :storage => :file_system, |
| 6 | 6 | :max_size => 500.kilobytes, |
| 7 | 7 | :resize_to => '320x200>', |
| 8 | - :thumbnails => { :thumb => '100x100>' } | |
| 8 | + :thumbnails => { :thumb => '100x100>', :minor => '64x64>' } | |
| 9 | 9 | |
| 10 | 10 | validates_as_attachment |
| 11 | 11 | end | ... | ... |
app/models/product_category.rb
| ... | ... | @@ -2,4 +2,12 @@ class ProductCategory < Category |
| 2 | 2 | has_many :products |
| 3 | 3 | has_many :consumptions |
| 4 | 4 | has_many :consumers, :through => :consumptions, :source => :profile_id |
| 5 | + | |
| 6 | + def tree | |
| 7 | + children.inject([]){|all,c| all + c.tree } << self | |
| 8 | + end | |
| 9 | + | |
| 10 | + def all_products | |
| 11 | + Product.find(:all, :conditions => { :product_category_id => tree.map(&:id) }) | |
| 12 | + end | |
| 5 | 13 | end | ... | ... |
app/views/category/view.rhtml
| 1 | -<h2><%= _('Category: %s') % @category.full_name %></h2> | |
| 1 | +<%= @category.ancestors.reverse.map { |a| link_to_category(a) }.join(' → ') %> | |
| 2 | + | |
| 3 | +<h2><%= _('Category: %s') % @category.name %></h2> | |
| 2 | 4 | |
| 3 | 5 | <%= render :partial => @category.class.name.underscore %> |
| 6 | + | |
| 7 | +<h4> <%= _('Children categories: ') %> </h4> | |
| 8 | +<% unless @category.children.empty? %> | |
| 9 | + <ul> | |
| 10 | + <% @category.children.each do |c| %> | |
| 11 | + <li> <%= link_to_category(c) %> </li> | |
| 12 | + <% end %> | |
| 13 | + </ul> | |
| 14 | +<% end %> | ... | ... |
app/views/consumed_products/index.rhtml
| ... | ... | @@ -3,6 +3,6 @@ |
| 3 | 3 | <p> <%= link_to _('Add product'), :action => 'new' %> </p> |
| 4 | 4 | |
| 5 | 5 | <% @consumptions.each do |consumption| %> |
| 6 | - <p> <b> <%= link_to consumption.product_category.name %> </b> | |
| 6 | + <p> <b> <%= link_to_category(consumption.product_category) %> </b> | |
| 7 | 7 | <%= link_to _('destroy'), :action => 'destroy', :id => consumption %> <br/> |
| 8 | 8 | <% end %> | ... | ... |
app/views/consumed_products/new.rhtml
| 1 | 1 | <h2> <%= _('Add product') %> </h2> |
| 2 | 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') %> | |
| 3 | +<%= error_messages_for :consumption %> | |
| 4 | + | |
| 5 | +<% form_for :consumption, @consumption do |f| %> | |
| 6 | + <p> <%= _('Product: ') %> <%= f.select "product_category_id", ProductCategory.find(:all).map{|pc| [pc.name, pc.id]} %></p> | |
| 7 | + <%= submit_tag _('Add product') %> | |
| 8 | + <%= link_to _('Cancel'), :action => 'index' %> | |
| 6 | 9 | <% end %> | ... | ... |
app/views/consumed_products/show.rhtml
| ... | ... | @@ -1,10 +0,0 @@ |
| 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/_form.rhtml
| ... | ... | @@ -7,4 +7,5 @@ |
| 7 | 7 | <%= display_form_field( _('Image:'), file_field_tag( "product[image_builder][uploaded_data]" ) ) %> |
| 8 | 8 | <%= display_form_field( _('category:'), f.select( :product_category_id,ProductCategory.find(:all).map{|pc|[pc.name,pc.id]}, {:include_blank => true} )) %> |
| 9 | 9 | <%= display_submit_tag(mode == 'new' ? _('Create product') : _('Save changes')) %> |
| 10 | + <%= link_to _('Cancel'), :action => 'index' %> | |
| 10 | 11 | <% end %> | ... | ... |
app/views/product_category_viewer/index.rhtml
app/views/product_category_viewer/view_category.rhtml
| ... | ... | @@ -1,13 +0,0 @@ |
| 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> |
app/views/profile_editor/index.rhtml
| ... | ... | @@ -14,15 +14,30 @@ |
| 14 | 14 | <%= file_manager_button(_('Manage Content'), 'icons-app/cms.png', :controller => 'cms') %> |
| 15 | 15 | |
| 16 | 16 | <%= file_manager_button(_('Change Password'), 'icons-app/change-password.png', :controller => 'account', :action => 'change_password') if profile.person? %> |
| 17 | - | |
| 17 | + | |
| 18 | + <%= file_manager_button(_('Manage Members'), 'icons-app/members.png', :controller => 'profile_members') %> | |
| 19 | + | |
| 20 | + <%= file_manager_button(_('Needed Products'), 'icons-app/consumed_product.png', :controller => 'consumed_products') %> | |
| 21 | + | |
| 18 | 22 | <%= file_manager_button(_('Manage Products'), 'icons-app/products.png', :controller => 'manage_products') if profile.enterprise? %> |
| 19 | 23 | |
| 20 | 24 | <% end %> |
| 21 | 25 | |
| 22 | -<h2><%= _('My organizations') %></h2> | |
| 26 | +<% if @profile.person? %> | |
| 27 | + <h2><%= _('My organizations') %></h2> | |
| 28 | + | |
| 29 | + <% file_manager do %> | |
| 23 | 30 | |
| 24 | -<% file_manager do %> | |
| 31 | + <% @profile.enterprise_memberships.each do |em| %> | |
| 32 | + <% if em.image %> | |
| 33 | + <%= file_manager_button(em.name, em.image.public_filename(:minor), :profile => em.identifier, :controller => 'profile_editor' ) %> | |
| 34 | + <% else %> | |
| 35 | + <%= link_to_myprofile(em.name, {}, em.identifier) %> | |
| 36 | + <% end %> | |
| 37 | + <% end %> | |
| 38 | + | |
| 39 | + <%= file_manager_button(_('Register a new Enterprise'), 'icons-app/enterprise-registration.png', :controller => 'enterprise_registration') %> | |
| 25 | 40 | |
| 26 | - <%= file_manager_button(_('Register a new Enterprise'), 'icons-app/enterprise-registration.png', :controller => 'enterprise_registration') %> | |
| 41 | + <% end %> | |
| 27 | 42 | |
| 28 | 43 | <% end %> | ... | ... |
app/views/profile_members/index.rhtml
| 1 | 1 | <h2> <%= _('Listing Members') %> </h2> |
| 2 | 2 | |
| 3 | -<%= link_to _('Affiliate yourself'), :action => 'add_role', :person => current_user.person, :role => Role.find_by_name('member') %> | |
| 3 | +<%= link_to _('Affiliate yourself'), :action => 'add_role', :person => current_user.person, :role => @member_role if @member_role %> | |
| 4 | 4 | |
| 5 | 5 | <ul> |
| 6 | 6 | <% @members.each do |m| %> | ... | ... |
4.78 KB
4.18 KB
test/unit/product_category_test.rb
| ... | ... | @@ -17,4 +17,40 @@ class ProductCategoryTest < Test::Unit::TestCase |
| 17 | 17 | assert c3.valid? |
| 18 | 18 | assert !c3.errors.invalid?(:type) |
| 19 | 19 | end |
| 20 | + | |
| 21 | + def test_tree | |
| 22 | + c0 = ProductCategory.create(:name => 'base_cat', :environment_id => 1) | |
| 23 | + assert ! c0.new_record? | |
| 24 | + assert_equivalent [c0], c0.tree | |
| 25 | + | |
| 26 | + c1 = ProductCategory.create(:name => 'cat_1', :parent => c0, :environment_id => 1) | |
| 27 | + c0.reload | |
| 28 | + assert_equivalent [c1], c1.tree | |
| 29 | + assert_equivalent [c0, c1], c0.tree | |
| 30 | + | |
| 31 | + c2 = ProductCategory.create(:name => 'cat_2', :parent => c0, :environment_id => 1) | |
| 32 | + c0.reload; c1.reload; | |
| 33 | + assert_equivalent [c0,c1,c2] , c0.tree | |
| 34 | + | |
| 35 | + c3 = ProductCategory.create(:name => 'cat_3', :parent => c2, :environment_id => 1) | |
| 36 | + c0.reload; c1.reload; c2.reload | |
| 37 | + assert_equivalent [c0,c1,c2,c3], c0.tree | |
| 38 | + assert_equivalent [c2,c3], c2.tree | |
| 39 | + | |
| 40 | + end | |
| 41 | + | |
| 42 | + def test_all_products | |
| 43 | + c0 = ProductCategory.create(:name => 'base_cat', :environment_id => 1) | |
| 44 | + assert_equivalent [], c0.all_products | |
| 45 | + | |
| 46 | + p0 = Product.create(:name => 'product1', :product_category => c0) | |
| 47 | + c0.reload | |
| 48 | + assert_equivalent [p0], c0.all_products | |
| 49 | + | |
| 50 | + c1 = ProductCategory.create(:name => 'cat_1', :parent => c0, :environment_id => 1) | |
| 51 | + p1 = Product.create(:name => 'product2', :product_category => c1) | |
| 52 | + c0.reload; c1.reload | |
| 53 | + assert_equivalent [p0, p1], c0.all_products | |
| 54 | + assert_equivalent [p1], c1.all_products | |
| 55 | + end | |
| 20 | 56 | end | ... | ... |