app/models/spotlight/blacklight_configuration.rb in blacklight-spotlight-0.2.0 vs app/models/spotlight/blacklight_configuration.rb in blacklight-spotlight-0.3.0
- old
+ new
@@ -11,10 +11,11 @@
serialize :index, Hash
serialize :per_page, Array
serialize :document_index_view_types, Array
include Spotlight::BlacklightConfigurationDefaults
+ include Spotlight::ImageDerivatives
# get rid of empty values
before_validation do |model|
model.index_fields.each do |k,v|
@@ -62,12 +63,14 @@
unless exhibit.searchable?
config.navbar.partials[:saved_searches].if = false
config.navbar.partials[:search_history].if = false
end
- config.default_autocomplete_solr_params[:fl] ||= "#{config.solr_document_model.unique_key} #{config.view_config(:show).title_field} #{config.view_config(:show).thumbnail_field}"
+ config.add_results_collection_tool 'save_search', if: :render_save_this_search?
+ config.default_autocomplete_solr_params[:fl] ||= "#{config.solr_document_model.unique_key} #{config.view_config(:show).title_field} #{spotlight_image_version_fields.join(' ')}"
+
config.default_solr_params = config.default_solr_params.merge(default_solr_params)
config.show.partials.insert(2, "spotlight/catalog/tags")
# Add any custom fields
@@ -82,24 +85,36 @@
elsif custom_index_fields[k]
set_custom_field_defaults(v)
else
set_index_field_defaults(v)
end
-
+ v.upstream_if = v.if unless v.if.nil?
v.if = :field_enabled?
v.normalize! config
v.validate!
end
+
+ config.show_fields.reject { |k,v| config.index_fields[k] }.each do |k,v|
+ config.index_fields[k] = v
+ set_show_field_defaults(v)
+
+ v.upstream_if = v.if unless v.if.nil?
+ v.if = :field_enabled?
+
+ v.normalize! config
+ v.validate!
+ end
config.show_fields = config.index_fields
unless sort_fields.blank?
config.sort_fields = Hash[config.sort_fields.sort_by { |k,v| field_weight(sort_fields, k) }]
config.sort_fields.each do |k, v|
- v.if = ((sort_fields[k] || {})[:enabled] == true)
+ v.upstream_if = v.if unless v.if.nil?
+ v.if = :field_enabled?
next if sort_fields[k].blank?
v.merge! sort_fields[k].symbolize_keys
v.normalize! config
v.validate!
@@ -111,11 +126,13 @@
config.facet_fields.each do |k, v|
next if facet_fields[k].blank?
v.merge! facet_fields[k].symbolize_keys
- v.if = v.enabled
+ v.upstream_if = v.if unless v.if.nil?
+ v.enabled = v.show
+ v.if = :field_enabled?
v.normalize! config
v.validate!
end
end
@@ -125,12 +142,13 @@
config.per_page.delete(default_per_page)
config.per_page.unshift(default_per_page)
end
config.view.each do |k,v|
- config.view[k].key = k
- config.view[k].if = :enabled_in_spotlight_view_type_configuration?
+ v.key = k
+ v.upstream_if = v.if unless v.if.nil?
+ v.if = :enabled_in_spotlight_view_type_configuration?
end unless document_index_view_types.blank?
config
end
end
@@ -144,21 +162,39 @@
##
# Get the "upstream" blacklight configuration to use
def default_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 = Spotlight::Engine.blacklight_config.deep_copy
+ add_exhibit_specific_fields(config)
config
end
end
protected
-
+ def add_exhibit_specific_fields config
+ config.add_facet_field Spotlight::SolrDocument.solr_field_for_tagger(exhibit), label: :'blacklight.search.fields.facet.exhibit_tag', show: false unless config.facet_fields.include? :exhibit_tag
+ end
+
+ def spotlight_image_version_fields
+ spotlight_image_derivatives.map do |version|
+ version[:field]
+ end
+ end
+
def set_index_field_defaults field
if index_fields.blank?
views = default_blacklight_config.view.keys | [:show, :enabled]
field.merge! Hash[views.map { |v| [v, true] }]
+ end
+ end
+
+ def set_show_field_defaults field
+ if index_fields.blank?
+ views = default_blacklight_config.view.keys
+ field.merge! Hash[views.map { |v| [v, false] }]
+ field.enabled = true
+ field.show = true
end
end
def set_custom_field_defaults field
field.show = true