diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index bab756f..db57669 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -1,50 +1,136 @@ class SearchController < PublicController helper TagsHelper + include SearchHelper before_filter :load_category - before_filter :prepare_filter before_filter :check_search_whole_site before_filter :load_search_assets - before_filter :check_valid_assets, :only => [ :assets ] no_design_blocks - protected + def articles + @asset = :articles + @query = params[:query] || '' + @order ||= [@asset] + @results ||= {} + @filter = filter + + pg_options = paginate_options(@asset, limit, params[:per_page]) + if !@query.blank? + ret = asset_class(@asset).find_by_contents(@query, pg_options, solr_options(@asset, params[:facet], params[:order_by])) + @results[@asset] = ret[:results] + @facets = ret[:facets] + else + @results[@asset] = asset_class(@asset).send('paginate', :all, pg_options) + @facets = {} + end + end - def load_search_assets - @search_in = where_to_search - @searching = {} - @search_in.each do |key, name| - @searching[key] = (params[:asset].blank? && (params[:find_in].nil? || params[:find_in].empty? || params[:find_in].include?(key.to_s))) || (params[:asset] == key.to_s) + alias :contents :articles + + def people + @asset = :people + @query = params[:query] || '' + @order ||= [@asset] + @results ||= {} + @filter = filter + @title = self.filter_description(params[:action] + '_' + @filter ) + + @results[@asset] = @environment.people.visible.send(@filter) + if !@query.blank? + ret = @results[@asset].find_by_contents(@query, {}, solr_options(@asset, params[:facet], params[:order_by])) + @results[@asset] = ret[:results] + @facets = ret[:facets] + else + @facets = {} end + @results[@asset] = @results[@asset].compact.paginate(:per_page => limit, :page => params[:page]) end - def prepare_filter - if @category - @noosfero_finder = CategoryFinder.new(@category) + def products + @asset = :products + @query = params[:query] || '' + @order ||= [@asset] + @results ||= {} + + pg_options = paginate_options(@asset, limit, params[:per_page]) + if !@query.blank? + ret = asset_class(@asset).find_by_contents(@query, pg_options, solr_options(@asset, params[:facet], params[:order_by])) + @results[@asset] = ret[:results] + @facets = ret[:facets] else - @noosfero_finder = EnvironmentFinder.new(@environment) + @results[@asset] = asset_class(@asset).send('paginate', :all, pg_options) + @facets = {} end end - def check_search_whole_site - if params[:search_whole_site_yes] or params[:search_whole_site] == 'yes' - redirect_to params.merge(:category_path => [], :search_whole_site => nil, :search_whole_site_yes => nil) + def enterprises + @asset = :enterprises + @query = params[:query] || '' + @order ||= [@asset] + @results ||= {} + + pg_options = paginate_options(@asset, limit, params[:per_page]) + if !@query.blank? + ret = asset_class(@asset).find_by_contents(@query, pg_options, solr_options(@asset, params[:facet], params[:order_by])) + @results[@asset] = ret[:results] + @facets = ret[:facets] + else + @results[@asset] = asset_class(@asset).send('paginate', :all, pg_options) + @facets = {} end end - def check_valid_assets - @asset = params[:asset].to_sym - if !where_to_search.map(&:first).include?(@asset) - render :text => 'go away', :status => 403 - return + def communities + @asset = :communities + @query = params[:query] || '' + @order ||= [@asset] + @results ||= {} + @filter = filter + @title = self.filter_description(params[:action] + '_' + @filter ) + + @results[@asset] = @environment.communities.visible.send(@filter) + if !@query.blank? + ret = @results[@asset].find_by_contents(@query, {}, solr_options(@asset, params[:facet], params[:order_by])) + @results[@asset] = ret[:results] + @facets = ret[:facets] + else + @facets = {} end + @results[@asset] = @results[@asset].compact.paginate(:per_page => limit, :page => params[:page]) end def events + @asset = :events + params[:asset] |= [@asset] + @query = params[:query] || '' + @order ||= [@asset] + @results ||= {} @category_id = @category ? @category.id : nil + if params[:year] || params[:month] + date = Date.new(year.to_i, month.to_i, 1) + date_range = (date - 1.month)..(date + 1.month).at_end_of_month + end + + if @query.blank? + # Ignore pagination for asset events + if date_range + @results[@asset] = Event.send('find', :all, + :conditions => [ + 'start_date BETWEEN :start_day AND :end_day OR end_date BETWEEN :start_day AND :end_day', + {:start_day => date_range.first, :end_day => date_range.last} + ]) + else + @results[@asset] = Event.send('find', :all) + end + else + pg_options = paginate_options(@asset, limit, params[:per_page]) + solr_options = solr_options(@asset, params[:facet], params[:per_page]) + @results[@asset] = Event.find_by_contents(@query, pg_options, solr_options)[:results] + end + @selected_day = nil @events_of_the_day = [] date = build_date(params[:year], params[:month], params[:day]) @@ -58,125 +144,24 @@ class SearchController < PublicController end end - events = @results[:events] - + events = @results[@asset] @calendar = populate_calendar(date, events) @previous_calendar = populate_calendar(date - 1.month, events) @next_calendar = populate_calendar(date + 1.month, events) end - def people - #nothing, just to enable - end - def enterprises - load_product_categories_menu(:enterprises) - @categories_menu = true - end - def communities - #nothing, just to enable - end - def articles - #nothins, just to enable - end - - def products - load_product_categories_menu(:products) - @categories_menu = true - end - - def load_product_categories_menu(asset) - @results[asset].uniq! - # REFACTOR DUPLICATED CODE inner loop doing the same thing that outter loop - - if !@query.blank? || @region && !params[:radius].blank? - ret = @noosfero_finder.find(asset, @query, calculate_find_options(asset, nil, params[:page], @product_category, @region, params[:radius], params[:year], params[:month], params[:order_by]).merge({:limit => :all})) - @result_ids = ret.is_a?(Hash) ? ret[:results] : ret - end - - end - - def calculate_find_options(asset, limit, page, product_category, region, radius, year, month, solr_order) - result = { :product_category => product_category, :per_page => limit, :page => page } - if [:enterprises, :people, :products].include?(asset) && region - result.merge!(:within => radius, :region => region.id) - end - - if month || year - date = Date.new(year.to_i, month.to_i, 1) - result[:date_range] = (date - 1.month)..(date + 1.month).at_end_of_month - end - - if asset_class(asset).methods.include?('facets') - result.merge!(:facets => {:zeros => false, :sort => :count, :fields => asset_class(asset).facets.keys, - :browse => params[:facet] ? params[:facet].map{ |k,v| k.to_s+':"'+v.to_s+'"'} : ''}) - end - - result[:order_by] = solr_order - - result - end - - # limit the number of results per page - # TODO: dont hardcore like this - def limit - searching = @searching.values.select{|v|v} - if params[:display] == 'map' - 2000 - else - (searching.size == 1) ? 20 : 6 - end - end - - public - - include SearchHelper - - ###################################################### - - def where_to_search - [ - [ :articles, N_('Articles') ], - [ :enterprises, N_('Enterprises') ], - [ :people, N_('People') ], - [ :communities, N_('Communities') ], - [ :products, N_('Products') ], - [ :events, N_('Events') ] - ].select {|key, name| !environment.enabled?('disable_asset_' + key.to_s) } - end - - def cities - @cities = City.find(:all, :order => 'name', :conditions => ['parent_id = ? and lat is not null and lng is not null', params[:state_id]]) - render :action => 'cities', :layout => false - end - - def complete_region - # FIXME this logic should be in the model - @regions = Region.find(:all, :conditions => [ '(name like ? or name like ?) and lat is not null and lng is not null', '%' + params[:region][:name] + '%', '%' + params[:region][:name].capitalize + '%' ]) - render :action => 'complete_region', :layout => false - end - def index - @query = params[:query] || '' - @product_category = ProductCategory.find(params[:product_category]) if params[:product_category] - - @region = City.find_by_id(params[:city]) if !params[:city].blank? && params[:city] =~ /^\d+$/ - - # how many assets we are searching for? - number_of_result_assets = @searching.values.select{|v| v}.size - @results = {} - @facets = {} @order = [] @names = {} where_to_search.select { |key,description| @searching[key] }.each do |key, description| + send(key) @order << key - find_options = calculate_find_options(key, limit, params[:page], @product_category, @region, params[:radius], params[:year], params[:month], params[:order_by]); - ret = @noosfero_finder.find(key, @query, find_options) - @results[key] = ret.is_a?(Hash) ? ret[:results] : ret - @facets[key] = ret.is_a?(Hash) ? ret[:facets] : {} @names[key] = getterm(description) end + @asset = nil + @facets = {} if @results.keys.size == 1 specific_action = @results.keys.first @@ -187,34 +172,76 @@ class SearchController < PublicController return end end - - render :action => 'index' end alias :assets :index - ####################################################### - # view the summary of one category def category_index @results = {} @order = [] @names = {} [ - [ :people, _('People'), @noosfero_finder.recent('people', limit) ], - [ :enterprises, __('Enterprises'), @noosfero_finder.recent('enterprises', limit) ], - [ :products, _('Products'), @noosfero_finder.recent('products', limit) ], - [ :events, _('Upcoming events'), @noosfero_finder.upcoming_events({:per_page => limit}) ], - [ :communities, __('Communities'), @noosfero_finder.recent('communities', limit) ], - [ :most_commented_articles, _('Most commented articles'), @noosfero_finder.most_commented_articles(limit) ], - [ :articles, _('Articles'), @noosfero_finder.recent('text_articles', limit) ] + [ :people, _('People'), recent('people') ], + [ :enterprises, __('Enterprises'), recent('enterprises') ], + [ :products, _('Products'), recent('products') ], + [ :events, _('Upcoming events'), upcoming_events({:per_page => limit}) ], + [ :communities, __('Communities'), recent('communities', limit) ], + [ :most_commented_articles, _('Most commented articles'), most_commented_articles(limit) ], + [ :articles, _('Articles'), recent('text_articles', limit) ] ].each do |key, name, list| @order << key @results[key] = list @names[key] = name end + @facets = {} + end + + protected + + def recent(asset, limit = nil) + find(asset, nil, :limit => limit, :order => 'created_at DESC, id DESC') + end + + def most_commented_articles(limit=10, options={}) + options = {:page => 1, :per_page => limit, :order => 'comments_count DESC'}.merge(options) + Article.paginate(:all, options_for_find(Article, options)) + end + + def upcoming_events(options = {}) + options.delete(:page) + options.delete(:per_page) + + Event.find(:all, {:include => :categories, :conditions => [ 'categories.id = ? and start_date >= ?', category_id, Date.today ], :order => 'start_date' }.merge(options)) end + + attr_reader :category + attr_reader :category_id + + def load_category + unless params[:category_path].blank? + path = params[:category_path].join('/') + @category = environment.categories.find_by_path(path) + if @category.nil? + render_not_found(path) + end + @category_id = @category.id + end + end + + def where_to_search + [ + [ :articles, N_('Articles') ], + [ :enterprises, N_('Enterprises') ], + [ :people, N_('People') ], + [ :communities, N_('Communities') ], + [ :products, N_('Products') ], + [ :events, N_('Events') ] + ].select {|key, name| !environment.enabled?('disable_asset_' + key.to_s) } + end + + ####################################################### def tags @tags_cache_key = "tags_env_#{environment.id.to_s}" @@ -248,4 +275,90 @@ class SearchController < PublicController render :partial => 'events/events_by_day' end + def current_events(year, month, options={}) + options.delete(:page) + options.delete(:per_page) + + range = Event.date_range(year, month) + + Event.find(:all, {:include => :categories, :conditions => { 'categories.id' => category_id, :start_date => range }}.merge(options)) + end + + def filter + if FILTERS.include?(params[:filter]) + params[:filter] + else + 'more_recent' + end + end + + def filter_description(str) + { + 'contents_more_recent' => _('More recent contents'), + 'contents_more_popular' => _('More popular contents'), + 'people_more_recent' => _('More recent people'), + 'people_more_active' => _('More active people'), + 'people_more_popular' => _('More popular people'), + 'communities_more_recent' => _('More recent communities'), + 'communities_more_active' => _('More active communities'), + 'communities_more_popular' => _('More popular communities'), + }[str] || str + end + + def load_search_assets + @search_in = where_to_search + @searching = {} + @search_in.each do |key, name| + @searching[key] = (params[:asset].blank? && (params[:find_in].nil? || params[:find_in].empty? || params[:find_in].include?(key.to_s))) || (params[:asset] == key.to_s) + end + end + + def check_search_whole_site + if params[:search_whole_site_yes] or params[:search_whole_site] == 'yes' + redirect_to params.merge(:category_path => [], :search_whole_site => nil, :search_whole_site_yes => nil) + end + end + + FILTERS = %w( + more_recent + more_active + more_popular + ) + + def paginate_options(asset, limit, page) + result = { :per_page => limit, :page => page } + end + + def solr_options(asset, facet, solr_order) + result = {} + + if asset_class(asset).methods.include?('facets') + result.merge!(:facets => {:zeros => false, :sort => :count, :fields => asset_class(asset).facets.keys, + :browse => facet ? facet.map{ |k,v| k.to_s+':"'+v.to_s+'"'} : ''}) + end + + if solr_order + result[:order_by] = solr_order + end + + result + end + + def limit + searching = @searching.values.select{|v|v} + if params[:display] == 'map' + 2000 + else + (searching.size == 1) ? 20 : 6 + end + end + + def asset_class(asset) + asset.to_s.singularize.camelize.constantize + end + + def asset_table(asset) + asset_class(asset).table_name + end + end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index bfe6bba..49b71a6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -572,7 +572,7 @@ module ApplicationHelper end extra_info = extra_info.nil? ? '' : content_tag( 'span', extra_info, :class => 'extra_info' ) links = links_for_balloon(profile) - content_tag tag, + content_tag('div', content_tag(tag, (environment.enabled?(:show_balloon_with_profile_links_when_clicked) ? link_to( content_tag( 'span', _('Profile links')), '#', :onclick => "toggleSubmenu(this, '#{profile.short_name}', #{links.to_json}); return false", :class => "menu-submenu-trigger #{trigger_class}", :url => url) : "") + link_to( content_tag( 'span', profile_image( profile, size ), :class => 'profile-image' ) + @@ -582,7 +582,7 @@ module ApplicationHelper :class => 'profile_link url', :help => _('Click on this icon to go to the %s\'s home page') % profile.name, :title => profile.name ), - :class => 'vcard' + :class => 'vcard'), :class => 'common-profile-list-block') end def gravatar_url_for(email, options = {}) @@ -887,9 +887,6 @@ module ApplicationHelper def search_page_title(title, options={}) title = "

" + title + "

" title += "

" + _("Searched for '%s'") % options[:query] + "

" if !options[:query].blank? - title += "

" + _("In category %s") % options[:category] + "

" if !options[:category].blank? - title += "

" + _("within %d km from %s") % [options[:distance], options[:region]] + "

" if !options[:distance].blank? && !options[:region].blank? - title += "

" + _("%d results found") % options[:total_results] + "

" if !options[:total_results].blank? title end @@ -1105,33 +1102,46 @@ module ApplicationHelper ") : '') end - def browse_people_menu + def search_contents_menu + links = [ + {s_('contents|More Recent') => {:href => url_for({:controller => 'search', :action => 'contents', :filter => 'more_recent'})}}, + #{s_('contents|More Popular') => {:href => url_for({:controller => 'search', :action => 'contents', :filter => 'more_popular'})}} + ] + if logged_in? + links.push(_('New Content') => lightbox_options({:href => url_for({:controller => 'cms', :action => 'new', :profile => current_user.login, :cms => true})})) + end + + link_to(content_tag(:span, _('Contents'), :class => 'icon-menu-contents'), {:controller => "search", :action => 'contents'}, :id => 'submenu-contents') + + link_to(content_tag(:span, _('Contents Menu')), '#', :onclick => "toggleSubmenu(this,'',#{links.to_json}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-contents-trigger') + end + + def search_people_menu links = [ - {s_('people|More Recent') => {:href => url_for({:controller => 'browse', :action => 'people', :filter => 'more_recent'})}}, - {s_('people|More Active') => {:href => url_for({:controller => 'browse', :action => 'people', :filter => 'more_active'})}}, - {s_('people|More Popular') => {:href => url_for({:controller => 'browse', :action => 'people', :filter => 'more_popular'})}} + {s_('people|More Recent') => {:href => url_for({:controller => 'search', :action => 'people', :filter => 'more_recent'})}}, + {s_('people|More Active') => {:href => url_for({:controller => 'search', :action => 'people', :filter => 'more_active'})}}, + {s_('people|More Popular') => {:href => url_for({:controller => 'search', :action => 'people', :filter => 'more_popular'})}} ] if logged_in? links.push(_('My friends') => {:href => url_for({:profile => current_user.login, :controller => 'friends'})}) links.push(_('Invite friends') => {:href => url_for({:profile => current_user.login, :controller => 'invite', :action => 'friends'})}) end - link_to(content_tag(:span, _('People'), :class => 'icon-menu-people'), {:controller => "browse", :action => 'people'}, :id => 'submenu-people') + + link_to(content_tag(:span, _('People'), :class => 'icon-menu-people'), {:controller => "search", :action => 'people'}, :id => 'submenu-people') + link_to(content_tag(:span, _('People Menu')), '#', :onclick => "toggleSubmenu(this,'',#{links.to_json}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-people-trigger') end - def browse_communities_menu + def search_communities_menu links = [ - {s_('communities|More Recent') => {:href => url_for({:controller => 'browse', :action => 'communities', :filter => 'more_recent'})}}, - {s_('communities|More Active') => {:href => url_for({:controller => 'browse', :action => 'communities', :filter => 'more_active'})}}, - {s_('communities|More Popular') => {:href => url_for({:controller => 'browse', :action => 'communities', :filter => 'more_popular'})}} + {s_('communities|More Recent') => {:href => url_for({:controller => 'search', :action => 'communities', :filter => 'more_recent'})}}, + {s_('communities|More Active') => {:href => url_for({:controller => 'search', :action => 'communities', :filter => 'more_active'})}}, + {s_('communities|More Popular') => {:href => url_for({:controller => 'search', :action => 'communities', :filter => 'more_popular'})}} ] if logged_in? links.push(_('My communities') => {:href => url_for({:profile => current_user.login, :controller => 'memberships'})}) links.push(_('New community') => {:href => url_for({:profile => current_user.login, :controller => 'memberships', :action => 'new_community'})}) end - link_to(content_tag(:span, _('Communities'), :class => 'icon-menu-community'), {:controller => "browse", :action => 'communities'}, :id => 'submenu-communities') + + link_to(content_tag(:span, _('Communities'), :class => 'icon-menu-community'), {:controller => "search", :action => 'communities'}, :id => 'submenu-communities') + link_to(content_tag(:span, _('Communities Menu')), '#', :onclick => "toggleSubmenu(this,'',#{links.to_json}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-communities-trigger') end diff --git a/app/views/browse/_article.rhtml b/app/views/browse/_article.rhtml deleted file mode 100644 index e36e667..0000000 --- a/app/views/browse/_article.rhtml +++ /dev/null @@ -1,11 +0,0 @@ -
  • - <%= link_to(result.title, result.view_url) %> -
    - - <%= _('by %s') % link_to(result.author.name, result.author.url) %> - - - <%= (@filter == 'more_recent' ? result.send(@filter + '_label') + show_date(result.created_at) : result.send(@filter + '_label')) %> - -
    -
  • diff --git a/app/views/browse/_display_results.rhtml b/app/views/browse/_display_results.rhtml deleted file mode 100644 index cee76a0..0000000 --- a/app/views/browse/_display_results.rhtml +++ /dev/null @@ -1,19 +0,0 @@ -
    - -
    - <% if @results.empty? %> -
    -
    <%= _('None') %>
    -
    - <% end %> - -
    -
    - -
    -
    - diff --git a/app/views/browse/_person.rhtml b/app/views/browse/_person.rhtml deleted file mode 100644 index 54001f6..0000000 --- a/app/views/browse/_person.rhtml +++ /dev/null @@ -1,3 +0,0 @@ -<%= profile_image_link result, :portrait, 'li', - "#{result.city}" + - (@filter == 'more_recent' ? result.send(@filter + '_label') + show_date(result.created_at) : result.send(@filter + '_label')) %> diff --git a/app/views/browse/_profile.rhtml b/app/views/browse/_profile.rhtml deleted file mode 100644 index 755ccb2..0000000 --- a/app/views/browse/_profile.rhtml +++ /dev/null @@ -1 +0,0 @@ -<%= profile_image_link result, :portrait, 'li', @filter == 'more_recent' ? result.send(@filter + '_label') + show_date(result.created_at) : result.send(@filter + '_label') %> diff --git a/app/views/browse/_search_form.rhtml b/app/views/browse/_search_form.rhtml deleted file mode 100644 index 841f1ff..0000000 --- a/app/views/browse/_search_form.rhtml +++ /dev/null @@ -1,10 +0,0 @@ -<% form_tag( { :controller => 'browse', :action => action}, :method => 'get', :class => 'search_form' ) do %> - -
    - - <%= text_field_tag 'query', @query, :size => 50 %> - - <%= submit_button(:search, _('Search')) %> -
    - -<% end %> diff --git a/app/views/browse/communities.rhtml b/app/views/browse/communities.rhtml deleted file mode 100644 index df1c709..0000000 --- a/app/views/browse/communities.rhtml +++ /dev/null @@ -1,9 +0,0 @@ -<%= search_page_title( @title, { :query => @query} ) %> - -<%= render :partial => 'search_form', :locals => {:action => 'communities'} %> - -<%= render :partial => 'display_results' %> - -<%= pagination_links @results %> - -
    diff --git a/app/views/browse/contents.rhtml b/app/views/browse/contents.rhtml deleted file mode 100644 index 8cc3a88..0000000 --- a/app/views/browse/contents.rhtml +++ /dev/null @@ -1,9 +0,0 @@ -<%= search_page_title( @title, { :query => @query} ) %> - -<%= render :partial => 'search_form', :locals => {:action => 'contents'} %> - -<%= render :partial => 'display_results' %> - -<%= pagination_links @results %> - -
    diff --git a/app/views/browse/people.rhtml b/app/views/browse/people.rhtml deleted file mode 100644 index 2a4f142..0000000 --- a/app/views/browse/people.rhtml +++ /dev/null @@ -1,9 +0,0 @@ -<%= search_page_title( @title, { :query => @query} ) %> - -<%= render :partial => 'search_form', :locals => {:action => 'people'} %> - -<%= render :partial => 'display_results' %> - -<%= pagination_links @results %> - -
    diff --git a/app/views/search/_content.rhtml b/app/views/search/_content.rhtml new file mode 120000 index 0000000..54e6981 --- /dev/null +++ b/app/views/search/_content.rhtml @@ -0,0 +1 @@ +_article.rhtml \ No newline at end of file diff --git a/app/views/search/_enterprise.rhtml b/app/views/search/_enterprise.rhtml deleted file mode 100644 index 438499b..0000000 --- a/app/views/search/_enterprise.rhtml +++ /dev/null @@ -1,17 +0,0 @@ -<% if params[:query].blank? %> - <%= profile_image_link enterprise, :portrait %> -<% else %> -
    - <%= profile_image_link enterprise, :portrait %> - <%= enterprise.name %> - <%= _("Region: ") + enterprise.region.name if enterprise.region %> - <%= enterprise.description %> - -
    - <% enterprise.top_level_categorization.each do |parent, children| %> - <%= parent.name + ':' %> - <%= children.collect(&:name).join(', ') %> - <% end %> -
    -
    -<% end %> diff --git a/app/views/search/_profile.rhtml b/app/views/search/_profile.rhtml index b6a43c7..d23203f 100644 --- a/app/views/search/_profile.rhtml +++ b/app/views/search/_profile.rhtml @@ -1 +1,20 @@ -<%= profile_image_link profile, :portrait %> +<% if @query.blank? || !profile.enterprise? %> + <%= profile_image_link profile, :portrait %> +<% else %> +
    + <%= profile_image_link profile, :portrait %> + <%= profile.name %> + <%= _("Region: ") + profile.region.name if profile.region %>
    + <% if !profile.description.blank? %> + <%= profile.description %>
    + <% end %> + +
    + <% profile.top_level_categorization.each do |parent, children| %> + <%= parent.name + ':' %> + <%= children.collect(&:name).join(', ') %> +
    + <% end %> +
    +
    +<% end %> diff --git a/app/views/search/_search_form.rhtml b/app/views/search/_search_form.rhtml index d84b5d4..3933729 100644 --- a/app/views/search/_search_form.rhtml +++ b/app/views/search/_search_form.rhtml @@ -1,7 +1,7 @@
    <% simple_search = false unless defined? simple_search %> -<% form_tag( { :controller => 'search', :action => 'index', :asset => nil, :category_path => ( @category ? @category.explode_path : [] ) }, +<% form_tag( { :controller => 'search', :action => @asset ? @asset : 'index', :asset => nil, :category_path => ( @category ? @category.explode_path : [] ) }, :method => 'get', :class => 'search_form' ) do %> <%= '

    %s

    ' % form_title if defined? form_title %> @@ -20,41 +20,6 @@ <% end %>
    -
    -
    -

    <%= _('Search within:') %>

    -
    -
    - - <%= select_city %> - - - <%= labelled_select(_('Distance:'), 'radius', :first, :last, nil, [15, 30, 50, 100, 150, 200, 300, 400, 500, 1000].map{|n|[n, n.to_s + 'km']}) %> - -
    -
    - -
    -

    <%= _('Search for:') %>

    - -
    -
    -
    - - <% if simple_search %> - <%= link_to_function(_('More options'), nil, :id => 'advanced_search_link') do |page| - page['advanced_search_link'].hide - page['advanced-search-options'].toggle - end %> - <% end %> - <% if lightbox?; button_bar do %> <%= lightbox_close_button _('Close') %> <% end; end %> diff --git a/app/views/search/articles.rhtml b/app/views/search/articles.rhtml index 12b3bcf..4b336c8 100644 --- a/app/views/search/articles.rhtml +++ b/app/views/search/articles.rhtml @@ -1,8 +1,5 @@ <%= search_page_title( _('Articles'), { :query => @query, - :category => @category ? @category.name : nil, - :total_results => @total_results, - :region => @region ? @region.name : nil, - :distance => @radius } ) %> + :total_results => @total_results } ) %> <%= search_page_link_to_all( { :asset => params[:asset], :category => @category }) %> @@ -10,7 +7,7 @@ <%= render :partial => 'search_form', :locals => { :form_title => @query.blank? ? _('Search') : _("Refine your search"), :simple_search => true } %> <% if !@query.blank? %> - <%= facets_menu(:articles, @facets[:articles]) %> + <%= facets_menu(:articles, @facets) %> <% end %> <%= render :partial => 'results_header', :locals => { :asset => :articles, :results => @results[:articles] } %> diff --git a/app/views/search/cities.rhtml b/app/views/search/cities.rhtml deleted file mode 100644 index f34cd1b..0000000 --- a/app/views/search/cities.rhtml +++ /dev/null @@ -1,7 +0,0 @@ -<% if !@cities.empty? %> - <% @cities.each do |city| %> - - <% end %> -<% else %> - -<% end%> diff --git a/app/views/search/communities.rhtml b/app/views/search/communities.rhtml index d3436bb..5b87dee 100644 --- a/app/views/search/communities.rhtml +++ b/app/views/search/communities.rhtml @@ -1,8 +1,5 @@ <%= search_page_title( __('Communities'), { :query => @query, - :category => @category ? @category.name : nil, - :total_results => @total_results, - :region => @region ? @region.name : nil, - :distance => @radius } ) %> + :total_results => @total_results } ) %> <%= search_page_link_to_all( { :asset => params[:asset], :category => @category }) %> @@ -16,7 +13,7 @@ <% end %> <% if !@query.blank? %> - <%= facets_menu(:communities, @facets[:communities]) %> + <%= facets_menu(:communities, @facets) %> <% end %> <%= render :partial => 'results_header', :locals => { :asset => :communities, :results => @results[:communities] } %> diff --git a/app/views/search/complete_region.rhtml b/app/views/search/complete_region.rhtml deleted file mode 100644 index ccc28b3..0000000 --- a/app/views/search/complete_region.rhtml +++ /dev/null @@ -1,7 +0,0 @@ -<% unless @regions.empty? %> - -<% end%> diff --git a/app/views/search/contents.rhtml b/app/views/search/contents.rhtml new file mode 120000 index 0000000..3015e62 --- /dev/null +++ b/app/views/search/contents.rhtml @@ -0,0 +1 @@ +articles.rhtml \ No newline at end of file diff --git a/app/views/search/enterprises.rhtml b/app/views/search/enterprises.rhtml index 21d2f87..6adb59b 100644 --- a/app/views/search/enterprises.rhtml +++ b/app/views/search/enterprises.rhtml @@ -6,12 +6,7 @@ <% end %> -<% if @radius && @region %> -

    <%=h (_('Within %s km from %s') % [@radius, @region.name]) %>

    -<% end %> - -<%= search_page_link_to_all( { :asset => params[:asset], - :category => @category }) %> +<%= search_page_link_to_all( { :asset => params[:asset] }) %> <%= render :partial => 'search_form', :locals => { :form_title => _("Refine your search"), :simple_search => true } %> @@ -25,11 +20,9 @@
    <% end %> -<% cache(:action => 'assets', :asset => 'enterprises', :category_path => params[:category_path], :query => @query, :product_category => @product_category, :region => @region, :radius => params[:radius]) do %> - <% if @query.blank? %> - <%= product_categories_menu(:enterprises, @product_category, @result_ids) %> - <% else %> - <%= facets_menu(:enterprises, @facets[:enterprises]) %> +<% cache(:action => 'assets', :asset => 'enterprises', :query => @query) do %> + <% if !@query.blank? %> + <%= facets_menu(:enterprises, @facets) %> <% end %> <% end %> diff --git a/app/views/search/index.rhtml b/app/views/search/index.rhtml index 54b3bf5..fb19583 100644 --- a/app/views/search/index.rhtml +++ b/app/views/search/index.rhtml @@ -1,6 +1,7 @@
    -<%= search_page_title(_('Search Results'), :query => CGI.escapeHTML(@query), :category => @category ? @category.name : nil, :total_results => @total_results) %> +<%= search_page_title(_('Search Results'), :query => CGI.escapeHTML(@query), + :total_results => @total_results) %> <%= render :partial => 'search_form', :locals => { :form_title => _("Refine your search"), :simple_search => true } %> diff --git a/app/views/search/people.rhtml b/app/views/search/people.rhtml index c18c336..efcd50c 100644 --- a/app/views/search/people.rhtml +++ b/app/views/search/people.rhtml @@ -1,8 +1,5 @@ <%= search_page_title( _('People'), { :query => @query, - :category => @category ? @category.name : nil, - :total_results => @total_results, - :region => @region ? @region.name : nil, - :distance => @radius } ) %> + :total_results => @total_results } ) %> <%= search_page_link_to_all( { :asset => params[:asset], :category => @category }) %> @@ -10,7 +7,7 @@ <%= render :partial => 'search_form', :locals => { :form_title => @query.blank? ? _('Search') : _("Refine your search"), :simple_search => true } %> <% if !@query.blank? %> - <%= facets_menu(:people, @facets[:people]) %> + <%= facets_menu(:people, @facets) %> <% end %> <%= render :partial => 'results_header', :locals => { :asset => :people, :results => @results[:people] } %> diff --git a/app/views/search/products.rhtml b/app/views/search/products.rhtml index 8128119..a03a92e 100644 --- a/app/views/search/products.rhtml +++ b/app/views/search/products.rhtml @@ -1,8 +1,5 @@ <%= search_page_title( _('Products and Services'), { :query => @query, - :category => @category ? @category.name : nil, - :total_results => @total_results, - :region => @region ? @region.name : nil, - :distance => @radius } ) %> + :total_results => @total_results } ) %> <%= search_page_link_to_all( { :asset => params[:asset], :category => @category }) %> @@ -13,11 +10,9 @@
    <% end %> -<% cache(:action => 'assets', :asset => 'products', :category_path => params[:category_path], :query => @query, :product_category => @product_category, :region => @region, :radius => params[:radius]) do %> - <% if @query.empty? %> - <%= product_categories_menu(:products, @product_category, @result_ids) %> - <% else %> - <%= facets_menu(:products, @facets[:products]) %> +<% cache(:action => 'assets', :asset => 'products', :query => @query) do %> + <% if !@query.blank? %> + <%= facets_menu(:products, @facets) %> <% end %> <% end %> -- libgit2 0.21.2