Commit 20566b3e8c5e427571cc3229fb2331cb7130692d

Authored by Rodrigo Souto
1 parent 6d204ee1

Display selector

app/controllers/public/search_controller.rb
... ... @@ -144,7 +144,7 @@ class SearchController < PublicController
144 144 def load_query
145 145 @asset = (params[:asset] || params[:action]).to_sym
146 146 @order ||= [@asset]
147   - params[:display] ||= 'items'
  147 + params[:display] ||= DEFAULT_DISPLAY[@asset]
148 148 @searches ||= {}
149 149  
150 150 @query = params[:query] || ''
... ...
app/helpers/search_helper.rb
... ... @@ -14,11 +14,20 @@ module SearchHelper
14 14 :events, _('Events'),
15 15 ]
16 16  
  17 + DEFAULT_DISPLAY = {
  18 + :articles => 'full',
  19 + :communities => 'compact',
  20 + :enterprises => 'full',
  21 + :events => 'full',
  22 + :people => 'compact',
  23 + :products => 'full',
  24 + }
  25 +
17 26 # FIXME remove it after search_controler refactored
18 27 include EventsHelper
19 28  
20 29 def multiple_search?
21   - ['index', 'category_index'].include?(params[:action]) or @searches.size > 1
  30 + ['index', 'category_index'].include?(params[:action]) || @searches.size > 1
22 31 end
23 32  
24 33 def map_search?
... ... @@ -46,13 +55,12 @@ module SearchHelper
46 55 [:enterprises, :products].include?(asset)
47 56 end
48 57  
49   - def display_items?(asset)
50   - puts "\n\n" + asset.inspect + "\n\n"
51   - ![:products, :events].include?(asset)
  58 + def display_compact?(asset)
  59 + [:communities, :enterprises, :people].include?(asset)
52 60 end
53 61  
54 62 def display_full?(asset)
55   - [:enterprises, :products].include?(asset)
  63 + [:articles, :enterprises, :events, :products].include?(asset)
56 64 end
57 65  
58 66 def display_results(asset = nil)
... ... @@ -81,12 +89,12 @@ module SearchHelper
81 89 end
82 90  
83 91 def display_selector(asset, display, float = 'right')
84   - if [display_map?(asset), display_items?(asset), display_full?(asset)].select {|option| option}.count > 1
85   - items_link = display_items?(asset) ? (display == 'items' ? _('Items') : link_to(_('Items'), params.merge(:display => 'items'))) : nil
  92 + if [display_map?(asset), display_compact?(asset), display_full?(asset)].select {|option| option}.count > 1
  93 + compact_link = display_compact?(asset) ? (display == 'compact' ? _('Compact') : link_to(_('Compact'), params.merge(:display => 'compact'))) : nil
86 94 map_link = display_map?(asset) ? (display == 'map' ? _('Map') : link_to(_('Map'), params.merge(:display => 'map'))) : nil
87 95 full_link = display_full?(asset) ? (display == 'full' ? _('Full') : link_to(_('Full'), params.merge(:display => 'full'))) : nil
88 96 content_tag('div',
89   - content_tag('strong', _('Display')) + ': ' + [items_link, map_link, full_link].compact.join(' | '),
  97 + content_tag('strong', _('Display')) + ': ' + [compact_link, map_link, full_link].compact.join(' | '),
90 98 :id => 'search-display-filter',
91 99 :style => "float: #{float}"
92 100 )
... ...
app/views/search/_article.rhtml
... ... @@ -1,12 +0,0 @@
1   -<li class="search-article-item article-item">
2   - <%= link_to(article.title, article.url, :class => "search-result-title") %>
3   - <div class="search-content-first-column">
4   - <%= render :partial => 'image', :object => article %>
5   - </div>
6   - <table class="noborder search-content-second-column">
7   - <%= render :partial => 'article_common', :object => article %>
8   - </table>
9   - <%= render :partial => 'article_last_change', :object => article %>
10   -
11   - <div style="clear:both"></div>
12   -</li>
app/views/search/_compact_profile.html.erb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +<% profile = item %>
  2 +<% filter_label = profile.send(@filter + '_label') %>
  3 +<% filter_label += show_date(profile.created_at) if @filter == 'more_recent' %>
  4 +<li class="search-profile-item">
  5 + <%= profile_image_link profile, :portrait, 'div', filter_label %>
  6 +</li>
... ...
app/views/search/_display_results.rhtml
... ... @@ -4,19 +4,19 @@
4 4  
5 5 <div class="search-results-<%= name %> search-results-box <%= "search-results-empty" if search[:results].blank? %>">
6 6 <% if !search[:results].blank? %>
7   - <% partial = partial_for_class(name.to_s.singularize.camelize.constantize) %>
8 7  
9 8 <% if multiple_search? %>
10 9 <h3><%= @names[name] %></h3>
11 10 <% if search[:results].total_entries > SearchController::MULTIPLE_SEARCH_LIMIT %>
12 11 <%= link_to(_('see all (%d)') % search[:results].total_entries, params.merge(:action => name), :class => 'see-more' ) %>
13 12 <% end %>
  13 + <% params[:display] = 'compact' %>
14 14 <% end %>
15 15  
16   - <div class="search-results-innerbox search-results-type-<%= partial %> <%= 'common-profile-list-block' if partial == 'profile' %>">
  16 + <div class="search-results-innerbox search-results-type-<%= name.to_s %> <%= 'common-profile-list-block' if [:enterprises, :people, :communities].include?(name) %>">
17 17 <ul>
18 18 <% search[:results].each do |hit| %>
19   - <%= render :partial => partial_for_class(hit.class), :object => hit %>
  19 + <%= render :partial => partial_for_class(hit.class, params[:display]), :locals => {:item => hit} %>
20 20 <% end %>
21 21 </ul>
22 22 </div>
... ...
app/views/search/_event.rhtml
... ... @@ -1,25 +0,0 @@
1   -<li class="search-event-item article-item">
2   -<%= link_to(event.title, event.url, :class => "search-result-title") %>
3   -<div class="search-content-first-column">
4   - <%= render :partial => 'image', :object => event %>
5   -</div>
6   -<table class="noborder search-content-second-column">
7   - <% if event.start_date %>
8   - <tr class="search-article-event-date">
9   - <td class="search-field-label"><%= _('Start date') %></td>
10   - <td class="article-item-date"><%= event.start_date %></td>
11   - </tr>
12   - <% end %>
13   - <% if event.end_date %>
14   - <tr class="search-article-event-date">
15   - <td class="search-field-label"><%= _('End date') %></td>
16   - <td class="article-item-date"><%= event.end_date %></td>
17   - </tr>
18   - <% end %>
19   -
20   - <%= render :partial => 'article_common', :object => event %>
21   -</table>
22   -<%= render :partial => 'article_last_change', :object => event %>
23   -
24   -<div style="clear: both"></div>
25   -</li>
app/views/search/_full_article.html.erb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +<% article = item %>
  2 +<li class="search-article-item article-item">
  3 + <%= link_to(article.title, article.url, :class => "search-result-title") %>
  4 + <div class="search-content-first-column">
  5 + <%= render :partial => 'image', :object => article %>
  6 + </div>
  7 + <table class="noborder search-content-second-column">
  8 + <%= render :partial => 'article_common', :object => article %>
  9 + </table>
  10 + <%= render :partial => 'article_last_change', :object => article %>
  11 +
  12 + <div style="clear:both"></div>
  13 +</li>
... ...
app/views/search/_full_enterprise.html.erb 0 → 100644
... ... @@ -0,0 +1,39 @@
  1 +<% profile = item %>
  2 +<li class="search-profile-item">
  3 + <div class="search-enterprise-item">
  4 + <div class="search-enterprise-item-column-left">
  5 + <%= profile_image_link profile, :portrait, 'div',
  6 + @filter == 'more_recent' ? profile.send(@filter + '_label') + show_date(profile.created_at) : profile.send(@filter + '_label') %>
  7 + </div>
  8 + <div class="search-enterprise-item-column-right">
  9 + <%= link_to_homepage(profile.name, profile.identifier, :class => "search-result-title") %>
  10 + <div class="search-enterprise-description">
  11 + <% if profile.description %>
  12 + <% body_stripped = strip_tags(profile.description) %>
  13 + <% elsif profile.home_page and profile.home_page.body %>
  14 + <% body_stripped = strip_tags(profile.home_page.body) %>
  15 + <% end %>
  16 + <%= excerpt(body_stripped, body_stripped.first(3), 200) if body_stripped %>
  17 + </div>
  18 + <div class="search-enterprise-region">
  19 + <span class="search-enterprise-region-label"><%= _("City") %></span>
  20 + <% if profile.region %>
  21 + <span class="search-enterprise-region-name"><%= city_with_state(profile.region) %></span>
  22 + <% end %>
  23 + </div>
  24 +
  25 + <div class="search-enterprise-categorization">
  26 + <% profile.top_level_categorization.each do |parent, children| %>
  27 + <div class="search-enterprise-category-<%=parent.id%> search-enterprise-category">
  28 + <span class="search-enterprise-categorization-parent"><%= parent.name %></span>
  29 + <span class="search-enterprise-categorization-children">
  30 + <%= children.collect(&:name).join(', ') %>
  31 + </span>
  32 + </div>
  33 + <% end %>
  34 + </div>
  35 + </div>
  36 +
  37 + <hr class="clearfix" />
  38 + </div>
  39 +</li>
... ...
app/views/search/_full_event.html.erb 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +<% event = item %>
  2 +<li class="search-event-item article-item">
  3 +<%= link_to(event.title, event.url, :class => "search-result-title") %>
  4 +<div class="search-content-first-column">
  5 + <%= render :partial => 'image', :object => event %>
  6 +</div>
  7 +<table class="noborder search-content-second-column">
  8 + <% if event.start_date %>
  9 + <tr class="search-article-event-date">
  10 + <td class="search-field-label"><%= _('Start date') %></td>
  11 + <td class="article-item-date"><%= event.start_date %></td>
  12 + </tr>
  13 + <% end %>
  14 + <% if event.end_date %>
  15 + <tr class="search-article-event-date">
  16 + <td class="search-field-label"><%= _('End date') %></td>
  17 + <td class="article-item-date"><%= event.end_date %></td>
  18 + </tr>
  19 + <% end %>
  20 +
  21 + <%= render :partial => 'article_common', :object => event %>
  22 +</table>
  23 +<%= render :partial => 'article_last_change', :object => event %>
  24 +
  25 +<div style="clear: both"></div>
  26 +</li>
... ...
app/views/search/_full_product.rhtml 0 → 100644
... ... @@ -0,0 +1,86 @@
  1 +<% product = item %>
  2 +<% extra_content = @plugins.dispatch(:asset_product_extras, product).collect { |content| instance_eval(&content) } %>
  3 +<% extra_properties = @plugins.dispatch(:asset_product_properties, product)%>
  4 +
  5 +<li class="search-product-item <%= 'highlighted' if product.highlighted? %>">
  6 +
  7 + <div class="search-product-item-first-column">
  8 + <%= render :partial => 'search/image', :object => product %>
  9 +
  10 + <% if product.available %>
  11 + <% if product.price && product.price > 0 %>
  12 + <% has_discount = product.discount && product.discount > 0 %>
  13 + <% if product.price %>
  14 + <span class="search-product-price-textid"><%=_("from") if has_discount %></span><%= price_span(product.price, :class => "search-product-price " + (has_discount ? 'with-discount' : '')) %>
  15 + <% if has_discount %>
  16 + <span class="search-product-price-textid"><%=_("by")%></span><%= price_span(product.price_with_discount, :class => "search-product-price") %>
  17 + <% end %>
  18 + <% if product.unit %>
  19 + <span class="search-product-unit">&nbsp;<%= _('/') %>&nbsp;<%= product.unit.name %></span>
  20 + <% end %>
  21 + <% end %>
  22 + <div class="search-product-inputs-info">
  23 + <% if p = product.percentage_from_solidarity_economy %>
  24 + <div class="search-product-percentage-from-solidarity-economy search-product-ecosol-percentage-icon-<%= p[0].to_s %>"
  25 + title="<%=_('Percentage of inputs from solidarity economy')%>">
  26 + <%= p[1] %>
  27 + </div>
  28 + <% end %>
  29 +
  30 + <% if product.price_described? %>
  31 + <% title = (product.inputs.relevant_to_price + product.price_details).map{ |i|
  32 + '<div class="search-product-input-dots-to-price">' +
  33 + '<div class="search-product-input-name">' + i.name + '</div>' +
  34 + price_span(i.price, :class => 'search-product-input-price') +
  35 + '</div>' }.join('') %>
  36 + <%= link_to_function _("Open Price"), '', :title => title, :class => "search-product-price-details" %>
  37 + <% end %>
  38 + </div>
  39 + <% end %>
  40 + <% else %>
  41 + <span class="product-not-available"><%= _('Not available') %></div>
  42 + <% end %>
  43 +
  44 + </div>
  45 + <div class="search-product-item-second-column">
  46 + <%= link_to_product product, :class => 'search-result-title' %>
  47 + <div class="search-product-supplier">
  48 + <span class="search-field-label"><%= _('Supplier') %> </span><%= link_to_homepage(product.enterprise.name, product.enterprise.identifier) %>
  49 + </div>
  50 + <div class="search-product-description">
  51 + <% if product.description %>
  52 + <% desc_stripped = strip_tags(product.description) %>
  53 + <span class="search-field-label"><%= _('Description') %> </span><%= excerpt(desc_stripped, desc_stripped.first(3), 300) %>
  54 + <% end %>
  55 + </div>
  56 + </div>
  57 + <div class="search-product-item-third-column">
  58 + <div class="search-product-region">
  59 + <% if product.enterprise.region %>
  60 + <span class="search-field-label"><%= _('City') %></span>
  61 + <br /><%= city_with_state(product.enterprise.region) %>
  62 + <% end %>
  63 + </div>
  64 + <div class="search-product-qualifiers">
  65 + <% if product.product_qualifiers.count > 0 %>
  66 + <span class="search-field-label"><%= _('Qualifiers') %></span>
  67 + <% product.product_qualifiers.each do |pq| %>
  68 + <% if pq.qualifier %>
  69 + <span class="search-product-qualifier"><%= pq.qualifier.name + (pq.certifier.nil? ? _(";") : '') %></span>
  70 + <% end %>
  71 + <% if pq.certifier %>
  72 + <span class="search-product-certifier">&nbsp;<%= _('cert. ') + pq.certifier.name + _(";") %></span>
  73 + <% end %>
  74 + <% end %>
  75 + <% end %>
  76 + </div>
  77 + </div>
  78 +
  79 + <div style="clear: both"></div>
  80 +
  81 + <%= extra_content.join('\n') %>
  82 + <% extra_properties.each do |property| %>
  83 + <div><%= property[:name] + ': ' + instance_eval(&property[:content]) %></div>
  84 + <% end %>
  85 +
  86 +</li>
... ...
app/views/search/_product.rhtml
... ... @@ -1,85 +0,0 @@
1   -<% extra_content = @plugins.dispatch(:asset_product_extras, product).collect { |content| instance_eval(&content) } %>
2   -<% extra_properties = @plugins.dispatch(:asset_product_properties, product)%>
3   -
4   -<li class="search-product-item <%= 'highlighted' if product.highlighted? %>">
5   -
6   - <div class="search-product-item-first-column">
7   - <%= render :partial => 'search/image', :object => product %>
8   -
9   - <% if product.available %>
10   - <% if product.price && product.price > 0 %>
11   - <% has_discount = product.discount && product.discount > 0 %>
12   - <% if product.price %>
13   - <span class="search-product-price-textid"><%=_("from") if has_discount %></span><%= price_span(product.price, :class => "search-product-price " + (has_discount ? 'with-discount' : '')) %>
14   - <% if has_discount %>
15   - <span class="search-product-price-textid"><%=_("by")%></span><%= price_span(product.price_with_discount, :class => "search-product-price") %>
16   - <% end %>
17   - <% if product.unit %>
18   - <span class="search-product-unit">&nbsp;<%= _('/') %>&nbsp;<%= product.unit.name %></span>
19   - <% end %>
20   - <% end %>
21   - <div class="search-product-inputs-info">
22   - <% if p = product.percentage_from_solidarity_economy %>
23   - <div class="search-product-percentage-from-solidarity-economy search-product-ecosol-percentage-icon-<%= p[0].to_s %>"
24   - title="<%=_('Percentage of inputs from solidarity economy')%>">
25   - <%= p[1] %>
26   - </div>
27   - <% end %>
28   -
29   - <% if product.price_described? %>
30   - <% title = (product.inputs.relevant_to_price + product.price_details).map{ |i|
31   - '<div class="search-product-input-dots-to-price">' +
32   - '<div class="search-product-input-name">' + i.name + '</div>' +
33   - price_span(i.price, :class => 'search-product-input-price') +
34   - '</div>' }.join('') %>
35   - <%= link_to_function _("Open Price"), '', :title => title, :class => "search-product-price-details" %>
36   - <% end %>
37   - </div>
38   - <% end %>
39   - <% else %>
40   - <span class="product-not-available"><%= _('Not available') %></div>
41   - <% end %>
42   -
43   - </div>
44   - <div class="search-product-item-second-column">
45   - <%= link_to_product product, :class => 'search-result-title' %>
46   - <div class="search-product-supplier">
47   - <span class="search-field-label"><%= _('Supplier') %> </span><%= link_to_homepage(product.enterprise.name, product.enterprise.identifier) %>
48   - </div>
49   - <div class="search-product-description">
50   - <% if product.description %>
51   - <% desc_stripped = strip_tags(product.description) %>
52   - <span class="search-field-label"><%= _('Description') %> </span><%= excerpt(desc_stripped, desc_stripped.first(3), 300) %>
53   - <% end %>
54   - </div>
55   - </div>
56   - <div class="search-product-item-third-column">
57   - <div class="search-product-region">
58   - <% if product.enterprise.region %>
59   - <span class="search-field-label"><%= _('City') %></span>
60   - <br /><%= city_with_state(product.enterprise.region) %>
61   - <% end %>
62   - </div>
63   - <div class="search-product-qualifiers">
64   - <% if product.product_qualifiers.count > 0 %>
65   - <span class="search-field-label"><%= _('Qualifiers') %></span>
66   - <% product.product_qualifiers.each do |pq| %>
67   - <% if pq.qualifier %>
68   - <span class="search-product-qualifier"><%= pq.qualifier.name + (pq.certifier.nil? ? _(";") : '') %></span>
69   - <% end %>
70   - <% if pq.certifier %>
71   - <span class="search-product-certifier">&nbsp;<%= _('cert. ') + pq.certifier.name + _(";") %></span>
72   - <% end %>
73   - <% end %>
74   - <% end %>
75   - </div>
76   - </div>
77   -
78   - <div style="clear: both"></div>
79   -
80   - <%= extra_content.join('\n') %>
81   - <% extra_properties.each do |property| %>
82   - <div><%= property[:name] + ': ' + instance_eval(&property[:content]) %></div>
83   - <% end %>
84   -
85   -</li>
app/views/search/_profile.rhtml
... ... @@ -1,43 +0,0 @@
1   -<li class="search-profile-item">
2   -<% if @empty_query || multiple_search? || !profile.enterprise? %>
3   - <%= profile_image_link profile, :portrait, 'div',
4   - @filter == 'more_recent' ? profile.send(@filter + '_label') + show_date(profile.created_at) : profile.send(@filter + '_label') %>
5   -<% else %>
6   - <div class="search-enterprise-item">
7   - <div class="search-enterprise-item-column-left">
8   - <%= profile_image_link profile, :portrait, 'div',
9   - @filter == 'more_recent' ? profile.send(@filter + '_label') + show_date(profile.created_at) : profile.send(@filter + '_label') %>
10   - </div>
11   - <div class="search-enterprise-item-column-right">
12   - <%= link_to_homepage(profile.name, profile.identifier, :class => "search-result-title") %>
13   - <div class="search-enterprise-description">
14   - <% if profile.description %>
15   - <% body_stripped = strip_tags(profile.description) %>
16   - <% elsif profile.home_page and profile.home_page.body %>
17   - <% body_stripped = strip_tags(profile.home_page.body) %>
18   - <% end %>
19   - <%= excerpt(body_stripped, body_stripped.first(3), 200) if body_stripped %>
20   - </div>
21   - <div class="search-enterprise-region">
22   - <span class="search-enterprise-region-label"><%= _("City") %></span>
23   - <% if profile.region %>
24   - <span class="search-enterprise-region-name"><%= city_with_state(profile.region) %></span>
25   - <% end %>
26   - </div>
27   -
28   - <div class="search-enterprise-categorization">
29   - <% profile.top_level_categorization.each do |parent, children| %>
30   - <div class="search-enterprise-category-<%=parent.id%> search-enterprise-category">
31   - <span class="search-enterprise-categorization-parent"><%= parent.name %></span>
32   - <span class="search-enterprise-categorization-children">
33   - <%= children.collect(&:name).join(', ') %>
34   - </span>
35   - </div>
36   - <% end %>
37   - </div>
38   - </div>
39   -
40   - <hr class="clearfix" />
41   - </div>
42   -<% end %>
43   -</li>
app/views/search/_results_header.rhtml
1 1 <div class="search-results-header <%= "search-no-results" if @searches[@asset].nil? or @searches[@asset].length == 0 %>">
2 2 <div id='search-filter-title'><%= filter_title(@asset, @filter) %></div>
3   - <%= display_selector(@asset, params[:display]) if !map_search? %>
  3 + <%= display_selector(@asset, params[:display]) %>
4 4 <div style="clear: both"></div>
5 5 </div>
... ...