diff --git a/app/controllers/admin/categories_controller.rb b/app/controllers/admin/categories_controller.rb
index 169860a..5964843 100644
--- a/app/controllers/admin/categories_controller.rb
+++ b/app/controllers/admin/categories_controller.rb
@@ -5,9 +5,9 @@ class CategoriesController < AdminController
helper :categories
def index
- # WORKAROUND: restricting the category trees to display. Region and
- # ProductCategory have VERY LARGE trees.
@categories = environment.categories.find(:all, :conditions => "parent_id is null AND type is null")
+ @regions = environment.regions.find(:all, :conditions => {:parent_id => nil})
+ @product_categories = environment.product_categories.find(:all, :conditions => {:parent_id => nil})
end
ALLOWED_TYPES = CategoriesHelper::TYPES.map {|item| item[1] }
diff --git a/app/models/environment.rb b/app/models/environment.rb
index 5558434..2d6b4d1 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -147,6 +147,7 @@ class Environment < ActiveRecord::Base
has_many :categories
has_many :display_categories, :class_name => 'Category', :conditions => 'display_color is not null and parent_id is null', :order => 'display_color'
+ has_many :product_categories, :conditions => { :type => 'ProductCategory'}
has_many :regions
has_many :roles
diff --git a/app/views/categories/_category.rhtml b/app/views/categories/_category.rhtml
index 33f8541..6914cd1 100644
--- a/app/views/categories/_category.rhtml
+++ b/app/views/categories/_category.rhtml
@@ -2,6 +2,12 @@
<%= display_color_for_category(category) %>
<%= category.name %>
+
+ <%= link_to_function(_('Show'), "['category_#{category.id}','hide_button_#{category.id}'].each(Element.show); Element.hide('show_button_#{category.id}');") unless category.children.empty? %>
+
+
+ <%= link_to_function(_('Hide'), "['category_#{category.id}','hide_button_#{category.id}'].each(Element.hide); Element.show('show_button_#{category.id}') ") %>
+
<%= link_to _('Add subcategory'), :action => 'new', :parent_id => category %>
@@ -10,11 +16,12 @@
- <% unless category.children.empty? %>
-
- <%= render :partial => 'category', :collection => category.children %>
-
- <% end %>
+
+ <% unless category.children.empty? %>
+
+ <%= render :partial => 'category', :collection => category.children %>
+
+ <% end %>
+
-
diff --git a/app/views/categories/index.rhtml b/app/views/categories/index.rhtml
index e0de9f2..b463659 100644
--- a/app/views/categories/index.rhtml
+++ b/app/views/categories/index.rhtml
@@ -3,8 +3,25 @@
<%= render :partial => 'category', :collection => @categories %>
-
<%= link_to _('New category'), :action => 'new' %>
+<%= _('Product Categories') %>
+
+ <%= render :partial => 'category', :collection => @product_categories %>
+
+
+
+ <%= link_to _('New category'), :action => 'new', :type => 'ProductCategory' %>
+
+
+<%= _('Regions') %>
+
+ <%= render :partial => 'category', :collection => @regions %>
+
+
+
+ <%= link_to _('New category'), :action => 'new', :type => 'Region' %>
+
+
diff --git a/features/admin_categories.feature b/features/admin_categories.feature
new file mode 100644
index 0000000..e098ce8
--- /dev/null
+++ b/features/admin_categories.feature
@@ -0,0 +1,56 @@
+Feature: manage categories
+ As an administrator
+ I want to manage the categories
+
+ Background:
+ Given the following categories
+ | name | display_in_menu |
+ | Food | true |
+ | Book | true |
+ And the following categories
+ | parent | name | display_in_menu |
+ | Food | Vegetarian | true |
+ | Food | Steak | true |
+ Given I am logged in as admin
+
+ @selenium
+ Scenario: admin user could create a category
+ Given I follow "Administration"
+ And I follow "Manage Categories"
+ And I follow "New category"
+ When I fill in "Name" with "Category 1"
+ And I press "Save"
+ Then I should see "Categories"
+ And I should see "Category 1"
+
+ @selenium
+ Scenario: admin user could see all the category tree
+ Given I follow "Administration"
+ And I follow "Manage Categories"
+ When I follow "Show"
+ Then I should see "Vegetarian"
+ And I should see "Steak"
+
+ @selenium
+ Scenario: admin user could hide the category tree
+ Given I follow "Administration"
+ And I follow "Manage Categories"
+ When I follow "Show"
+ Then I should see "Vegetarian"
+ And I should see "Steak"
+ When I follow "Hide"
+ Then I should not see "Vegetarian"
+ And I should not see "Steak"
+
+ @selenium
+ Scenario: the show link is available just for categories with category tree
+ Given the following category
+ | parent | name | display_in_menu |
+ | Steak | Pig | true |
+ And I follow "Administration"
+ And I follow "Manage Categories"
+ Then I should see "Food Show"
+ When I follow "Show"
+ Then I should see "Vegetarian"
+ And I should not see "Vegetarian Show"
+ And I should see "Steak Show"
diff --git a/features/step_definitions/noosfero_steps.rb b/features/step_definitions/noosfero_steps.rb
index 344a45e..6daf87b 100644
--- a/features/step_definitions/noosfero_steps.rb
+++ b/features/step_definitions/noosfero_steps.rb
@@ -85,12 +85,12 @@ Given /^the following validation info$/ do |table|
end
end
-Given /^the following (product_categories|product_category|category|categories)$/ do |kind,table|
+Given /^the following (product_categories|product_category|category|categories|regions?)$/ do |kind,table|
klass = kind.singularize.camelize.constantize
table.hashes.each do |row|
parent = row.delete("parent")
if parent
- parent = Category.find_by_slug(parent)
+ parent = Category.find_by_slug(parent.to_slug)
row.merge!({:parent_id => parent.id})
end
category = klass.create!({:environment_id => Environment.default.id}.merge(row))
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index 8220fc8..06366d4 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -3905,3 +3905,7 @@ h1#agenda-title {
.fg-button span {
padding: 0.1em 1em !important;
}
+
+.treeitem .button{
+ display: inline;
+}
diff --git a/test/functional/categories_controller_test.rb b/test/functional/categories_controller_test.rb
index 8218656..56f1055 100644
--- a/test/functional/categories_controller_test.rb
+++ b/test/functional/categories_controller_test.rb
@@ -36,6 +36,8 @@ class CategoriesControllerTest < Test::Unit::TestCase
assert_response :success
assert_template 'index'
assert_kind_of Array, assigns(:categories)
+ assert_kind_of Array, assigns(:product_categories)
+ assert_kind_of Array, assigns(:regions)
assert_tag :tag => 'a', :attributes => { :href => '/admin/categories/new'}
end
@@ -178,11 +180,13 @@ class CategoriesControllerTest < Test::Unit::TestCase
should 'not list regions and product categories' do
Environment.default.categories.destroy_all
c = Category.create!(:name => 'Regular category', :environment => Environment.default)
- ProductCategory.create!(:name => 'Product category', :environment => Environment.default)
- Region.create!(:name => 'Some region', :environment => Environment.default)
+ p = ProductCategory.create!(:name => 'Product category', :environment => Environment.default)
+ r = Region.create!(:name => 'Some region', :environment => Environment.default)
get :index
assert_equal [c], assigns(:categories)
+ assert_equal [p], assigns(:product_categories)
+ assert_equal [r], assigns(:regions)
end
end
diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb
index a44effc..8afc5d9 100644
--- a/test/unit/environment_test.rb
+++ b/test/unit/environment_test.rb
@@ -131,6 +131,22 @@ class EnvironmentTest < Test::Unit::TestCase
assert cats.include?(subcat)
end
+ def test_should_list_all_product_categories
+ env = fast_create(Environment)
+ Category.create!(:name => 'first category', :environment_id => env.id)
+ cat = Category.create!(:name => 'second category', :environment_id => env.id)
+ Category.create!(:name => 'child category', :environment_id => env.id, :parent_id => cat.id)
+ cat1 = ProductCategory.create!(:name => 'first product category', :environment_id => env.id)
+ cat2 = ProductCategory.create!(:name => 'second product category', :environment_id => env.id)
+ subcat = ProductCategory.create!(:name => 'child product category', :environment_id => env.id, :parent_id => cat2.id)
+
+ cats = env.product_categories
+ assert_equal 3, cats.size
+ assert cats.include?(cat1)
+ assert cats.include?(cat2)
+ assert cats.include?(subcat)
+ end
+
should 'list displayable categories' do
env = fast_create(Environment)
cat1 = env.categories.create(:name => 'category one', :display_color => 1)
--
libgit2 0.21.2