diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 1bd6c0e..131c205 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -454,6 +454,23 @@ module ApplicationHelper
:class => 'vcard'
end
+ # displays a link to the community homepage with its image (as generated by
+ # #profile_image) and its name and number of members beside it.
+ def community_image_link( profile, size=:portrait, tag='li' )
+ name = profile.short_name
+ content_tag tag,
+ link_to(
+ content_tag( 'span', profile_image( profile, size ), :class => 'profile-image' ) +
+ content_tag( 'span', name, :class => 'org' ) +
+ content_tag( 'span', n_('1 member', '%s members', profile.members.count) % profile.members.count, :class => 'community-member-count' ),
+ profile.url,
+ :onclick => 'document.location.href = this.href', # work-arround for ie.
+ :class => 'profile_link url',
+ :help => _('Click on this icon to go to the %s\'s home page') % profile.name,
+ :title => profile.name ),
+ :class => 'vcard'
+ end
+
def gravatar_url_for(email, options = {})
# Ta dando erro de roteamento
url_for( { :gravatar_id => Digest::MD5.hexdigest(email),
diff --git a/app/models/block.rb b/app/models/block.rb
index 491adcd..b0db40a 100644
--- a/app/models/block.rb
+++ b/app/models/block.rb
@@ -86,6 +86,10 @@ class Block < ActiveRecord::Base
end
end
+ def view_title
+ title
+ end
+
def cacheable?
true
end
diff --git a/app/models/communities_block.rb b/app/models/communities_block.rb
index b8f6dd3..397735e 100644
--- a/app/models/communities_block.rb
+++ b/app/models/communities_block.rb
@@ -1,11 +1,17 @@
class CommunitiesBlock < ProfileListBlock
+ settings_items :limit, :default => 3
+
def self.description
__('A block that displays your communities')
end
def default_title
- __('Communities')
+ __('{#} communities')
+ end
+
+ def profile_image_link_method
+ :community_image_link
end
def help
@@ -17,17 +23,21 @@ class CommunitiesBlock < ProfileListBlock
case owner
when Profile
lambda do
- link_to __('See all'), :profile => owner.identifier, :controller => 'profile', :action => 'communities'
+ link_to __('View all'), :profile => owner.identifier, :controller => 'profile', :action => 'communities'
end
when Environment
lambda do
- link_to __('See all'), :controller => 'search', :action => 'assets', :asset => 'communities'
+ link_to __('View all'), :controller => 'search', :action => 'assets', :asset => 'communities'
end
else
''
end
end
+ def profile_count
+ owner.communities.count
+ end
+
def profile_finder
@profile_finder ||= CommunitiesBlock::Finder.new(self)
end
diff --git a/app/models/enterprises_block.rb b/app/models/enterprises_block.rb
index f08f082..bce64b0 100644
--- a/app/models/enterprises_block.rb
+++ b/app/models/enterprises_block.rb
@@ -1,7 +1,7 @@
class EnterprisesBlock < ProfileListBlock
def default_title
- __('Enterprises')
+ __('{#} enterprises')
end
def help
@@ -17,17 +17,20 @@ class EnterprisesBlock < ProfileListBlock
case owner
when Profile
lambda do
- link_to __('See all'), :profile => owner.identifier, :controller => 'profile', :action => 'enterprises'
+ link_to __('View all'), :profile => owner.identifier, :controller => 'profile', :action => 'enterprises'
end
when Environment
lambda do
- link_to __('See all'), :controller => 'search', :action => 'assets', :asset => 'enterprises'
+ link_to __('View all'), :controller => 'search', :action => 'assets', :asset => 'enterprises'
end
else
''
end
end
+ def profile_count
+ owner.enterprises.count
+ end
def profile_finder
@profile_finder ||= EnterprisesBlock::Finder.new(self)
diff --git a/app/models/favorite_enterprises_block.rb b/app/models/favorite_enterprises_block.rb
index 2ad70d5..7aa6378 100644
--- a/app/models/favorite_enterprises_block.rb
+++ b/app/models/favorite_enterprises_block.rb
@@ -16,10 +16,13 @@ class FavoriteEnterprisesBlock < ProfileListBlock
owner = self.owner
return '' unless owner.kind_of?(Person)
lambda do
- link_to __('All favorite enterprises'), :profile => owner.identifier, :controller => 'profile', :action => 'favorite_enterprises'
+ link_to __('View all'), :profile => owner.identifier, :controller => 'profile', :action => 'favorite_enterprises'
end
end
+ def profile_count
+ owner.favorite_enterprises.count
+ end
def profile_finder
@profile_finder ||= FavoriteEnterprisesBlock::Finder.new(self)
diff --git a/app/models/friends_block.rb b/app/models/friends_block.rb
index d784289..3774f7c 100644
--- a/app/models/friends_block.rb
+++ b/app/models/friends_block.rb
@@ -5,7 +5,7 @@ class FriendsBlock < ProfileListBlock
end
def default_title
- __('Friends')
+ __('{#} friends')
end
def help
@@ -15,7 +15,7 @@ class FriendsBlock < ProfileListBlock
def footer
owner_id = owner.identifier
lambda do
- link_to __('See all'), :profile => owner_id, :controller => 'profile', :action => 'friends'
+ link_to __('View all'), :profile => owner_id, :controller => 'profile', :action => 'friends'
end
end
@@ -29,4 +29,8 @@ class FriendsBlock < ProfileListBlock
@profile_finder ||= FriendsBlock::Finder.new(self)
end
+ def profile_count
+ owner.friends.count
+ end
+
end
diff --git a/app/models/members_block.rb b/app/models/members_block.rb
index 76cf0b4..f1dcc72 100644
--- a/app/models/members_block.rb
+++ b/app/models/members_block.rb
@@ -5,7 +5,7 @@ class MembersBlock < ProfileListBlock
end
def default_title
- _('Members')
+ _('{#} members')
end
def help
@@ -19,6 +19,10 @@ class MembersBlock < ProfileListBlock
end
end
+ def profile_count
+ owner.members.count
+ end
+
def profile_finder
@profile_finder ||= MembersBlock::Finder.new(self)
end
diff --git a/app/models/people_block.rb b/app/models/people_block.rb
index f2f6e0f..783938c 100644
--- a/app/models/people_block.rb
+++ b/app/models/people_block.rb
@@ -24,7 +24,7 @@ class PeopleBlock < ProfileListBlock
def footer
lambda do
- link_to _('All people'), :controller => 'search', :action => 'assets', :asset => 'people'
+ link_to _('View all'), :controller => 'search', :action => 'assets', :asset => 'people'
end
end
diff --git a/app/models/profile_list_block.rb b/app/models/profile_list_block.rb
index f8879e0..31373db 100644
--- a/app/models/profile_list_block.rb
+++ b/app/models/profile_list_block.rb
@@ -52,7 +52,7 @@ class ProfileListBlock < Block
# the title of the block. Probably will be overriden in subclasses.
def default_title
- _('People and Groups')
+ _('{#} People or Groups')
end
def help
@@ -61,13 +61,14 @@ class ProfileListBlock < Block
def content
profiles = self.profiles
- title = self.title
+ title = self.view_title
nl = "\n"
+ link_method = profile_image_link_method
lambda do
count=0
list = profiles.map {|item|
count+=1
- profile_image_link( item ) #+
+ send(link_method, item ) #+
}.join("\n ")
if list.empty?
list = '
'+ _('None') +'
'
@@ -80,4 +81,16 @@ class ProfileListBlock < Block
end
end
+ def profile_image_link_method
+ :profile_image_link
+ end
+
+ def view_title
+ title.gsub('{#}', profile_count.to_s)
+ end
+
+ def profile_count #defined in children
+ 0
+ end
+
end
diff --git a/test/unit/block_test.rb b/test/unit/block_test.rb
index 042f090..b91e1bc 100644
--- a/test/unit/block_test.rb
+++ b/test/unit/block_test.rb
@@ -46,6 +46,12 @@ class BlockTest < Test::Unit::TestCase
assert_equal 'my title', b.title
end
+ should 'have default view_title ' do
+ b = Block.new
+ b.expects(:title).returns('my title')
+ assert_equal 'my title', b.view_title
+ end
+
should 'have a visible setting' do
b = Block.new
assert b.visible?
diff --git a/test/unit/communities_block_test.rb b/test/unit/communities_block_test.rb
index 6ea2f96..9d66865 100644
--- a/test/unit/communities_block_test.rb
+++ b/test/unit/communities_block_test.rb
@@ -49,7 +49,7 @@ class CommunitiesBlockTest < Test::Unit::TestCase
block = CommunitiesBlock.new
block.expects(:owner).returns(profile)
- expects(:__).with('All communities').returns('All communities')
+ expects(:__).with('View all').returns('All communities')
expects(:link_to).with('All communities', :controller => 'profile', :profile => 'theprofile', :action => 'communities')
instance_eval(&block.footer)
end
@@ -59,7 +59,7 @@ class CommunitiesBlockTest < Test::Unit::TestCase
block = CommunitiesBlock.new
block.expects(:owner).returns(env)
- expects(:__).with('All communities').returns('All communities')
+ expects(:__).with('View all').returns('All communities')
expects(:link_to).with('All communities', :controller => 'search', :action => 'assets', :asset => 'communities')
instance_eval(&block.footer)
@@ -86,4 +86,19 @@ class CommunitiesBlockTest < Test::Unit::TestCase
assert_equal [public_community], block.profiles
end
+ should 'count number of owner communities' do
+ user = create_user('testuser').person
+
+ community1 = Community.create!(:name => 'test community 1', :identifier => 'comm1', :environment => Environment.default)
+ community1.add_member(user)
+
+ community2 = Community.create!(:name => 'test community 2', :identifier => 'comm2', :environment => Environment.default)
+ community2.add_member(user)
+
+ block = CommunitiesBlock.new
+ block.expects(:owner).at_least_once.returns(user)
+
+ assert_equal 2, block.profile_count
+ end
+
end
diff --git a/test/unit/enterprises_block_test.rb b/test/unit/enterprises_block_test.rb
index 874ca9f..9647b1c 100644
--- a/test/unit/enterprises_block_test.rb
+++ b/test/unit/enterprises_block_test.rb
@@ -74,7 +74,7 @@ class EnterprisesBlockTest < Test::Unit::TestCase
block = EnterprisesBlock.new
block.expects(:owner).returns(profile)
- expects(:__).with('All enterprises').returns('All enterprises')
+ expects(:__).with('View all').returns('All enterprises')
expects(:link_to).with('All enterprises', :controller => 'profile', :profile => 'theprofile', :action => 'enterprises')
instance_eval(&block.footer)
@@ -85,7 +85,7 @@ class EnterprisesBlockTest < Test::Unit::TestCase
block = EnterprisesBlock.new
block.expects(:owner).returns(env)
- expects(:__).with('All enterprises').returns('All enterprises')
+ expects(:__).with('View all').returns('All enterprises')
expects(:link_to).with('All enterprises', :controller => 'search', :action => 'assets', :asset => 'enterprises')
instance_eval(&block.footer)
end
@@ -96,4 +96,21 @@ class EnterprisesBlockTest < Test::Unit::TestCase
assert_equal '', block.footer
end
+ should 'count number of owner enterprises' do
+ user = create_user('testuser').person
+
+ ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => Environment.default)
+ ent1.expects(:closed?).returns(false)
+ ent1.add_member(user)
+
+ ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'ent2', :environment => Environment.default)
+ ent2.expects(:closed?).returns(false)
+ ent2.add_member(user)
+
+ block = EnterprisesBlock.new
+ block.expects(:owner).at_least_once.returns(user)
+
+ assert_equal 2, block.profile_count
+ end
+
end
diff --git a/test/unit/favorite_enterprises_block_test.rb b/test/unit/favorite_enterprises_block_test.rb
index 54bc639..3b2fb53 100644
--- a/test/unit/favorite_enterprises_block_test.rb
+++ b/test/unit/favorite_enterprises_block_test.rb
@@ -48,8 +48,8 @@ class FavoriteEnterprisesBlockTest < ActiveSupport::TestCase
block = FavoriteEnterprisesBlock.new
block.expects(:owner).returns(person)
- expects(:__).with('All favorite enterprises').returns('All enterprises')
- expects(:link_to).with('All enterprises', :controller => 'profile', :profile => 'theprofile', :action => 'favorite_enterprises')
+ expects(:__).with('View all').returns('View all enterprises')
+ expects(:link_to).with('View all enterprises', :controller => 'profile', :profile => 'theprofile', :action => 'favorite_enterprises')
instance_eval(&block.footer)
end
@@ -60,4 +60,19 @@ class FavoriteEnterprisesBlockTest < ActiveSupport::TestCase
assert_equal '', block.footer
end
+ should 'count number of owner favorite enterprises' do
+ user = create_user('testuser').person
+
+ ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => Environment.default)
+
+ ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'ent2', :environment => Environment.default)
+
+ user.favorite_enterprises << [ent1, ent2]
+
+ block = FavoriteEnterprisesBlock.new
+ block.expects(:owner).at_least_once.returns(user)
+
+ assert_equal 2, block.profile_count
+ end
+
end
diff --git a/test/unit/friends_block_test.rb b/test/unit/friends_block_test.rb
index cabd1ed..4e4695b 100644
--- a/test/unit/friends_block_test.rb
+++ b/test/unit/friends_block_test.rb
@@ -39,9 +39,25 @@ class FriendsBlockTest < ActiveSupport::TestCase
def self._(s); s; end
def self.gettext(s); s; end
- expects(:link_to).with('All friends', :profile => 'theuser', :controller => 'profile', :action => 'friends')
+ expects(:link_to).with('View all', :profile => 'theuser', :controller => 'profile', :action => 'friends')
instance_eval(&block.footer)
end
+ should 'count number of owner friends' do
+ p1 = create_user('testuser1').person
+ p2 = create_user('testuser2').person
+ p3 = create_user('testuser3').person
+ p4 = create_user('testuser4').person
+
+ p1.add_friend(p2)
+ p1.add_friend(p3)
+ p1.add_friend(p4)
+
+ block = FriendsBlock.new
+ block.expects(:owner).returns(p1)
+
+ assert_equal 3, block.profile_count
+ end
+
end
diff --git a/test/unit/members_block_test.rb b/test/unit/members_block_test.rb
index 0b7c792..3048729 100644
--- a/test/unit/members_block_test.rb
+++ b/test/unit/members_block_test.rb
@@ -52,4 +52,19 @@ class MembersBlockTest < Test::Unit::TestCase
assert_equal [member3, member1], block.profiles
end
+ should 'count number of owner members' do
+ profile = create_user('mytestuser').person
+ owner = mock
+
+ member1 = mock; member1.stubs(:id).returns(1)
+ member2 = mock; member2.stubs(:id).returns(2)
+ member3 = mock; member3.stubs(:id).returns(3)
+
+ owner.expects(:members).returns([member1, member2, member3])
+
+ block = MembersBlock.new
+ block.expects(:owner).returns(owner)
+ assert_equal 3, block.profile_count
+ end
end
+
diff --git a/test/unit/people_block_test.rb b/test/unit/people_block_test.rb
index 7e02ce5..92647e9 100644
--- a/test/unit/people_block_test.rb
+++ b/test/unit/people_block_test.rb
@@ -36,8 +36,8 @@ class PeopleBlockTest < ActiveSupport::TestCase
block = PeopleBlock.new
block.stubs(:owner).returns(Environment.default)
- expects(:link_to).with('All people', :controller => 'search', :action => 'assets', :asset => 'people')
- expects(:_).with('All people').returns('All people')
+ expects(:_).with('View all').returns('View all people')
+ expects(:link_to).with('View all people', :controller => 'search', :action => 'assets', :asset => 'people')
instance_eval(&block.footer)
end
diff --git a/test/unit/profile_list_block_test.rb b/test/unit/profile_list_block_test.rb
index 6475aec..a4585c5 100644
--- a/test/unit/profile_list_block_test.rb
+++ b/test/unit/profile_list_block_test.rb
@@ -67,5 +67,13 @@ class ProfileListBlockTest < Test::Unit::TestCase
assert_respond_to ProfileListBlock::Finder.new(nil), :pick_random
end
-
+ should 'provide view_title' do
+ p = ProfileListBlock.new(:title => 'Title from block')
+ assert_equal 'Title from block', p.view_title
+ end
+
+ should 'provide view title with variables' do
+ p = ProfileListBlock.new(:title => '{#} members')
+ assert_equal '0 members', p.view_title
+ end
end
--
libgit2 0.21.2