Commit dedffcc6a535cfe7a097770c1485e1658565e929
1 parent
6b8af367
Exists in
master
and in
29 other branches
ActionItem696: enhancing my networks block
Showing
11 changed files
with
81 additions
and
77 deletions
Show diff stats
app/controllers/my_profile/profile_design_controller.rb
@@ -5,7 +5,7 @@ class ProfileDesignController < BoxOrganizerController | @@ -5,7 +5,7 @@ class ProfileDesignController < BoxOrganizerController | ||
5 | protect 'edit_profile_design', :profile | 5 | protect 'edit_profile_design', :profile |
6 | 6 | ||
7 | def available_blocks | 7 | def available_blocks |
8 | - blocks = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock, LinkListBlock ] | 8 | + blocks = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock, LinkListBlock, MyNetworkBlock ] |
9 | 9 | ||
10 | # blocks exclusive for organizations | 10 | # blocks exclusive for organizations |
11 | if profile.has_members? | 11 | if profile.has_members? |
@@ -16,7 +16,6 @@ class ProfileDesignController < BoxOrganizerController | @@ -16,7 +16,6 @@ class ProfileDesignController < BoxOrganizerController | ||
16 | if profile.person? | 16 | if profile.person? |
17 | blocks << FriendsBlock | 17 | blocks << FriendsBlock |
18 | blocks << FavoriteEnterprisesBlock | 18 | blocks << FavoriteEnterprisesBlock |
19 | - blocks << MyNetworkBlock | ||
20 | end | 19 | end |
21 | 20 | ||
22 | # product block exclusive for enterprises in environments that permits it | 21 | # product block exclusive for enterprises in environments that permits it |
app/models/my_network_block.rb
@@ -15,18 +15,13 @@ class MyNetworkBlock < Block | @@ -15,18 +15,13 @@ class MyNetworkBlock < Block | ||
15 | end | 15 | end |
16 | 16 | ||
17 | def content | 17 | def content |
18 | - block_title(title) + | ||
19 | - content_tag( | ||
20 | - 'ul', | ||
21 | - content_tag('li', link_to(n_( 'One article published', '%s articles published', owner.articles.count) % | ||
22 | - content_tag('b', owner.articles.count), owner.public_profile_url.merge(:action => 'sitemap') )) + | ||
23 | - content_tag('li', link_to(n__('One friend', '%s friends', owner.friends.count) % | ||
24 | - content_tag('b', owner.friends.count), owner.public_profile_url.merge(:action => 'friends'))) + | ||
25 | - content_tag('li', link_to(n__('One community', '%s communities', owner.communities.size) % | ||
26 | - content_tag('b', owner.communities.size), owner.public_profile_url.merge(:action => 'communities'))) + | ||
27 | - content_tag('li', link_to(n_('One tag', '%s tags', owner.tags.size) % | ||
28 | - content_tag('b', owner.tags.size), owner.public_profile_url.merge(:action => 'tags'))) | ||
29 | - ) | 18 | + block = self |
19 | + lambda do | ||
20 | + render :file => 'blocks/my_network', :locals => { | ||
21 | + :title => block.title, | ||
22 | + :owner => block.owner | ||
23 | + } | ||
24 | + end | ||
30 | end | 25 | end |
31 | 26 | ||
32 | end | 27 | end |
@@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
1 | +<%= block_title(title) %> | ||
2 | + | ||
3 | +<%= render :file => 'blocks/my_network/' + owner.class.name.underscore, :locals => { :owner => owner } %> | ||
4 | + | ||
5 | +<ul> | ||
6 | + <li><%= link_to(__('Homepage'), owner.url, :class => 'url') %></li> | ||
7 | + <li><%= link_to(_('View profile'), owner.public_profile_url) %></li> | ||
8 | + <% if !user.nil? and owner.organization? and user.has_permission?('edit_profile', profile) %> | ||
9 | + <li><%= link_to _('Control panel'), :controller => 'profile_editor' %></li> | ||
10 | + <% end %> | ||
11 | +</ul> | ||
12 | + | ||
13 | +<div class="my-network-actions"> | ||
14 | + <%= render :file => 'blocks/profile_info_actions/' + owner.class.name.underscore %> | ||
15 | +</div> |
@@ -0,0 +1,8 @@ | @@ -0,0 +1,8 @@ | ||
1 | +<ul> | ||
2 | + <li><%= link_to(n_( 'One article published', '%s articles published', owner.articles.count) % | ||
3 | + content_tag('b', owner.articles.count), owner.public_profile_url.merge(:action => 'sitemap') ) %></li> | ||
4 | + <li><%= link_to(n_( 'One member', '%s members', owner.members.count) % | ||
5 | + content_tag('b', owner.members.count), owner.public_profile_url.merge(:action => 'members') ) %></li> | ||
6 | + <li><%= link_to(n_('One tag', '%s tags', owner.tags.size) % | ||
7 | + content_tag('b', owner.tags.size), owner.public_profile_url.merge(:action => 'tags')) %></li> | ||
8 | +</ul> |
@@ -0,0 +1,10 @@ | @@ -0,0 +1,10 @@ | ||
1 | +<ul> | ||
2 | + <li><%= link_to(n_( 'One article published', '%s articles published', owner.articles.count) % | ||
3 | + content_tag('b', owner.articles.count), owner.public_profile_url.merge(:action => 'sitemap') ) %></li> | ||
4 | + <li><%= link_to(n__('One friend', '%s friends', owner.friends.count) % | ||
5 | + content_tag('b', owner.friends.count), owner.public_profile_url.merge(:action => 'friends')) %></li> | ||
6 | + <li><%= link_to(n__('One community', '%s communities', owner.communities.size) % | ||
7 | + content_tag('b', owner.communities.size), owner.public_profile_url.merge(:action => 'communities')) %></li> | ||
8 | + <li><%= link_to(n_('One tag', '%s tags', owner.tags.size) % | ||
9 | + content_tag('b', owner.tags.size), owner.public_profile_url.merge(:action => 'tags')) %></li> | ||
10 | +</ul> |
app/views/blocks/profile_info.rhtml
@@ -14,7 +14,6 @@ | @@ -14,7 +14,6 @@ | ||
14 | </div> | 14 | </div> |
15 | </div> | 15 | </div> |
16 | 16 | ||
17 | - | ||
18 | <ul class="profile-info-data"> | 17 | <ul class="profile-info-data"> |
19 | <li><%= link_to __('Homepage'), block.owner.url, :class => 'url' %></li> | 18 | <li><%= link_to __('Homepage'), block.owner.url, :class => 'url' %></li> |
20 | <li><%= link_to _('View profile'), block.owner.public_profile_url %></li> | 19 | <li><%= link_to _('View profile'), block.owner.public_profile_url %></li> |
@@ -37,7 +36,7 @@ | @@ -37,7 +36,7 @@ | ||
37 | <% end %> | 36 | <% end %> |
38 | 37 | ||
39 | <div class="profile-info-options"> | 38 | <div class="profile-info-options"> |
40 | - <%= render :file => 'blocks/profile_info_actions/' + block.owner.class.name.underscore %> | 39 | + <%= render :file => 'blocks/profile_info_actions/' + block.owner.class.name.underscore %> |
41 | </div> | 40 | </div> |
42 | 41 | ||
43 | </div><!-- end class="vcard" --> | 42 | </div><!-- end class="vcard" --> |
public/designs/themes/zen3/stylesheets/blocks/my-network-block.css
@@ -22,3 +22,16 @@ | @@ -22,3 +22,16 @@ | ||
22 | color: #600; | 22 | color: #600; |
23 | } | 23 | } |
24 | 24 | ||
25 | + | ||
26 | +.my-network-block .my-network-actions ul { | ||
27 | + text-align: center; | ||
28 | +} | ||
29 | + | ||
30 | +.my-network-actions ul { | ||
31 | + padding: 0; | ||
32 | + padding-bottom: 10px; | ||
33 | +} | ||
34 | + | ||
35 | +.my-network-actions li { | ||
36 | + list-style: none; | ||
37 | +} |
test/functional/profile_controller_test.rb
@@ -143,19 +143,33 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -143,19 +143,33 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
143 | should 'show a link to own control panel' do | 143 | should 'show a link to own control panel' do |
144 | login_as(@profile.identifier) | 144 | login_as(@profile.identifier) |
145 | get :index, :profile => @profile.identifier | 145 | get :index, :profile => @profile.identifier |
146 | - assert_tag :tag => 'ul', :attributes => { :class => 'profile-info-data' }, :descendant => { :tag => 'a', :content => 'Control panel' } | 146 | + assert_tag :tag => 'a', :content => 'Control panel' |
147 | + end | ||
148 | + | ||
149 | + should 'show a link to own control panel in my-network-block if is a group' do | ||
150 | + login_as(@profile.identifier) | ||
151 | + community = Community.create!(:name => 'my test community') | ||
152 | + community.blocks.each{|i| i.destroy} | ||
153 | + community.boxes[0].blocks << MyNetworkBlock.new | ||
154 | + community.add_admin(@profile) | ||
155 | + get :index, :profile => community.identifier | ||
156 | + assert_tag :tag => 'a', :content => 'Control panel' | ||
147 | end | 157 | end |
148 | 158 | ||
149 | should 'not show a link to others control panel' do | 159 | should 'not show a link to others control panel' do |
150 | login_as(@profile.identifier) | 160 | login_as(@profile.identifier) |
151 | other = create_user('person_1').person | 161 | other = create_user('person_1').person |
162 | + other.blocks.each{|i| i.destroy} | ||
163 | + other.boxes[0].blocks << ProfileInfoBlock.new | ||
152 | get :index, :profile => other.identifier | 164 | get :index, :profile => other.identifier |
153 | assert_no_tag :tag => 'ul', :attributes => { :class => 'profile-info-data' }, :descendant => { :tag => 'a', :content => 'Control panel' } | 165 | assert_no_tag :tag => 'ul', :attributes => { :class => 'profile-info-data' }, :descendant => { :tag => 'a', :content => 'Control panel' } |
154 | end | 166 | end |
155 | 167 | ||
156 | - should 'show a link to control panel if user has profile_editor permission' do | 168 | + should 'show a link to control panel if user has profile_editor permission and is a group' do |
157 | login_as(@profile.identifier) | 169 | login_as(@profile.identifier) |
158 | - get :index, :profile => @profile.identifier | 170 | + community = Community.create!(:name => 'my test community') |
171 | + community.add_admin(@profile) | ||
172 | + get :index, :profile => community.identifier | ||
159 | assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{@profile.identifier}" }, :content => 'Control panel' | 173 | assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{@profile.identifier}" }, :content => 'Control panel' |
160 | end | 174 | end |
161 | 175 | ||
@@ -251,8 +265,9 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -251,8 +265,9 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
251 | end | 265 | end |
252 | 266 | ||
253 | should 'display "Site map" link for profiles' do | 267 | should 'display "Site map" link for profiles' do |
254 | - get :index, :profile => 'ze' | ||
255 | - assert_tag :tag => 'a', :content => "Site map", :attributes => { :href => '/profile/ze/sitemap' } | 268 | + profile = create_user('testmapuser').person |
269 | + get :index, :profile => profile.identifier | ||
270 | + assert_tag :tag => 'a', :content => "Site map", :attributes => { :href => '/profile/testmapuser/sitemap' } | ||
256 | end | 271 | end |
257 | 272 | ||
258 | should 'list top level articles in sitemap' do | 273 | should 'list top level articles in sitemap' do |
test/unit/my_network_block_test.rb
@@ -19,62 +19,12 @@ class MyNetworkBlockTest < ActiveSupport::TestCase | @@ -19,62 +19,12 @@ class MyNetworkBlockTest < ActiveSupport::TestCase | ||
19 | assert_not_equal Block.new.default_title, MyNetworkBlock.new.default_title | 19 | assert_not_equal Block.new.default_title, MyNetworkBlock.new.default_title |
20 | end | 20 | end |
21 | 21 | ||
22 | - should 'count articles' do | ||
23 | - mock_articles = mock | ||
24 | - owner.stubs(:articles).returns(mock_articles) | ||
25 | - owner.stubs(:tags).returns({}) # don't let tags call articles | ||
26 | - mock_articles.stubs(:count).returns(5) | ||
27 | - | ||
28 | - assert_tag_in_string block.content, :tag => 'li', :descendant => { | ||
29 | - :tag => 'a', | ||
30 | - :descendant => { :tag => 'b', :content => '5' }, | ||
31 | - :content => ' articles published', | ||
32 | - :attributes => { :href => /\/profile\/testuser\/sitemap$/ } | ||
33 | - } | ||
34 | - end | ||
35 | - | ||
36 | - should 'count friends' do | ||
37 | - mock_friends = mock | ||
38 | - owner.stubs(:friends).returns(mock_friends) | ||
39 | - mock_friends.stubs(:count).returns(8) | ||
40 | - | ||
41 | - assert_tag_in_string block.content, :tag => 'li', :descendant => { | ||
42 | - :tag => 'a', | ||
43 | - :descendant => { :tag => 'b', :content => '8' }, | ||
44 | - :content => ' friends', | ||
45 | - :attributes => { :href => /\profile\/testuser\/friends/ } | ||
46 | - } | ||
47 | - end | ||
48 | - | ||
49 | - should 'count communities' do | ||
50 | - mock_communities = mock | ||
51 | - owner.stubs(:communities).returns(mock_communities) | ||
52 | - mock_communities.stubs(:size).returns(23) | ||
53 | - | ||
54 | - assert_tag_in_string block.content, :tag => 'li', :descendant => { | ||
55 | - :tag => 'a', | ||
56 | - :descendant => { :tag => 'b', :content => '23' }, | ||
57 | - :content => ' communities', | ||
58 | - :attributes => { :href => /\profile\/testuser\/communities/ } | ||
59 | - } | ||
60 | - end | ||
61 | - | ||
62 | - should 'count tags' do | ||
63 | - mock_tags = mock | ||
64 | - owner.stubs(:tags).returns(mock_tags) | ||
65 | - mock_tags.stubs(:size).returns(436) | ||
66 | - | ||
67 | - assert_tag_in_string block.content, :tag => 'li', :descendant => { | ||
68 | - :tag => 'a', | ||
69 | - :descendant => { :tag => 'b', :content => '436' }, | ||
70 | - :content => ' tags', | ||
71 | - :attributes => { :href => /\profile\/testuser\/tags/ } | ||
72 | - } | ||
73 | - end | ||
74 | - | ||
75 | - should 'display its title' do | ||
76 | - block.stubs(:title).returns('My Network') | ||
77 | - assert_tag_in_string block.content, :content => 'My Network' | 22 | + should 'display my-profile' do |
23 | + self.expects(:render).with(:file => 'blocks/my_network', :locals => { | ||
24 | + :title => 'My network', | ||
25 | + :owner => owner | ||
26 | + }) | ||
27 | + instance_eval(& block.content) | ||
78 | end | 28 | end |
79 | 29 | ||
80 | end | 30 | end |