diff --git a/app/controllers/my_profile/profile_design_controller.rb b/app/controllers/my_profile/profile_design_controller.rb
index 82862bd..4a2e314 100644
--- a/app/controllers/my_profile/profile_design_controller.rb
+++ b/app/controllers/my_profile/profile_design_controller.rb
@@ -16,6 +16,7 @@ class ProfileDesignController < BoxOrganizerController
if profile.person?
blocks << FriendsBlock
blocks << FavoriteEnterprisesBlock
+ blocks << MyNetworkBlock
end
# blocks exclusive for enterprises
diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb
index d50858c..1ea0994 100644
--- a/app/controllers/public/profile_controller.rb
+++ b/app/controllers/public/profile_controller.rb
@@ -9,6 +9,10 @@ class ProfileController < ApplicationController
@tags = profile.tags
end
+ def tags
+ @tags = profile.tags
+ end
+
def tag
@tag = params[:id]
@tagged = profile.find_tagged_with(@tag)
diff --git a/app/models/my_network_block.rb b/app/models/my_network_block.rb
new file mode 100644
index 0000000..3a6c868
--- /dev/null
+++ b/app/models/my_network_block.rb
@@ -0,0 +1,24 @@
+class MyNetworkBlock < Block
+
+ include ActionController::UrlWriter
+
+ def self.description
+ _('A block that displays a summary of your network')
+ end
+
+ def default_title
+ _('My network')
+ end
+
+ def content
+ block_title(title) +
+ content_tag(
+ 'ul',
+ content_tag('li', link_to(n_( 'One article published', '%d articles published', owner.articles.count) % owner.articles.count, owner.public_profile_url.merge(:action => 'sitemap') )) +
+ content_tag('li', link_to(n__('One friend', '%d friends', owner.friends.count) % owner.friends.count, owner.public_profile_url.merge(:action => 'friends'))) +
+ content_tag('li', link_to(n__('One community', '%d communities', owner.communities.count) % owner.communities.count, owner.public_profile_url.merge(:action => 'communities'))) +
+ content_tag('li', link_to(n_('One tag', '%d tags', owner.tags.count) % owner.tags.count, owner.public_profile_url.merge(:action => 'tags')))
+ )
+ end
+
+end
diff --git a/app/models/profile.rb b/app/models/profile.rb
index ec137da..c1ec980 100644
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -278,7 +278,7 @@ class Profile < ActiveRecord::Base
end
# FIXME this can be SLOW
- def tags(public_only = false)
+ def tags
totals = {}
articles.each do |article|
article.tags.each do |tag|
diff --git a/app/views/profile/tags.rhtml b/app/views/profile/tags.rhtml
new file mode 100644
index 0000000..48db95b
--- /dev/null
+++ b/app/views/profile/tags.rhtml
@@ -0,0 +1,3 @@
+
<%= _("%s's tags") % @profile.name %>
+
+<%= tag_cloud(@tags, :id, { :action => :tag}, {:show_count => true} ) %>
diff --git a/lib/zen3_terminology.rb b/lib/zen3_terminology.rb
index 78eb0b9..23c6594 100644
--- a/lib/zen3_terminology.rb
+++ b/lib/zen3_terminology.rb
@@ -38,6 +38,10 @@ class Zen3Terminology < Noosfero::Terminology::Custom
'Favorite Enterprises' => N_('Favorite Organizations'),
'Enterprises in "%s"' => N_('Organizations in "%s"'),
'Register a new Enterprise' => N_('Register a new organization'),
+ 'One friend' => N_('One contact'),
+ '%d friends' => N_('%d contacts'),
+ 'One community' => N_('One group'),
+ '%d communities' => N_('%d groups'),
})
end
diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb
index bf21053..6dff00f 100644
--- a/test/functional/profile_controller_test.rb
+++ b/test/functional/profile_controller_test.rb
@@ -249,4 +249,12 @@ class ProfileControllerTest < Test::Unit::TestCase
assert_equal @profile.top_level_articles, assigns(:articles)
end
+ should 'list tags' do
+ Person.any_instance.stubs(:tags).returns({ 'one' => 1, 'two' => 2})
+ get :tags, :profile => 'testuser'
+
+ assert_tag :tag => 'div', :attributes => { :class => /main-block/ }, :descendant => { :tag => 'a', :attributes => { :href => '/profile/testuser/tag/one'} }
+ assert_tag :tag => 'div', :attributes => { :class => /main-block/ }, :descendant => { :tag => 'a', :attributes => { :href => '/profile/testuser/tag/two'} }
+ end
+
end
diff --git a/test/unit/my_network_block_test.rb b/test/unit/my_network_block_test.rb
new file mode 100644
index 0000000..3dea326
--- /dev/null
+++ b/test/unit/my_network_block_test.rb
@@ -0,0 +1,60 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class MyNetworkBlockTest < ActiveSupport::TestCase
+
+ def setup
+ @block = MyNetworkBlock.new
+ @owner = Person.new(:identifier => 'testuser')
+ @block.stubs(:owner).returns(@owner)
+
+ owner.stubs(:environment).returns(Environment.default)
+ end
+ attr_reader :owner, :block
+
+ should 'provide description' do
+ assert_not_equal Block.description, MyNetworkBlock.description
+ end
+
+ should 'provide default title' do
+ assert_not_equal Block.new.default_title, MyNetworkBlock.new.default_title
+ end
+
+ should 'count articles' do
+ mock_articles = mock
+ owner.stubs(:articles).returns(mock_articles)
+ owner.stubs(:tags).returns({}) # don't let tags call articles
+ mock_articles.stubs(:count).returns(5)
+
+ assert_tag_in_string block.content, :tag => 'li', :descendant => { :tag => 'a', :content => '5 articles published', :attributes => { :href => /\/profile\/testuser\/sitemap$/ } }
+ end
+
+ should 'count friends' do
+ mock_friends = mock
+ owner.stubs(:friends).returns(mock_friends)
+ mock_friends.stubs(:count).returns(8)
+
+ assert_tag_in_string block.content, :tag => 'li', :descendant => { :tag => 'a', :content => '8 friends', :attributes => { :href => /\profile\/testuser\/friends/ }}
+ end
+
+ should 'count communities' do
+ mock_communities = mock
+ owner.stubs(:communities).returns(mock_communities)
+ mock_communities.stubs(:count).returns(23)
+
+ assert_tag_in_string block.content, :tag => 'li', :descendant => { :tag => 'a', :content => '23 communities', :attributes => { :href => /\profile\/testuser\/communities/ }}
+ end
+
+ should 'count tags' do
+ mock_tags = mock
+ owner.stubs(:tags).returns(mock_tags)
+ mock_tags.stubs(:count).returns(436)
+
+ assert_tag_in_string block.content, :tag => 'li', :descendant => { :tag => 'a', :content => '436 tags', :attributes => { :href => /\profile\/testuser\/tags/ }}
+ end
+
+ should 'display its title' do
+ block.stubs(:title).returns('My Network')
+ assert_tag_in_string block.content, :content => 'My Network'
+ end
+
+end
diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb
index 1273509..b839ae9 100644
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -317,6 +317,10 @@ class ProfileTest < Test::Unit::TestCase
assert_equivalent [ third], profile.find_tagged_with('third-tag')
end
+ should 'provide tag count' do
+ assert_equal 0, Profile.new.tags.count
+ end
+
should 'have administator role' do
Role.expects(:find_by_key).with('profile_admin').returns(Role.new)
assert_kind_of Role, Profile::Roles.admin
--
libgit2 0.21.2