From e1a0da0107e96192f877de78737ef41575ab94c4 Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Tue, 22 May 2012 17:25:32 +0000 Subject: [PATCH] Restrict altBeautify fix and disabled searches --- app/controllers/public/search_controller.rb | 26 +++++++++++++------------- app/helpers/search_helper.rb | 12 +++++++++++- app/models/environment.rb | 3 +++ app/models/input.rb | 3 +++ app/views/search/_product.rhtml | 12 ++++-------- app/views/search/products.rhtml | 40 +++++++++++++++++++--------------------- public/javascripts/application.js | 31 +++++++++++++++++++++++++++---- test/functional/search_controller_test.rb | 34 +++++++++++++++++----------------- vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/parser_methods.rb | 14 ++++++++------ 9 files changed, 105 insertions(+), 70 deletions(-) diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index 128a32e..65a0d31 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -44,8 +44,9 @@ class SearchController < PublicController end def products + public_filters = ['public:true', 'enabled:true'] if !@empty_query - full_text_search ['public:true', 'enabled:true'] + full_text_search public_filters else @one_page = true @geosearch = logged_in? && current_user.person.lat && current_user.person.lng @@ -53,11 +54,11 @@ class SearchController < PublicController extra_limit = LIST_SEARCH_LIMIT*5 sql_options = {:limit => LIST_SEARCH_LIMIT, :order => 'random()'} if @geosearch - full_text_search ['public:true', "{!geofilt}"], :sql_options => sql_options, :extra_limit => extra_limit, + full_text_search public_filters, :sql_options => sql_options, :extra_limit => extra_limit, :alternate_query => "{!boost b=recip(geodist(),#{"%e" % (1.to_f/DistBoost)},1,1)}", :radius => DistFilt, :latitude => current_user.person.lat, :longitude => current_user.person.lng else - full_text_search ['public:true'], :sql_options => sql_options, :extra_limit => extra_limit, + full_text_search public_filters, :sql_options => sql_options, :extra_limit => extra_limit, :boost_functions => ['recip(ms(NOW/HOUR,updated_at),1.3e-10,1,1)'] end end @@ -190,7 +191,9 @@ class SearchController < PublicController end def load_category - unless params[:category_path].blank? + if params[:category_path].blank? + render_not_found if params[:action] == 'category_index' + else path = params[:category_path].join('/') @category = environment.categories.find_by_path(path) if @category.nil? @@ -229,22 +232,19 @@ class SearchController < PublicController end def load_search_assets - @enabled_searches = [ - [ :articles, _('Contents') ], - [ :enterprises, _('Enterprises') ], - [ :people, _('People') ], - [ :communities, _('Communities') ], - [ :products, _('Products and Services') ], - [ :events, _('Events') ] - ].select {|key, name| !environment.enabled?('disable_asset_' + key.to_s) } + if Searches.keys.include?(params[:action].to_sym) and environment.enabled?("disable_asset_#{params[:action]}") + render_not_found + return + end + @enabled_searches = Searches.select {|key, name| environment.disabled?("disable_asset_#{params[:action]}") } @searching = {} @titles = {} @enabled_searches.each do |key, name| @titles[key] = name @searching[key] = params[:action] == 'index' || params[:action] == key.to_s end - @names = @titles if @names.nil? + @names = @titles if @names.nil? end def limit diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 1ce7df2..da79499 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -6,6 +6,16 @@ module SearchHelper MULTIPLE_SEARCH_LIMIT = 8 DistFilt = 200 DistBoost = 50 + + Searches = ActiveSupport::OrderedHash[ + :articles, _('Contents'), + :enterprises, _('Enterprises'), + :people, _('People'), + :communities, _('Communities'), + :products, _('Products and Services'), + :events, _('Events'), + ] + SortOptions = { :products => ActiveSupport::OrderedHash[ :none, {:label => _('Relevance')}, :more_recent, {:label => _('More Recent'), :solr_opts => {:sort => 'updated_at desc, score desc'}}, @@ -112,7 +122,7 @@ module SearchHelper if count > 0 url = params.merge(:facet => params[:facet].merge( - id => facet[:label_id].nil? ? value : params[:facet][id].merge( facet[:label_id] => params[:facet][id][facet[:label_id]].to_a.push(value) ) + id => facet[:label_id].nil? ? value : params[:facet][id].merge( facet[:label_id] => params[:facet][id][facet[:label_id]].to_a | [value] ) )) else # preserve others filters and change this filter diff --git a/app/models/environment.rb b/app/models/environment.rb index 4425906..d2593fb 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -281,6 +281,9 @@ class Environment < ActiveRecord::Base def enabled?(feature) self.settings["#{feature}_enabled".to_sym] == true end + def disabled?(feature) + !self.enabled?(feature) + end # enables the features identified by features, which is expected to # be an Enumarable object containing the identifiers of the desired features. diff --git a/app/models/input.rb b/app/models/input.rb index 541fbc4..006dc5a 100644 --- a/app/models/input.rb +++ b/app/models/input.rb @@ -59,4 +59,7 @@ class Input < ActiveRecord::Base return 0 if self.amount_used.blank? || self.price_per_unit.blank? self.amount_used * self.price_per_unit end + + alias_method :price, :cost + end diff --git a/app/views/search/_product.rhtml b/app/views/search/_product.rhtml index 142b511..6d1bf20 100644 --- a/app/views/search/_product.rhtml +++ b/app/views/search/_product.rhtml @@ -27,15 +27,10 @@ <% end %> <% if product.price_described? %> - <% title = product.inputs.map{ |i| + <% title = (product.inputs + product.price_details).map{ |i| '
' + '
' + i.product_category.name + '
' + - price_span(i.cost, :class => 'search-product-input-price') + - '
' }.join('') %> - <% title += product.price_details.map{ |p| - '
' + - '
' + p.production_cost.name + '
' + - price_span(p.price, :class => 'search-product-input-price') + + price_span(i.price, :class => 'search-product-input-price') + '
' }.join('') %> <%= link_to_function _("Open Price"), '', :title => title, :class => "search-product-price-details" %> <% end %> @@ -80,10 +75,11 @@ +
+ <%= extra_content.join('\n') %> <% extra_properties.each do |property| %>
<%= property[:name] + ': ' + instance_eval(&property[:content]) %>
<% end %> -

diff --git a/app/views/search/products.rhtml b/app/views/search/products.rhtml index ddec0b3..74e8f02 100644 --- a/app/views/search/products.rhtml +++ b/app/views/search/products.rhtml @@ -1,28 +1,26 @@ -<% if @environment.settings[:disable_asset_products_enabled] %> - Product search disabled -<% else %> +<%= search_page_title( @titles[:products], @category ) %> - <%= search_page_title( @titles[:products], @category ) %> - -
- <% if !@empty_query %> - <% button_bar do %> - <%= display_map_list_button %> - <% end %> - <%= facets_menu(:products, @facets) %> - <% end %> -
+
+ <% if !@empty_query %> + <% button_bar do %> + <%= display_map_list_button %> +<% end %> + <%= facets_menu(:products, @facets) %> +<% end %> +
-
- <%= render :partial => 'search_form', :locals => { :hint => _('Type the product, service, city or qualifier desired') } %> - <%= render :partial => 'results_header' %> +
+ <%= render :partial => 'search_form', :locals => { :hint => _('Type the product, service, city or qualifier desired') } %> + <%= render :partial => 'results_header' %> - <%= display_results(true) %> - <% if !@one_page and params[:display] != 'map' %> - <%= pagination_links @results[:products] %> - <% end %> -
+ <%= display_results(true) %> + <% if !@one_page and params[:display] != 'map' %> + <%= pagination_links @results[:products] %> +<% end %> +
+<% javascript_tag do %> + jQuery('.search-product-price-details').altBeautify(); <% end %>
diff --git a/public/javascripts/application.js b/public/javascripts/application.js index a89fe9a..2576362 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -756,6 +756,11 @@ $.fn.hint = function (blurClass) { })(jQuery); +/* + * altBeautify: put a styled tooltip on elements with + * HTML on title and alt attributes. + */ + var altBeautify = jQuery('