Module: BlacklightFacetExtras::Hierarchy::ViewHelperExtension

Defined in:
lib/blacklight_facet_extras/hierarchy/view_helper_extension.rb

Instance Method Summary collapse

Instance Method Details

#add_facet_params(field, value) ⇒ Object



26
27
28
29
30
# File 'lib/blacklight_facet_extras/hierarchy/view_helper_extension.rb', line 26

def add_facet_params field, value
  p = super(field, value) 
  p[:f][field] = [p[:f][field].last] if facet_hierarchy_config(field)
  p  
end

#facet_values_for(solr_field) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/blacklight_facet_extras/hierarchy/view_helper_extension.rb', line 11

def facet_values_for(solr_field)
  config = facet_hierarchy_config(solr_field)
  facet_field = super(solr_field)
  return facet_field unless config

  items = facet_field.items.map do  |i|
    value = i.value.split('/').last
    BlacklightFacetExtras::FacetItem.new(i.value.split("/", 2).last, i.hits, :display_label => value)
  end

  facet_field.items.replace(items)

  facet_field
end

#remove_facet_params(field, value, source_params = params) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/blacklight_facet_extras/hierarchy/view_helper_extension.rb', line 32

def remove_facet_params(field, value, source_params=params)
  p = super(field, value, source_params) 

  if facet_hierarchy_config(field)
    hierarchy = value.split("/")
    hierarchy.pop
    unless hierarchy.empty?
      p[:f][field] ||= []
      p[:f][field] << hierarchy.join("/") 
    end
  end
  p
end

#render_constraint_element(label, value, options = {}) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/blacklight_facet_extras/hierarchy/view_helper_extension.rb', line 46

def render_constraint_element(label, value, options = {})
  options[:classes] ||= []
  return super(label, value, options) unless options[:classes].any? { |x| blacklight_hierarchy_config.keys.map { |y| "filter-#{y.parameterize}" }.include? x }

  return ''.html_safe if value.blank?
  render(:partial => "catalog/hierarchical_constraints_element", :locals => {:label => label, :value => value, :options => options})
end

#render_facet_limit(solr_field) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/blacklight_facet_extras/hierarchy/view_helper_extension.rb', line 2

def render_facet_limit(solr_field)
  config = facet_hierarchy_config(solr_field)
  if ( config )
    render(:partial => "catalog/_facet_partials/hierarchy", :locals=> {:solr_field => solr_field })
  else
    super(solr_field)
  end
end