From fcf765cfd4de3aba2d77c17a5e5a0ebdc754908e Mon Sep 17 00:00:00 2001 From: Eduardo Passos Date: Mon, 9 Feb 2015 23:48:49 +0000 Subject: [PATCH] statistics-block: add products counter --- plugins/statistics/lib/statistics_block.rb | 13 ++++++++++++- plugins/statistics/test/functional/statistics_plugin_environment_design_controller_test.rb | 22 ++++++++++++++++------ plugins/statistics/test/functional/statistics_plugin_home_controller_test.rb | 14 ++++++++++++++ plugins/statistics/test/unit/statistics_block_test.rb | 36 +++++++++++++++++++++++++++++++++++- plugins/statistics/views/box_organizer/_statistics_block.html.erb | 24 ++++++++++++++---------- plugins/statistics/views/statistics_block.html.erb | 3 +++ 6 files changed, 94 insertions(+), 18 deletions(-) diff --git a/plugins/statistics/lib/statistics_block.rb b/plugins/statistics/lib/statistics_block.rb index ec4bccc..3cab8f4 100644 --- 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 diff --git a/plugins/statistics/test/functional/statistics_plugin_environment_design_controller_test.rb b/plugins/statistics/test/functional/statistics_plugin_environment_design_controller_test.rb index 89c63ae..7638e3a 100644 --- 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 diff --git a/plugins/statistics/test/functional/statistics_plugin_home_controller_test.rb b/plugins/statistics/test/functional/statistics_plugin_home_controller_test.rb index fe327ad..b511966 100644 --- 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! diff --git a/plugins/statistics/test/unit/statistics_block_test.rb b/plugins/statistics/test/unit/statistics_block_test.rb index 921d40a..96f34d9 100644 --- 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) diff --git a/plugins/statistics/views/box_organizer/_statistics_block.html.erb b/plugins/statistics/views/box_organizer/_statistics_block.html.erb index 7bbe640..a42c21a 100644 --- 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 %> diff --git a/plugins/statistics/views/statistics_block.html.erb b/plugins/statistics/views/statistics_block.html.erb index 5a323f5..f5e7054 100644 --- 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') %>
  • <%= block.enterprises%> <%= _('enterprises')%>
  • <% end %> + <% if block.is_visible?('product_counter') && !block.environment.enabled?('disable_asset_products') %> +
  • <%= block.products%> <%= _('products')%>
  • + <% end %> <% if block.is_visible?('community_counter') %>
  • <%= block.communities%> <%= _('communities')%>
  • <% end %> -- libgit2 0.21.2