Commit ced5fa1464f34c980944aa6ee5c994c1213b0ac6
1 parent
b4b7ad92
Exists in
staging
and in
29 other branches
Remove InterestsBlock#content method
This removes html generation from the class improving MVC responsability separation. It required the creation of a new method, interests, and view move/rename.
Showing
3 changed files
with
43 additions
and
45 deletions
Show diff stats
plugins/sniffer/lib/sniffer_plugin/interests_block.rb
@@ -16,22 +16,20 @@ class SnifferPlugin::InterestsBlock < Block | @@ -16,22 +16,20 @@ class SnifferPlugin::InterestsBlock < Block | ||
16 | _("This block show interests of your profile or environment") | 16 | _("This block show interests of your profile or environment") |
17 | end | 17 | end |
18 | 18 | ||
19 | - def content(args = {}) | ||
20 | - block = self | 19 | + def interests |
20 | + results = nil | ||
21 | profile = block.owner | 21 | profile = block.owner |
22 | - proc do | ||
23 | - if block.owner.is_a?(Profile) | ||
24 | - interests = profile.snnifer_opportunities | ||
25 | - interests |= profile.inputs if sniffer.profile.enterprise? | ||
26 | - else # Environment | ||
27 | - interests = SnifferPlugin::Opportunity.product_categories.limit(5).order('created_at DESC').all | ||
28 | - interests += Input.limit(5).order('created_at DESC').all | ||
29 | - interests.sort{ |a, b| -1 * a.created_at.to_i <=> b.created_at.to_i } | ||
30 | - end | ||
31 | - | ||
32 | - render :file => 'blocks/sniffer_plugin/interests_block', | ||
33 | - :locals => {:block => block, :interests => interests} | 22 | + |
23 | + if profile.is_a?(Profile) | ||
24 | + results = profile.snnifer_opportunities | ||
25 | + results |= profile.inputs if sniffer.profile.enterprise? | ||
26 | + else # Environment | ||
27 | + results = SnifferPlugin::Opportunity.product_categories.limit(5).order('created_at DESC').all | ||
28 | + results += Input.limit(5).order('created_at DESC').all | ||
29 | + results.sort{ |a, b| -1 * a.created_at.to_i <=> b.created_at.to_i } | ||
34 | end | 30 | end |
31 | + | ||
32 | + return results | ||
35 | end | 33 | end |
36 | 34 | ||
37 | end | 35 | end |
@@ -0,0 +1,31 @@ | @@ -0,0 +1,31 @@ | ||
1 | +<%= block_title block.title, block.subtitle %> | ||
2 | + | ||
3 | +<% if block.owner.is_a?(Profile) %> | ||
4 | + <ul> | ||
5 | + <% block.interests.each do |interest| %> | ||
6 | + <li><%= interest.product_category.name %></li> | ||
7 | + <% end %> | ||
8 | + </ul> | ||
9 | + | ||
10 | + <div> | ||
11 | + <% if logged_in? and (current_user.person.is_admin?(environment) or profile.admins.include?(current_user.person)) %> | ||
12 | + <%= _('Edit %{inputs} and %{block.interests}') % { | ||
13 | + :inputs => link_to(_("products' inputs"), :controller => :manage_products, :action => :index), | ||
14 | + :interests => link_to(_('declared interests'), :controller => :sniffer_plugin_myprofile, :action => :edit), | ||
15 | + } %> | ||
16 | + <% end %> | ||
17 | + </div> | ||
18 | +<% else %> | ||
19 | + <ul> | ||
20 | + <% block.interests.each do |interest| %> | ||
21 | + <li> | ||
22 | + <% profile = interest.is_a?(SnifferPlugin::Opportunity) ? interest.profile : interest.product.enterprise %> | ||
23 | + <%= _('%{interest} from %{profile}') % { | ||
24 | + :interest => interest.product_category.name, | ||
25 | + :profile => link_to_profile(profile.name, profile), | ||
26 | + } %> | ||
27 | + </li> | ||
28 | + <% end %> | ||
29 | + </ul> | ||
30 | +<% end %> | ||
31 | + |
plugins/sniffer/views/blocks/sniffer_plugin/interests_block.html.erb
@@ -1,31 +0,0 @@ | @@ -1,31 +0,0 @@ | ||
1 | -<%= block_title block.title, block.subtitle %> | ||
2 | - | ||
3 | -<% if block.owner.is_a?(Profile) %> | ||
4 | - <ul> | ||
5 | - <% interests.each do |interest| %> | ||
6 | - <li><%= interest.product_category.name %></li> | ||
7 | - <% end %> | ||
8 | - </ul> | ||
9 | - | ||
10 | - <div> | ||
11 | - <% if logged_in? and (current_user.person.is_admin?(environment) or profile.admins.include?(current_user.person)) %> | ||
12 | - <%= _('Edit %{inputs} and %{interests}') % { | ||
13 | - :inputs => link_to(_("products' inputs"), :controller => :manage_products, :action => :index), | ||
14 | - :interests => link_to(_('declared interests'), :controller => :sniffer_plugin_myprofile, :action => :edit), | ||
15 | - } %> | ||
16 | - <% end %> | ||
17 | - </div> | ||
18 | -<% else %> | ||
19 | - <ul> | ||
20 | - <% interests.each do |interest| %> | ||
21 | - <li> | ||
22 | - <% profile = interest.is_a?(SnifferPlugin::Opportunity) ? interest.profile : interest.product.enterprise %> | ||
23 | - <%= _('%{interest} from %{profile}') % { | ||
24 | - :interest => interest.product_category.name, | ||
25 | - :profile => link_to_profile(profile.name, profile), | ||
26 | - } %> | ||
27 | - </li> | ||
28 | - <% end %> | ||
29 | - </ul> | ||
30 | -<% end %> | ||
31 | - |