Commit cd53e5e5a940050e3c28aef6af236bf26b4fff43
1 parent
b9a0b4d3
Exists in
master
and in
29 other branches
On the way of search display options
Showing
7 changed files
with
33 additions
and
21 deletions
Show diff stats
app/controllers/public/search_controller.rb
@@ -144,7 +144,7 @@ class SearchController < PublicController | @@ -144,7 +144,7 @@ class SearchController < PublicController | ||
144 | def load_query | 144 | def load_query |
145 | @asset = (params[:asset] || params[:action]).to_sym | 145 | @asset = (params[:asset] || params[:action]).to_sym |
146 | @order ||= [@asset] | 146 | @order ||= [@asset] |
147 | - params[:display] ||= 'list' | 147 | + params[:display] ||= 'items' |
148 | @searches ||= {} | 148 | @searches ||= {} |
149 | 149 | ||
150 | @query = params[:query] || '' | 150 | @query = params[:query] || '' |
app/helpers/application_helper.rb
@@ -265,9 +265,9 @@ module ApplicationHelper | @@ -265,9 +265,9 @@ module ApplicationHelper | ||
265 | 265 | ||
266 | VIEW_EXTENSIONS = %w[.rhtml .html.erb] | 266 | VIEW_EXTENSIONS = %w[.rhtml .html.erb] |
267 | 267 | ||
268 | - def partial_for_class_in_view_path(klass, view_path, suffix = nil) | 268 | + def partial_for_class_in_view_path(klass, view_path, prefix = nil, suffix = nil) |
269 | return nil if klass.nil? | 269 | return nil if klass.nil? |
270 | - name = [klass.name.underscore, suffix].compact.map(&:to_s).join('_') | 270 | + name = [prefix, klass.name.underscore, suffix].compact.map(&:to_s).join('_') |
271 | 271 | ||
272 | search_name = String.new(name) | 272 | search_name = String.new(name) |
273 | if search_name.include?("/") | 273 | if search_name.include?("/") |
@@ -282,14 +282,14 @@ module ApplicationHelper | @@ -282,14 +282,14 @@ module ApplicationHelper | ||
282 | return name if File.exists?(File.join(path)) | 282 | return name if File.exists?(File.join(path)) |
283 | end | 283 | end |
284 | 284 | ||
285 | - partial_for_class_in_view_path(klass.superclass, view_path, suffix) | 285 | + partial_for_class_in_view_path(klass.superclass, view_path, prefix, suffix) |
286 | end | 286 | end |
287 | 287 | ||
288 | - def partial_for_class(klass, suffix=nil) | 288 | + def partial_for_class(klass, prefix=nil, suffix=nil) |
289 | raise ArgumentError, 'No partial for object. Is there a partial for any class in the inheritance hierarchy?' if klass.nil? | 289 | raise ArgumentError, 'No partial for object. Is there a partial for any class in the inheritance hierarchy?' if klass.nil? |
290 | name = klass.name.underscore | 290 | name = klass.name.underscore |
291 | @controller.view_paths.each do |view_path| | 291 | @controller.view_paths.each do |view_path| |
292 | - partial = partial_for_class_in_view_path(klass, view_path, suffix) | 292 | + partial = partial_for_class_in_view_path(klass, view_path, prefix, suffix) |
293 | return partial if partial | 293 | return partial if partial |
294 | end | 294 | end |
295 | 295 |
app/helpers/search_helper.rb
@@ -42,12 +42,21 @@ module SearchHelper | @@ -42,12 +42,21 @@ module SearchHelper | ||
42 | :align => 'center', :class => 'search-category-context') if category | 42 | :align => 'center', :class => 'search-category-context') if category |
43 | end | 43 | end |
44 | 44 | ||
45 | - def map_capable?(asset) | 45 | + def display_map?(asset) |
46 | + [:enterprises, :products].include?(asset) | ||
47 | + end | ||
48 | + | ||
49 | + def display_items?(asset) | ||
50 | + puts "\n\n" + asset.inspect + "\n\n" | ||
51 | + ![:products, :events].include?(asset) | ||
52 | + end | ||
53 | + | ||
54 | + def display_full?(asset) | ||
46 | [:enterprises, :products].include?(asset) | 55 | [:enterprises, :products].include?(asset) |
47 | end | 56 | end |
48 | 57 | ||
49 | def display_results(asset = nil) | 58 | def display_results(asset = nil) |
50 | - if map_capable?(asset) and map_search? | 59 | + if display_map?(asset) and map_search? |
51 | partial = 'google_maps' | 60 | partial = 'google_maps' |
52 | klass = 'map' | 61 | klass = 'map' |
53 | else | 62 | else |
@@ -71,15 +80,13 @@ module SearchHelper | @@ -71,15 +80,13 @@ module SearchHelper | ||
71 | end | 80 | end |
72 | end | 81 | end |
73 | 82 | ||
74 | - def display_filter(asset, display, float = 'right') | ||
75 | - if map_capable?(asset) | ||
76 | - list_link = display == 'list' ? _('List') : link_to(_('List'), params.merge(:display => 'list')) | ||
77 | - map_link = display == 'map' ? _('Map') : link_to(_('Map'), params.merge(:display => 'map')) | 83 | + 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 | ||
86 | + map_link = display_map?(asset) ? (display == 'map' ? _('Map') : link_to(_('Map'), params.merge(:display => 'map'))) : nil | ||
87 | + full_link = display_full?(asset) ? (display == 'full' ? _('Full') : link_to(_('Full'), params.merge(:display => 'full'))) : nil | ||
78 | content_tag('div', | 88 | content_tag('div', |
79 | - content_tag('strong', _('Display')) + ': ' + | ||
80 | - list_link + | ||
81 | - ' | ' + | ||
82 | - map_link, | 89 | + content_tag('strong', _('Display')) + ': ' + [items_link, map_link, full_link].compact.join(' | '), |
83 | :id => 'search-display-filter', | 90 | :id => 'search-display-filter', |
84 | :style => "float: #{float}" | 91 | :style => "float: #{float}" |
85 | ) | 92 | ) |
app/models/enterprise.rb
@@ -183,4 +183,8 @@ class Enterprise < Organization | @@ -183,4 +183,8 @@ class Enterprise < Organization | ||
183 | Scrap.find_by_sql("SELECT id, updated_at, 'Scrap' AS klass FROM scraps WHERE scraps.receiver_id = #{self.id} AND scraps.scrap_id IS NULL UNION SELECT id, updated_at, 'ActionTracker::Record' AS klass FROM action_tracker WHERE action_tracker.target_id = #{self.id} UNION SELECT action_tracker.id, action_tracker.updated_at, 'ActionTracker::Record' AS klass FROM action_tracker INNER JOIN articles ON action_tracker.target_id = articles.id WHERE articles.profile_id = #{self.id} AND action_tracker.target_type = 'Article' ORDER BY action_tracker.updated_at DESC") | 183 | Scrap.find_by_sql("SELECT id, updated_at, 'Scrap' AS klass FROM scraps WHERE scraps.receiver_id = #{self.id} AND scraps.scrap_id IS NULL UNION SELECT id, updated_at, 'ActionTracker::Record' AS klass FROM action_tracker WHERE action_tracker.target_id = #{self.id} UNION SELECT action_tracker.id, action_tracker.updated_at, 'ActionTracker::Record' AS klass FROM action_tracker INNER JOIN articles ON action_tracker.target_id = articles.id WHERE articles.profile_id = #{self.id} AND action_tracker.target_type = 'Article' ORDER BY action_tracker.updated_at DESC") |
184 | end | 184 | end |
185 | 185 | ||
186 | + def more_recent_label | ||
187 | + '' | ||
188 | + end | ||
189 | + | ||
186 | end | 190 | end |
app/views/search/_profile.rhtml
@@ -5,7 +5,8 @@ | @@ -5,7 +5,8 @@ | ||
5 | <% else %> | 5 | <% else %> |
6 | <div class="search-enterprise-item"> | 6 | <div class="search-enterprise-item"> |
7 | <div class="search-enterprise-item-column-left"> | 7 | <div class="search-enterprise-item-column-left"> |
8 | - <%= profile_image_link profile, :portrait, 'div' %> | 8 | + <%= profile_image_link profile, :portrait, 'div', |
9 | + @filter == 'more_recent' ? profile.send(@filter + '_label') + show_date(profile.created_at) : profile.send(@filter + '_label') %> | ||
9 | </div> | 10 | </div> |
10 | <div class="search-enterprise-item-column-right"> | 11 | <div class="search-enterprise-item-column-right"> |
11 | <%= link_to_homepage(profile.name, profile.identifier, :class => "search-result-title") %> | 12 | <%= link_to_homepage(profile.name, profile.identifier, :class => "search-result-title") %> |
app/views/search/_results_header.rhtml
1 | <div class="search-results-header <%= "search-no-results" if @searches[@asset].nil? or @searches[@asset].length == 0 %>"> | 1 | <div class="search-results-header <%= "search-no-results" if @searches[@asset].nil? or @searches[@asset].length == 0 %>"> |
2 | - <div id='search-filter-title'><%= @filter_title if @filter_title %></div> | ||
3 | - <%= display_filter(@asset, params[:display]) if map_capable?(@asset) %> | 2 | + <div id='search-filter-title'><%= filter_title(@asset, @filter) %></div> |
3 | + <%= display_selector(@asset, params[:display]) if !map_search? %> | ||
4 | <div style="clear: both"></div> | 4 | <div style="clear: both"></div> |
5 | </div> | 5 | </div> |
app/views/tasks/_task.rhtml
@@ -50,13 +50,13 @@ | @@ -50,13 +50,13 @@ | ||
50 | <% fields_for "tasks[#{task.id}][task]", task do |f| %> | 50 | <% fields_for "tasks[#{task.id}][task]", task do |f| %> |
51 | <% if task.accept_details %> | 51 | <% if task.accept_details %> |
52 | <div id="on-accept-information-<%=task.id%>" style="display: none"> | 52 | <div id="on-accept-information-<%=task.id%>" style="display: none"> |
53 | - <%= render :partial => partial_for_class(task.class, :accept_details), :locals => {:task => task, :f => f} %> | 53 | + <%= render :partial => partial_for_class(task.class, nil, :accept_details), :locals => {:task => task, :f => f} %> |
54 | </div> | 54 | </div> |
55 | <% end %> | 55 | <% end %> |
56 | 56 | ||
57 | <% if task.reject_details %> | 57 | <% if task.reject_details %> |
58 | <div id="on-reject-information-<%=task.id%>" style="display: none"> | 58 | <div id="on-reject-information-<%=task.id%>" style="display: none"> |
59 | - <%= render :partial => partial_for_class(task.class, :reject_details), :locals => {:task => task, :f => f} %> | 59 | + <%= render :partial => partial_for_class(task.class, nil, :reject_details), :locals => {:task => task, :f => f} %> |
60 | </div> | 60 | </div> |
61 | <% end %> | 61 | <% end %> |
62 | <% end %> | 62 | <% end %> |