app/models/spotlight/blacklight_configuration.rb in blacklight-spotlight-0.1.0 vs app/models/spotlight/blacklight_configuration.rb in blacklight-spotlight-0.2.0

- old
+ new

@@ -1,10 +1,10 @@ require 'blacklight/utils' module Spotlight class BlacklightConfiguration < ActiveRecord::Base - belongs_to :exhibit + belongs_to :exhibit, touch: true serialize :facet_fields, Hash serialize :index_fields, Hash serialize :sort_fields, Hash serialize :default_solr_params, Hash serialize :show, Hash @@ -19,27 +19,28 @@ model.index_fields.each do |k,v| v[:enabled] ||= v.any? { |k1, v1| !v1.blank? } default_blacklight_config.view.keys.each do |view| - v[view] &&= ActiveRecord::ConnectionAdapters::Column.value_to_boolean(v[view]) + v[view] &&= value_to_boolean(v[view]) end - v[:show] &&= ActiveRecord::ConnectionAdapters::Column.value_to_boolean(v[:show]) + v[:show] &&= value_to_boolean(v[:show]) v.reject! { |k, v1| v1.blank? and !v1 === false } end if model.index_fields model.facet_fields.each do |k,v| - v[:show] &&= ActiveRecord::ConnectionAdapters::Column.value_to_boolean(v[:show]) + v[:show] &&= 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] &&= value_to_boolean(v[:enabled]) v[:enabled] ||= true if v[:enabled].nil? + v[:label] = default_blacklight_config.sort_fields[k][:label] unless v[:label].present? 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 @@ -56,12 +57,17 @@ config = default_blacklight_config.inheritable_copy config.show.merge! show unless show.blank? config.index.merge! index unless index.blank? - config.default_autocomplete_solr_params[:fl] = "id #{config.index.title_field} #{config.index.thumbnail_field}" + 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.default_solr_params = config.default_solr_params.merge(default_solr_params) config.show.partials.insert(2, "spotlight/catalog/tags") # Add any custom fields @@ -164,9 +170,18 @@ def field_weight fields, index if fields[index] and fields[index][:weight] fields[index][:weight].to_i else 100 + (fields.keys.index(index) || fields.keys.length) + end + end + + def value_to_boolean v + if defined? ActiveRecord::Type + # Rails 4.2+ + ActiveRecord::Type::Boolean.new.type_cast_from_database v + else + ActiveRecord::ConnectionAdapters::Column.value_to_boolean v end end end end