app/models/spotlight/blacklight_configuration.rb in blacklight-spotlight-0.0.2 vs app/models/spotlight/blacklight_configuration.rb in blacklight-spotlight-0.0.3
- old
+ new
@@ -1,10 +1,10 @@
require 'blacklight/utils'
module Spotlight
class BlacklightConfiguration < ActiveRecord::Base
- has_one :exhibit
+ belongs_to :exhibit
serialize :facet_fields, Hash
serialize :index_fields, Hash
serialize :sort_fields, Hash
serialize :default_solr_params, Hash
serialize :show, Hash
@@ -25,18 +25,22 @@
v[:show] &&= ActiveRecord::ConnectionAdapters::Column.value_to_boolean(v[:show])
v.reject! { |k, v1| v1.blank? and !v1 === false }
end if model.index_fields
- [:facet_fields, :sort_fields].each do |field|
- model.send(field).each do |k,v|
- v[:enabled] &&= ActiveRecord::ConnectionAdapters::Column.value_to_boolean(v[:enabled])
- v[:enabled] ||= true if v[:enabled].nil?
- v.reject! { |k, v1| v1.blank? and !v1 === false }
- end if model.send(field)
- end
+ model.facet_fields.each do |k,v|
+ v[:show] &&= ActiveRecord::ConnectionAdapters::Column.value_to_boolean(v[:show])
+ v[:show] ||= true if v[:show].nil?
+ v.reject! { |k, v1| v1.blank? and !v1 === false }
+ end if model.facet_fields
+ model.sort_fields.each do |k,v|
+ v[:enabled] &&= ActiveRecord::ConnectionAdapters::Column.value_to_boolean(v[:enabled])
+ v[:enabled] ||= true if v[:enabled].nil?
+ v.reject! { |k, v1| v1.blank? and !v1 === false }
+ end if model.sort_fields
+
model.per_page.reject!(&:blank?) if model.per_page
model.document_index_view_types.reject!(&:blank?) if model.document_index_view_types
end
##
@@ -100,13 +104,11 @@
v.validate!
end
end
unless facet_fields.blank?
- active_facet_fields = facet_fields.select { |k,v| v[:enabled] == true }
- config.facet_fields.slice! *active_facet_fields.keys
- config.facet_fields = Hash[config.facet_fields.sort_by { |k,v| field_weight(active_facet_fields, k) }]
+ config.facet_fields = Hash[config.facet_fields.sort_by { |k,v| field_weight(facet_fields, k) }]
config.facet_fields.each do |k, v|
next if facet_fields[k].blank?
v.merge! facet_fields[k].symbolize_keys
@@ -129,11 +131,11 @@
Hash[default_blacklight_config.index_fields.merge(custom_index_fields).sort_by { |k,v| field_weight(index_fields, k) }]
end
def custom_index_fields
Hash[exhibit.custom_fields.map do |x|
- field = Blacklight::Configuration::IndexField.new x.configuration.merge(field: x.field, helper_method: :exhibit_specific_field)
+ field = Blacklight::Configuration::IndexField.new x.configuration.merge(field: x.field)
[x.field, field]
end]
end
##
@@ -148,10 +150,14 @@
end
##
# Get the "upstream" blacklight configuration to use
def default_blacklight_config
- ::CatalogController.blacklight_config
+ @default_blacklight_config ||= begin
+ config = ::CatalogController.blacklight_config.deep_copy
+ config.add_facet_field Spotlight::SolrDocument.solr_field_for_tagger(exhibit), label: "Exhibit Tags", show: false
+ config
+ end
end
protected
# @return [Integer] the weight (sort order) for this field