noosfero | 3 new commits pushed to repository
Bráulio Bhavamitra
gitlab at gitlab.com
Mon Feb 9 23:28:13 BRST 2015
Bráulio Bhavamitra pushed to refs/heads/master at <a href="https://gitlab.com/noosfero/noosfero">Noosfero / noosfero</a>
Commits:
<a href="https://gitlab.com/noosfero/noosfero/commit/fcf765cfd4de3aba2d77c17a5e5a0ebdc754908e">fcf765cf</a> by Eduardo Passos
statistics-block: add products counter
- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/f6ef9a7fd43d4106e1d30344a76d6e8ab4a96311">f6ef9a7f</a> by Eduardo Passos
Display products counter only for enabled enterprises
- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/87aaba822ef43cb1ca8fbc7c9721f284d8766e03">87aaba82</a> by Bráulio Bhavamitra
Merge branch 'count-products' into 'master'
Count products enterprise
Method to count Enterprise's visible and enabled products.
See merge request !460
- - - - -
Changes:
=====================================
plugins/statistics/lib/statistics_block.rb
=====================================
--- a/plugins/statistics/lib/statistics_block.rb
+++ b/plugins/statistics/lib/statistics_block.rb
@@ -3,13 +3,14 @@ class StatisticsBlock < Block
settings_items :community_counter, :default => false
settings_items :user_counter, :default => true
settings_items :enterprise_counter, :default => false
+ settings_items :product_counter, :default => false
settings_items :category_counter, :default => false
settings_items :tag_counter, :default => true
settings_items :comment_counter, :default => true
settings_items :hit_counter, :default => false
settings_items :templates_ids_counter, Hash, :default => {}
- attr_accessible :comment_counter, :community_counter, :user_counter, :enterprise_counter, :category_counter, :tag_counter, :hit_counter, :templates_ids_counter
+ attr_accessible :comment_counter, :community_counter, :user_counter, :enterprise_counter, :product_counter, :category_counter, :tag_counter, :hit_counter, :templates_ids_counter
USER_COUNTERS = [:community_counter, :user_counter, :enterprise_counter, :tag_counter, :comment_counter, :hit_counter]
COMMUNITY_COUNTERS = [:user_counter, :tag_counter, :comment_counter, :hit_counter]
@@ -91,6 +92,16 @@ class StatisticsBlock < Block
end
end
+ def products
+ if owner.kind_of?(Environment)
+ owner.products.where("profiles.enabled = 't' and profiles.visible = 't'").count
+ elsif owner.kind_of?(Enterprise)
+ owner.products.count
+ else
+ 0
+ end
+ end
+
def communities
if owner.kind_of?(Environment) || owner.kind_of?(Person)
owner.communities.visible.count
=====================================
plugins/statistics/test/functional/statistics_plugin_environment_design_controller_test.rb
=====================================
--- a/plugins/statistics/test/functional/statistics_plugin_environment_design_controller_test.rb
+++ b/plugins/statistics/test/functional/statistics_plugin_environment_design_controller_test.rb
@@ -42,18 +42,19 @@ class EnvironmentDesignControllerTest < ActionController::TestCase
@block.user_counter = true
@block.community_counter = true
@block.enterprise_counter = true
+ @block.product_counter = true
@block.category_counter = true
@block.tag_counter = true
@block.comment_counter = true
@block.hit_counter = true
@block.save!
get :edit, :id => @block.id
- post :save, :id => @block.id, :block => {:user_counter => '0', :community_counter => '0', :enterprise_counter => '0',
- :category_counter => '0', :tag_counter => '0', :comment_counter => '0', :hit_counter => '0' }
+ post :save, :id => @block.id, :block => {:user_counter => '0', :community_counter => '0', :enterprise_counter => '0', :product_counter => '0', :category_counter => '0', :tag_counter => '0', :comment_counter => '0', :hit_counter => '0'}
@block.reload
any_checked = @block.is_visible?('user_counter') ||
@block.is_visible?('community_counter') ||
@block.is_visible?('enterprise_counter') ||
+ @block.is_visible?('product_counter') ||
@block.is_visible?('category_counter') ||
@block.is_visible?('tag_counter') ||
@block.is_visible?('comment_counter') ||
@@ -66,18 +67,20 @@ class EnvironmentDesignControllerTest < ActionController::TestCase
@block.user_counter = false
@block.community_counter = false
@block.enterprise_counter = false
+ @block.product_counter = false
@block.category_counter = false
@block.tag_counter = false
@block.comment_counter = false
@block.hit_counter = false
@block.save!
get :edit, :id => @block.id
- post :save, :id => @block.id, :block => {:user_counter => '1', :community_counter => '1', :enterprise_counter => '1',
+ post :save, :id => @block.id, :block => {:user_counter => '1', :community_counter => '1', :enterprise_counter => '1', :product_counter => '1',
:category_counter => '1', :tag_counter => '1', :comment_counter => '1', :hit_counter => '1' }
@block.reload
all_checked = @block.is_visible?('user_counter') &&
@block.is_visible?('community_counter') &&
@block.is_visible?('enterprise_counter') &&
+ @block.is_visible?('product_counter') &&
@block.is_visible?('category_counter') &&
@block.is_visible?('tag_counter') &&
@block.is_visible?('comment_counter') &&
@@ -128,14 +131,21 @@ class EnvironmentDesignControllerTest < ActionController::TestCase
assert_no_tag :input, :attributes => {:id => 'block_enterprise_counter', :checked => 'checked'}
end
- should 'not input category counter be checked by default' do
+ should 'not input product counter be checked by default' do
+ get :edit, :id => @block.id
+
+ assert_tag :input, :attributes => {:id => 'block_product_counter'}
+ assert_no_tag :input, :attributes => {:id => 'block_product_counter', :checked => 'checked'}
+ end
+
+ should 'not input category counter be checked by default' do
get :edit, :id => @block.id
assert_tag :input, :attributes => {:id => 'block_category_counter'}
assert_no_tag :input, :attributes => {:id => 'block_category_counter', :checked => 'checked'}
end
- should 'input tag counter be checked by default' do
+ should 'input tag counter be checked by default' do
get :edit, :id => @block.id
assert_tag :input, :attributes => {:id => 'block_tag_counter', :checked => 'checked'}
@@ -152,4 +162,4 @@ class EnvironmentDesignControllerTest < ActionController::TestCase
assert_no_tag :input, :attributes => {:id => 'block_hit_counter', :checked => 'checked'}
end
-end
+end
\ No newline at end of file
=====================================
plugins/statistics/test/functional/statistics_plugin_home_controller_test.rb
=====================================
--- a/plugins/statistics/test/functional/statistics_plugin_home_controller_test.rb
+++ b/plugins/statistics/test/functional/statistics_plugin_home_controller_test.rb
@@ -74,6 +74,20 @@ class HomeControllerTest < ActionController::TestCase
assert_no_tag :tag => 'div', :attributes => {:class => 'statistics-block-data'}, :descendant => { :tag => 'li', :attributes => {:class => 'enterprises'} }
end
+ should 'display products class in statistics-block-data block' do
+ @block.product_counter = true
+ @block.save!
+ get :index
+
+ assert_tag :tag => 'div', :attributes => {:class => 'statistics-block-data'}, :descendant => { :tag => 'li', :attributes => {:class => 'products'} }
+ end
+
+ should 'not display products class in statistics-block-data block' do
+ get :index
+
+ assert_no_tag :tag => 'div', :attributes => {:class => 'statistics-block-data'}, :descendant => { :tag => 'li', :attributes => {:class => 'products'} }
+ end
+
should 'display categories class in statistics-block-data block' do
@block.category_counter = true
@block.save!
=====================================
plugins/statistics/test/unit/statistics_block_test.rb
=====================================
--- a/plugins/statistics/test/unit/statistics_block_test.rb
+++ b/plugins/statistics/test/unit/statistics_block_test.rb
@@ -8,7 +8,7 @@ class StatisticsBlockTest < ActiveSupport::TestCase
end
end
- ['community_counter', 'enterprise_counter', 'category_counter', 'hit_counter'].map do |counter|
+ ['community_counter', 'enterprise_counter', 'product_counter', 'category_counter', 'hit_counter'].map do |counter|
should "#{counter} be false by default" do
b = StatisticsBlock.new
assert !b.is_visible?(counter)
@@ -139,6 +139,40 @@ class StatisticsBlockTest < ActiveSupport::TestCase
assert_equal 2, b.enterprises
end
+ should 'return the amount of visible environment products' do
+ b = StatisticsBlock.new
+ e = fast_create(Environment)
+
+ e1 = fast_create(Enterprise, :visible => true, :enabled => true, :environment_id => e.id)
+ e2 = fast_create(Enterprise, :visible => true, :enabled => false, :environment_id => e.id)
+ e3 = fast_create(Enterprise, :visible => false, :enabled => true, :environment_id => e.id)
+
+ fast_create(Product, :profile_id => e1.id)
+ fast_create(Product, :profile_id => e1.id)
+ fast_create(Product, :profile_id => e2.id)
+ fast_create(Product, :profile_id => e2.id)
+ fast_create(Product, :profile_id => e3.id)
+ fast_create(Product, :profile_id => e3.id)
+
+ b.expects(:owner).at_least_once.returns(e)
+
+ assert_equal 2, b.products
+ end
+
+ should 'return the amount of visible enterprise products' do
+ b = StatisticsBlock.new
+
+ e = fast_create(Enterprise)
+
+ fast_create(Product, :profile_id => e.id)
+ fast_create(Product, :profile_id => e.id)
+ fast_create(Product, :profile_id => nil)
+
+ b.expects(:owner).at_least_once.returns(e)
+
+ assert_equal 2, b.products
+ end
+
should 'categories return the amount of categories of the Environment' do
b = StatisticsBlock.new
e = fast_create(Environment)
=====================================
plugins/statistics/views/box_organizer/_statistics_block.html.erb
=====================================
--- a/plugins/statistics/views/box_organizer/_statistics_block.html.erb
+++ b/plugins/statistics/views/box_organizer/_statistics_block.html.erb
@@ -1,32 +1,36 @@
<%= labelled_form_field check_box(:block, :user_counter) + _('Show user counter'), '' %>
<% if @block.is_counter_available?(:community_counter) %>
-<%= labelled_form_field check_box(:block, :community_counter) + _('Show community counter'), '' %>
+ <%= labelled_form_field check_box(:block, :community_counter) + _('Show community counter'), '' %>
<% end %>
<% if @block.is_counter_available?(:enterprise_counter) %>
-<%= labelled_form_field check_box(:block, :enterprise_counter) + _('Show enterprise counter'), '' %>
+ <%= labelled_form_field check_box(:block, :enterprise_counter) + _('Show enterprise counter'), '' %>
+<% end %>
+
+<% if @block.is_counter_available?(:product_counter) %>
+ <%= labelled_form_field check_box(:block, :product_counter) + _('Show product counter'), '' %>
<% end %>
<% if @block.is_counter_available?(:category_counter) %>
-<%= labelled_form_field check_box(:block, :category_counter) + _('Show category counter'), '' %>
+ <%= labelled_form_field check_box(:block, :category_counter) + _('Show category counter'), '' %>
<% end %>
<% if @block.is_counter_available?(:tag_counter) %>
-<%= labelled_form_field check_box(:block, :tag_counter) + _('Show tag counter'), '' %>
+ <%= labelled_form_field check_box(:block, :tag_counter) + _('Show tag counter'), '' %>
<% end %>
<% if @block.is_counter_available?(:comment_counter) %>
-<%= labelled_form_field check_box(:block, :comment_counter) + _('Show comment counter'), '' %>
+ <%= labelled_form_field check_box(:block, :comment_counter) + _('Show comment counter'), '' %>
<% end %>
<% if @block.is_counter_available?(:hit_counter) %>
-<%= labelled_form_field check_box(:block, :hit_counter) + _('Show hit counter'), '' %>
+ <%= labelled_form_field check_box(:block, :hit_counter) + _('Show hit counter'), '' %>
<% end %>
<% if @block.is_counter_available?(:templates_ids_counter) %>
-<% @block.templates.map do |item|%>
- <%= hidden_field_tag("block[templates_ids_counter][#{item.id}]", false)%>
- <%= labelled_form_field check_box_tag("block[templates_ids_counter][#{item.id}]", true, @block.is_template_counter_active?(item.id)) + _("Show counter for communities with template %s" % item.name), '' %>
-<% end %>
+ <% @block.templates.map do |item|%>
+ <%= hidden_field_tag("block[templates_ids_counter][#{item.id}]", false)%>
+ <%= labelled_form_field check_box_tag("block[templates_ids_counter][#{item.id}]", true, @block.is_template_counter_active?(item.id)) + _("Show counter for communities with template %s" % item.name), '' %>
+ <% end %>
<% end %>
=====================================
plugins/statistics/views/statistics_block.html.erb
=====================================
--- a/plugins/statistics/views/statistics_block.html.erb
+++ b/plugins/statistics/views/statistics_block.html.erb
@@ -9,6 +9,9 @@
<% if block.is_visible?('enterprise_counter') && !block.environment.enabled?('disable_asset_enterprises') %>
<li class="enterprises"><span class="amount"><%= block.enterprises%> </span><span class="label"><%= _('enterprises')%></span></li>
<% end %>
+ <% if block.is_visible?('product_counter') && block.environment.enabled?('products_for_enterprises') %>
+ <li class="products"><span class="amount"><%= block.products%> </span><span class="label"><%= _('products')%></span></li>
+ <% end %>
<% if block.is_visible?('community_counter') %>
<li class="communities"><span class="amount"><%= block.communities%> </span><span class="label"><%= _('communities')%></span></li>
<% end %>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150210/aaf52c1d/attachment-0001.html>
More information about the Noosfero-dev
mailing list