app/helpers/blacklight/hierarchy_helper.rb in blacklight-hierarchy-4.1.0 vs app/helpers/blacklight/hierarchy_helper.rb in blacklight-hierarchy-4.2.0

- old
+ new

@@ -1,5 +1,7 @@ +require 'deprecation' + module Blacklight::HierarchyHelper # Putting bare HTML strings in a helper sucks. But in this case, with a # lot of recursive tree-walking going on, it's an order of magnitude faster # than either render(:partial) or content_tag def render_facet_hierarchy_item(field_name, data, key) @@ -11,11 +13,11 @@ ul = '' li = '' li << facet_toggle_button(field_name, id) if subset.any? li << if item.nil? key - elsif facet_in_params?(field_name, item.qvalue) + elsif qfacet_selected?(field_name, item) render_selected_qfacet_value(field_name, item) else render_qfacet_value(field_name, item, id: id) end @@ -26,11 +28,18 @@ ul = "<ul role=\"group\">#{subul}</ul>".html_safe end %(<li class="#{li_class}" role="treeitem">#{li.html_safe}#{ul.html_safe}</li>).html_safe end + deprecation_deprecate :render_facet_hierarchy_item + def qfacet_selected?(field_name, item) + config = facet_configuration_for_field(field_name) + search_state.has_facet?(config, value: facet_value_for_facet_item(item.qvalue)) + end + private :qfacet_selected? + # @param [Blacklight::Configuration::FacetField] as defined in controller with config.add_facet_field (and with :partial => 'blacklight/hierarchy/facet_hierarchy') # @return [String] html for the facet tree def render_hierarchy(bl_facet_field, delim = '_') field_name = bl_facet_field.field prefix = field_name.gsub("#{delim}#{field_name.split(/#{delim}/).last}", '') @@ -40,15 +49,19 @@ return '' unless tree tree.keys.sort.collect do |key| render_facet_hierarchy_item(field_name, tree[key], key) end.join("\n").html_safe end + deprecation_deprecate :render_hierarchy def render_qfacet_value(facet_solr_field, item, options = {}) id = options.delete(:id) - (link_to_unless(options[:suppress_link], item.value, path_for_facet(facet_solr_field, item.qvalue), id: id, class: 'facet_select') + ' ' + render_facet_count(item.hits)).html_safe + facet_config = facet_configuration_for_field(facet_solr_field) + path_for_facet = facet_item_presenter(facet_config, item.qvalue, facet_solr_field).href + (link_to_unless(options[:suppress_link], item.value, path_for_facet, id: id, class: 'facet_select') + ' ' + render_facet_count(item.hits)).html_safe end + deprecation_deprecate :render_qfacet_value # Standard display of a SELECTED facet value, no link, special span with class, and 'remove' button. def render_selected_qfacet_value(facet_solr_field, item) remove_href = search_action_path(search_state.remove_facet_params(facet_solr_field, item.qvalue)) content_tag(:span, render_qfacet_value(facet_solr_field, item, suppress_link: true), class: 'selected') + ' ' + @@ -56,13 +69,12 @@ content_tag(:span, '[remove]', class: 'sr-only'), remove_href, class: 'remove' ) end + deprecation_deprecate :render_selected_qfacet_value - HierarchicalFacetItem = Struct.new :qvalue, :value, :hits - # @param [String] hkey - a key to access the rest of the hierarchy tree, as defined in controller config.facet_display[:hierarchy] declaration. # e.g. if you had this in controller: # config.facet_display = { # :hierarchy => { # 'wf' => [['wps','wsp','swp'], ':'], @@ -101,10 +113,11 @@ loc[:_] = HierarchicalFacetItem.new(facet_item.value, facet_item.value.split(split_regex).last, facet_item.hits) end end @facet_tree[hkey] end + deprecation_deprecate :facet_tree def facet_toggle_button(field_name, described_by) aria_label = I18n.t( "blacklight.hierarchy.#{field_name}_toggle_aria_label", default: :'blacklight.hierarchy.toggle_aria_label' @@ -129,15 +142,17 @@ # FIXME: remove baked in underscore separator in field name def is_hierarchical?(field_name) (prefix, order) = field_name.split(/_/, 2) (list = blacklight_config.facet_display[:hierarchy][prefix]) && list.include?(order) end + deprecation_deprecate :is_hierarchical? def facet_order(prefix) param_name = "#{prefix}_facet_order".to_sym params[param_name] || blacklight_config.facet_display[:hierarchy][prefix].first end + deprecation_deprecate :facet_order def facet_after(prefix, order) orders = blacklight_config.facet_display[:hierarchy][prefix] orders[orders.index(order) + 1] || orders.first end @@ -146,19 +161,22 @@ def hide_facet?(field_name) return false unless is_hierarchical?(field_name) prefix = field_name.split(/_/).first field_name != "#{prefix}_#{facet_order(prefix)}" end + deprecation_deprecate :hide_facet? + # FIXME: remove baked in colon separator def rotate_facet_value(val, from, to) components = Hash[from.split(//).zip(val.split(/:/))] new_values = components.values_at(*to.split(//)) new_values.pop while new_values.last.nil? return nil if new_values.include?(nil) new_values.compact.join(':') end + deprecation_deprecate :rotate_facet_value # FIXME: remove baked in underscore separator in field name def rotate_facet_params(prefix, from, to, p = params.dup) return p if from == to from_field = "#{prefix}_#{from}" @@ -170,10 +188,11 @@ p[:f].delete(from_field) p[:f][to_field].compact! p[:f].delete(to_field) if p[:f][to_field].empty? p end + deprecation_deprecate :rotate_facet_params # FIXME: remove baked in underscore separator in field name def render_facet_rotate(field_name) return unless is_hierarchical?(field_name) (prefix, order) = field_name.split(/_/, 2) @@ -181,6 +200,7 @@ new_order = facet_after(prefix, order) new_params = rotate_facet_params(prefix, order, new_order) new_params["#{prefix}_facet_order"] = new_order link_to image_tag('icons/rotate.png', title: new_order.upcase).html_safe, new_params, class: 'no-underline' end + deprecation_deprecate :render_facet_rotate end