Commit cd53e5e5a940050e3c28aef6af236bf26b4fff43
1 parent
b9a0b4d3
Exists in
master
and in
23 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 | 144 | def load_query |
| 145 | 145 | @asset = (params[:asset] || params[:action]).to_sym |
| 146 | 146 | @order ||= [@asset] |
| 147 | - params[:display] ||= 'list' | |
| 147 | + params[:display] ||= 'items' | |
| 148 | 148 | @searches ||= {} |
| 149 | 149 | |
| 150 | 150 | @query = params[:query] || '' | ... | ... |
app/helpers/application_helper.rb
| ... | ... | @@ -265,9 +265,9 @@ module ApplicationHelper |
| 265 | 265 | |
| 266 | 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 | 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 | 272 | search_name = String.new(name) |
| 273 | 273 | if search_name.include?("/") |
| ... | ... | @@ -282,14 +282,14 @@ module ApplicationHelper |
| 282 | 282 | return name if File.exists?(File.join(path)) |
| 283 | 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 | 286 | end |
| 287 | 287 | |
| 288 | - def partial_for_class(klass, suffix=nil) | |
| 288 | + def partial_for_class(klass, prefix=nil, suffix=nil) | |
| 289 | 289 | raise ArgumentError, 'No partial for object. Is there a partial for any class in the inheritance hierarchy?' if klass.nil? |
| 290 | 290 | name = klass.name.underscore |
| 291 | 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 | 293 | return partial if partial |
| 294 | 294 | end |
| 295 | 295 | ... | ... |
app/helpers/search_helper.rb
| ... | ... | @@ -42,12 +42,21 @@ module SearchHelper |
| 42 | 42 | :align => 'center', :class => 'search-category-context') if category |
| 43 | 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 | 55 | [:enterprises, :products].include?(asset) |
| 47 | 56 | end |
| 48 | 57 | |
| 49 | 58 | def display_results(asset = nil) |
| 50 | - if map_capable?(asset) and map_search? | |
| 59 | + if display_map?(asset) and map_search? | |
| 51 | 60 | partial = 'google_maps' |
| 52 | 61 | klass = 'map' |
| 53 | 62 | else |
| ... | ... | @@ -71,15 +80,13 @@ module SearchHelper |
| 71 | 80 | end |
| 72 | 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 | 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 | 90 | :id => 'search-display-filter', |
| 84 | 91 | :style => "float: #{float}" |
| 85 | 92 | ) | ... | ... |
app/models/enterprise.rb
| ... | ... | @@ -183,4 +183,8 @@ class Enterprise < Organization |
| 183 | 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 | 184 | end |
| 185 | 185 | |
| 186 | + def more_recent_label | |
| 187 | + '' | |
| 188 | + end | |
| 189 | + | |
| 186 | 190 | end | ... | ... |
app/views/search/_profile.rhtml
| ... | ... | @@ -5,7 +5,8 @@ |
| 5 | 5 | <% else %> |
| 6 | 6 | <div class="search-enterprise-item"> |
| 7 | 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 | 10 | </div> |
| 10 | 11 | <div class="search-enterprise-item-column-right"> |
| 11 | 12 | <%= link_to_homepage(profile.name, profile.identifier, :class => "search-result-title") %> | ... | ... |
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 | - <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 | 4 | <div style="clear: both"></div> |
| 5 | 5 | </div> | ... | ... |
app/views/tasks/_task.rhtml
| ... | ... | @@ -50,13 +50,13 @@ |
| 50 | 50 | <% fields_for "tasks[#{task.id}][task]", task do |f| %> |
| 51 | 51 | <% if task.accept_details %> |
| 52 | 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 | 54 | </div> |
| 55 | 55 | <% end %> |
| 56 | 56 | |
| 57 | 57 | <% if task.reject_details %> |
| 58 | 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 | 60 | </div> |
| 61 | 61 | <% end %> |
| 62 | 62 | <% end %> | ... | ... |