Commit 13ed467bf487418e3a73a2267974e39753bbce4e

Authored by Daniela Feitosa
Committed by Antonio Terceiro
1 parent b8d2a3be

ActionItem1043: blocks enhancements

* changed 'all <profile>' to simply 'view all'
 * adding number to profile list blocks title
 * added mebers info to communities block
app/helpers/application_helper.rb
@@ -454,6 +454,23 @@ module ApplicationHelper @@ -454,6 +454,23 @@ module ApplicationHelper
454 :class => 'vcard' 454 :class => 'vcard'
455 end 455 end
456 456
  457 + # displays a link to the community homepage with its image (as generated by
  458 + # #profile_image) and its name and number of members beside it.
  459 + def community_image_link( profile, size=:portrait, tag='li' )
  460 + name = profile.short_name
  461 + content_tag tag,
  462 + link_to(
  463 + content_tag( 'span', profile_image( profile, size ), :class => 'profile-image' ) +
  464 + content_tag( 'span', name, :class => 'org' ) +
  465 + content_tag( 'span', n_('1 member', '%s members', profile.members.count) % profile.members.count, :class => 'community-member-count' ),
  466 + profile.url,
  467 + :onclick => 'document.location.href = this.href', # work-arround for ie.
  468 + :class => 'profile_link url',
  469 + :help => _('Click on this icon to go to the <b>%s</b>\'s home page') % profile.name,
  470 + :title => profile.name ),
  471 + :class => 'vcard'
  472 + end
  473 +
457 def gravatar_url_for(email, options = {}) 474 def gravatar_url_for(email, options = {})
458 # Ta dando erro de roteamento 475 # Ta dando erro de roteamento
459 url_for( { :gravatar_id => Digest::MD5.hexdigest(email), 476 url_for( { :gravatar_id => Digest::MD5.hexdigest(email),
app/models/block.rb
@@ -86,6 +86,10 @@ class Block &lt; ActiveRecord::Base @@ -86,6 +86,10 @@ class Block &lt; ActiveRecord::Base
86 end 86 end
87 end 87 end
88 88
  89 + def view_title
  90 + title
  91 + end
  92 +
89 def cacheable? 93 def cacheable?
90 true 94 true
91 end 95 end
app/models/communities_block.rb
1 class CommunitiesBlock < ProfileListBlock 1 class CommunitiesBlock < ProfileListBlock
2 2
  3 + settings_items :limit, :default => 3
  4 +
3 def self.description 5 def self.description
4 __('A block that displays your communities') 6 __('A block that displays your communities')
5 end 7 end
6 8
7 def default_title 9 def default_title
8 - __('Communities') 10 + __('{#} communities')
  11 + end
  12 +
  13 + def profile_image_link_method
  14 + :community_image_link
9 end 15 end
10 16
11 def help 17 def help
@@ -17,17 +23,21 @@ class CommunitiesBlock &lt; ProfileListBlock @@ -17,17 +23,21 @@ class CommunitiesBlock &lt; ProfileListBlock
17 case owner 23 case owner
18 when Profile 24 when Profile
19 lambda do 25 lambda do
20 - link_to __('See all'), :profile => owner.identifier, :controller => 'profile', :action => 'communities' 26 + link_to __('View all'), :profile => owner.identifier, :controller => 'profile', :action => 'communities'
21 end 27 end
22 when Environment 28 when Environment
23 lambda do 29 lambda do
24 - link_to __('See all'), :controller => 'search', :action => 'assets', :asset => 'communities' 30 + link_to __('View all'), :controller => 'search', :action => 'assets', :asset => 'communities'
25 end 31 end
26 else 32 else
27 '' 33 ''
28 end 34 end
29 end 35 end
30 36
  37 + def profile_count
  38 + owner.communities.count
  39 + end
  40 +
31 def profile_finder 41 def profile_finder
32 @profile_finder ||= CommunitiesBlock::Finder.new(self) 42 @profile_finder ||= CommunitiesBlock::Finder.new(self)
33 end 43 end
app/models/enterprises_block.rb
1 class EnterprisesBlock < ProfileListBlock 1 class EnterprisesBlock < ProfileListBlock
2 2
3 def default_title 3 def default_title
4 - __('Enterprises') 4 + __('{#} enterprises')
5 end 5 end
6 6
7 def help 7 def help
@@ -17,17 +17,20 @@ class EnterprisesBlock &lt; ProfileListBlock @@ -17,17 +17,20 @@ class EnterprisesBlock &lt; ProfileListBlock
17 case owner 17 case owner
18 when Profile 18 when Profile
19 lambda do 19 lambda do
20 - link_to __('See all'), :profile => owner.identifier, :controller => 'profile', :action => 'enterprises' 20 + link_to __('View all'), :profile => owner.identifier, :controller => 'profile', :action => 'enterprises'
21 end 21 end
22 when Environment 22 when Environment
23 lambda do 23 lambda do
24 - link_to __('See all'), :controller => 'search', :action => 'assets', :asset => 'enterprises' 24 + link_to __('View all'), :controller => 'search', :action => 'assets', :asset => 'enterprises'
25 end 25 end
26 else 26 else
27 '' 27 ''
28 end 28 end
29 end 29 end
30 30
  31 + def profile_count
  32 + owner.enterprises.count
  33 + end
31 34
32 def profile_finder 35 def profile_finder
33 @profile_finder ||= EnterprisesBlock::Finder.new(self) 36 @profile_finder ||= EnterprisesBlock::Finder.new(self)
app/models/favorite_enterprises_block.rb
@@ -16,10 +16,13 @@ class FavoriteEnterprisesBlock &lt; ProfileListBlock @@ -16,10 +16,13 @@ class FavoriteEnterprisesBlock &lt; ProfileListBlock
16 owner = self.owner 16 owner = self.owner
17 return '' unless owner.kind_of?(Person) 17 return '' unless owner.kind_of?(Person)
18 lambda do 18 lambda do
19 - link_to __('All favorite enterprises'), :profile => owner.identifier, :controller => 'profile', :action => 'favorite_enterprises' 19 + link_to __('View all'), :profile => owner.identifier, :controller => 'profile', :action => 'favorite_enterprises'
20 end 20 end
21 end 21 end
22 22
  23 + def profile_count
  24 + owner.favorite_enterprises.count
  25 + end
23 26
24 def profile_finder 27 def profile_finder
25 @profile_finder ||= FavoriteEnterprisesBlock::Finder.new(self) 28 @profile_finder ||= FavoriteEnterprisesBlock::Finder.new(self)
app/models/friends_block.rb
@@ -5,7 +5,7 @@ class FriendsBlock &lt; ProfileListBlock @@ -5,7 +5,7 @@ class FriendsBlock &lt; ProfileListBlock
5 end 5 end
6 6
7 def default_title 7 def default_title
8 - __('Friends') 8 + __('{#} friends')
9 end 9 end
10 10
11 def help 11 def help
@@ -15,7 +15,7 @@ class FriendsBlock &lt; ProfileListBlock @@ -15,7 +15,7 @@ class FriendsBlock &lt; ProfileListBlock
15 def footer 15 def footer
16 owner_id = owner.identifier 16 owner_id = owner.identifier
17 lambda do 17 lambda do
18 - link_to __('See all'), :profile => owner_id, :controller => 'profile', :action => 'friends' 18 + link_to __('View all'), :profile => owner_id, :controller => 'profile', :action => 'friends'
19 end 19 end
20 end 20 end
21 21
@@ -29,4 +29,8 @@ class FriendsBlock &lt; ProfileListBlock @@ -29,4 +29,8 @@ class FriendsBlock &lt; ProfileListBlock
29 @profile_finder ||= FriendsBlock::Finder.new(self) 29 @profile_finder ||= FriendsBlock::Finder.new(self)
30 end 30 end
31 31
  32 + def profile_count
  33 + owner.friends.count
  34 + end
  35 +
32 end 36 end
app/models/members_block.rb
@@ -5,7 +5,7 @@ class MembersBlock &lt; ProfileListBlock @@ -5,7 +5,7 @@ class MembersBlock &lt; ProfileListBlock
5 end 5 end
6 6
7 def default_title 7 def default_title
8 - _('Members') 8 + _('{#} members')
9 end 9 end
10 10
11 def help 11 def help
@@ -19,6 +19,10 @@ class MembersBlock &lt; ProfileListBlock @@ -19,6 +19,10 @@ class MembersBlock &lt; ProfileListBlock
19 end 19 end
20 end 20 end
21 21
  22 + def profile_count
  23 + owner.members.count
  24 + end
  25 +
22 def profile_finder 26 def profile_finder
23 @profile_finder ||= MembersBlock::Finder.new(self) 27 @profile_finder ||= MembersBlock::Finder.new(self)
24 end 28 end
app/models/people_block.rb
@@ -24,7 +24,7 @@ class PeopleBlock &lt; ProfileListBlock @@ -24,7 +24,7 @@ class PeopleBlock &lt; ProfileListBlock
24 24
25 def footer 25 def footer
26 lambda do 26 lambda do
27 - link_to _('All people'), :controller => 'search', :action => 'assets', :asset => 'people' 27 + link_to _('View all'), :controller => 'search', :action => 'assets', :asset => 'people'
28 end 28 end
29 end 29 end
30 30
app/models/profile_list_block.rb
@@ -52,7 +52,7 @@ class ProfileListBlock &lt; Block @@ -52,7 +52,7 @@ class ProfileListBlock &lt; Block
52 52
53 # the title of the block. Probably will be overriden in subclasses. 53 # the title of the block. Probably will be overriden in subclasses.
54 def default_title 54 def default_title
55 - _('People and Groups') 55 + _('{#} People or Groups')
56 end 56 end
57 57
58 def help 58 def help
@@ -61,13 +61,14 @@ class ProfileListBlock &lt; Block @@ -61,13 +61,14 @@ class ProfileListBlock &lt; Block
61 61
62 def content 62 def content
63 profiles = self.profiles 63 profiles = self.profiles
64 - title = self.title 64 + title = self.view_title
65 nl = "\n" 65 nl = "\n"
  66 + link_method = profile_image_link_method
66 lambda do 67 lambda do
67 count=0 68 count=0
68 list = profiles.map {|item| 69 list = profiles.map {|item|
69 count+=1 70 count+=1
70 - profile_image_link( item ) #+ 71 + send(link_method, item ) #+
71 }.join("\n ") 72 }.join("\n ")
72 if list.empty? 73 if list.empty?
73 list = '<div class="common-profile-list-block-none">'+ _('None') +'</div>' 74 list = '<div class="common-profile-list-block-none">'+ _('None') +'</div>'
@@ -80,4 +81,16 @@ class ProfileListBlock &lt; Block @@ -80,4 +81,16 @@ class ProfileListBlock &lt; Block
80 end 81 end
81 end 82 end
82 83
  84 + def profile_image_link_method
  85 + :profile_image_link
  86 + end
  87 +
  88 + def view_title
  89 + title.gsub('{#}', profile_count.to_s)
  90 + end
  91 +
  92 + def profile_count #defined in children
  93 + 0
  94 + end
  95 +
83 end 96 end
test/unit/block_test.rb
@@ -46,6 +46,12 @@ class BlockTest &lt; Test::Unit::TestCase @@ -46,6 +46,12 @@ class BlockTest &lt; Test::Unit::TestCase
46 assert_equal 'my title', b.title 46 assert_equal 'my title', b.title
47 end 47 end
48 48
  49 + should 'have default view_title ' do
  50 + b = Block.new
  51 + b.expects(:title).returns('my title')
  52 + assert_equal 'my title', b.view_title
  53 + end
  54 +
49 should 'have a visible setting' do 55 should 'have a visible setting' do
50 b = Block.new 56 b = Block.new
51 assert b.visible? 57 assert b.visible?
test/unit/communities_block_test.rb
@@ -49,7 +49,7 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase @@ -49,7 +49,7 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase
49 block = CommunitiesBlock.new 49 block = CommunitiesBlock.new
50 block.expects(:owner).returns(profile) 50 block.expects(:owner).returns(profile)
51 51
52 - expects(:__).with('All communities').returns('All communities') 52 + expects(:__).with('View all').returns('All communities')
53 expects(:link_to).with('All communities', :controller => 'profile', :profile => 'theprofile', :action => 'communities') 53 expects(:link_to).with('All communities', :controller => 'profile', :profile => 'theprofile', :action => 'communities')
54 instance_eval(&block.footer) 54 instance_eval(&block.footer)
55 end 55 end
@@ -59,7 +59,7 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase @@ -59,7 +59,7 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase
59 block = CommunitiesBlock.new 59 block = CommunitiesBlock.new
60 block.expects(:owner).returns(env) 60 block.expects(:owner).returns(env)
61 61
62 - expects(:__).with('All communities').returns('All communities') 62 + expects(:__).with('View all').returns('All communities')
63 expects(:link_to).with('All communities', :controller => 'search', :action => 'assets', :asset => 'communities') 63 expects(:link_to).with('All communities', :controller => 'search', :action => 'assets', :asset => 'communities')
64 64
65 instance_eval(&block.footer) 65 instance_eval(&block.footer)
@@ -86,4 +86,19 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase @@ -86,4 +86,19 @@ class CommunitiesBlockTest &lt; Test::Unit::TestCase
86 assert_equal [public_community], block.profiles 86 assert_equal [public_community], block.profiles
87 end 87 end
88 88
  89 + should 'count number of owner communities' do
  90 + user = create_user('testuser').person
  91 +
  92 + community1 = Community.create!(:name => 'test community 1', :identifier => 'comm1', :environment => Environment.default)
  93 + community1.add_member(user)
  94 +
  95 + community2 = Community.create!(:name => 'test community 2', :identifier => 'comm2', :environment => Environment.default)
  96 + community2.add_member(user)
  97 +
  98 + block = CommunitiesBlock.new
  99 + block.expects(:owner).at_least_once.returns(user)
  100 +
  101 + assert_equal 2, block.profile_count
  102 + end
  103 +
89 end 104 end
test/unit/enterprises_block_test.rb
@@ -74,7 +74,7 @@ class EnterprisesBlockTest &lt; Test::Unit::TestCase @@ -74,7 +74,7 @@ class EnterprisesBlockTest &lt; Test::Unit::TestCase
74 block = EnterprisesBlock.new 74 block = EnterprisesBlock.new
75 block.expects(:owner).returns(profile) 75 block.expects(:owner).returns(profile)
76 76
77 - expects(:__).with('All enterprises').returns('All enterprises') 77 + expects(:__).with('View all').returns('All enterprises')
78 expects(:link_to).with('All enterprises', :controller => 'profile', :profile => 'theprofile', :action => 'enterprises') 78 expects(:link_to).with('All enterprises', :controller => 'profile', :profile => 'theprofile', :action => 'enterprises')
79 79
80 instance_eval(&block.footer) 80 instance_eval(&block.footer)
@@ -85,7 +85,7 @@ class EnterprisesBlockTest &lt; Test::Unit::TestCase @@ -85,7 +85,7 @@ class EnterprisesBlockTest &lt; Test::Unit::TestCase
85 block = EnterprisesBlock.new 85 block = EnterprisesBlock.new
86 block.expects(:owner).returns(env) 86 block.expects(:owner).returns(env)
87 87
88 - expects(:__).with('All enterprises').returns('All enterprises') 88 + expects(:__).with('View all').returns('All enterprises')
89 expects(:link_to).with('All enterprises', :controller => 'search', :action => 'assets', :asset => 'enterprises') 89 expects(:link_to).with('All enterprises', :controller => 'search', :action => 'assets', :asset => 'enterprises')
90 instance_eval(&block.footer) 90 instance_eval(&block.footer)
91 end 91 end
@@ -96,4 +96,21 @@ class EnterprisesBlockTest &lt; Test::Unit::TestCase @@ -96,4 +96,21 @@ class EnterprisesBlockTest &lt; Test::Unit::TestCase
96 assert_equal '', block.footer 96 assert_equal '', block.footer
97 end 97 end
98 98
  99 + should 'count number of owner enterprises' do
  100 + user = create_user('testuser').person
  101 +
  102 + ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => Environment.default)
  103 + ent1.expects(:closed?).returns(false)
  104 + ent1.add_member(user)
  105 +
  106 + ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'ent2', :environment => Environment.default)
  107 + ent2.expects(:closed?).returns(false)
  108 + ent2.add_member(user)
  109 +
  110 + block = EnterprisesBlock.new
  111 + block.expects(:owner).at_least_once.returns(user)
  112 +
  113 + assert_equal 2, block.profile_count
  114 + end
  115 +
99 end 116 end
test/unit/favorite_enterprises_block_test.rb
@@ -48,8 +48,8 @@ class FavoriteEnterprisesBlockTest &lt; ActiveSupport::TestCase @@ -48,8 +48,8 @@ class FavoriteEnterprisesBlockTest &lt; ActiveSupport::TestCase
48 block = FavoriteEnterprisesBlock.new 48 block = FavoriteEnterprisesBlock.new
49 block.expects(:owner).returns(person) 49 block.expects(:owner).returns(person)
50 50
51 - expects(:__).with('All favorite enterprises').returns('All enterprises')  
52 - expects(:link_to).with('All enterprises', :controller => 'profile', :profile => 'theprofile', :action => 'favorite_enterprises') 51 + expects(:__).with('View all').returns('View all enterprises')
  52 + expects(:link_to).with('View all enterprises', :controller => 'profile', :profile => 'theprofile', :action => 'favorite_enterprises')
53 53
54 instance_eval(&block.footer) 54 instance_eval(&block.footer)
55 end 55 end
@@ -60,4 +60,19 @@ class FavoriteEnterprisesBlockTest &lt; ActiveSupport::TestCase @@ -60,4 +60,19 @@ class FavoriteEnterprisesBlockTest &lt; ActiveSupport::TestCase
60 assert_equal '', block.footer 60 assert_equal '', block.footer
61 end 61 end
62 62
  63 + should 'count number of owner favorite enterprises' do
  64 + user = create_user('testuser').person
  65 +
  66 + ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => Environment.default)
  67 +
  68 + ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'ent2', :environment => Environment.default)
  69 +
  70 + user.favorite_enterprises << [ent1, ent2]
  71 +
  72 + block = FavoriteEnterprisesBlock.new
  73 + block.expects(:owner).at_least_once.returns(user)
  74 +
  75 + assert_equal 2, block.profile_count
  76 + end
  77 +
63 end 78 end
test/unit/friends_block_test.rb
@@ -39,9 +39,25 @@ class FriendsBlockTest &lt; ActiveSupport::TestCase @@ -39,9 +39,25 @@ class FriendsBlockTest &lt; ActiveSupport::TestCase
39 39
40 def self._(s); s; end 40 def self._(s); s; end
41 def self.gettext(s); s; end 41 def self.gettext(s); s; end
42 - expects(:link_to).with('All friends', :profile => 'theuser', :controller => 'profile', :action => 'friends') 42 + expects(:link_to).with('View all', :profile => 'theuser', :controller => 'profile', :action => 'friends')
43 43
44 instance_eval(&block.footer) 44 instance_eval(&block.footer)
45 end 45 end
46 46
  47 + should 'count number of owner friends' do
  48 + p1 = create_user('testuser1').person
  49 + p2 = create_user('testuser2').person
  50 + p3 = create_user('testuser3').person
  51 + p4 = create_user('testuser4').person
  52 +
  53 + p1.add_friend(p2)
  54 + p1.add_friend(p3)
  55 + p1.add_friend(p4)
  56 +
  57 + block = FriendsBlock.new
  58 + block.expects(:owner).returns(p1)
  59 +
  60 + assert_equal 3, block.profile_count
  61 + end
  62 +
47 end 63 end
test/unit/members_block_test.rb
@@ -52,4 +52,19 @@ class MembersBlockTest &lt; Test::Unit::TestCase @@ -52,4 +52,19 @@ class MembersBlockTest &lt; Test::Unit::TestCase
52 assert_equal [member3, member1], block.profiles 52 assert_equal [member3, member1], block.profiles
53 end 53 end
54 54
  55 + should 'count number of owner members' do
  56 + profile = create_user('mytestuser').person
  57 + owner = mock
  58 +
  59 + member1 = mock; member1.stubs(:id).returns(1)
  60 + member2 = mock; member2.stubs(:id).returns(2)
  61 + member3 = mock; member3.stubs(:id).returns(3)
  62 +
  63 + owner.expects(:members).returns([member1, member2, member3])
  64 +
  65 + block = MembersBlock.new
  66 + block.expects(:owner).returns(owner)
  67 + assert_equal 3, block.profile_count
  68 + end
55 end 69 end
  70 +
test/unit/people_block_test.rb
@@ -36,8 +36,8 @@ class PeopleBlockTest &lt; ActiveSupport::TestCase @@ -36,8 +36,8 @@ class PeopleBlockTest &lt; ActiveSupport::TestCase
36 block = PeopleBlock.new 36 block = PeopleBlock.new
37 block.stubs(:owner).returns(Environment.default) 37 block.stubs(:owner).returns(Environment.default)
38 38
39 - expects(:link_to).with('All people', :controller => 'search', :action => 'assets', :asset => 'people')  
40 - expects(:_).with('All people').returns('All people') 39 + expects(:_).with('View all').returns('View all people')
  40 + expects(:link_to).with('View all people', :controller => 'search', :action => 'assets', :asset => 'people')
41 instance_eval(&block.footer) 41 instance_eval(&block.footer)
42 end 42 end
43 43
test/unit/profile_list_block_test.rb
@@ -67,5 +67,13 @@ class ProfileListBlockTest &lt; Test::Unit::TestCase @@ -67,5 +67,13 @@ class ProfileListBlockTest &lt; Test::Unit::TestCase
67 assert_respond_to ProfileListBlock::Finder.new(nil), :pick_random 67 assert_respond_to ProfileListBlock::Finder.new(nil), :pick_random
68 end 68 end
69 69
70 - 70 + should 'provide view_title' do
  71 + p = ProfileListBlock.new(:title => 'Title from block')
  72 + assert_equal 'Title from block', p.view_title
  73 + end
  74 +
  75 + should 'provide view title with variables' do
  76 + p = ProfileListBlock.new(:title => '{#} members')
  77 + assert_equal '0 members', p.view_title
  78 + end
71 end 79 end