Skip to content

Commit

Permalink
Add remove_constraint_url
Browse files Browse the repository at this point in the history
So that applications (CurationConcerns in this case) can customize the
remove constraint url.
  • Loading branch information
jcoyne committed Apr 5, 2016
1 parent ccc7372 commit d2c22e1
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions app/helpers/blacklight/render_constraints_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Blacklight::RenderConstraintsHelperBehavior

##
# Check if the query has any constraints defined (a query, facet, etc)
#
#
# @param [Hash] query parameters
# @return [Boolean]
def query_has_constraints?(localized_params = params)
Expand All @@ -29,19 +29,30 @@ def render_constraints(localized_params = params)
##
# Render the query constraints
#
# @param [Hash] query parameters
# @param [ActionController::Parameters] query parameters
# @return [String]
def render_constraints_query(localized_params = params)
# So simple don't need a view template, we can just do it here.
scope = localized_params.delete(:route_set) || self
return "".html_safe if localized_params[:q].blank?

options = localized_params.merge(:q=>nil, :action=>'index')
options.permit!
render_constraint_element(constraint_query_label(localized_params),
localized_params[:q],
classes: ["query"],
remove: scope.url_for(options))
remove: remove_constraint_url(localized_params))
end

##
# Provide a url for removing a particular constraint. This can be overriden
# in the case that you want parameters other than the defaults to be removed
# (e.g. :search_field)
#
# @param [ActionController::Parameters] localized_params query parameters
# @return [String]
def remove_constraint_url(localized_params)
scope = localized_params.delete(:route_set) || self
options = localized_params.merge(q: nil, action: 'index')
options.permit!
scope.url_for(options)
end

##
Expand Down Expand Up @@ -92,7 +103,6 @@ def render_filter_element(facet, values, path)
# @option options [Array<String>] :classes an array of classes to add to container span for constraint.
# @return [String]
def render_constraint_element(label, value, options = {})
render(:partial => "catalog/constraints_element", :locals => {:label => label, :value => value, :options => options})
render(:partial => "catalog/constraints_element", :locals => {:label => label, :value => value, :options => options})
end

end

0 comments on commit d2c22e1

Please sign in to comment.