diff --git a/app/controllers/my_profile/profile_members_controller.rb b/app/controllers/my_profile/profile_members_controller.rb
index 5e9afec..d9ce095 100644
--- a/app/controllers/my_profile/profile_members_controller.rb
+++ b/app/controllers/my_profile/profile_members_controller.rb
@@ -1,8 +1,9 @@
class ProfileMembersController < MyProfileController
- protect 'manage_memberships', :profile
+# protect 'manage_memberships', :profile
def index
@members = profile.members
+ @member_role = Role.find_by_name('member')
end
def change_roles
diff --git a/app/models/consumption.rb b/app/models/consumption.rb
index d2c182f..5dd4a22 100644
--- a/app/models/consumption.rb
+++ b/app/models/consumption.rb
@@ -1,4 +1,6 @@
class Consumption < ActiveRecord::Base
belongs_to :profile
belongs_to :product_category
+
+ validates_uniqueness_of :product_category_id, :scope => :profile_id
end
diff --git a/app/models/image.rb b/app/models/image.rb
index e11c36c..0ac1f5d 100644
--- a/app/models/image.rb
+++ b/app/models/image.rb
@@ -5,7 +5,7 @@ class Image < ActiveRecord::Base
:storage => :file_system,
:max_size => 500.kilobytes,
:resize_to => '320x200>',
- :thumbnails => { :thumb => '100x100>' }
+ :thumbnails => { :thumb => '100x100>', :minor => '64x64>' }
validates_as_attachment
end
diff --git a/app/models/product_category.rb b/app/models/product_category.rb
index 1f318c2..ec4240d 100644
--- a/app/models/product_category.rb
+++ b/app/models/product_category.rb
@@ -2,4 +2,12 @@ class ProductCategory < Category
has_many :products
has_many :consumptions
has_many :consumers, :through => :consumptions, :source => :profile_id
+
+ def tree
+ children.inject([]){|all,c| all + c.tree } << self
+ end
+
+ def all_products
+ Product.find(:all, :conditions => { :product_category_id => tree.map(&:id) })
+ end
end
diff --git a/app/views/category/view.rhtml b/app/views/category/view.rhtml
index 7a9f435..540aae8 100644
--- a/app/views/category/view.rhtml
+++ b/app/views/category/view.rhtml
@@ -1,3 +1,14 @@
-
<%= _('Category: %s') % @category.full_name %>
+<%= @category.ancestors.reverse.map { |a| link_to_category(a) }.join(' → ') %>
+
+<%= _('Category: %s') % @category.name %>
<%= render :partial => @category.class.name.underscore %>
+
+ <%= _('Children categories: ') %>
+<% unless @category.children.empty? %>
+
+ <% @category.children.each do |c| %>
+ - <%= link_to_category(c) %>
+ <% end %>
+
+<% end %>
diff --git a/app/views/consumed_products/index.rhtml b/app/views/consumed_products/index.rhtml
index a0295c0..0ccbd41 100644
--- a/app/views/consumed_products/index.rhtml
+++ b/app/views/consumed_products/index.rhtml
@@ -3,6 +3,6 @@
<%= link_to _('Add product'), :action => 'new' %>
<% @consumptions.each do |consumption| %>
- <%= link_to consumption.product_category.name %>
+
<%= link_to_category(consumption.product_category) %>
<%= link_to _('destroy'), :action => 'destroy', :id => consumption %>
<% end %>
diff --git a/app/views/consumed_products/new.rhtml b/app/views/consumed_products/new.rhtml
index 8068071..e79a4b6 100644
--- a/app/views/consumed_products/new.rhtml
+++ b/app/views/consumed_products/new.rhtml
@@ -1,6 +1,9 @@
<%= _('Add product') %>
-<% form_for :consumption, @consuption do |f| %>
- <%= _('Product: ') %> <%= f.select "product_category_id", ProductCategory.find(:all).map{|pc| [pc.name, pc.id]} %>
- <%= display_submit_tag _('Add product') %>
+<%= error_messages_for :consumption %>
+
+<% form_for :consumption, @consumption do |f| %>
+ <%= _('Product: ') %> <%= f.select "product_category_id", ProductCategory.find(:all).map{|pc| [pc.name, pc.id]} %>
+ <%= submit_tag _('Add product') %>
+ <%= link_to _('Cancel'), :action => 'index' %>
<% end %>
diff --git a/app/views/consumed_products/show.rhtml b/app/views/consumed_products/show.rhtml
deleted file mode 100644
index 10a3a4d..0000000
--- a/app/views/consumed_products/show.rhtml
+++ /dev/null
@@ -1,10 +0,0 @@
- <%= @product.name %>
-
- <%= image_tag @product.image.public_filename if @product.image %>
- <%= _('Price: ') %> <%= @product.price %>
- <%= _('Description: ') %> <%= @product.description %>
- <%= _('Category: ') %> <%= @product.product_category ? @product.product_category.name : _('Uncategorized product') %>
-
-<%= link_to _('destroy'), :action => 'destroy', :id => @product %>
-
-<%= link_to _('back'), :action => 'index' %>
diff --git a/app/views/manage_products/_form.rhtml b/app/views/manage_products/_form.rhtml
index 0fe3032..3dbadb3 100644
--- a/app/views/manage_products/_form.rhtml
+++ b/app/views/manage_products/_form.rhtml
@@ -7,4 +7,5 @@
<%= display_form_field( _('Image:'), file_field_tag( "product[image_builder][uploaded_data]" ) ) %>
<%= display_form_field( _('category:'), f.select( :product_category_id,ProductCategory.find(:all).map{|pc|[pc.name,pc.id]}, {:include_blank => true} )) %>
<%= display_submit_tag(mode == 'new' ? _('Create product') : _('Save changes')) %>
+ <%= link_to _('Cancel'), :action => 'index' %>
<% end %>
diff --git a/app/views/product_category_viewer/index.rhtml b/app/views/product_category_viewer/index.rhtml
deleted file mode 100644
index 6efb0c3..0000000
--- a/app/views/product_category_viewer/index.rhtml
+++ /dev/null
@@ -1,7 +0,0 @@
- <%= _('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
deleted file mode 100644
index 46b1168..0000000
--- a/app/views/product_category_viewer/view_category.rhtml
+++ /dev/null
@@ -1,13 +0,0 @@
-<%= @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/app/views/profile_editor/index.rhtml b/app/views/profile_editor/index.rhtml
index a4e58e3..bcade11 100644
--- a/app/views/profile_editor/index.rhtml
+++ b/app/views/profile_editor/index.rhtml
@@ -14,15 +14,30 @@
<%= file_manager_button(_('Manage Content'), 'icons-app/cms.png', :controller => 'cms') %>
<%= file_manager_button(_('Change Password'), 'icons-app/change-password.png', :controller => 'account', :action => 'change_password') if profile.person? %>
-
+
+ <%= file_manager_button(_('Manage Members'), 'icons-app/members.png', :controller => 'profile_members') %>
+
+ <%= file_manager_button(_('Needed Products'), 'icons-app/consumed_product.png', :controller => 'consumed_products') %>
+
<%= file_manager_button(_('Manage Products'), 'icons-app/products.png', :controller => 'manage_products') if profile.enterprise? %>
<% end %>
-<%= _('My organizations') %>
+<% if @profile.person? %>
+ <%= _('My organizations') %>
+
+ <% file_manager do %>
-<% file_manager do %>
+ <% @profile.enterprise_memberships.each do |em| %>
+ <% if em.image %>
+ <%= file_manager_button(em.name, em.image.public_filename(:minor), :profile => em.identifier, :controller => 'profile_editor' ) %>
+ <% else %>
+ <%= link_to_myprofile(em.name, {}, em.identifier) %>
+ <% end %>
+ <% end %>
+
+ <%= file_manager_button(_('Register a new Enterprise'), 'icons-app/enterprise-registration.png', :controller => 'enterprise_registration') %>
- <%= file_manager_button(_('Register a new Enterprise'), 'icons-app/enterprise-registration.png', :controller => 'enterprise_registration') %>
+ <% end %>
<% end %>
diff --git a/app/views/profile_members/index.rhtml b/app/views/profile_members/index.rhtml
index 22ecbea..0293c56 100644
--- a/app/views/profile_members/index.rhtml
+++ b/app/views/profile_members/index.rhtml
@@ -1,6 +1,6 @@
<%= _('Listing Members') %>
-<%= link_to _('Affiliate yourself'), :action => 'add_role', :person => current_user.person, :role => Role.find_by_name('member') %>
+<%= link_to _('Affiliate yourself'), :action => 'add_role', :person => current_user.person, :role => @member_role if @member_role %>
<% @members.each do |m| %>
diff --git a/public/images/icons-app/consumed_product.png b/public/images/icons-app/consumed_product.png
new file mode 120000
index 0000000..796d046
--- /dev/null
+++ b/public/images/icons-app/consumed_product.png
@@ -0,0 +1 @@
+fr_stock_add.png
\ No newline at end of file
diff --git a/public/images/icons-app/fr_stock_add.png b/public/images/icons-app/fr_stock_add.png
new file mode 100644
index 0000000..1e2666a
Binary files /dev/null and b/public/images/icons-app/fr_stock_add.png differ
diff --git a/public/images/icons-app/members.png b/public/images/icons-app/members.png
new file mode 120000
index 0000000..483bc7b
--- /dev/null
+++ b/public/images/icons-app/members.png
@@ -0,0 +1 @@
+stock_new-meeting.png
\ No newline at end of file
diff --git a/public/images/icons-app/stock_new-meeting.png b/public/images/icons-app/stock_new-meeting.png
new file mode 100644
index 0000000..d2bfa3c
Binary files /dev/null and b/public/images/icons-app/stock_new-meeting.png differ
diff --git a/test/unit/consumption_test.rb b/test/unit/consumption_test.rb
new file mode 100644
index 0000000..dd75d65
--- /dev/null
+++ b/test/unit/consumption_test.rb
@@ -0,0 +1,10 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class ConsumptionTest < Test::Unit::TestCase
+ fixtures :consumptions
+
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end
diff --git a/test/unit/product_category_test.rb b/test/unit/product_category_test.rb
index 817369d..36e16f1 100644
--- a/test/unit/product_category_test.rb
+++ b/test/unit/product_category_test.rb
@@ -17,4 +17,40 @@ class ProductCategoryTest < Test::Unit::TestCase
assert c3.valid?
assert !c3.errors.invalid?(:type)
end
+
+ def test_tree
+ c0 = ProductCategory.create(:name => 'base_cat', :environment_id => 1)
+ assert ! c0.new_record?
+ assert_equivalent [c0], c0.tree
+
+ c1 = ProductCategory.create(:name => 'cat_1', :parent => c0, :environment_id => 1)
+ c0.reload
+ assert_equivalent [c1], c1.tree
+ assert_equivalent [c0, c1], c0.tree
+
+ c2 = ProductCategory.create(:name => 'cat_2', :parent => c0, :environment_id => 1)
+ c0.reload; c1.reload;
+ assert_equivalent [c0,c1,c2] , c0.tree
+
+ c3 = ProductCategory.create(:name => 'cat_3', :parent => c2, :environment_id => 1)
+ c0.reload; c1.reload; c2.reload
+ assert_equivalent [c0,c1,c2,c3], c0.tree
+ assert_equivalent [c2,c3], c2.tree
+
+ end
+
+ def test_all_products
+ c0 = ProductCategory.create(:name => 'base_cat', :environment_id => 1)
+ assert_equivalent [], c0.all_products
+
+ p0 = Product.create(:name => 'product1', :product_category => c0)
+ c0.reload
+ assert_equivalent [p0], c0.all_products
+
+ c1 = ProductCategory.create(:name => 'cat_1', :parent => c0, :environment_id => 1)
+ p1 = Product.create(:name => 'product2', :product_category => c1)
+ c0.reload; c1.reload
+ assert_equivalent [p0, p1], c0.all_products
+ assert_equivalent [p1], c1.all_products
+ end
end
--
libgit2 0.21.2